From 152fcccd4489378a8ed9391e3e191df4aeba6435 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 30 Sep 2016 20:09:06 +0200 Subject: Add users management UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove the “add a user” from the config page - add a CRUD on user - fix some missing translations (+ bad indentation) --- .../UserBundle/Controller/ManageControllerTest.php | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/Wallabag/UserBundle/Controller/ManageControllerTest.php (limited to 'tests') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php new file mode 100644 index 00000000..247eb6ba --- /dev/null +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -0,0 +1,71 @@ +getClient(); + + $client->request('GET', '/users/'); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('login', $client->getResponse()->headers->get('location')); + } + + public function testCompleteScenario() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + // Create a new user in the database + $crawler = $client->request('GET', '/users/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /users/"); + $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('user.form.save')->form(array( + 'new_user[username]' => 'test_user', + 'new_user[email]' => 'test@test.io', + 'new_user[plainPassword][first]' => 'test', + 'new_user[plainPassword][second]' => 'test', + )); + + $client->submit($form); + $client->followRedirect(); + $crawler = $client->request('GET', '/users/'); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("test_user")')->count(), 'Missing element td:contains("test_user")'); + + // Edit the user + $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); + + $form = $crawler->selectButton('user.form.save')->form(array( + 'user[name]' => 'Foo User', + 'user[username]' => 'test_user', + 'user[email]' => 'test@test.io', + 'user[enabled]' => true, + 'user[locked]' => false, + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo User" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo User"]')->count(), 'Missing element [value="Foo User"]'); + + $crawler = $client->request('GET', '/users/'); + $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); + + // Delete the user + $client->submit($crawler->selectButton('user.form.delete')->form()); + $crawler = $client->followRedirect(); + + // Check the user has been delete on the list + $this->assertNotRegExp('/Foo User/', $client->getResponse()->getContent()); + } +} -- cgit v1.2.3 From eb4142e0afa5c83c9e301e38e57a72322be05e8c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 01:32:23 +0200 Subject: Remove NewUser test from Config --- .../CoreBundle/Controller/ConfigControllerTest.php | 114 --------------------- 1 file changed, 114 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index bb3ea9e2..1954c654 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -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]')); } @@ -283,119 +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->assertContains('flashes.config.notice.user_added', $crawler->filter('body')->extract(['_text'])[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'); -- cgit v1.2.3 From ccc7faec094387681a59faa5ca79a86e33f06972 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 13:21:45 +0200 Subject: Disabled delete button for the logged user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid some bad things to happen… --- tests/Wallabag/UserBundle/Controller/ManageControllerTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index 247eb6ba..19b824b8 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -68,4 +68,15 @@ class ManageControllerTest extends WallabagCoreTestCase // Check the user has been delete on the list $this->assertNotRegExp('/Foo User/', $client->getResponse()->getContent()); } + + public function testDeleteDisabledForLoggedUser() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/users/'.$this->getLoggedInUserId().'/edit'); + $disabled = $crawler->selectButton('user.form.delete')->extract('disabled'); + + $this->assertEquals('disabled', $disabled[0]); + } } -- cgit v1.2.3