BooleanTestCase.php 3.13 KB
Newer Older
1 2 3 4 5 6 7
<?php
class Doctrine_BooleanTestCase extends Doctrine_UnitTestCase {
    public function prepareData() { }
    public function prepareTables() {
        $this->tables = array("BooleanTest");
        parent::prepareTables();
    }
8
   
zYne's avatar
zYne committed
9
    public function testSetFalse() {
10
        $test = new BooleanTest();
zYne's avatar
zYne committed
11
        $test->is_working = false;
12

zYne's avatar
zYne committed
13 14
        $this->assertEqual($test->is_working, false);
        $this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY);
15 16
        $test->save();

zYne's avatar
zYne committed
17
        $test->refresh();
18
        $this->assertEqual($test->is_working, false);
zYne's avatar
zYne committed
19
    }
20

zYne's avatar
zYne committed
21
    public function testSetTrue() {
22
        $test = new BooleanTest();
zYne's avatar
zYne committed
23 24
        $test->is_working = true;
        $this->assertEqual($test->is_working, true);
25
        $test->save();
zYne's avatar
zYne committed
26 27 28 29 30 31 32 33 34
        
        $test->refresh();
        $this->assertEqual($test->is_working, true);
        
        $this->connection->clear();
        
        $test = $test->getTable()->find($test->id);
        $this->assertEqual($test->is_working, true);
    }
35 36 37 38
    public function testNormalQuerying() {
        $query = new Doctrine_Query($this->connection);
        $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = 0');
        $this->assertEqual(count($ret), 1);
39

40 41 42 43 44 45 46 47 48
        $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);
49 50

        $query = new Doctrine_Query($this->connection);
51 52 53 54 55 56
        $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
57
        $this->assertEqual(count($ret), 1);
58 59

        $query = new Doctrine_Query($this->connection);
60 61
        $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = true');
        Doctrine_Lib::formatSql($query->getQuery());
zYne's avatar
zYne committed
62
        $this->assertEqual(count($ret), 1);
63
    }
zYne's avatar
zYne committed
64

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    public function testSavingNullValue() {
        $test = new BooleanTest();
        $this->is_working = null;

        $this->assertEqual($this->is_working, null);
        $this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY);
        $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);
        $this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY);
        $test->save();

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

87 88
}
?>