ZeroValuesTestCase.php 2.58 KB
Newer Older
Jonathan.Wage's avatar
Jonathan.Wage committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
/*
 *  $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
19
 * <http://www.phpdoctrine.org>.
Jonathan.Wage's avatar
Jonathan.Wage committed
20 21 22 23 24 25 26 27 28
 */

/**
 * Doctrine_Record_State_TestCase
 *
 * @package     Doctrine
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @category    Object Relational Mapping
29
 * @link        www.phpdoctrine.org
Jonathan.Wage's avatar
Jonathan.Wage committed
30 31 32
 * @since       1.0
 * @version     $Revision$
 */
Jonathan.Wage's avatar
Jonathan.Wage committed
33 34 35 36
class Doctrine_Record_ZeroValues_TestCase extends Doctrine_UnitTestCase
{
    public function prepareTables()
    {
zYne's avatar
zYne committed
37
        $this->tables[] = 'ZeroValueTest';
pookey's avatar
pookey committed
38

Jonathan.Wage's avatar
Jonathan.Wage committed
39 40
        parent::prepareTables();
    }
pookey's avatar
pookey committed
41

Jonathan.Wage's avatar
Jonathan.Wage committed
42 43
    public function prepareData()
    {
zYne's avatar
zYne committed
44
        $user = new ZeroValueTest();
Jonathan.Wage's avatar
Jonathan.Wage committed
45 46 47 48 49 50
        $user['is_super_admin'] = 0; // set it to 0 and it should be 0 when we pull it back from the database
        $user['username'] = 'jwage';
        $user['salt'] = 'test';
        $user['password'] = 'test';
        $user->save();
    }
pookey's avatar
pookey committed
51

Jonathan.Wage's avatar
Jonathan.Wage committed
52
    public function testZeroValuesMaintained()
zYne's avatar
zYne committed
53 54 55 56 57 58 59 60 61 62 63 64
    {
        $users = $this->dbh->query('SELECT * FROM zero_value_test')->fetchAll(PDO::FETCH_ASSOC);

        $this->assertIdentical($users[0]['is_super_admin'], '0');
    }

    public function testZeroValuesMaintained2()
    {
        $q = new Doctrine_Query();
        $q->from('ZeroValueTest');
        $users = $q->execute(array(), Doctrine::FETCH_ARRAY);

zYne's avatar
zYne committed
65
        $this->assertIdentical($users[0]['is_super_admin'], false);
zYne's avatar
zYne committed
66 67 68 69 70
        // check for aggregate bug
        $this->assertTrue( ! isset($users[0][0]));
    }

    public function testZeroValuesMaintained3()
Jonathan.Wage's avatar
Jonathan.Wage committed
71
    {
Jonathan.Wage's avatar
Jonathan.Wage committed
72
        $q = new Doctrine_Query();
zYne's avatar
zYne committed
73
        $q->from('ZeroValueTest');
Jonathan.Wage's avatar
Jonathan.Wage committed
74
        $users = $q->execute();
pookey's avatar
pookey committed
75

zYne's avatar
zYne committed
76
        $this->assertIdentical($users[0]['is_super_admin'], false);
Jonathan.Wage's avatar
Jonathan.Wage committed
77
    }
zYne's avatar
zYne committed
78

Jonathan.Wage's avatar
Jonathan.Wage committed
79
}