From 27ea492cf72657a7ba2deb3d45302923ddd289b8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 21 Jan 2016 16:36:17 +0100 Subject: Add tests on TagAllCommand Some simple tests --- .../CoreBundle/Tests/Command/TagAllCommandTest.php | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Tests/Command/TagAllCommandTest.php (limited to 'src/Wallabag/CoreBundle/Tests') 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 @@ +getClient()->getKernel()); + $application->add(new TagAllCommand()); + + $command = $application->find('wallabag:tag:all'); + + $tester = new CommandTester($command); + $tester->execute(array( + 'command' => $command->getName(), + )); + } + + public function testRunTagAllCommandWithBadUsername() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new TagAllCommand()); + + $command = $application->find('wallabag:tag:all'); + + $tester = new CommandTester($command); + $tester->execute(array( + 'command' => $command->getName(), + 'username' => 'unknown', + )); + + $this->assertContains('User "unknown" not found', $tester->getDisplay()); + } + + public function testRunTagAllCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new TagAllCommand()); + + $command = $application->find('wallabag:tag:all'); + + $tester = new CommandTester($command); + $tester->execute(array( + 'command' => $command->getName(), + 'username' => 'admin', + )); + + $this->assertContains('Tagging entries for user « admin »... Done', $tester->getDisplay()); + } +} -- cgit v1.2.3 From a0d6ccc5ca0dc0082467cc65b006150aff2488c4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 21 Jan 2016 16:37:25 +0100 Subject: Fix bad type after using findByUrlAndUserId It returns an object since few commits this part of (untested) code still use an array. Also add test for that part of code. --- .../Tests/Controller/EntryControllerTest.php | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests') 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 $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $crawler = $client->followRedirect(); + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + + $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); + $this->assertEquals($this->url, $content->getUrl()); + $this->assertContains('Google', $content->getTitle()); + } + + public function testPostNewOkUrlExist() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[type=submit]')->form(); + + $data = array( + 'entry[url]' => $this->url, + ); - $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); - $this->assertContains('Google', $alert[0]); + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); } /** -- cgit v1.2.3 From a3cac44c78a1d798e3282daa6b8c3e59e8ebc690 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 21 Jan 2016 18:06:10 +0100 Subject: Add for deleting rule from an other user --- .../Tests/Controller/ConfigControllerTest.php | 55 +++++++++++++++++++--- 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests') 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 return array( array( array( - 'rss_config[rule]' => 'unknownVar <= 3', - 'rss_config[tags]' => 'cool tag', + 'tagging_rule[rule]' => 'unknownVar <= 3', + 'tagging_rule[tags]' => 'cool tag', + ), + array( + 'The variable', + 'does not exist.', ), - 'The variable « unknownVar » does not exist.', ), array( array( - 'rss_config[rule]' => 'length(domainName) <= 42', - 'rss_config[tags]' => 'cool tag', + 'tagging_rule[rule]' => 'length(domainName) <= 42', + 'tagging_rule[tags]' => 'cool tag', + ), + array( + 'The operator', + 'does not exist.', ), - 'The operator « length » does not exist.', ), ); } + + /** + * @dataProvider dataForTaggingRuleFailed + */ + public function testTaggingRuleCreationFail($data, $messages) + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config'); + + $this->assertTrue($client->getResponse()->isSuccessful()); + + $form = $crawler->filter('button[id=tagging_rule_save]')->form(); + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + foreach ($messages as $message) { + $this->assertContains($message, $client->getResponse()->getContent()); + } + } + + public function testDeletingTaggingRuleFromAnOtherUser() + { + $this->logInAs('bob'); + $client = $this->getClient(); + + $rule = $client->getContainer()->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:TaggingRule') + ->findAll()[0]; + + $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); + $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent()); + } } -- cgit v1.2.3