diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Controller')
4 files changed, 255 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index d7d341aa..11c86423 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php | |||
@@ -28,6 +28,8 @@ class ConfigControllerTest extends WallabagTestCase | |||
28 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); | 28 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
29 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | 29 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); |
30 | $this->assertCount(1, $crawler->filter('button[id=user_save]')); | 30 | $this->assertCount(1, $crawler->filter('button[id=user_save]')); |
31 | $this->assertCount(1, $crawler->filter('button[id=new_user_save]')); | ||
32 | $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); | ||
31 | } | 33 | } |
32 | 34 | ||
33 | public function testUpdate() | 35 | public function testUpdate() |
@@ -347,4 +349,128 @@ class ConfigControllerTest extends WallabagTestCase | |||
347 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); | 349 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); |
348 | $this->assertContains('User "wallace" added', $alert[0]); | 350 | $this->assertContains('User "wallace" added', $alert[0]); |
349 | } | 351 | } |
352 | |||
353 | public function testRssUpdateResetToken() | ||
354 | { | ||
355 | $this->logInAs('admin'); | ||
356 | $client = $this->getClient(); | ||
357 | |||
358 | // reset the token | ||
359 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
360 | $user = $em | ||
361 | ->getRepository('WallabagCoreBundle:User') | ||
362 | ->findOneByUsername('admin'); | ||
363 | |||
364 | if (!$user) { | ||
365 | $this->markTestSkipped('No user found in db.'); | ||
366 | } | ||
367 | |||
368 | $config = $user->getConfig(); | ||
369 | $config->setRssToken(null); | ||
370 | $em->persist($config); | ||
371 | $em->flush(); | ||
372 | |||
373 | $crawler = $client->request('GET', '/config'); | ||
374 | |||
375 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
376 | |||
377 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); | ||
378 | $this->assertContains('You need to generate a token first.', $body[0]); | ||
379 | |||
380 | $client->request('GET', '/generate-token'); | ||
381 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
382 | |||
383 | $crawler = $client->followRedirect(); | ||
384 | |||
385 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); | ||
386 | $this->assertNotContains('You need to generate a token first.', $body[0]); | ||
387 | } | ||
388 | |||
389 | public function testGenerateTokenAjax() | ||
390 | { | ||
391 | $this->logInAs('admin'); | ||
392 | $client = $this->getClient(); | ||
393 | |||
394 | $client->request( | ||
395 | 'GET', | ||
396 | '/generate-token', | ||
397 | array(), | ||
398 | array(), | ||
399 | array('HTTP_X-Requested-With' => 'XMLHttpRequest') | ||
400 | ); | ||
401 | |||
402 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
403 | $content = json_decode($client->getResponse()->getContent(), true);; | ||
404 | $this->assertArrayHasKey('token', $content); | ||
405 | } | ||
406 | |||
407 | public function testRssUpdate() | ||
408 | { | ||
409 | $this->logInAs('admin'); | ||
410 | $client = $this->getClient(); | ||
411 | |||
412 | $crawler = $client->request('GET', '/config'); | ||
413 | |||
414 | if (500 == $client->getResponse()->getStatusCode()) { | ||
415 | var_export($client->getResponse()->getContent()); | ||
416 | die(); | ||
417 | } | ||
418 | |||
419 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
420 | |||
421 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | ||
422 | |||
423 | $data = array( | ||
424 | 'rss_config[rss_limit]' => 12, | ||
425 | ); | ||
426 | |||
427 | $client->submit($form, $data); | ||
428 | |||
429 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
430 | |||
431 | $crawler = $client->followRedirect(); | ||
432 | |||
433 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); | ||
434 | $this->assertContains('RSS information updated', $alert[0]); | ||
435 | } | ||
436 | |||
437 | public function dataForRssFailed() | ||
438 | { | ||
439 | return array( | ||
440 | array( | ||
441 | array( | ||
442 | 'rss_config[rss_limit]' => 0, | ||
443 | ), | ||
444 | 'This value should be 1 or more.', | ||
445 | ), | ||
446 | array( | ||
447 | array( | ||
448 | 'rss_config[rss_limit]' => 1000000000000, | ||
449 | ), | ||
450 | 'This will certainly kill the app', | ||
451 | ), | ||
452 | ); | ||
453 | } | ||
454 | |||
455 | /** | ||
456 | * @dataProvider dataForRssFailed | ||
457 | */ | ||
458 | public function testRssFailed($data, $expectedMessage) | ||
459 | { | ||
460 | $this->logInAs('admin'); | ||
461 | $client = $this->getClient(); | ||
462 | |||
463 | $crawler = $client->request('GET', '/config'); | ||
464 | |||
465 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
466 | |||
467 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | ||
468 | |||
469 | $crawler = $client->submit($form, $data); | ||
470 | |||
471 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
472 | |||
473 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); | ||
474 | $this->assertContains($expectedMessage, $alert[0]); | ||
475 | } | ||
350 | } | 476 | } |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 99a3a945..1a0d586c 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | |||
@@ -60,7 +60,7 @@ class EntryControllerTest extends WallabagTestCase | |||
60 | $form = $crawler->filter('button[type=submit]')->form(); | 60 | $form = $crawler->filter('button[type=submit]')->form(); |
61 | 61 | ||
62 | $data = array( | 62 | $data = array( |
63 | 'entry[url]' => 'https://www.mailjet.com/blog/mailjet-zapier-integrations-made-easy/', | 63 | 'entry[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', |
64 | ); | 64 | ); |
65 | 65 | ||
66 | $client->submit($form, $data); | 66 | $client->submit($form, $data); |
@@ -70,7 +70,7 @@ class EntryControllerTest extends WallabagTestCase | |||
70 | $crawler = $client->followRedirect(); | 70 | $crawler = $client->followRedirect(); |
71 | 71 | ||
72 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); | 72 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); |
73 | $this->assertContains('Mailjet', $alert[0]); | 73 | $this->assertContains('Google', $alert[0]); |
74 | } | 74 | } |
75 | 75 | ||
76 | public function testArchive() | 76 | public function testArchive() |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php new file mode 100644 index 00000000..8f627b4b --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php | |||
@@ -0,0 +1,126 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | ||
4 | |||
5 | use Wallabag\CoreBundle\Tests\WallabagTestCase; | ||
6 | |||
7 | class RssControllerTest extends WallabagTestCase | ||
8 | { | ||
9 | public function validateDom($xml, $nb = null) | ||
10 | { | ||
11 | $doc = new \DOMDocument(); | ||
12 | $doc->loadXML($xml); | ||
13 | |||
14 | $xpath = new \DOMXpath($doc); | ||
15 | |||
16 | if (null === $nb) { | ||
17 | $this->assertGreaterThan(0, $xpath->query('//item')->length); | ||
18 | } else { | ||
19 | $this->assertEquals($nb, $xpath->query('//item')->length); | ||
20 | } | ||
21 | |||
22 | $this->assertEquals(1, $xpath->query('/rss')->length); | ||
23 | $this->assertEquals(1, $xpath->query('/rss/channel')->length); | ||
24 | |||
25 | foreach ($xpath->query('//item') as $item) { | ||
26 | $this->assertEquals(1, $xpath->query('title', $item)->length); | ||
27 | $this->assertEquals(1, $xpath->query('source', $item)->length); | ||
28 | $this->assertEquals(1, $xpath->query('link', $item)->length); | ||
29 | $this->assertEquals(1, $xpath->query('guid', $item)->length); | ||
30 | $this->assertEquals(1, $xpath->query('pubDate', $item)->length); | ||
31 | $this->assertEquals(1, $xpath->query('description', $item)->length); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | public function dataForBadUrl() | ||
36 | { | ||
37 | return array( | ||
38 | array( | ||
39 | '/admin/YZIOAUZIAO/unread.xml' | ||
40 | ), | ||
41 | array( | ||
42 | '/wallace/YZIOAUZIAO/starred.xml' | ||
43 | ), | ||
44 | array( | ||
45 | '/wallace/YZIOAUZIAO/archives.xml' | ||
46 | ), | ||
47 | ); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * @dataProvider dataForBadUrl | ||
52 | */ | ||
53 | public function testBadUrl($url) | ||
54 | { | ||
55 | $client = $this->getClient(); | ||
56 | |||
57 | $client->request('GET', $url); | ||
58 | |||
59 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
60 | } | ||
61 | |||
62 | public function testUnread() | ||
63 | { | ||
64 | $client = $this->getClient(); | ||
65 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
66 | $user = $em | ||
67 | ->getRepository('WallabagCoreBundle:User') | ||
68 | ->findOneByUsername('admin'); | ||
69 | |||
70 | $config = $user->getConfig(); | ||
71 | $config->setRssToken('SUPERTOKEN'); | ||
72 | $config->setRssLimit(2); | ||
73 | $em->persist($config); | ||
74 | $em->flush(); | ||
75 | |||
76 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | ||
77 | |||
78 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
79 | |||
80 | $this->validateDom($client->getResponse()->getContent(), 2); | ||
81 | } | ||
82 | |||
83 | public function testStarred() | ||
84 | { | ||
85 | $client = $this->getClient(); | ||
86 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
87 | $user = $em | ||
88 | ->getRepository('WallabagCoreBundle:User') | ||
89 | ->findOneByUsername('admin'); | ||
90 | |||
91 | $config = $user->getConfig(); | ||
92 | $config->setRssToken('SUPERTOKEN'); | ||
93 | $config->setRssLimit(1); | ||
94 | $em->persist($config); | ||
95 | $em->flush(); | ||
96 | |||
97 | $client = $this->getClient(); | ||
98 | $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); | ||
99 | |||
100 | $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); | ||
101 | |||
102 | $this->validateDom($client->getResponse()->getContent()); | ||
103 | } | ||
104 | |||
105 | public function testArchives() | ||
106 | { | ||
107 | $client = $this->getClient(); | ||
108 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
109 | $user = $em | ||
110 | ->getRepository('WallabagCoreBundle:User') | ||
111 | ->findOneByUsername('admin'); | ||
112 | |||
113 | $config = $user->getConfig(); | ||
114 | $config->setRssToken('SUPERTOKEN'); | ||
115 | $config->setRssLimit(null); | ||
116 | $em->persist($config); | ||
117 | $em->flush(); | ||
118 | |||
119 | $client = $this->getClient(); | ||
120 | $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); | ||
121 | |||
122 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
123 | |||
124 | $this->validateDom($client->getResponse()->getContent()); | ||
125 | } | ||
126 | } | ||
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 0eca7cde..c9907065 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -105,7 +105,7 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
105 | 105 | ||
106 | $this->assertGreaterThanOrEqual(1, count(json_decode($client->getResponse()->getContent()))); | 106 | $this->assertGreaterThanOrEqual(1, count(json_decode($client->getResponse()->getContent()))); |
107 | 107 | ||
108 | $this->assertContains('Mailjet', $client->getResponse()->getContent()); | 108 | $this->assertContains('Google', $client->getResponse()->getContent()); |
109 | 109 | ||
110 | $this->assertTrue( | 110 | $this->assertTrue( |
111 | $client->getResponse()->headers->contains( | 111 | $client->getResponse()->headers->contains( |