]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
Remove user reference in tag
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / ConfigControllerTest.php
index 116eec602f241c9f67aaf5fb06b945924fde5277..89ca31e2942b3f2288fe5f703d016174953ba9db 100644 (file)
@@ -44,9 +44,9 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $form = $crawler->filter('button[id=config_save]')->form();
 
         $data = array(
-            'config[theme]' => 0,
+            'config[theme]' => 'baggy',
             'config[items_per_page]' => '30',
-            'config[language]' => 'fr_FR',
+            'config[language]' => 'en',
         );
 
         $client->submit($form, $data);
@@ -63,14 +63,9 @@ class ConfigControllerTest extends WallabagCoreTestCase
     {
         return array(
             array(array(
-                'config[theme]' => 0,
+                'config[theme]' => 'baggy',
                 'config[items_per_page]' => '',
-                'config[language]' => 'fr_FR',
-            )),
-            array(array(
-                'config[theme]' => 0,
-                'config[items_per_page]' => '12',
-                'config[language]' => '',
+                'config[language]' => 'en',
             )),
         );
     }
@@ -258,7 +253,8 @@ class ConfigControllerTest extends WallabagCoreTestCase
             array(
                 array(
                     'new_user[username]' => '',
-                    'new_user[password]' => '',
+                    'new_user[plainPassword][first]' => '',
+                    'new_user[plainPassword][second]' => '',
                     'new_user[email]' => '',
                 ),
                 'Please enter a username',
@@ -266,7 +262,8 @@ class ConfigControllerTest extends WallabagCoreTestCase
             array(
                 array(
                     'new_user[username]' => 'a',
-                    'new_user[password]' => 'mypassword',
+                    'new_user[plainPassword][first]' => 'mypassword',
+                    'new_user[plainPassword][second]' => 'mypassword',
                     'new_user[email]' => '',
                 ),
                 'The username is too short',
@@ -274,7 +271,8 @@ class ConfigControllerTest extends WallabagCoreTestCase
             array(
                 array(
                     'new_user[username]' => 'wallace',
-                    'new_user[password]' => 'mypassword',
+                    'new_user[plainPassword][first]' => 'mypassword',
+                    'new_user[plainPassword][second]' => 'mypassword',
                     'new_user[email]' => 'test',
                 ),
                 'The email is not valid',
@@ -282,11 +280,21 @@ class ConfigControllerTest extends WallabagCoreTestCase
             array(
                 array(
                     'new_user[username]' => 'admin',
-                    'new_user[password]' => 'wallacewallace',
+                    'new_user[plainPassword][first]' => 'wallacewallace',
+                    'new_user[plainPassword][second]' => 'wallacewallace',
                     'new_user[email]' => 'wallace@wallace.me',
                 ),
                 'The username is already used',
             ),
+            array(
+                array(
+                    'new_user[username]' => 'wallace',
+                    'new_user[plainPassword][first]' => 'mypassword1',
+                    'new_user[plainPassword][second]' => 'mypassword2',
+                    'new_user[email]' => 'wallace@wallace.me',
+                ),
+                'This value is not valid',
+            ),
         );
     }
 
@@ -325,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',
         );
 
@@ -337,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()
@@ -347,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) {
@@ -462,4 +479,59 @@ 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(
+                    'rss_config[rule]' => 'unknownVar <= 3',
+                    'rss_config[tags]' => 'cool tag',
+                ),
+                'The variable « unknownVar » does not exist.',
+            ),
+            array(
+                array(
+                    'rss_config[rule]' => 'length(domainName) <= 42',
+                    'rss_config[tags]' => 'cool tag',
+                ),
+                'The operator « length » does not exist.',
+            ),
+        );
+    }
 }