root/trunk/generator/test/classes/propel/GeneratedNestedSetPeerTest.php

Revision 1082, 6.3 kB (checked in by tony, 3 months ago)

Refs #683: Added support for PHP 5.3 namespaces

Line 
1 <?php
2
3 use bookstore::Peer as PropelPeer;
4 use bookstore::Model as PropelModel;
5
6 /*
7  *  $Id: GeneratedNestedSetPeerTest.php 989 2008-03-11 14:29:30Z heltem $
8  *
9  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
13  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
15  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
16  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
17  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
19  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20  *
21  * This software consists of voluntary contributions made by many individuals
22  * and is licensed under the LGPL. For more information please see
23  * <http://propel.phpdb.org>.
24  */
25
26 require_once 'cms/CmsTestBase.php';
27
28 /**
29  * Tests the generated nested-set Object classes.
30  *
31  * This test uses generated Bookstore-Cms classes to test the behavior of various
32  * object operations.  The _idea_ here is to test every possible generated method
33  * from Object.tpl; if necessary, bookstore will be expanded to accommodate this.
34  *
35  * The database is relaoded before every test and flushed after every test.  This
36  * means that you can always rely on the contents of the databases being the same
37  * for each test method in this class.  See the CmsDataPopulator::populate()
38  * method for the exact contents of the database.
39  *
40  * @see        CmsDataPopulator
41  */
42 class GeneratedNestedSetPeerTest extends CmsTestBase {
43
44     /**
45      * Test retrieveRoot() as true
46      */
47     public function testRetrieveRootExist()
48     {
49         $pp = PropelPeer::PagePeer::retrieveRoot(1);
50         $this->assertNotNull($pp, 'Node must exist and not be null');
51         $this->assertEquals(1, $pp->getLeftValue(), 'Node left value must be equal to 1');
52     }
53
54     /**
55      * Test retrieveRoot() as false
56      */
57     public function testRetrieveRootNotExist()
58     {
59         $pp = PropelPeer::PagePeer::retrieveRoot(2);
60         $this->assertNull($pp, 'Root with such scopeId must not exist');
61     }
62
63     /**
64      * Test xxxNestedSetPeer::isRoot() as true
65      */
66     public function testPeerIsRootTrue()
67     {
68         $pp = PropelPeer::PagePeer::retrieveRoot(1);
69         $this->assertTrue(PropelPeer::PagePeer::isRoot($pp), 'Node must be root');
70     }
71
72     /**
73      * Test xxxNestedSetPeer::isRoot() as false
74      */
75     public function testPeerIsRootFalse()
76     {
77         $c = new ::Criteria(PropelPeer::PagePeer::DATABASE_NAME);
78         $c->add(PropelPeer::PagePeer::TITLE, 'school', ::Criteria::EQUAL);
79
80         $school = PropelPeer::PagePeer::doSelectOne($c);
81         $this->assertFalse(PropelPeer::PagePeer::isRoot($school), 'Node must not be root');
82     }
83
84     /**
85      * Test xxxNestedSetPeer::retrieveParent() as true.
86      */
87     public function testPeerRetrieveParentTrue()
88     {
89         $c = new ::Criteria(PropelPeer::PagePeer::DATABASE_NAME);
90         $c->add(PropelPeer::PagePeer::TITLE, 'school', ::Criteria::EQUAL);
91
92         $school = PropelPeer::PagePeer::doSelectOne($c);
93         $this->assertNotNull(PropelPeer::PagePeer::retrieveParent($school), 'Parent node must exist');
94     }
95
96     /**
97      * Test xxxNestedSetPeer::retrieveParent() as false.
98      */
99     public function testPeerRetrieveParentFalse()
100     {
101         $c = new ::Criteria(PropelPeer::PagePeer::DATABASE_NAME);
102         $c->add(PropelPeer::PagePeer::TITLE, 'home', ::Criteria::EQUAL);
103
104         $home = PropelPeer::PagePeer::doSelectOne($c);
105         $this->assertNull(PropelPeer::PagePeer::retrieveParent($home), 'Parent node must not exist and retrieved not be null');
106     }
107
108     /**
109      * Test xxxNestedSetPeer::hasParent() as true.
110      */
111     public function testPeerHasParentTrue()
112     {
113         $c = new ::Criteria();
114         $c->add(PropelPeer::PagePeer::TITLE, 'school', ::Criteria::EQUAL);
115
116         $school = PropelPeer::PagePeer::doSelectOne($c);
117         $this->assertTrue(PropelPeer::PagePeer::hasParent($school), 'Node must have parent node');
118     }
119
120     /**
121      * Test xxxNestedSetPeer::hasParent() as false
122      */
123     public function testPeerHasParentFalse()
124     {
125         $c = new ::Criteria();
126         $c->add(PropelPeer::PagePeer::TITLE, 'home', ::Criteria::EQUAL);
127
128         $home = PropelPeer::PagePeer::doSelectOne($c);
129         $this->assertFalse(PropelPeer::PagePeer::hasParent($home), 'Root node must not have parent');
130     }
131
132     /**
133      * Test xxxNestedSetPeer::isValid() as true.
134      */
135     public function testPeerIsValidTrue()
136     {
137         $c = new ::Criteria();
138         $c->add(PropelPeer::PagePeer::TITLE, 'school', ::Criteria::EQUAL);
139
140         $school = PropelPeer::PagePeer::doSelectOne($c);
141         $this->assertTrue(PropelPeer::PagePeer::isValid($school), 'Node must be valid');
142     }
143
144     /**
145      * Test xxxNestedSetPeer::isValid() as false
146      */
147     public function testPeerIsValidFalse()
148     {
149         $page = new PropelModel::Page();
150         $this->assertFalse(PropelPeer::PagePeer::isValid($page), 'Node left and right values must be invalid');
151         $this->assertFalse(PropelPeer::PagePeer::isValid(null), 'Null must be invalid');
152     }
153
154     /**
155      * Test xxxNestedSetPeer::isLeaf() as true.
156      */
157     public function testPeerIsLeafTrue()
158     {
159         $c = new ::Criteria();
160         $c->add(PropelPeer::PagePeer::TITLE, 'simulator', ::Criteria::EQUAL);
161
162         $simulator = PropelPeer::PagePeer::doSelectOne($c);
163         $this->assertTrue(PropelPeer::PagePeer::isLeaf($simulator), 'Node must be a leaf');
164     }
165
166     /**
167      * Test xxxNestedSetPeer::isLeaf() as false
168      */
169     public function testPeerIsLeafFalse()
170     {
171         $c = new ::Criteria();
172         $c->add(PropelPeer::PagePeer::TITLE, 'contact', ::Criteria::EQUAL);
173
174         $contact = PropelPeer::PagePeer::doSelectOne($c);
175         $this->assertFalse(PropelPeer::PagePeer::isLeaf($contact), 'Node must not be a leaf');
176     }
177
178     /**
179      * Test xxxNestedSetPeer::createRoot()
180      */
181     public function testPeerCreateRoot()
182     {
183         $page = new PropelModel::Page();
184         PropelPeer::PagePeer::createRoot($page);
185         $this->assertEquals(1, $page->getLeftValue(), 'Node left value must equal 1');
186         $this->assertEquals(2, $page->getRightValue(), 'Node right value must equal 2');
187     }
188
189     /**
190      * Test xxxNestedSetPeer::createRoot() exception
191      * @expectedException PropelException
192      */
193     public function testPeerCreateRootException()
194     {
195         $c = new ::Criteria();
196         $c->add(PropelPeer::PagePeer::TITLE, 'home', ::Criteria::EQUAL);
197
198         $home = PropelPeer::PagePeer::doSelectOne($c);
199         PropelPeer::PagePeer::createRoot($home);
200     }
201
202 }
203
204 ?>
205
Note: See TracBrowser for help on using the browser.