root/tags/0.10.1/tests/AccessTestCase.php

Revision 3183, 3.8 KB (checked in by romanb, 14 months ago)

Refactoring. Started to introduced a clear separation between column names and field names (aka column aliases).
Doctrine_Connection, DQL Parser classes/methods map field names => column names.
Doctrine_Hydrate maps column names => field names during hydration.
Column names are only stored in Doctrine_Table:: and Doctrine_Table::.
Relations use column names in 'local'/'foreign'.
When using field names (column aliases) you need to use the column names in 'local'/'foreign' when setting up a relation (hasOne/hasMany), not the field names.

In other words column names are only used to communicate with the database. field names are used everywhere else. the casing of field names does not matter. column names are forced to lower case for portability. If you dont use field names (column aliases) your column names are your field names (and therefore all lowercase).

Line 
1<?php
2/*
3 *  $Id$
4 *
5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 *
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the LGPL. For more information, see
19 * <http://www.phpdoctrine.com>.
20 */
21
22/**
23 * Doctrine_Access_TestCase
24 *
25 * @package     Doctrine
26 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
27 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28 * @category    Object Relational Mapping
29 * @link        www.phpdoctrine.com
30 * @since       1.0
31 * @version     $Revision$
32 */
33class Doctrine_Access_TestCase extends Doctrine_UnitTestCase 
34{
35    public function prepareData() 
36    { }
37
38    public function prepareTables() 
39    {
40        $this->tables = array('Entity', 'User'); 
41        parent::prepareTables();
42    }
43
44    public function testUnset() 
45    {
46
47    }
48    public function testIsset() 
49    {
50        $user = new User();
51
52        $this->assertTrue(isset($user->name)); 
53        $this->assertFalse(isset($user->unknown));
54       
55        $this->assertTrue(isset($user['name']));
56        $this->assertFalse(isset($user['unknown']));
57       
58        $coll = new Doctrine_Collection('User');
59       
60        $this->assertFalse(isset($coll[0]));
61        // test repeated call
62        $this->assertFalse(isset($coll[0]));
63        $coll[0];
64       
65        $this->assertTrue(isset($coll[0]));
66        // test repeated call
67        $this->assertTrue(isset($coll[0]));
68    }
69
70    public function testOffsetMethods() 
71    {
72        $user = new User();
73        $this->assertEqual($user['name'], null);
74
75        $user['name'] = 'Jack';
76        $this->assertEqual($user['name'], 'Jack');
77
78        $user->save();
79
80        $user = $this->connection->getTable('User')->find($user->identifier());
81        $this->assertEqual($user->name, 'Jack');
82
83        $user['name'] = 'Jack';
84        $this->assertEqual($user['name'], 'Jack');
85        $user['name'] = 'zYne';
86        $this->assertEqual($user['name'], 'zYne');
87    }
88
89    public function testOverload() 
90    {
91        $user = new User();
92        $this->assertEqual($user->name,null);
93
94        $user->name = 'Jack';
95
96        $this->assertEqual($user->name, 'Jack');
97       
98        $user->save();
99
100        $user = $this->connection->getTable('User')->find($user->identifier());
101        $this->assertEqual($user->name, 'Jack');
102
103        $user->name = 'Jack';
104        $this->assertEqual($user->name, 'Jack');
105        $user->name = 'zYne';
106        $this->assertEqual($user->name, 'zYne');
107    }
108   
109    public function testSet() {
110        $user = new User();
111        $this->assertEqual($user->get('name'),null);
112
113        $user->set('name', 'Jack');
114        $this->assertEqual($user->get('name'), 'Jack');
115
116        $user->save();
117
118        $user = $this->connection->getTable('User')->find($user->identifier());
119
120        $this->assertEqual($user->get('name'), 'Jack');
121
122        $user->set('name', 'Jack');
123        $this->assertEqual($user->get('name'), 'Jack');
124    }
125}
Note: See TracBrowser for help on using the browser.