aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php61
-rw-r--r--tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php8
-rw-r--r--tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php18
-rw-r--r--tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php (renamed from tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php)16
4 files changed, 77 insertions, 26 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 7193f9b0..bb3ea9e2 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -56,8 +56,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
56 56
57 $crawler = $client->followRedirect(); 57 $crawler = $client->followRedirect();
58 58
59 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 59 $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]);
60 $this->assertContains('flashes.config.notice.config_saved', $alert[0]);
61 } 60 }
62 61
63 public function testChangeReadingSpeed() 62 public function testChangeReadingSpeed()
@@ -213,8 +212,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
213 212
214 $crawler = $client->followRedirect(); 213 $crawler = $client->followRedirect();
215 214
216 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 215 $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]);
217 $this->assertContains('flashes.config.notice.password_updated', $alert[0]);
218 } 216 }
219 217
220 public function dataForUserFailed() 218 public function dataForUserFailed()
@@ -382,8 +380,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
382 380
383 $crawler = $client->followRedirect(); 381 $crawler = $client->followRedirect();
384 382
385 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 383 $this->assertContains('flashes.config.notice.user_added', $crawler->filter('body')->extract(['_text'])[0]);
386 $this->assertContains('flashes.config.notice.user_added', $alert[0]);
387 384
388 $em = $client->getContainer()->get('doctrine.orm.entity_manager'); 385 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
389 $user = $em 386 $user = $em
@@ -474,8 +471,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
474 471
475 $crawler = $client->followRedirect(); 472 $crawler = $client->followRedirect();
476 473
477 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 474 $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]);
478 $this->assertContains('flashes.config.notice.rss_updated', $alert[0]);
479 } 475 }
480 476
481 public function dataForRssFailed() 477 public function dataForRssFailed()
@@ -540,8 +536,32 @@ class ConfigControllerTest extends WallabagCoreTestCase
540 536
541 $crawler = $client->followRedirect(); 537 $crawler = $client->followRedirect();
542 538
543 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 539 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
544 $this->assertContains('flashes.config.notice.tagging_rules_updated', $alert[0]); 540
541 $editLink = $crawler->filter('.mode_edit')->last()->link();
542
543 $crawler = $client->click($editLink);
544 $this->assertEquals(302, $client->getResponse()->getStatusCode());
545 $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location'));
546
547 $crawler = $client->followRedirect();
548
549 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
550
551 $data = [
552 'tagging_rule[rule]' => 'readingTime <= 30',
553 'tagging_rule[tags]' => 'short reading',
554 ];
555
556 $client->submit($form, $data);
557
558 $this->assertEquals(302, $client->getResponse()->getStatusCode());
559
560 $crawler = $client->followRedirect();
561
562 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
563
564 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
545 565
546 $deleteLink = $crawler->filter('.delete')->last()->link(); 566 $deleteLink = $crawler->filter('.delete')->last()->link();
547 567
@@ -549,8 +569,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
549 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 569 $this->assertEquals(302, $client->getResponse()->getStatusCode());
550 570
551 $crawler = $client->followRedirect(); 571 $crawler = $client->followRedirect();
552 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 572 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
553 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $alert[0]);
554 } 573 }
555 574
556 public function dataForTaggingRuleFailed() 575 public function dataForTaggingRuleFailed()
@@ -613,7 +632,23 @@ class ConfigControllerTest extends WallabagCoreTestCase
613 ->getRepository('WallabagCoreBundle:TaggingRule') 632 ->getRepository('WallabagCoreBundle:TaggingRule')
614 ->findAll()[0]; 633 ->findAll()[0];
615 634
616 $crawler = $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); 635 $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId());
636
637 $this->assertEquals(403, $client->getResponse()->getStatusCode());
638 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
639 $this->assertContains('You can not access this tagging rule', $body[0]);
640 }
641
642 public function testEditingTaggingRuleFromAnOtherUser()
643 {
644 $this->logInAs('bob');
645 $client = $this->getClient();
646
647 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
648 ->getRepository('WallabagCoreBundle:TaggingRule')
649 ->findAll()[0];
650
651 $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId());
617 652
618 $this->assertEquals(403, $client->getResponse()->getStatusCode()); 653 $this->assertEquals(403, $client->getResponse()->getStatusCode());
619 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 654 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
index e29b58b5..2e6fccfb 100644
--- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
+++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
@@ -125,16 +125,14 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase
125 $this->assertTrue($converter->supports($params)); 125 $this->assertTrue($converter->supports($params));
126 } 126 }
127 127
128 /**
129 * @expectedException InvalidArgumentException
130 * @expectedExceptionMessage Route attribute is missing
131 */
132 public function testApplyEmptyRequest() 128 public function testApplyEmptyRequest()
133 { 129 {
134 $params = new ParamConverter([]); 130 $params = new ParamConverter([]);
135 $converter = new UsernameRssTokenConverter(); 131 $converter = new UsernameRssTokenConverter();
136 132
137 $converter->apply(new Request(), $params); 133 $res = $converter->apply(new Request(), $params);
134
135 $this->assertFalse($res);
138 } 136 }
139 137
140 /** 138 /**
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
index 8ec2a75a..b1c8c946 100644
--- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
+++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
@@ -8,7 +8,23 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase
8{ 8{
9 public function testRemoveWww() 9 public function testRemoveWww()
10 { 10 {
11 $extension = new WallabagExtension(); 11 $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository')
16 ->disableOriginalConstructor()
17 ->getMock();
18
19 $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
20 ->disableOriginalConstructor()
21 ->getMock();
22
23 $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')
24 ->disableOriginalConstructor()
25 ->getMock();
26
27 $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator);
12 28
13 $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr')); 29 $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr'));
14 $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr')); 30 $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr'));
diff --git a/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
index e45722fa..0cebd3e4 100644
--- a/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php
+++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\EventListener; 3namespace Tests\Wallabag\UserBundle\EventListener;
4 4
5use FOS\UserBundle\Event\FilterUserResponseEvent; 5use FOS\UserBundle\Event\FilterUserResponseEvent;
6use FOS\UserBundle\FOSUserEvents; 6use FOS\UserBundle\FOSUserEvents;
@@ -8,10 +8,10 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
8use Symfony\Component\HttpFoundation\Request; 8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\HttpFoundation\Response; 9use Symfony\Component\HttpFoundation\Response;
10use Wallabag\CoreBundle\Entity\Config; 10use Wallabag\CoreBundle\Entity\Config;
11use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener; 11use Wallabag\UserBundle\EventListener\CreateConfigListener;
12use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
13 13
14class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase 14class CreateConfigListenerTest extends \PHPUnit_Framework_TestCase
15{ 15{
16 private $em; 16 private $em;
17 private $listener; 17 private $listener;
@@ -25,12 +25,13 @@ class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
25 ->disableOriginalConstructor() 25 ->disableOriginalConstructor()
26 ->getMock(); 26 ->getMock();
27 27
28 $this->listener = new RegistrationConfirmedListener( 28 $this->listener = new CreateConfigListener(
29 $this->em, 29 $this->em,
30 'baggy', 30 'baggy',
31 20, 31 20,
32 50, 32 50,
33 'fr' 33 'fr',
34 1
34 ); 35 );
35 36
36 $this->dispatcher = new EventDispatcher(); 37 $this->dispatcher = new EventDispatcher();
@@ -55,7 +56,7 @@ class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
55 $this->em->expects($this->never())->method('flush'); 56 $this->em->expects($this->never())->method('flush');
56 57
57 $this->dispatcher->dispatch( 58 $this->dispatcher->dispatch(
58 FOSUserEvents::REGISTRATION_CONFIRMED, 59 FOSUserEvents::REGISTRATION_COMPLETED,
59 $event 60 $event
60 ); 61 );
61 } 62 }
@@ -76,6 +77,7 @@ class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
76 $config->setItemsPerPage(20); 77 $config->setItemsPerPage(20);
77 $config->setRssLimit(50); 78 $config->setRssLimit(50);
78 $config->setLanguage('fr'); 79 $config->setLanguage('fr');
80 $config->setReadingSpeed(1);
79 81
80 $this->em->expects($this->once()) 82 $this->em->expects($this->once())
81 ->method('persist') 83 ->method('persist')
@@ -84,7 +86,7 @@ class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
84 ->method('flush'); 86 ->method('flush');
85 87
86 $this->dispatcher->dispatch( 88 $this->dispatcher->dispatch(
87 FOSUserEvents::REGISTRATION_CONFIRMED, 89 FOSUserEvents::REGISTRATION_COMPLETED,
88 $event 90 $event
89 ); 91 );
90 } 92 }