BooleanTestCase.php 4.43 KB
Newer Older
1
<?php
zYne's avatar
zYne committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.phpdoctrine.com>.
 */

/**
 * Doctrine_Boolean_TestCase
 *
 * @package     Doctrine
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @category    Object Relational Mapping
 * @link        www.phpdoctrine.com
 * @since       1.0
 * @version     $Revision$
 */
class Doctrine_Boolean_TestCase extends Doctrine_UnitTestCase {
34 35 36 37 38
    public function prepareData() { }
    public function prepareTables() {
        $this->tables = array("BooleanTest");
        parent::prepareTables();
    }
39
   
zYne's avatar
zYne committed
40
    public function testSetFalse() {
41
        $test = new BooleanTest();
zYne's avatar
zYne committed
42
        $test->is_working = false;
43

zYne's avatar
zYne committed
44
        $this->assertEqual($test->is_working, false);
zYne's avatar
zYne committed
45
        $this->assertEqual($test->state(), Doctrine_Record::STATE_TDIRTY);
46 47
        $test->save();

zYne's avatar
zYne committed
48
        $test->refresh();
49
        $this->assertEqual($test->is_working, false);
zYne's avatar
zYne committed
50
    }
51

zYne's avatar
zYne committed
52
    public function testSetTrue() {
53
        $test = new BooleanTest();
zYne's avatar
zYne committed
54 55
        $test->is_working = true;
        $this->assertEqual($test->is_working, true);
56
        $test->save();
zYne's avatar
zYne committed
57 58 59 60 61 62 63 64 65
        
        $test->refresh();
        $this->assertEqual($test->is_working, true);
        
        $this->connection->clear();
        
        $test = $test->getTable()->find($test->id);
        $this->assertEqual($test->is_working, true);
    }
66 67 68 69
    public function testNormalQuerying() {
        $query = new Doctrine_Query($this->connection);
        $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = 0');
        $this->assertEqual(count($ret), 1);
70

71 72 73 74 75 76 77 78 79
        $query = new Doctrine_Query($this->connection);
        $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = 1');
        Doctrine_Lib::formatSql($query->getQuery());
        $this->assertEqual(count($ret), 1);
    }
    public function testPreparedQueries() {
        $query = new Doctrine_Query($this->connection);
        $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = ?', array(false));
        $this->assertEqual(count($ret), 1);
80 81

        $query = new Doctrine_Query($this->connection);
82 83 84 85 86 87
        $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = ?', array(true));
        $this->assertEqual(count($ret), 1);
    }
    public function testFetchingWithSmartConversion() {
        $query = new Doctrine_Query($this->connection);
        $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = false');
zYne's avatar
zYne committed
88
        $this->assertEqual(count($ret), 1);
89 90

        $query = new Doctrine_Query($this->connection);
91 92
        $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = true');
        Doctrine_Lib::formatSql($query->getQuery());
zYne's avatar
zYne committed
93
        $this->assertEqual(count($ret), 1);
94
    }
zYne's avatar
zYne committed
95

96 97 98 99 100
    public function testSavingNullValue() {
        $test = new BooleanTest();
        $this->is_working = null;

        $this->assertEqual($this->is_working, null);
zYne's avatar
zYne committed
101
        $this->assertEqual($test->state(), Doctrine_Record::STATE_TDIRTY);
102 103 104 105 106 107 108 109 110
        $test->save();

        $test->refresh();
        $this->assertEqual($test->is_working, null);
        
        $test = new BooleanTest();
        $this->is_working_notnull = null;

        $this->assertEqual($this->is_working_notnull, false);
zYne's avatar
zYne committed
111
        $this->assertEqual($test->state(), Doctrine_Record::STATE_TDIRTY);
112 113 114 115 116 117
        $test->save();

        $test->refresh();
        $this->assertEqual($test->is_working_notnull, false);
    }

118 119
}
?>