AccessTestCase.php 3.78 KB
Newer Older
doctrine's avatar
doctrine committed
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
/*
 *  $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_Access_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$
 */
33 34 35 36 37 38 39
class Doctrine_Access_TestCase extends Doctrine_UnitTestCase 
{
    public function prepareData() 
    { }

    public function prepareTables() 
    {
zYne's avatar
zYne committed
40
        $this->tables = array('Entity', 'User'); 
zYne's avatar
zYne committed
41
        parent::prepareTables();
doctrine's avatar
doctrine committed
42
    }
43 44 45

    public function testUnset() 
    {
46 47

    }
48 49
    public function testIsset() 
    {
50
        $user = new User();
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
        $this->assertTrue(isset($user->name));  
        $this->assertFalse(isset($user->unknown));
        
        $this->assertTrue(isset($user['name']));
        $this->assertFalse(isset($user['unknown']));
        
        $coll = new Doctrine_Collection('User');
        
        $this->assertFalse(isset($coll[0]));
        // test repeated call
        $this->assertFalse(isset($coll[0]));
        $coll[0];
        
        $this->assertTrue(isset($coll[0]));
        // test repeated call
        $this->assertTrue(isset($coll[0]));
    }
69 70 71

    public function testOffsetMethods() 
    {
72
        $user = new User();
73
        $this->assertEqual($user['name'], null);
doctrine's avatar
doctrine committed
74

zYne's avatar
zYne committed
75 76
        $user['name'] = 'Jack';
        $this->assertEqual($user['name'], 'Jack');
77 78

        $user->save();
doctrine's avatar
doctrine committed
79

80
        $user = $this->connection->getMapper('User')->find($user->identifier());
zYne's avatar
zYne committed
81
        $this->assertEqual($user->name, 'Jack');
82

zYne's avatar
zYne committed
83 84 85 86
        $user['name'] = 'Jack';
        $this->assertEqual($user['name'], 'Jack');
        $user['name'] = 'zYne';
        $this->assertEqual($user['name'], 'zYne');
doctrine's avatar
doctrine committed
87
    }
88 89 90

    public function testOverload() 
    {
91 92 93
        $user = new User();
        $this->assertEqual($user->name,null);

zYne's avatar
zYne committed
94
        $user->name = 'Jack';
doctrine's avatar
doctrine committed
95

zYne's avatar
zYne committed
96
        $this->assertEqual($user->name, 'Jack');
97 98
        
        $user->save();
doctrine's avatar
doctrine committed
99

100
        $user = $this->connection->getMapper('User')->find($user->identifier());
zYne's avatar
zYne committed
101
        $this->assertEqual($user->name, 'Jack');
doctrine's avatar
doctrine committed
102

zYne's avatar
zYne committed
103 104 105 106
        $user->name = 'Jack';
        $this->assertEqual($user->name, 'Jack');
        $user->name = 'zYne';
        $this->assertEqual($user->name, 'zYne');
doctrine's avatar
doctrine committed
107
    }
108
    
doctrine's avatar
doctrine committed
109
    public function testSet() {
110
        $user = new User();
zYne's avatar
zYne committed
111
        $this->assertEqual($user->get('name'),null);
doctrine's avatar
doctrine committed
112

zYne's avatar
zYne committed
113 114
        $user->set('name', 'Jack');
        $this->assertEqual($user->get('name'), 'Jack');
doctrine's avatar
doctrine committed
115

116
        $user->save();
doctrine's avatar
doctrine committed
117

118
        $user = $this->connection->getMapper('User')->find($user->identifier());
119

zYne's avatar
zYne committed
120
        $this->assertEqual($user->get('name'), 'Jack');
121

zYne's avatar
zYne committed
122 123
        $user->set('name', 'Jack');
        $this->assertEqual($user->get('name'), 'Jack');
doctrine's avatar
doctrine committed
124 125
    }
}