]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | |
4 | ||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | |
6 | ||
7 | class EntryControllerTest extends WallabagCoreTestCase | |
8 | { | |
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 | ||
11 | public function testLogin() | |
12 | { | |
13 | $client = $this->getClient(); | |
14 | ||
15 | $client->request('GET', '/new'); | |
16 | ||
17 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
18 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
19 | } | |
20 | ||
21 | public function testGetNew() | |
22 | { | |
23 | $this->logInAs('admin'); | |
24 | $client = $this->getClient(); | |
25 | ||
26 | $crawler = $client->request('GET', '/new'); | |
27 | ||
28 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
29 | ||
30 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
31 | $this->assertCount(1, $crawler->filter('button[type=submit]')); | |
32 | } | |
33 | ||
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 | ||
59 | public function testPostNewEmpty() | |
60 | { | |
61 | $this->logInAs('admin'); | |
62 | $client = $this->getClient(); | |
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 | ||
77 | /** | |
78 | * This test will require an internet connection. | |
79 | */ | |
80 | public function testPostNewOk() | |
81 | { | |
82 | $this->logInAs('admin'); | |
83 | $client = $this->getClient(); | |
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( | |
92 | 'entry[url]' => $this->url, | |
93 | ); | |
94 | ||
95 | $client->submit($form, $data); | |
96 | ||
97 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
98 | ||
99 | $crawler = $client->followRedirect(); | |
100 | ||
101 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); | |
102 | $this->assertContains('Google', $alert[0]); | |
103 | } | |
104 | ||
105 | /** | |
106 | * This test will require an internet connection. | |
107 | */ | |
108 | public function testPostNewThatWillBeTaggued() | |
109 | { | |
110 | $this->logInAs('admin'); | |
111 | $client = $this->getClient(); | |
112 | ||
113 | $crawler = $client->request('GET', '/new'); | |
114 | ||
115 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
116 | ||
117 | $form = $crawler->filter('button[type=submit]')->form(); | |
118 | ||
119 | $data = array( | |
120 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
121 | ); | |
122 | ||
123 | $client->submit($form, $data); | |
124 | ||
125 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
126 | ||
127 | $crawler = $client->followRedirect(); | |
128 | ||
129 | $em = $client->getContainer() | |
130 | ->get('doctrine.orm.entity_manager'); | |
131 | $entry = $em | |
132 | ->getRepository('WallabagCoreBundle:Entry') | |
133 | ->findOneByUrl($url); | |
134 | $tags = $entry->getTags(); | |
135 | ||
136 | $this->assertCount(1, $tags); | |
137 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
138 | ||
139 | $em->remove($entry); | |
140 | $em->flush(); | |
141 | } | |
142 | ||
143 | public function testArchive() | |
144 | { | |
145 | $this->logInAs('admin'); | |
146 | $client = $this->getClient(); | |
147 | ||
148 | $client->request('GET', '/archive/list'); | |
149 | ||
150 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
151 | } | |
152 | ||
153 | public function testStarred() | |
154 | { | |
155 | $this->logInAs('admin'); | |
156 | $client = $this->getClient(); | |
157 | ||
158 | $client->request('GET', '/starred/list'); | |
159 | ||
160 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
161 | } | |
162 | ||
163 | /** | |
164 | * @depends testPostNewOk | |
165 | */ | |
166 | public function testView() | |
167 | { | |
168 | $this->logInAs('admin'); | |
169 | $client = $this->getClient(); | |
170 | ||
171 | $content = $client->getContainer() | |
172 | ->get('doctrine.orm.entity_manager') | |
173 | ->getRepository('WallabagCoreBundle:Entry') | |
174 | ->findOneByUrl($this->url); | |
175 | ||
176 | $client->request('GET', '/view/'.$content->getId()); | |
177 | ||
178 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
179 | $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); | |
180 | } | |
181 | ||
182 | public function testEdit() | |
183 | { | |
184 | $this->logInAs('admin'); | |
185 | $client = $this->getClient(); | |
186 | ||
187 | $content = $client->getContainer() | |
188 | ->get('doctrine.orm.entity_manager') | |
189 | ->getRepository('WallabagCoreBundle:Entry') | |
190 | ->findOneByUrl($this->url); | |
191 | ||
192 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
193 | ||
194 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
195 | ||
196 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
197 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
198 | } | |
199 | ||
200 | public function testEditUpdate() | |
201 | { | |
202 | $this->logInAs('admin'); | |
203 | $client = $this->getClient(); | |
204 | ||
205 | $content = $client->getContainer() | |
206 | ->get('doctrine.orm.entity_manager') | |
207 | ->getRepository('WallabagCoreBundle:Entry') | |
208 | ->findOneByUrl($this->url); | |
209 | ||
210 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
211 | ||
212 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
213 | ||
214 | $form = $crawler->filter('button[type=submit]')->form(); | |
215 | ||
216 | $data = array( | |
217 | 'entry[title]' => 'My updated title hehe :)', | |
218 | ); | |
219 | ||
220 | $client->submit($form, $data); | |
221 | ||
222 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
223 | ||
224 | $crawler = $client->followRedirect(); | |
225 | ||
226 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(array('_text'))); | |
227 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
228 | } | |
229 | ||
230 | public function testToggleArchive() | |
231 | { | |
232 | $this->logInAs('admin'); | |
233 | $client = $this->getClient(); | |
234 | ||
235 | $content = $client->getContainer() | |
236 | ->get('doctrine.orm.entity_manager') | |
237 | ->getRepository('WallabagCoreBundle:Entry') | |
238 | ->findOneByUrl($this->url); | |
239 | ||
240 | $client->request('GET', '/archive/'.$content->getId()); | |
241 | ||
242 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
243 | ||
244 | $res = $client->getContainer() | |
245 | ->get('doctrine.orm.entity_manager') | |
246 | ->getRepository('WallabagCoreBundle:Entry') | |
247 | ->find($content->getId()); | |
248 | ||
249 | $this->assertEquals($res->isArchived(), true); | |
250 | } | |
251 | ||
252 | public function testToggleStar() | |
253 | { | |
254 | $this->logInAs('admin'); | |
255 | $client = $this->getClient(); | |
256 | ||
257 | $content = $client->getContainer() | |
258 | ->get('doctrine.orm.entity_manager') | |
259 | ->getRepository('WallabagCoreBundle:Entry') | |
260 | ->findOneByUrl($this->url); | |
261 | ||
262 | $client->request('GET', '/star/'.$content->getId()); | |
263 | ||
264 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
265 | ||
266 | $res = $client->getContainer() | |
267 | ->get('doctrine.orm.entity_manager') | |
268 | ->getRepository('WallabagCoreBundle:Entry') | |
269 | ->findOneById($content->getId()); | |
270 | ||
271 | $this->assertEquals($res->isStarred(), true); | |
272 | } | |
273 | ||
274 | public function testDelete() | |
275 | { | |
276 | $this->logInAs('admin'); | |
277 | $client = $this->getClient(); | |
278 | ||
279 | $content = $client->getContainer() | |
280 | ->get('doctrine.orm.entity_manager') | |
281 | ->getRepository('WallabagCoreBundle:Entry') | |
282 | ->findOneByUrl($this->url); | |
283 | ||
284 | $client->request('GET', '/delete/'.$content->getId()); | |
285 | ||
286 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
287 | ||
288 | $client->request('GET', '/delete/'.$content->getId()); | |
289 | ||
290 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
291 | } | |
292 | ||
293 | public function testViewOtherUserEntry() | |
294 | { | |
295 | $this->logInAs('admin'); | |
296 | $client = $this->getClient(); | |
297 | ||
298 | $content = $client->getContainer() | |
299 | ->get('doctrine.orm.entity_manager') | |
300 | ->getRepository('WallabagCoreBundle:Entry') | |
301 | ->findOneByUsernameAndNotArchived('bob'); | |
302 | ||
303 | $client->request('GET', '/view/'.$content->getId()); | |
304 | ||
305 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
306 | } | |
307 | ||
308 | public function testFilterOnReadingTime() | |
309 | { | |
310 | $this->logInAs('admin'); | |
311 | $client = $this->getClient(); | |
312 | ||
313 | $crawler = $client->request('GET', '/unread/list'); | |
314 | ||
315 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
316 | ||
317 | $data = array( | |
318 | 'entry_filter[readingTime][right_number]' => 11, | |
319 | 'entry_filter[readingTime][left_number]' => 11, | |
320 | ); | |
321 | ||
322 | $crawler = $client->submit($form, $data); | |
323 | ||
324 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
325 | } | |
326 | ||
327 | public function testFilterOnCreationDate() | |
328 | { | |
329 | $this->logInAs('admin'); | |
330 | $client = $this->getClient(); | |
331 | ||
332 | $crawler = $client->request('GET', '/unread/list'); | |
333 | ||
334 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
335 | ||
336 | $data = array( | |
337 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
338 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), | |
339 | ); | |
340 | ||
341 | $crawler = $client->submit($form, $data); | |
342 | ||
343 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
344 | ||
345 | $data = array( | |
346 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
347 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
348 | ); | |
349 | ||
350 | $crawler = $client->submit($form, $data); | |
351 | ||
352 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
353 | ||
354 | $data = array( | |
355 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
356 | 'entry_filter[createdAt][right_date]' => '01/01/1970', | |
357 | ); | |
358 | ||
359 | $crawler = $client->submit($form, $data); | |
360 | ||
361 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
362 | } | |
363 | ||
364 | public function testPaginationWithFilter() | |
365 | { | |
366 | $this->logInAs('admin'); | |
367 | $client = $this->getClient(); | |
368 | $crawler = $client->request('GET', '/config'); | |
369 | ||
370 | $form = $crawler->filter('button[id=config_save]')->form(); | |
371 | ||
372 | $data = array( | |
373 | 'config[items_per_page]' => '1', | |
374 | ); | |
375 | ||
376 | $client->submit($form, $data); | |
377 | ||
378 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
379 | ||
380 | $crawler = $client->request('GET', 'unread/list'.$parameters); | |
381 | ||
382 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
383 | ||
384 | // reset pagination | |
385 | $crawler = $client->request('GET', '/config'); | |
386 | $form = $crawler->filter('button[id=config_save]')->form(); | |
387 | $data = array( | |
388 | 'config[items_per_page]' => '12', | |
389 | ); | |
390 | $client->submit($form, $data); | |
391 | } | |
392 | ||
393 | public function testFilterOnDomainName() | |
394 | { | |
395 | $this->logInAs('admin'); | |
396 | $client = $this->getClient(); | |
397 | ||
398 | $crawler = $client->request('GET', '/unread/list'); | |
399 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
400 | $data = array( | |
401 | 'entry_filter[domainName]' => 'domain', | |
402 | ); | |
403 | ||
404 | $crawler = $client->submit($form, $data); | |
405 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
406 | ||
407 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
408 | $data = array( | |
409 | 'entry_filter[domainName]' => 'wallabag', | |
410 | ); | |
411 | ||
412 | $crawler = $client->submit($form, $data); | |
413 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
414 | } | |
415 | ||
416 | public function testFilterOnStatus() | |
417 | { | |
418 | $this->logInAs('admin'); | |
419 | $client = $this->getClient(); | |
420 | ||
421 | $crawler = $client->request('GET', '/unread/list'); | |
422 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
423 | $form['entry_filter[isArchived]']->tick(); | |
424 | $form['entry_filter[isStarred]']->untick(); | |
425 | ||
426 | $crawler = $client->submit($form); | |
427 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
428 | ||
429 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
430 | $form['entry_filter[isArchived]']->untick(); | |
431 | $form['entry_filter[isStarred]']->tick(); | |
432 | ||
433 | $crawler = $client->submit($form); | |
434 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
435 | } | |
436 | ||
437 | public function testPreviewPictureFilter() | |
438 | { | |
439 | $this->logInAs('admin'); | |
440 | $client = $this->getClient(); | |
441 | ||
442 | $crawler = $client->request('GET', '/unread/list'); | |
443 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
444 | $form['entry_filter[previewPicture]']->tick(); | |
445 | ||
446 | $crawler = $client->submit($form); | |
447 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
448 | } | |
449 | ||
450 | public function testFilterOnLanguage() | |
451 | { | |
452 | $this->logInAs('admin'); | |
453 | $client = $this->getClient(); | |
454 | ||
455 | $crawler = $client->request('GET', '/unread/list'); | |
456 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
457 | $data = array( | |
458 | 'entry_filter[language]' => 'fr', | |
459 | ); | |
460 | ||
461 | $crawler = $client->submit($form, $data); | |
462 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
463 | ||
464 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
465 | $data = array( | |
466 | 'entry_filter[language]' => 'en', | |
467 | ); | |
468 | ||
469 | $crawler = $client->submit($form, $data); | |
470 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
471 | } | |
472 | } |