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