X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FTests%2FController%2FConfigControllerTest.php;h=c8807425aa031bcc82ee6cbf19aa6efb949b4552;hb=567421af5019bf5937aa2b4214b405d87a1f1f86;hp=3c1589229fdfde946f5b7f352b8dc9efd4de10e8;hpb=769e19dc4ab1a068e8165a7b237f42a78a6d312f;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 3c158922..c8807425 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -46,7 +46,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $data = array( 'config[theme]' => 'baggy', 'config[items_per_page]' => '30', - 'config[language]' => 'fr_FR', + 'config[language]' => 'en', ); $client->submit($form, $data); @@ -65,12 +65,7 @@ class ConfigControllerTest extends WallabagCoreTestCase array(array( 'config[theme]' => 'baggy', 'config[items_per_page]' => '', - 'config[language]' => 'fr_FR', - )), - array(array( - 'config[theme]' => 'baggy', - 'config[items_per_page]' => '12', - 'config[language]' => '', + 'config[language]' => 'en', )), ); } @@ -102,7 +97,7 @@ class ConfigControllerTest extends WallabagCoreTestCase return array( array( array( - 'change_passwd[old_password]' => 'baggy', + 'change_passwd[old_password]' => 'material', 'change_passwd[new_password][first]' => '', 'change_passwd[new_password][second]' => '', ), @@ -192,14 +187,14 @@ class ConfigControllerTest extends WallabagCoreTestCase 'update_user[name]' => '', 'update_user[email]' => '', ), - 'This value should not be blank.', + 'Please enter an email', ), array( array( 'update_user[name]' => '', 'update_user[email]' => 'test', ), - 'This value is not a valid email address.', + 'The email is not valid', ), ); } @@ -258,42 +253,47 @@ class ConfigControllerTest extends WallabagCoreTestCase array( array( 'new_user[username]' => '', - 'new_user[password]' => '', + 'new_user[plainPassword][first]' => '', + 'new_user[plainPassword][second]' => '', 'new_user[email]' => '', ), - 'This value should not be blank.', + 'Please enter a username', ), array( array( - 'new_user[username]' => 'ad', - 'new_user[password]' => '', + 'new_user[username]' => 'a', + 'new_user[plainPassword][first]' => 'mypassword', + 'new_user[plainPassword][second]' => 'mypassword', 'new_user[email]' => '', ), - 'This value is too short.', + 'The username is too short', ), array( array( 'new_user[username]' => 'wallace', - 'new_user[password]' => '', + 'new_user[plainPassword][first]' => 'mypassword', + 'new_user[plainPassword][second]' => 'mypassword', 'new_user[email]' => 'test', ), - 'This value is not a valid email address.', + 'The email is not valid', ), array( array( - 'new_user[username]' => 'wallace', - 'new_user[password]' => 'admin', + 'new_user[username]' => 'admin', + 'new_user[plainPassword][first]' => 'wallacewallace', + 'new_user[plainPassword][second]' => 'wallacewallace', 'new_user[email]' => 'wallace@wallace.me', ), - 'Password should by at least', + 'The username is already used', ), array( array( - 'new_user[username]' => 'admin', - 'new_user[password]' => 'wallacewallace', + 'new_user[username]' => 'wallace', + 'new_user[plainPassword][first]' => 'mypassword1', + 'new_user[plainPassword][second]' => 'mypassword2', 'new_user[email]' => 'wallace@wallace.me', ), - 'This value is already used', + 'This value is not valid', ), ); } @@ -333,7 +333,8 @@ class ConfigControllerTest extends WallabagCoreTestCase $data = array( 'new_user[username]' => 'wallace', - 'new_user[password]' => 'wallace1', + 'new_user[plainPassword][first]' => 'wallace1', + 'new_user[plainPassword][second]' => 'wallace1', 'new_user[email]' => 'wallace@wallace.me', ); @@ -345,6 +346,14 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); $this->assertContains('User "wallace" added', $alert[0]); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('wallace'); + + $this->assertTrue(false !== $user); + $this->assertTrue($user->isEnabled()); } public function testRssUpdateResetToken() @@ -355,7 +364,7 @@ class ConfigControllerTest extends WallabagCoreTestCase // reset the token $em = $client->getContainer()->get('doctrine.orm.entity_manager'); $user = $em - ->getRepository('WallabagCoreBundle:User') + ->getRepository('WallabagUserBundle:User') ->findOneByUsername('admin'); if (!$user) { @@ -397,7 +406,7 @@ class ConfigControllerTest extends WallabagCoreTestCase ); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $content = json_decode($client->getResponse()->getContent(), true);; + $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('token', $content); } @@ -470,4 +479,102 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); $this->assertContains($expectedMessage, $alert[0]); } + + public function testTaggingRuleCreation() + { + $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(); + + $data = array( + 'tagging_rule[rule]' => 'readingTime <= 3', + 'tagging_rule[tags]' => 'short reading', + ); + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); + $this->assertContains('Tagging rules updated', $alert[0]); + + $deleteLink = $crawler->filter('.delete')->last()->link(); + + $crawler = $client->click($deleteLink); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); + $this->assertContains('Tagging rule deleted', $alert[0]); + } + + public function dataForTaggingRuleFailed() + { + return array( + array( + array( + 'tagging_rule[rule]' => 'unknownVar <= 3', + 'tagging_rule[tags]' => 'cool tag', + ), + array( + 'The variable', + 'does not exist.', + ), + ), + array( + array( + 'tagging_rule[rule]' => 'length(domainName) <= 42', + 'tagging_rule[tags]' => 'cool tag', + ), + array( + 'The operator', + '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()); + } }