aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/UserBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/UserBundle')
-rw-r--r--tests/Wallabag/UserBundle/Controller/ManageControllerTest.php30
-rw-r--r--tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php66
2 files changed, 90 insertions, 6 deletions
diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
index 4faddfc4..b46256a6 100644
--- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
+++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
@@ -10,7 +10,7 @@ class ManageControllerTest extends WallabagCoreTestCase
10 { 10 {
11 $client = $this->getClient(); 11 $client = $this->getClient();
12 12
13 $client->request('GET', '/users/'); 13 $client->request('GET', '/users/list');
14 14
15 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers->get('location')); 16 $this->assertContains('login', $client->getResponse()->headers->get('location'));
@@ -22,7 +22,7 @@ class ManageControllerTest extends WallabagCoreTestCase
22 $client = $this->getClient(); 22 $client = $this->getClient();
23 23
24 // Create a new user in the database 24 // Create a new user in the database
25 $crawler = $client->request('GET', '/users/'); 25 $crawler = $client->request('GET', '/users/list');
26 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Unexpected HTTP status code for GET /users/'); 26 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Unexpected HTTP status code for GET /users/');
27 $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link()); 27 $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link());
28 28
@@ -30,13 +30,13 @@ class ManageControllerTest extends WallabagCoreTestCase
30 $form = $crawler->selectButton('user.form.save')->form(array( 30 $form = $crawler->selectButton('user.form.save')->form(array(
31 'new_user[username]' => 'test_user', 31 'new_user[username]' => 'test_user',
32 'new_user[email]' => 'test@test.io', 32 'new_user[email]' => 'test@test.io',
33 'new_user[plainPassword][first]' => 'test', 33 'new_user[plainPassword][first]' => 'testtest',
34 'new_user[plainPassword][second]' => 'test', 34 'new_user[plainPassword][second]' => 'testtest',
35 )); 35 ));
36 36
37 $client->submit($form); 37 $client->submit($form);
38 $client->followRedirect(); 38 $client->followRedirect();
39 $crawler = $client->request('GET', '/users/'); 39 $crawler = $client->request('GET', '/users/list');
40 40
41 // Check data in the show view 41 // Check data in the show view
42 $this->assertGreaterThan(0, $crawler->filter('td:contains("test_user")')->count(), 'Missing element td:contains("test_user")'); 42 $this->assertGreaterThan(0, $crawler->filter('td:contains("test_user")')->count(), 'Missing element td:contains("test_user")');
@@ -57,7 +57,7 @@ class ManageControllerTest extends WallabagCoreTestCase
57 // Check the element contains an attribute with value equals "Foo User" 57 // Check the element contains an attribute with value equals "Foo User"
58 $this->assertGreaterThan(0, $crawler->filter('[value="Foo User"]')->count(), 'Missing element [value="Foo User"]'); 58 $this->assertGreaterThan(0, $crawler->filter('[value="Foo User"]')->count(), 'Missing element [value="Foo User"]');
59 59
60 $crawler = $client->request('GET', '/users/'); 60 $crawler = $client->request('GET', '/users/list');
61 $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); 61 $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link());
62 62
63 // Delete the user 63 // Delete the user
@@ -78,4 +78,22 @@ class ManageControllerTest extends WallabagCoreTestCase
78 78
79 $this->assertEquals('disabled', $disabled[0]); 79 $this->assertEquals('disabled', $disabled[0]);
80 } 80 }
81
82 public function testUserSearch()
83 {
84 $this->logInAs('admin');
85 $client = $this->getClient();
86
87 // Search on unread list
88 $crawler = $client->request('GET', '/users/list');
89
90 $form = $crawler->filter('form[name=search_users]')->form();
91 $data = [
92 'search_user[term]' => 'admin',
93 ];
94
95 $crawler = $client->submit($form, $data);
96
97 $this->assertCount(2, $crawler->filter('tr')); // 1 result + table header
98 }
81} 99}
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 @@
1<?php
2
3namespace Tests\Wallabag\UserBundle\EventListener;
4
5use Symfony\Component\EventDispatcher\EventDispatcher;
6use Symfony\Component\HttpFoundation\Request;
7use Wallabag\UserBundle\EventListener\AuthenticationFailureListener;
8use Monolog\Logger;
9use Monolog\Handler\TestHandler;
10use Symfony\Component\HttpFoundation\RequestStack;
11use Symfony\Component\Security\Core\AuthenticationEvents;
12use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
13
14class AuthenticationFailureListenerTest extends \PHPUnit_Framework_TestCase
15{
16 private $requestStack;
17 private $logHandler;
18 private $listener;
19 private $dispatcher;
20
21 protected function setUp()
22 {
23 $request = Request::create('/');
24 $request->request->set('_username', 'admin');
25
26 $this->requestStack = new RequestStack();
27 $this->requestStack->push($request);
28
29 $this->logHandler = new TestHandler();
30 $logger = new Logger('test', [$this->logHandler]);
31
32 $this->listener = new AuthenticationFailureListener(
33 $this->requestStack,
34 $logger
35 );
36
37 $this->dispatcher = new EventDispatcher();
38 $this->dispatcher->addSubscriber($this->listener);
39 }
40
41 public function testOnAuthenticationFailure()
42 {
43 $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
44 ->disableOriginalConstructor()
45 ->getMock();
46
47 $exception = $this->getMockBuilder('Symfony\Component\Security\Core\Exception\AuthenticationException')
48 ->disableOriginalConstructor()
49 ->getMock();
50
51 $event = new AuthenticationFailureEvent(
52 $token,
53 $exception
54 );
55
56 $this->dispatcher->dispatch(
57 AuthenticationEvents::AUTHENTICATION_FAILURE,
58 $event
59 );
60
61 $records = $this->logHandler->getRecords();
62
63 $this->assertCount(1, $records);
64 $this->assertSame('Authentication failure for user "admin", from IP "127.0.0.1", with UA: "Symfony/3.X".', $records[0]['message']);
65 }
66}