AccessTestCase.php 3.76 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 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_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$
 */
class Doctrine_Access_TestCase extends Doctrine_UnitTestCase {
34
    public function prepareData() { }
doctrine's avatar
doctrine committed
35
    public function prepareTables() {
zYne's avatar
zYne committed
36
        $this->tables = array('Entity', 'User'); 
zYne's avatar
zYne committed
37
        parent::prepareTables();
doctrine's avatar
doctrine committed
38
    }
zYne's avatar
zYne committed
39
    public function testUnset() {        
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

    }
    public function testIsset() {
        $user = new User();
        
        $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]));
    }
doctrine's avatar
doctrine committed
62
    public function testOffsetMethods() {
63
        $user = new User();
zYne's avatar
zYne committed
64
        $this->assertEqual($user['name'],null);
doctrine's avatar
doctrine committed
65

zYne's avatar
zYne committed
66 67
        $user['name'] = 'Jack';
        $this->assertEqual($user['name'], 'Jack');
68 69

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

zYne's avatar
zYne committed
71 72
        $user = $this->connection->getTable('User')->find($user->obtainIdentifier());
        $this->assertEqual($user->name, 'Jack');
73

zYne's avatar
zYne committed
74 75 76 77
        $user['name'] = 'Jack';
        $this->assertEqual($user['name'], 'Jack');
        $user['name'] = 'zYne';
        $this->assertEqual($user['name'], 'zYne');
doctrine's avatar
doctrine committed
78 79
    }
    public function testOverload() {
80 81 82
        $user = new User();
        $this->assertEqual($user->name,null);

zYne's avatar
zYne committed
83
        $user->name = 'Jack';
doctrine's avatar
doctrine committed
84

zYne's avatar
zYne committed
85
        $this->assertEqual($user->name, 'Jack');
86 87
        
        $user->save();
doctrine's avatar
doctrine committed
88

zYne's avatar
zYne committed
89 90
        $user = $this->connection->getTable('User')->find($user->obtainIdentifier());
        $this->assertEqual($user->name, 'Jack');
doctrine's avatar
doctrine committed
91

zYne's avatar
zYne committed
92 93 94 95
        $user->name = 'Jack';
        $this->assertEqual($user->name, 'Jack');
        $user->name = 'zYne';
        $this->assertEqual($user->name, 'zYne');
doctrine's avatar
doctrine committed
96 97
    }
    public function testSet() {
98
        $user = new User();
zYne's avatar
zYne committed
99
        $this->assertEqual($user->get('name'),null);
doctrine's avatar
doctrine committed
100

zYne's avatar
zYne committed
101 102
        $user->set('name', 'Jack');
        $this->assertEqual($user->get('name'), 'Jack');
doctrine's avatar
doctrine committed
103

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

zYne's avatar
zYne committed
106
        $user = $this->connection->getTable('User')->find($user->obtainIdentifier());
107

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

zYne's avatar
zYne committed
110 111
        $user->set('name', 'Jack');
        $this->assertEqual($user->get('name'), 'Jack');
doctrine's avatar
doctrine committed
112 113 114
    }
}
?>