From a2daa32d0c6f71aa8553aed3c6ed58d7aa861baa Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 27 Apr 2017 16:40:18 +0200 Subject: Fix tests Signed-off-by: Thomas Citharel --- .../UserBundle/Controller/ManageControllerTest.php | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/UserBundle') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index 4faddfc4..4154ad12 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -10,7 +10,7 @@ class ManageControllerTest extends WallabagCoreTestCase { $client = $this->getClient(); - $client->request('GET', '/users/'); + $client->request('GET', '/users/index'); $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertContains('login', $client->getResponse()->headers->get('location')); @@ -22,7 +22,7 @@ class ManageControllerTest extends WallabagCoreTestCase $client = $this->getClient(); // Create a new user in the database - $crawler = $client->request('GET', '/users/'); + $crawler = $client->request('GET', '/users/index'); $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Unexpected HTTP status code for GET /users/'); $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link()); @@ -36,7 +36,7 @@ class ManageControllerTest extends WallabagCoreTestCase $client->submit($form); $client->followRedirect(); - $crawler = $client->request('GET', '/users/'); + $crawler = $client->request('GET', '/users/index'); // Check data in the show view $this->assertGreaterThan(0, $crawler->filter('td:contains("test_user")')->count(), 'Missing element td:contains("test_user")'); @@ -57,7 +57,7 @@ class ManageControllerTest extends WallabagCoreTestCase // 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->request('GET', '/users/index'); $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); // Delete the user @@ -78,4 +78,22 @@ class ManageControllerTest extends WallabagCoreTestCase $this->assertEquals('disabled', $disabled[0]); } + + public function testUserSearch() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + // Search on unread list + $crawler = $client->request('GET', '/users/index'); + + $form = $crawler->filter('form[name=search_users]')->form(); + $data = [ + 'search_user[term]' => 'admin', + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(2, $crawler->filter('tr')); // 1 result + table header + } } -- cgit v1.2.3 From d01dc5a81e7fde37d98fe6b10b9329b53add5b6a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 29 Apr 2017 19:39:51 +0200 Subject: rename index to list Signed-off-by: Thomas Citharel --- tests/Wallabag/UserBundle/Controller/ManageControllerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/UserBundle') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index 4154ad12..44b9a030 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -10,7 +10,7 @@ class ManageControllerTest extends WallabagCoreTestCase { $client = $this->getClient(); - $client->request('GET', '/users/index'); + $client->request('GET', '/users/list'); $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertContains('login', $client->getResponse()->headers->get('location')); @@ -22,7 +22,7 @@ class ManageControllerTest extends WallabagCoreTestCase $client = $this->getClient(); // Create a new user in the database - $crawler = $client->request('GET', '/users/index'); + $crawler = $client->request('GET', '/users/list'); $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Unexpected HTTP status code for GET /users/'); $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link()); @@ -36,7 +36,7 @@ class ManageControllerTest extends WallabagCoreTestCase $client->submit($form); $client->followRedirect(); - $crawler = $client->request('GET', '/users/index'); + $crawler = $client->request('GET', '/users/list'); // Check data in the show view $this->assertGreaterThan(0, $crawler->filter('td:contains("test_user")')->count(), 'Missing element td:contains("test_user")'); @@ -57,7 +57,7 @@ class ManageControllerTest extends WallabagCoreTestCase // 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/index'); + $crawler = $client->request('GET', '/users/list'); $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); // Delete the user @@ -85,7 +85,7 @@ class ManageControllerTest extends WallabagCoreTestCase $client = $this->getClient(); // Search on unread list - $crawler = $client->request('GET', '/users/index'); + $crawler = $client->request('GET', '/users/list'); $form = $crawler->filter('form[name=search_users]')->form(); $data = [ -- cgit v1.2.3 From d069bff4f606be75c47a3415f2a5af13d6f04865 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 07:56:41 +0200 Subject: Remove unknown validation_groups The Profile validation_groups does not exist and then for validation to be skipped (like password length) --- tests/Wallabag/UserBundle/Controller/ManageControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/UserBundle') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index 44b9a030..b46256a6 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -30,8 +30,8 @@ class ManageControllerTest extends WallabagCoreTestCase $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', + 'new_user[plainPassword][first]' => 'testtest', + 'new_user[plainPassword][second]' => 'testtest', )); $client->submit($form); -- cgit v1.2.3 From f81a34e37929a822755d120215d2f18f042ff713 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Jun 2017 09:45:43 +0200 Subject: Use a listener to catch auth failure --- .../AuthenticationFailureListenerTest.php | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php (limited to 'tests/Wallabag/UserBundle') diff --git a/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php b/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php new file mode 100644 index 00000000..6191ea13 --- /dev/null +++ b/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php @@ -0,0 +1,66 @@ +request->set('_username', 'admin'); + + $this->requestStack = new RequestStack(); + $this->requestStack->push($request); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + + $this->listener = new AuthenticationFailureListener( + $this->requestStack, + $logger + ); + + $this->dispatcher = new EventDispatcher(); + $this->dispatcher->addSubscriber($this->listener); + } + + public function testOnAuthenticationFailure() + { + $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') + ->disableOriginalConstructor() + ->getMock(); + + $exception = $this->getMockBuilder('Symfony\Component\Security\Core\Exception\AuthenticationException') + ->disableOriginalConstructor() + ->getMock(); + + $event = new AuthenticationFailureEvent( + $token, + $exception + ); + + $this->dispatcher->dispatch( + AuthenticationEvents::AUTHENTICATION_FAILURE, + $event + ); + + $records = $this->logHandler->getRecords(); + + $this->assertCount(1, $records); + $this->assertSame('Authentication failure for user "admin", from IP "127.0.0.1", with UA: "Symfony/3.X".', $records[0]['message']); + } +} -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../UserBundle/Controller/ManageControllerTest.php | 16 ++++++++-------- .../EventListener/AuthenticationFailureListenerTest.php | 6 +++--- .../EventListener/CreateConfigListenerTest.php | 2 +- tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'tests/Wallabag/UserBundle') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index b46256a6..adc2cf09 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -12,7 +12,7 @@ class ManageControllerTest extends WallabagCoreTestCase $client->request('GET', '/users/list'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('login', $client->getResponse()->headers->get('location')); } @@ -23,16 +23,16 @@ class ManageControllerTest extends WallabagCoreTestCase // Create a new user in the database $crawler = $client->request('GET', '/users/list'); - $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Unexpected HTTP status code for GET /users/'); + $this->assertSame(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( + $form = $crawler->selectButton('user.form.save')->form([ 'new_user[username]' => 'test_user', 'new_user[email]' => 'test@test.io', 'new_user[plainPassword][first]' => 'testtest', 'new_user[plainPassword][second]' => 'testtest', - )); + ]); $client->submit($form); $client->followRedirect(); @@ -44,12 +44,12 @@ class ManageControllerTest extends WallabagCoreTestCase // Edit the user $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); - $form = $crawler->selectButton('user.form.save')->form(array( + $form = $crawler->selectButton('user.form.save')->form([ 'user[name]' => 'Foo User', 'user[username]' => 'test_user', 'user[email]' => 'test@test.io', 'user[enabled]' => true, - )); + ]); $client->submit($form); $crawler = $client->followRedirect(); @@ -73,10 +73,10 @@ class ManageControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $crawler = $client->request('GET', '/users/'.$this->getLoggedInUserId().'/edit'); + $crawler = $client->request('GET', '/users/' . $this->getLoggedInUserId() . '/edit'); $disabled = $crawler->selectButton('user.form.delete')->extract('disabled'); - $this->assertEquals('disabled', $disabled[0]); + $this->assertSame('disabled', $disabled[0]); } public function testUserSearch() diff --git a/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php b/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php index 6191ea13..9e33cdca 100644 --- a/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\UserBundle\EventListener; +use Monolog\Handler\TestHandler; +use Monolog\Logger; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; -use Wallabag\UserBundle\EventListener\AuthenticationFailureListener; -use Monolog\Logger; -use Monolog\Handler\TestHandler; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Security\Core\AuthenticationEvents; use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent; +use Wallabag\UserBundle\EventListener\AuthenticationFailureListener; class AuthenticationFailureListenerTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php index 01796ded..e5a145b8 100644 --- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php @@ -8,8 +8,8 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Wallabag\CoreBundle\Entity\Config; -use Wallabag\UserBundle\EventListener\CreateConfigListener; use Wallabag\UserBundle\Entity\User; +use Wallabag\UserBundle\EventListener\CreateConfigListener; class CreateConfigListenerTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php index 21412da6..7381ccf1 100644 --- a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php +++ b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php @@ -68,8 +68,8 @@ TWIG; $msg = $this->spool->getMessages()[0]; $this->assertArrayHasKey('test@wallabag.io', $msg->getTo()); - $this->assertEquals(['nobody@test.io' => 'wallabag test'], $msg->getFrom()); - $this->assertEquals('subject', $msg->getSubject()); + $this->assertSame(['nobody@test.io' => 'wallabag test'], $msg->getFrom()); + $this->assertSame('subject', $msg->getSubject()); $this->assertContains('text body http://0.0.0.0/support', $msg->toString()); $this->assertContains('html body 666666', $msg->toString()); } -- cgit v1.2.3