diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
3 files changed, 137 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Command/TagAllCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/TagAllCommandTest.php new file mode 100644 index 00000000..653c1a93 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Command/TagAllCommandTest.php | |||
@@ -0,0 +1,60 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Tests\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Wallabag\CoreBundle\Command\TagAllCommand; | ||
8 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | ||
9 | |||
10 | class TagAllCommandTest extends WallabagCoreTestCase | ||
11 | { | ||
12 | /** | ||
13 | * @expectedException Symfony\Component\Console\Exception\RuntimeException | ||
14 | * @expectedExceptionMessage Not enough arguments (missing: "username") | ||
15 | */ | ||
16 | public function testRunTagAllCommandWithoutUsername() | ||
17 | { | ||
18 | $application = new Application($this->getClient()->getKernel()); | ||
19 | $application->add(new TagAllCommand()); | ||
20 | |||
21 | $command = $application->find('wallabag:tag:all'); | ||
22 | |||
23 | $tester = new CommandTester($command); | ||
24 | $tester->execute(array( | ||
25 | 'command' => $command->getName(), | ||
26 | )); | ||
27 | } | ||
28 | |||
29 | public function testRunTagAllCommandWithBadUsername() | ||
30 | { | ||
31 | $application = new Application($this->getClient()->getKernel()); | ||
32 | $application->add(new TagAllCommand()); | ||
33 | |||
34 | $command = $application->find('wallabag:tag:all'); | ||
35 | |||
36 | $tester = new CommandTester($command); | ||
37 | $tester->execute(array( | ||
38 | 'command' => $command->getName(), | ||
39 | 'username' => 'unknown', | ||
40 | )); | ||
41 | |||
42 | $this->assertContains('User "unknown" not found', $tester->getDisplay()); | ||
43 | } | ||
44 | |||
45 | public function testRunTagAllCommand() | ||
46 | { | ||
47 | $application = new Application($this->getClient()->getKernel()); | ||
48 | $application->add(new TagAllCommand()); | ||
49 | |||
50 | $command = $application->find('wallabag:tag:all'); | ||
51 | |||
52 | $tester = new CommandTester($command); | ||
53 | $tester->execute(array( | ||
54 | 'command' => $command->getName(), | ||
55 | 'username' => 'admin', | ||
56 | )); | ||
57 | |||
58 | $this->assertContains('Tagging entries for user « admin »... Done', $tester->getDisplay()); | ||
59 | } | ||
60 | } | ||
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 89ca31e2..c8807425 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php | |||
@@ -520,18 +520,61 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
520 | return array( | 520 | return array( |
521 | array( | 521 | array( |
522 | array( | 522 | array( |
523 | 'rss_config[rule]' => 'unknownVar <= 3', | 523 | 'tagging_rule[rule]' => 'unknownVar <= 3', |
524 | 'rss_config[tags]' => 'cool tag', | 524 | 'tagging_rule[tags]' => 'cool tag', |
525 | ), | ||
526 | array( | ||
527 | 'The variable', | ||
528 | 'does not exist.', | ||
525 | ), | 529 | ), |
526 | 'The variable « unknownVar » does not exist.', | ||
527 | ), | 530 | ), |
528 | array( | 531 | array( |
529 | array( | 532 | array( |
530 | 'rss_config[rule]' => 'length(domainName) <= 42', | 533 | 'tagging_rule[rule]' => 'length(domainName) <= 42', |
531 | 'rss_config[tags]' => 'cool tag', | 534 | 'tagging_rule[tags]' => 'cool tag', |
535 | ), | ||
536 | array( | ||
537 | 'The operator', | ||
538 | 'does not exist.', | ||
532 | ), | 539 | ), |
533 | 'The operator « length » does not exist.', | ||
534 | ), | 540 | ), |
535 | ); | 541 | ); |
536 | } | 542 | } |
543 | |||
544 | /** | ||
545 | * @dataProvider dataForTaggingRuleFailed | ||
546 | */ | ||
547 | public function testTaggingRuleCreationFail($data, $messages) | ||
548 | { | ||
549 | $this->logInAs('admin'); | ||
550 | $client = $this->getClient(); | ||
551 | |||
552 | $crawler = $client->request('GET', '/config'); | ||
553 | |||
554 | $this->assertTrue($client->getResponse()->isSuccessful()); | ||
555 | |||
556 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | ||
557 | |||
558 | $client->submit($form, $data); | ||
559 | |||
560 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
561 | |||
562 | foreach ($messages as $message) { | ||
563 | $this->assertContains($message, $client->getResponse()->getContent()); | ||
564 | } | ||
565 | } | ||
566 | |||
567 | public function testDeletingTaggingRuleFromAnOtherUser() | ||
568 | { | ||
569 | $this->logInAs('bob'); | ||
570 | $client = $this->getClient(); | ||
571 | |||
572 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | ||
573 | ->getRepository('WallabagCoreBundle:TaggingRule') | ||
574 | ->findAll()[0]; | ||
575 | |||
576 | $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); | ||
577 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
578 | $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent()); | ||
579 | } | ||
537 | } | 580 | } |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 1d1620dc..32d6a575 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | |||
@@ -127,10 +127,35 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
127 | 127 | ||
128 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 128 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
129 | 129 | ||
130 | $crawler = $client->followRedirect(); | 130 | $content = $client->getContainer() |
131 | ->get('doctrine.orm.entity_manager') | ||
132 | ->getRepository('WallabagCoreBundle:Entry') | ||
133 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
134 | |||
135 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | ||
136 | $this->assertEquals($this->url, $content->getUrl()); | ||
137 | $this->assertContains('Google', $content->getTitle()); | ||
138 | } | ||
139 | |||
140 | public function testPostNewOkUrlExist() | ||
141 | { | ||
142 | $this->logInAs('admin'); | ||
143 | $client = $this->getClient(); | ||
144 | |||
145 | $crawler = $client->request('GET', '/new'); | ||
146 | |||
147 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
148 | |||
149 | $form = $crawler->filter('button[type=submit]')->form(); | ||
150 | |||
151 | $data = array( | ||
152 | 'entry[url]' => $this->url, | ||
153 | ); | ||
131 | 154 | ||
132 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); | 155 | $client->submit($form, $data); |
133 | $this->assertContains('Google', $alert[0]); | 156 | |
157 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
158 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | ||
134 | } | 159 | } |
135 | 160 | ||
136 | /** | 161 | /** |