]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
Added help on config screen
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / ConfigControllerTest.php
index 7193f9b0e4331976f2768557425af73ec36faa2a..d4fbe2d44221c4767a0f4c2f08ae7b9fd1dabfb9 100644 (file)
@@ -28,7 +28,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $this->assertCount(1, $crawler->filter('button[id=config_save]'));
         $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
         $this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
-        $this->assertCount(1, $crawler->filter('button[id=new_user_save]'));
         $this->assertCount(1, $crawler->filter('button[id=rss_config_save]'));
     }
 
@@ -56,8 +55,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->followRedirect();
 
-        $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text']));
-        $this->assertContains('flashes.config.notice.config_saved', $alert[0]);
+        $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]);
     }
 
     public function testChangeReadingSpeed()
@@ -213,8 +211,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->followRedirect();
 
-        $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text']));
-        $this->assertContains('flashes.config.notice.password_updated', $alert[0]);
+        $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]);
     }
 
     public function dataForUserFailed()
@@ -285,120 +282,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
     }
 
-    public function dataForNewUserFailed()
-    {
-        return [
-            [
-                [
-                    'new_user[username]' => '',
-                    'new_user[plainPassword][first]' => '',
-                    'new_user[plainPassword][second]' => '',
-                    'new_user[email]' => '',
-                ],
-                'fos_user.username.blank',
-            ],
-            [
-                [
-                    'new_user[username]' => 'a',
-                    'new_user[plainPassword][first]' => 'mypassword',
-                    'new_user[plainPassword][second]' => 'mypassword',
-                    'new_user[email]' => '',
-                ],
-                'fos_user.username.short',
-            ],
-            [
-                [
-                    'new_user[username]' => 'wallace',
-                    'new_user[plainPassword][first]' => 'mypassword',
-                    'new_user[plainPassword][second]' => 'mypassword',
-                    'new_user[email]' => 'test',
-                ],
-                'fos_user.email.invalid',
-            ],
-            [
-                [
-                    'new_user[username]' => 'admin',
-                    'new_user[plainPassword][first]' => 'wallacewallace',
-                    'new_user[plainPassword][second]' => 'wallacewallace',
-                    'new_user[email]' => 'wallace@wallace.me',
-                ],
-                'fos_user.username.already_used',
-            ],
-            [
-                [
-                    'new_user[username]' => 'wallace',
-                    'new_user[plainPassword][first]' => 'mypassword1',
-                    'new_user[plainPassword][second]' => 'mypassword2',
-                    'new_user[email]' => 'wallace@wallace.me',
-                ],
-                'validator.password_must_match',
-            ],
-        ];
-    }
-
-    /**
-     * @dataProvider dataForNewUserFailed
-     */
-    public function testNewUserFailed($data, $expectedMessage)
-    {
-        $this->logInAs('admin');
-        $client = $this->getClient();
-
-        $crawler = $client->request('GET', '/config');
-
-        $this->assertEquals(200, $client->getResponse()->getStatusCode());
-
-        $form = $crawler->filter('button[id=new_user_save]')->form();
-
-        $crawler = $client->submit($form, $data);
-
-        $this->assertEquals(200, $client->getResponse()->getStatusCode());
-
-        $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
-        $this->assertContains($expectedMessage, $alert[0]);
-    }
-
-    public function testNewUserCreated()
-    {
-        $this->logInAs('admin');
-        $client = $this->getClient();
-
-        $crawler = $client->request('GET', '/config');
-
-        $this->assertEquals(200, $client->getResponse()->getStatusCode());
-
-        $form = $crawler->filter('button[id=new_user_save]')->form();
-
-        $data = [
-            'new_user[username]' => 'wallace',
-            'new_user[plainPassword][first]' => 'wallace1',
-            'new_user[plainPassword][second]' => 'wallace1',
-            'new_user[email]' => 'wallace@wallace.me',
-        ];
-
-        $client->submit($form, $data);
-
-        $this->assertEquals(302, $client->getResponse()->getStatusCode());
-
-        $crawler = $client->followRedirect();
-
-        $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text']));
-        $this->assertContains('flashes.config.notice.user_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());
-        $this->assertEquals('material', $user->getConfig()->getTheme());
-        $this->assertEquals(12, $user->getConfig()->getItemsPerPage());
-        $this->assertEquals(50, $user->getConfig()->getRssLimit());
-        $this->assertEquals('en', $user->getConfig()->getLanguage());
-        $this->assertEquals(1, $user->getConfig()->getReadingSpeed());
-    }
-
     public function testRssUpdateResetToken()
     {
         $this->logInAs('admin');
@@ -474,8 +357,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->followRedirect();
 
-        $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text']));
-        $this->assertContains('flashes.config.notice.rss_updated', $alert[0]);
+        $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]);
     }
 
     public function dataForRssFailed()
@@ -491,7 +373,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
                 [
                     'rss_config[rss_limit]' => 1000000000000,
                 ],
-                'validator.rss_limit_too_hight',
+                'validator.rss_limit_too_high',
             ],
         ];
     }
@@ -540,8 +422,32 @@ class ConfigControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->followRedirect();
 
-        $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text']));
-        $this->assertContains('flashes.config.notice.tagging_rules_updated', $alert[0]);
+        $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
+
+        $editLink = $crawler->filter('.mode_edit')->last()->link();
+
+        $crawler = $client->click($editLink);
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+        $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location'));
+
+        $crawler = $client->followRedirect();
+
+        $form = $crawler->filter('button[id=tagging_rule_save]')->form();
+
+        $data = [
+            'tagging_rule[rule]' => 'readingTime <= 30',
+            'tagging_rule[tags]' => 'short reading',
+        ];
+
+        $client->submit($form, $data);
+
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+        $crawler = $client->followRedirect();
+
+        $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
+
+        $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
 
         $deleteLink = $crawler->filter('.delete')->last()->link();
 
@@ -549,8 +455,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $this->assertEquals(302, $client->getResponse()->getStatusCode());
 
         $crawler = $client->followRedirect();
-        $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text']));
-        $this->assertContains('flashes.config.notice.tagging_rules_deleted', $alert[0]);
+        $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
     }
 
     public function dataForTaggingRuleFailed()
@@ -613,7 +518,23 @@ class ConfigControllerTest extends WallabagCoreTestCase
             ->getRepository('WallabagCoreBundle:TaggingRule')
             ->findAll()[0];
 
-        $crawler = $client->request('GET', '/tagging-rule/delete/'.$rule->getId());
+        $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId());
+
+        $this->assertEquals(403, $client->getResponse()->getStatusCode());
+        $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
+        $this->assertContains('You can not access this tagging rule', $body[0]);
+    }
+
+    public function testEditingTaggingRuleFromAnOtherUser()
+    {
+        $this->logInAs('bob');
+        $client = $this->getClient();
+
+        $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:TaggingRule')
+            ->findAll()[0];
+
+        $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId());
 
         $this->assertEquals(403, $client->getResponse()->getStatusCode());
         $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));