| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
$app = 'frontend';
|
|
|
12 |
$fixtures = 'fixtures/fixtures.yml';
|
|
|
13 |
if (!include(dirname(__FILE__).'/../bootstrap/functional.php'))
|
|
|
14 |
{
|
|
|
15 |
return;
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
$b = new sfTestBrowser();
|
|
|
19 |
|
|
|
20 |
// file upload
|
|
|
21 |
$fileToUpload = dirname(__FILE__).'/fixtures/config/databases.yml';
|
|
|
22 |
$uploadedFile = sfConfig::get('sf_cache_dir').'/uploaded.yml';
|
|
|
23 |
$name = 'test';
|
|
|
24 |
$b->
|
|
|
25 |
get('/attachment/index')->
|
|
|
26 |
with('request')->begin()->
|
|
|
27 |
isParameter('module', 'attachment')->
|
|
|
28 |
isParameter('action', 'index')->
|
|
|
29 |
end()->
|
|
|
30 |
with('response')->isStatusCode(200)->
|
|
|
31 |
click('submit', array('attachment' => array('name' => $name, 'file' => $fileToUpload)))->
|
|
|
32 |
with('response')->begin()->
|
|
|
33 |
isRedirected()->
|
|
|
34 |
followRedirect()->
|
|
|
35 |
end()->
|
|
|
36 |
with('response')->begin()->
|
|
|
37 |
matches('/ok/')->
|
|
|
38 |
end()
|
|
|
39 |
;
|
|
|
40 |
|
|
|
41 |
$b->test()->ok(file_exists($uploadedFile), 'file is uploaded');
|
|
|
42 |
$b->test()->is(file_get_contents($uploadedFile), file_get_contents($fileToUpload), 'file is correctly uploaded');
|
|
|
43 |
|
|
|
44 |
$c = new Criteria();
|
|
|
45 |
$c->add(AttachmentPeer::NAME, $name);
|
|
|
46 |
$attachments = AttachmentPeer::doSelect($c);
|
|
|
47 |
|
|
|
48 |
$b->test()->is(count($attachments), 1, 'the attachment has been saved in the database');
|
|
|
49 |
$b->test()->is($attachments[0]->getFile(), 'uploaded.yml', 'the attachment filename has been saved in the database');
|
|
|
50 |
|
|
|
51 |
@unlink($uploadedFile);
|
|
|
52 |
AttachmentPeer::doDeleteAll();
|
|
|
53 |
$b->test()->ok(!file_exists($uploadedFile), 'uploaded file is deleted');
|
|
|
54 |
|
|
|
55 |
// file upload in embedded form
|
|
|
56 |
$b->
|
|
|
57 |
getAndCheck('attachment', 'embedded')->
|
|
|
58 |
with('response')->begin()->
|
|
|
59 |
checkElement('input[name="article[attachment][article_id]"]', false)->
|
|
|
60 |
checkElement('input[type="file"][name="article[attachment][file]"]')->
|
|
|
61 |
end()->
|
|
|
62 |
|
|
|
63 |
setField('article[title]', 'Test Article')->
|
|
|
64 |
setField('article[attachment][name]', $name)->
|
|
|
65 |
setField('article[attachment][file]', $fileToUpload)->
|
|
|
66 |
click('submit')->
|
|
|
67 |
|
|
|
68 |
with('form')->hasErrors(false)->
|
|
|
69 |
|
|
|
70 |
with('response')->begin()->
|
|
|
71 |
isRedirected()->
|
|
|
72 |
followRedirect()->
|
|
|
73 |
end()->
|
|
|
74 |
with('response')->begin()->
|
|
|
75 |
matches('/ok/')->
|
|
|
76 |
end()
|
|
|
77 |
;
|
|
|
78 |
|
|
|
79 |
$b->test()->ok(file_exists($uploadedFile), 'file is uploaded');
|
|
|
80 |
$b->test()->is(file_get_contents($uploadedFile), file_get_contents($fileToUpload), 'file is correctly uploaded');
|
|
|
81 |
|
|
|
82 |
$c = new Criteria();
|
|
|
83 |
$c->add(AttachmentPeer::NAME, $name);
|
|
|
84 |
$attachments = AttachmentPeer::doSelect($c);
|
|
|
85 |
|
|
|
86 |
$b->test()->is(count($attachments), 1, 'the attachment has been saved in the database');
|
|
|
87 |
$b->test()->ok($attachments[0]->getArticleId(), 'the attachment is tied to an article');
|
|
|
88 |
$b->test()->is($attachments[0]->getFile(), 'uploaded.yml', 'the attachment filename has been saved in the database');
|
|
|
89 |
|
|
|
90 |
// sfValidatorPropelUnique
|
|
|
91 |
|
|
|
92 |
// create a category with a unique name
|
|
|
93 |
$b->
|
|
|
94 |
get('/unique/category')->
|
|
|
95 |
with('request')->begin()->
|
|
|
96 |
isParameter('module', 'unique')->
|
|
|
97 |
isParameter('action', 'category')->
|
|
|
98 |
end()->
|
|
|
99 |
with('response')->isStatusCode(200)->
|
|
|
100 |
click('submit', array('category' => array('name' => 'foo')))->
|
|
|
101 |
with('response')->begin()->
|
|
|
102 |
isRedirected()->
|
|
|
103 |
followRedirect()->
|
|
|
104 |
end()->
|
|
|
105 |
with('response')->begin()->
|
|
|
106 |
matches('/ok/')->
|
|
|
107 |
end()
|
|
|
108 |
;
|
|
|
109 |
|
|
|
110 |
// create another category with the same name
|
|
|
111 |
// we must have an error
|
|
|
112 |
$b->
|
|
|
113 |
get('/unique/category')->
|
|
|
114 |
with('request')->begin()->
|
|
|
115 |
isParameter('module', 'unique')->
|
|
|
116 |
isParameter('action', 'category')->
|
|
|
117 |
end()->
|
|
|
118 |
with('response')->isStatusCode(200)->
|
|
|
119 |
click('submit', array('category' => array('name' => 'foo')))->
|
|
|
120 |
with('form')->begin()->
|
|
|
121 |
hasErrors(1)->
|
|
|
122 |
hasGlobalError(false)->
|
|
|
123 |
isError('name', 'invalid')->
|
|
|
124 |
end()->
|
|
|
125 |
with('response')->begin()->
|
|
|
126 |
checkElement('td[colspan="2"] .error_list li', 0)->
|
|
|
127 |
checkElement('.error_list li', 'An object with the same "name" already exist.')->
|
|
|
128 |
checkElement('.error_list li', 1)->
|
|
|
129 |
end()
|
|
|
130 |
;
|
|
|
131 |
|
|
|
132 |
// same thing but with a global error
|
|
|
133 |
$b->
|
|
|
134 |
get('/unique/category')->
|
|
|
135 |
with('request')->begin()->
|
|
|
136 |
isParameter('module', 'unique')->
|
|
|
137 |
isParameter('action', 'category')->
|
|
|
138 |
end()->
|
|
|
139 |
with('response')->isStatusCode(200)->
|
|
|
140 |
click('submit', array('category' => array('name' => 'foo'), 'global' => 1))->
|
|
|
141 |
with('form')->begin()->
|
|
|
142 |
hasErrors(1)->
|
|
|
143 |
hasGlobalError('invalid')->
|
|
|
144 |
isError('name', false)->
|
|
|
145 |
end()->
|
|
|
146 |
with('response')->begin()->
|
|
|
147 |
checkElement('td[colspan="2"] .error_list li', 'An object with the same "name" already exist.')->
|
|
|
148 |
checkElement('td[colspan="2"] .error_list li', 1)->
|
|
|
149 |
end()
|
|
|
150 |
;
|
|
|
151 |
|
|
|
152 |
// updating the same category again with the same name is allowed
|
|
|
153 |
$b->
|
|
|
154 |
get('/unique/category?category[id]='.CategoryPeer::getByName('foo')->getId())->
|
|
|
155 |
with('request')->begin()->
|
|
|
156 |
isParameter('module', 'unique')->
|
|
|
157 |
isParameter('action', 'category')->
|
|
|
158 |
end()->
|
|
|
159 |
with('response')->isStatusCode(200)->
|
|
|
160 |
click('submit')->
|
|
|
161 |
with('response')->begin()->
|
|
|
162 |
isRedirected()->
|
|
|
163 |
followRedirect()->
|
|
|
164 |
end()->
|
|
|
165 |
with('response')->begin()->
|
|
|
166 |
matches('/ok/')->
|
|
|
167 |
end()
|
|
|
168 |
;
|
|
|
169 |
|
|
|
170 |
// create an article with a unique title-category_id
|
|
|
171 |
$b->
|
|
|
172 |
get('/unique/article')->
|
|
|
173 |
with('request')->begin()->
|
|
|
174 |
isParameter('module', 'unique')->
|
|
|
175 |
isParameter('action', 'article')->
|
|
|
176 |
end()->
|
|
|
177 |
with('response')->isStatusCode(200)->
|
|
|
178 |
click('submit', array('article' => array('title' => 'foo', 'category_id' => 1)))->
|
|
|
179 |
with('response')->begin()->
|
|
|
180 |
isRedirected()->
|
|
|
181 |
followRedirect()->
|
|
|
182 |
end()->
|
|
|
183 |
with('response')->begin()->
|
|
|
184 |
matches('/ok/')->
|
|
|
185 |
end()
|
|
|
186 |
;
|
|
|
187 |
|
|
|
188 |
// create another article with the same title but a different category_id
|
|
|
189 |
$b->
|
|
|
190 |
get('/unique/article')->
|
|
|
191 |
with('request')->begin()->
|
|
|
192 |
isParameter('module', 'unique')->
|
|
|
193 |
isParameter('action', 'article')->
|
|
|
194 |
end()->
|
|
|
195 |
with('response')->isStatusCode(200)->
|
|
|
196 |
click('submit', array('article' => array('title' => 'foo', 'category_id' => 2)))->
|
|
|
197 |
with('response')->begin()->
|
|
|
198 |
isRedirected()->
|
|
|
199 |
followRedirect()->
|
|
|
200 |
end()->
|
|
|
201 |
with('response')->begin()->
|
|
|
202 |
matches('/ok/')->
|
|
|
203 |
end()
|
|
|
204 |
;
|
|
|
205 |
|
|
|
206 |
// create another article with the same title and category_id as the first one
|
|
|
207 |
// we must have an error
|
|
|
208 |
$b->
|
|
|
209 |
get('/unique/article')->
|
|
|
210 |
with('request')->begin()->
|
|
|
211 |
isParameter('module', 'unique')->
|
|
|
212 |
isParameter('action', 'article')->
|
|
|
213 |
end()->
|
|
|
214 |
with('response')->isStatusCode(200)->
|
|
|
215 |
click('submit', array('article' => array('title' => 'foo', 'category_id' => 1)))->
|
|
|
216 |
with('response')->checkElement('.error_list li', 'An object with the same "title, category_id" already exist.')
|
|
|
217 |
;
|
|
|
218 |
|
|
|
219 |
// update the category from the article form
|
|
|
220 |
$b->
|
|
|
221 |
get('/unique/edit')->
|
|
|
222 |
with('request')->begin()->
|
|
|
223 |
isParameter('module', 'unique')->
|
|
|
224 |
isParameter('action', 'edit')->
|
|
|
225 |
end()->
|
|
|
226 |
with('response')->begin()->
|
|
|
227 |
isStatusCode(200)->
|
|
|
228 |
checkElement('input[value="foo title"]')->
|
|
|
229 |
checkElement('#article_category_id option[selected="selected"]', 1)->
|
|
|
230 |
checkElement('input[value="Category 1"]')->
|
|
|
231 |
end()->
|
|
|
232 |
click('submit', array('article' => array('title' => 'foo bar', 'category' => array('name' => 'Category foo'))))->
|
|
|
233 |
with('response')->begin()->
|
|
|
234 |
isRedirected()->
|
|
|
235 |
followRedirect()->
|
|
|
236 |
end()->
|
|
|
237 |
with('response')->begin()->
|
|
|
238 |
checkElement('input[value="foo bar"]')->
|
|
|
239 |
checkElement('#article_category_id option[selected="selected"]', 1)->
|
|
|
240 |
checkElement('input[value="Category foo"]')->
|
|
|
241 |
end()
|
|
|
242 |
;
|
|
|
243 |
|
|
|
244 |
// sfValidatorPropelChoice
|
|
|
245 |
|
|
|
246 |
// submit a form with an impossible choice validator
|
|
|
247 |
$b->
|
|
|
248 |
get('/choice/article')->
|
|
|
249 |
with('request')->begin()->
|
|
|
250 |
isParameter('module', 'choice')->
|
|
|
251 |
isParameter('action', 'article')->
|
|
|
252 |
end()->
|
|
|
253 |
with('response')->begin()->
|
|
|
254 |
isStatusCode(200)->
|
|
|
255 |
end()->
|
|
|
256 |
click('submit', array('article' => array('title' => 'foobar', 'category_id' => 1, 'author_article_list' => array(1)), 'impossible_validator' => 1))->
|
|
|
257 |
with('form')->begin()->
|
|
|
258 |
hasErrors(1)->
|
|
|
259 |
isError('category_id', 'invalid')->
|
|
|
260 |
end()
|
|
|
261 |
;
|
|
|
262 |
|
|
|
263 |
// sfValidatorPropelChoice (multiple == true)
|
|
|
264 |
|
|
|
265 |
// submit a form with an impossible choice validator
|
|
|
266 |
$b->
|
|
|
267 |
get('/choice/article')->
|
|
|
268 |
with('request')->begin()->
|
|
|
269 |
isParameter('module', 'choice')->
|
|
|
270 |
isParameter('action', 'article')->
|
|
|
271 |
end()->
|
|
|
272 |
with('response')->begin()->
|
|
|
273 |
isStatusCode(200)->
|
|
|
274 |
end()->
|
|
|
275 |
click('submit', array('article' => array('title' => 'foobar', 'category_id' => 1, 'author_article_list' => array(1)), 'impossible_validator_many' => 1))->
|
|
|
276 |
with('form')->begin()->
|
|
|
277 |
hasErrors(1)->
|
|
|
278 |
isError('author_article_list', 'invalid')->
|
|
|
279 |
end()
|
|
|
280 |
;
|