forked from propelorm/Propel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneratedObjectMoreRelationTest.php
158 lines (114 loc) · 4.73 KB
/
GeneratedObjectMoreRelationTest.php
1
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/*
* $Id$
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Tests for More relations
*
* @author MArc J. Schmidt
* @version $Revision$
* @package generator.builder.om
*/
class GeneratedObjectMoreRelationTest extends PHPUnit_Framework_TestCase
{
/**
* Setup schema und some default data
*/
public function setUp()
{
parent::setUp();
if (!class_exists('MoreRelationTest\Page')) {
$schema = <<<EOF
<database name="more_relation_test" namespace="MoreRelationTest">
<table name="more_relation_test_page" phpName="Page">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="title" type="VARCHAR" size="100" primaryString="true" />
</table>
<table name="more_relation_test_content" phpName="Content">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="title" type="VARCHAR" size="100" />
<column name="content" type="LONGVARCHAR" required="false" />
<column name="page_id" type="INTEGER" required="false" />
<foreign-key foreignTable="more_relation_test_page" onDelete="cascade">
<reference local="page_id" foreign="id"/>
</foreign-key>
</table>
<table name="more_relation_test_comment" phpName="Comment">
<column name="user_id" required="true" primaryKey="true" type="INTEGER" />
<column name="page_id" required="true" primaryKey="true" type="INTEGER" />
<column name="comment" type="VARCHAR" size="100" />
<foreign-key foreignTable="more_relation_test_page" onDelete="cascade">
<reference local="page_id" foreign="id"/>
</foreign-key>
</table>
</database>
EOF;
$builder = new PropelQuickBuilder();
$builder->setSchema($schema);
$builder->build();
}
\MoreRelationTest\PagePeer::doDeleteAll();
\MoreRelationTest\ContentPeer::doDeleteAll();
for($i=1;$i<=2;$i++){
$page = new \MoreRelationTest\Page();
$page->setTitle('Page '.$i);
for($j=1;$j<=3;$j++){
$content = new \MoreRelationTest\Content();
$content->setTitle('Content '.$j);
$content->setContent(str_repeat('Content', $j));
$page->addContent($content);
$comment = new \MoreRelationTest\Comment();
$comment->setUserId($j);
$comment->setComment(str_repeat('Comment', $j));
$page->addComment($comment);
}
$page->save();
}
}
/**
* Composite PK deletion of a 1-to-n relation through set<RelationName>()
* where the PK is at them same time a FK.
*/
public function testCommentsDeletion(){
$commentCollection = new PropelObjectCollection();
$commentCollection->setModel('MoreRelationTest\\Comment');
$comment = new \MoreRelationTest\Comment();
$comment->setComment('I should be alone :-(');
$comment->setUserId(123);
$commentCollection[] = $comment;
$page = \MoreRelationTest\PageQuery::create()->findOne();
$id = $page->getId();
$count = \MoreRelationTest\CommentQuery::create()->filterByPageId($id)->count();
$this->assertEquals(3, $count, 'We created for each page 3 comments.');
$page->setComments($commentCollection);
$page->save();
unset($page);
$count = \MoreRelationTest\CommentQuery::create()->filterByPageId($id)->count();
$this->assertEquals(1, $count, 'We assigned a collection of only one item.');
}
/**
* Basic deletion of a 1-to-n relation through set<RelationName>().
*
*/
public function testContentsDeletion(){
$contentCollection = new PropelObjectCollection();
$contentCollection->setModel('MoreRelationTest\\Content');
$content = new \MoreRelationTest\Content();
$content->setTitle('I should be alone :-(');
$contentCollection[] = $content;
$page = \MoreRelationTest\PageQuery::create()->findOne();
$id = $page->getId();
$count = \MoreRelationTest\ContentQuery::create()->filterByPageId($id)->count();
$this->assertEquals(3, $count, 'We created for each page 3 contents.');
$page->setContents($contentCollection);
$page->save();
unset($page);
$count = \MoreRelationTest\ContentQuery::create()->filterByPageId($id)->count();
$this->assertEquals(1, $count, 'We assigned a collection of only one item.');
}
}