]>
Commit | Line | Data |
---|---|---|
93fd4692 NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Tests\Controller; |
93fd4692 | 4 | |
769e19dc | 5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; |
93fd4692 | 6 | |
769e19dc | 7 | class EntryControllerTest extends WallabagCoreTestCase |
93fd4692 | 8 | { |
02d17813 JB |
9 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; |
10 | ||
3b815d2d J |
11 | public function testLogin() |
12 | { | |
13 | $client = $this->getClient(); | |
14 | ||
eb3bd7ef | 15 | $client->request('GET', '/new'); |
3b815d2d J |
16 | |
17 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
18 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
19 | } | |
20 | ||
9c0c8820 | 21 | public function testGetNew() |
93fd4692 | 22 | { |
eb3bd7ef | 23 | $this->logInAs('admin'); |
3b815d2d | 24 | $client = $this->getClient(); |
93fd4692 | 25 | |
aa6e27cf | 26 | $crawler = $client->request('GET', '/new'); |
93fd4692 NL |
27 | |
28 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
9c0c8820 J |
29 | |
30 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
31 | $this->assertCount(1, $crawler->filter('button[type=submit]')); | |
32 | } | |
33 | ||
880a0e1c NL |
34 | public function testPostNewViaBookmarklet() |
35 | { | |
36 | $this->logInAs('admin'); | |
37 | $client = $this->getClient(); | |
38 | ||
39 | $crawler = $client->request('GET', '/'); | |
40 | ||
41 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
42 | ||
43 | // Good URL | |
44 | $crawler = $client->request('GET', '/bookmarklet', array('url' => $this->url)); | |
45 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
46 | $crawler = $client->followRedirect(); | |
47 | $crawler = $client->request('GET', '/'); | |
48 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
49 | ||
50 | $em = $client->getContainer() | |
51 | ->get('doctrine.orm.entity_manager'); | |
52 | $entry = $em | |
53 | ->getRepository('WallabagCoreBundle:Entry') | |
54 | ->findOneByUrl($this->url); | |
55 | $em->remove($entry); | |
56 | $em->flush(); | |
57 | } | |
58 | ||
9c0c8820 J |
59 | public function testPostNewEmpty() |
60 | { | |
eb3bd7ef | 61 | $this->logInAs('admin'); |
3b815d2d | 62 | $client = $this->getClient(); |
9c0c8820 J |
63 | |
64 | $crawler = $client->request('GET', '/new'); | |
65 | ||
66 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
67 | ||
68 | $form = $crawler->filter('button[type=submit]')->form(); | |
69 | ||
70 | $crawler = $client->submit($form); | |
71 | ||
72 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
73 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(array('_text'))); | |
74 | $this->assertEquals('This value should not be blank.', $alert[0]); | |
75 | } | |
76 | ||
8a493541 | 77 | /** |
75c48e3a | 78 | * This test will require an internet connection. |
8a493541 | 79 | */ |
9c0c8820 J |
80 | public function testPostNewOk() |
81 | { | |
eb3bd7ef | 82 | $this->logInAs('admin'); |
3b815d2d | 83 | $client = $this->getClient(); |
9c0c8820 J |
84 | |
85 | $crawler = $client->request('GET', '/new'); | |
86 | ||
87 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
88 | ||
89 | $form = $crawler->filter('button[type=submit]')->form(); | |
90 | ||
91 | $data = array( | |
02d17813 | 92 | 'entry[url]' => $this->url, |
9c0c8820 J |
93 | ); |
94 | ||
95 | $client->submit($form, $data); | |
96 | ||
97 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
98 | ||
99 | $crawler = $client->followRedirect(); | |
100 | ||
3b815d2d | 101 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); |
34c06cab | 102 | $this->assertContains('Google', $alert[0]); |
9c0c8820 J |
103 | } |
104 | ||
105 | public function testArchive() | |
106 | { | |
eb3bd7ef | 107 | $this->logInAs('admin'); |
3b815d2d | 108 | $client = $this->getClient(); |
9c0c8820 | 109 | |
9fb6ac83 | 110 | $client->request('GET', '/archive/list'); |
9c0c8820 J |
111 | |
112 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
113 | } | |
114 | ||
115 | public function testStarred() | |
116 | { | |
eb3bd7ef | 117 | $this->logInAs('admin'); |
3b815d2d | 118 | $client = $this->getClient(); |
9c0c8820 | 119 | |
9fb6ac83 | 120 | $client->request('GET', '/starred/list'); |
9c0c8820 J |
121 | |
122 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
123 | } | |
124 | ||
8a493541 JB |
125 | /** |
126 | * @depends testPostNewOk | |
127 | */ | |
9c0c8820 J |
128 | public function testView() |
129 | { | |
eb3bd7ef | 130 | $this->logInAs('admin'); |
3b815d2d | 131 | $client = $this->getClient(); |
9c0c8820 J |
132 | |
133 | $content = $client->getContainer() | |
134 | ->get('doctrine.orm.entity_manager') | |
135 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 136 | ->findOneByUrl($this->url); |
9c0c8820 | 137 | |
eb3bd7ef | 138 | $client->request('GET', '/view/'.$content->getId()); |
9c0c8820 J |
139 | |
140 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
141 | $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); | |
93fd4692 | 142 | } |
eb3bd7ef | 143 | |
82d6d9cb JB |
144 | public function testEdit() |
145 | { | |
146 | $this->logInAs('admin'); | |
147 | $client = $this->getClient(); | |
148 | ||
149 | $content = $client->getContainer() | |
150 | ->get('doctrine.orm.entity_manager') | |
151 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 152 | ->findOneByUrl($this->url); |
82d6d9cb JB |
153 | |
154 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
155 | ||
156 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
157 | ||
158 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
159 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
160 | } | |
161 | ||
162 | public function testEditUpdate() | |
163 | { | |
164 | $this->logInAs('admin'); | |
165 | $client = $this->getClient(); | |
166 | ||
167 | $content = $client->getContainer() | |
168 | ->get('doctrine.orm.entity_manager') | |
169 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 170 | ->findOneByUrl($this->url); |
82d6d9cb JB |
171 | |
172 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
173 | ||
174 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
175 | ||
176 | $form = $crawler->filter('button[type=submit]')->form(); | |
177 | ||
178 | $data = array( | |
179 | 'entry[title]' => 'My updated title hehe :)', | |
180 | ); | |
181 | ||
182 | $client->submit($form, $data); | |
183 | ||
184 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
185 | ||
186 | $crawler = $client->followRedirect(); | |
187 | ||
188 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(array('_text'))); | |
189 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
190 | } | |
191 | ||
eb3bd7ef J |
192 | public function testToggleArchive() |
193 | { | |
194 | $this->logInAs('admin'); | |
195 | $client = $this->getClient(); | |
196 | ||
197 | $content = $client->getContainer() | |
198 | ->get('doctrine.orm.entity_manager') | |
199 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 200 | ->findOneByUrl($this->url); |
eb3bd7ef J |
201 | |
202 | $client->request('GET', '/archive/'.$content->getId()); | |
203 | ||
204 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
205 | ||
206 | $res = $client->getContainer() | |
207 | ->get('doctrine.orm.entity_manager') | |
208 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 209 | ->find($content->getId()); |
eb3bd7ef J |
210 | |
211 | $this->assertEquals($res->isArchived(), true); | |
212 | } | |
213 | ||
214 | public function testToggleStar() | |
215 | { | |
216 | $this->logInAs('admin'); | |
217 | $client = $this->getClient(); | |
218 | ||
219 | $content = $client->getContainer() | |
220 | ->get('doctrine.orm.entity_manager') | |
221 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 222 | ->findOneByUrl($this->url); |
eb3bd7ef J |
223 | |
224 | $client->request('GET', '/star/'.$content->getId()); | |
225 | ||
226 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
227 | ||
228 | $res = $client->getContainer() | |
229 | ->get('doctrine.orm.entity_manager') | |
230 | ->getRepository('WallabagCoreBundle:Entry') | |
231 | ->findOneById($content->getId()); | |
232 | ||
233 | $this->assertEquals($res->isStarred(), true); | |
234 | } | |
235 | ||
236 | public function testDelete() | |
237 | { | |
238 | $this->logInAs('admin'); | |
239 | $client = $this->getClient(); | |
240 | ||
241 | $content = $client->getContainer() | |
242 | ->get('doctrine.orm.entity_manager') | |
243 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 244 | ->findOneByUrl($this->url); |
eb3bd7ef J |
245 | |
246 | $client->request('GET', '/delete/'.$content->getId()); | |
247 | ||
248 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
249 | ||
1d147791 | 250 | $client->request('GET', '/delete/'.$content->getId()); |
eb3bd7ef | 251 | |
1d147791 | 252 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 253 | } |
3d2b2d62 J |
254 | |
255 | public function testViewOtherUserEntry() | |
256 | { | |
159986c4 | 257 | $this->logInAs('admin'); |
3d2b2d62 J |
258 | $client = $this->getClient(); |
259 | ||
260 | $content = $client->getContainer() | |
261 | ->get('doctrine.orm.entity_manager') | |
262 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 263 | ->findOneByUsernameAndNotArchived('bob'); |
3d2b2d62 | 264 | |
159986c4 | 265 | $client->request('GET', '/view/'.$content->getId()); |
3d2b2d62 J |
266 | |
267 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
268 | } | |
26864574 | 269 | |
3f357ee2 | 270 | public function testFilterOnReadingTime() |
26864574 NL |
271 | { |
272 | $this->logInAs('admin'); | |
273 | $client = $this->getClient(); | |
274 | ||
275 | $crawler = $client->request('GET', '/unread/list'); | |
276 | ||
277 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
278 | ||
279 | $data = array( | |
280 | 'entry_filter[readingTime][right_number]' => 11, | |
8ce32af6 | 281 | 'entry_filter[readingTime][left_number]' => 11, |
26864574 NL |
282 | ); |
283 | ||
284 | $crawler = $client->submit($form, $data); | |
285 | ||
286 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
287 | } | |
ab2c93c7 | 288 | |
3f357ee2 NL |
289 | public function testFilterOnCreationDate() |
290 | { | |
291 | $this->logInAs('admin'); | |
292 | $client = $this->getClient(); | |
293 | ||
294 | $crawler = $client->request('GET', '/unread/list'); | |
295 | ||
296 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
297 | ||
298 | $data = array( | |
299 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
8ce32af6 | 300 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), |
3f357ee2 NL |
301 | ); |
302 | ||
303 | $crawler = $client->submit($form, $data); | |
304 | ||
e1779760 | 305 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
3f357ee2 | 306 | |
f90af145 JB |
307 | $data = array( |
308 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
309 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
310 | ); | |
311 | ||
312 | $crawler = $client->submit($form, $data); | |
313 | ||
314 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
315 | ||
3f357ee2 NL |
316 | $data = array( |
317 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
8ce32af6 | 318 | 'entry_filter[createdAt][right_date]' => '01/01/1970', |
3f357ee2 NL |
319 | ); |
320 | ||
321 | $crawler = $client->submit($form, $data); | |
322 | ||
323 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
3f357ee2 NL |
324 | } |
325 | ||
ab2c93c7 NL |
326 | public function testPaginationWithFilter() |
327 | { | |
328 | $this->logInAs('admin'); | |
329 | $client = $this->getClient(); | |
ab2c93c7 NL |
330 | $crawler = $client->request('GET', '/config'); |
331 | ||
332 | $form = $crawler->filter('button[id=config_save]')->form(); | |
333 | ||
334 | $data = array( | |
335 | 'config[items_per_page]' => '1', | |
336 | ); | |
337 | ||
338 | $client->submit($form, $data); | |
339 | ||
340 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
341 | ||
342 | $crawler = $client->request('GET', 'unread/list'.$parameters); | |
343 | ||
344 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
e1779760 NL |
345 | |
346 | // reset pagination | |
347 | $crawler = $client->request('GET', '/config'); | |
348 | $form = $crawler->filter('button[id=config_save]')->form(); | |
349 | $data = array( | |
350 | 'config[items_per_page]' => '12', | |
351 | ); | |
352 | $client->submit($form, $data); | |
ab2c93c7 | 353 | } |
443cecd2 NL |
354 | |
355 | public function testFilterOnDomainName() | |
356 | { | |
357 | $this->logInAs('admin'); | |
358 | $client = $this->getClient(); | |
359 | ||
360 | $crawler = $client->request('GET', '/unread/list'); | |
361 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
362 | $data = array( | |
02d17813 | 363 | 'entry_filter[domainName]' => 'domain', |
443cecd2 NL |
364 | ); |
365 | ||
366 | $crawler = $client->submit($form, $data); | |
02d17813 | 367 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
443cecd2 NL |
368 | |
369 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
370 | $data = array( | |
8ce32af6 | 371 | 'entry_filter[domainName]' => 'wallabag', |
443cecd2 NL |
372 | ); |
373 | ||
374 | $crawler = $client->submit($form, $data); | |
375 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
376 | } | |
e1779760 NL |
377 | |
378 | public function testFilterOnStatus() | |
379 | { | |
380 | $this->logInAs('admin'); | |
381 | $client = $this->getClient(); | |
382 | ||
383 | $crawler = $client->request('GET', '/unread/list'); | |
384 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
385 | $form['entry_filter[isArchived]']->tick(); | |
386 | $form['entry_filter[isStarred]']->untick(); | |
387 | ||
388 | $crawler = $client->submit($form); | |
159986c4 | 389 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 NL |
390 | |
391 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
392 | $form['entry_filter[isArchived]']->untick(); | |
393 | $form['entry_filter[isStarred]']->tick(); | |
394 | ||
395 | $crawler = $client->submit($form); | |
02d17813 | 396 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 | 397 | } |
497e0cad NL |
398 | |
399 | public function testPreviewPictureFilter() | |
400 | { | |
401 | $this->logInAs('admin'); | |
402 | $client = $this->getClient(); | |
403 | ||
404 | $crawler = $client->request('GET', '/unread/list'); | |
405 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
406 | $form['entry_filter[previewPicture]']->tick(); | |
407 | ||
408 | $crawler = $client->submit($form); | |
409 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
410 | } | |
d4ebe5c5 JB |
411 | |
412 | public function testFilterOnLanguage() | |
413 | { | |
414 | $this->logInAs('admin'); | |
415 | $client = $this->getClient(); | |
416 | ||
417 | $crawler = $client->request('GET', '/unread/list'); | |
418 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
419 | $data = array( | |
159986c4 | 420 | 'entry_filter[language]' => 'fr', |
d4ebe5c5 JB |
421 | ); |
422 | ||
423 | $crawler = $client->submit($form, $data); | |
02d17813 | 424 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
d4ebe5c5 JB |
425 | |
426 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
427 | $data = array( | |
428 | 'entry_filter[language]' => 'en', | |
429 | ); | |
430 | ||
431 | $crawler = $client->submit($form, $data); | |
432 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
433 | } | |
93fd4692 | 434 | } |