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

Revision 1082, 5.0 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: GeneratedNestedSetObjectTest.php 894 2007-12-27 14:39:01Z 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 GeneratedNestedSetObjectTest extends CmsTestBase {
43
44     /**
45      * Test xxxNestedSet::isRoot() as true
46      */
47     public function testObjectIsRootTrue()
48     {
49         $pp = PropelPeer::PagePeer::retrieveRoot(1);
50         $this->assertTrue($pp->isRoot(), 'Node must be root');
51     }
52
53     /**
54      * Test xxxNestedSet::isRoot() as false
55      */
56     public function testObjectIsRootFalse()
57     {
58         $c = new ::Criteria(PropelPeer::PagePeer::DATABASE_NAME);
59         $c->add(PropelPeer::PagePeer::TITLE, 'school', ::Criteria::EQUAL);
60
61         $school = PropelPeer::PagePeer::doSelectOne($c);
62         $this->assertFalse($school->isRoot(), 'Node must not be root');
63     }
64
65     /**
66      * Test xxxNestedSet::retrieveParent() as true.
67      */
68     public function testObjectRetrieveParentTrue()
69     {
70         $c = new ::Criteria(PropelPeer::PagePeer::DATABASE_NAME);
71         $c->add(PropelPeer::PagePeer::TITLE, 'school', ::Criteria::EQUAL);
72
73         $school = PropelPeer::PagePeer::doSelectOne($c);
74         $this->assertNotNull($school->retrieveParent(), 'Parent node must exist');
75     }
76
77     /**
78      * Test xxxNestedSet::retrieveParent() as false.
79      */
80     public function testObjectRetrieveParentFalse()
81     {
82         $c = new ::Criteria(PropelPeer::PagePeer::DATABASE_NAME);
83         $c->add(PropelPeer::PagePeer::TITLE, 'home', ::Criteria::EQUAL);
84
85         $home = PropelPeer::PagePeer::doSelectOne($c);
86         $this->assertNull($home->retrieveParent(), 'Parent node must not exist and retrieved not be null');
87     }
88
89     /**
90      * Test xxxNestedSet::hasParent() as true.
91      */
92     public function testObjectHasParentTrue()
93     {
94         $c = new ::Criteria();
95         $c->add(PropelPeer::PagePeer::TITLE, 'school', ::Criteria::EQUAL);
96
97         $school = PropelPeer::PagePeer::doSelectOne($c);
98         $this->assertTrue($school->hasParent(), 'Node must have parent node');
99     }
100
101     /**
102      * Test xxxNestedSet::hasParent() as false
103      */
104     public function testObjectHasParentFalse()
105     {
106         $c = new ::Criteria();
107         $c->add(PropelPeer::PagePeer::TITLE, 'home', ::Criteria::EQUAL);
108
109         $home = PropelPeer::PagePeer::doSelectOne($c);
110         $this->assertFalse($home->hasParent(), 'Root node must not have parent');
111     }
112
113     /**
114      * Test xxxNestedSet::isLeaf() as true.
115      */
116     public function testObjectIsLeafTrue()
117     {
118         $c = new ::Criteria();
119         $c->add(PropelPeer::PagePeer::TITLE, 'simulator', ::Criteria::EQUAL);
120
121         $simulator = PropelPeer::PagePeer::doSelectOne($c);
122         $this->assertTrue($simulator->isLeaf($simulator), 'Node must be a leaf');
123     }
124
125     /**
126      * Test xxxNestedSet::isLeaf() as false
127      */
128     public function testObjectIsLeafFalse()
129     {
130         $c = new ::Criteria();
131         $c->add(PropelPeer::PagePeer::TITLE, 'contact', ::Criteria::EQUAL);
132
133         $contact = PropelPeer::PagePeer::doSelectOne($c);
134         $this->assertFalse($contact->isLeaf($contact), 'Node must not be a leaf');
135     }
136
137     /**
138      * Test xxxNestedSet::makeRoot()
139      */
140     public function testObjectMakeRoot()
141     {
142         $page = new PropelModel::Page();
143         $page->makeRoot();
144         $this->assertEquals(1, $page->getLeftValue(), 'Node left value must equal 1');
145         $this->assertEquals(2, $page->getRightValue(), 'Node right value must equal 2');
146     }
147
148     /**
149      * Test xxxNestedSet::makeRoot() exception
150      * @expectedException PropelException
151      */
152     public function testObjectMakeRootException()
153     {
154         $c = new ::Criteria();
155         $c->add(PropelPeer::PagePeer::TITLE, 'home', ::Criteria::EQUAL);
156
157         $home = PropelPeer::PagePeer::doSelectOne($c);
158         $home->makeRoot();
159     }
160
161 }
162
163 ?>
Note: See TracBrowser for help on using the browser.