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.php82
-rw-r--r--tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php73
-rw-r--r--tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php2
3 files changed, 156 insertions, 1 deletions
diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
new file mode 100644
index 00000000..243a4459
--- /dev/null
+++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
@@ -0,0 +1,82 @@
1<?php
2
3namespace Wallabag\UserBundle\Tests\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6
7class ManageControllerTest extends WallabagCoreTestCase
8{
9 public function testLogin()
10 {
11 $client = $this->getClient();
12
13 $client->request('GET', '/users/');
14
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers->get('location'));
17 }
18
19 public function testCompleteScenario()
20 {
21 $this->logInAs('admin');
22 $client = $this->getClient();
23
24 // Create a new user in the database
25 $crawler = $client->request('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());
28
29 // Fill in the form and submit it
30 $form = $crawler->selectButton('user.form.save')->form(array(
31 'new_user[username]' => 'test_user',
32 'new_user[email]' => 'test@test.io',
33 'new_user[plainPassword][first]' => 'test',
34 'new_user[plainPassword][second]' => 'test',
35 ));
36
37 $client->submit($form);
38 $client->followRedirect();
39 $crawler = $client->request('GET', '/users/');
40
41 // Check data in the show view
42 $this->assertGreaterThan(0, $crawler->filter('td:contains("test_user")')->count(), 'Missing element td:contains("test_user")');
43
44 // Edit the user
45 $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link());
46
47 $form = $crawler->selectButton('user.form.save')->form(array(
48 'user[name]' => 'Foo User',
49 'user[username]' => 'test_user',
50 'user[email]' => 'test@test.io',
51 'user[enabled]' => true,
52 'user[locked]' => false,
53 ));
54
55 $client->submit($form);
56 $crawler = $client->followRedirect();
57
58 // Check the element contains an attribute with value equals "Foo User"
59 $this->assertGreaterThan(0, $crawler->filter('[value="Foo User"]')->count(), 'Missing element [value="Foo User"]');
60
61 $crawler = $client->request('GET', '/users/');
62 $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link());
63
64 // Delete the user
65 $client->submit($crawler->selectButton('user.form.delete')->form());
66 $crawler = $client->followRedirect();
67
68 // Check the user has been delete on the list
69 $this->assertNotRegExp('/Foo User/', $client->getResponse()->getContent());
70 }
71
72 public function testDeleteDisabledForLoggedUser()
73 {
74 $this->logInAs('admin');
75 $client = $this->getClient();
76
77 $crawler = $client->request('GET', '/users/'.$this->getLoggedInUserId().'/edit');
78 $disabled = $crawler->selectButton('user.form.delete')->extract('disabled');
79
80 $this->assertEquals('disabled', $disabled[0]);
81 }
82}
diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
new file mode 100644
index 00000000..a78b77bc
--- /dev/null
+++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
@@ -0,0 +1,73 @@
1<?php
2
3namespace Tests\Wallabag\UserBundle\EventListener;
4
5use FOS\UserBundle\Event\FilterUserResponseEvent;
6use FOS\UserBundle\FOSUserEvents;
7use Symfony\Component\EventDispatcher\EventDispatcher;
8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\HttpFoundation\Response;
10use Wallabag\CoreBundle\Entity\Config;
11use Wallabag\UserBundle\EventListener\CreateConfigListener;
12use Wallabag\UserBundle\Entity\User;
13
14class CreateConfigListenerTest extends \PHPUnit_Framework_TestCase
15{
16 private $em;
17 private $listener;
18 private $dispatcher;
19 private $request;
20 private $response;
21
22 protected function setUp()
23 {
24 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
25 ->disableOriginalConstructor()
26 ->getMock();
27
28 $this->listener = new CreateConfigListener(
29 $this->em,
30 'baggy',
31 20,
32 50,
33 'fr',
34 1
35 );
36
37 $this->dispatcher = new EventDispatcher();
38 $this->dispatcher->addSubscriber($this->listener);
39
40 $this->request = Request::create('/');
41 $this->response = Response::create();
42 }
43
44 public function testWithValidUser()
45 {
46 $user = new User();
47 $user->setEnabled(true);
48
49 $event = new FilterUserResponseEvent(
50 $user,
51 $this->request,
52 $this->response
53 );
54
55 $config = new Config($user);
56 $config->setTheme('baggy');
57 $config->setItemsPerPage(20);
58 $config->setRssLimit(50);
59 $config->setLanguage('fr');
60 $config->setReadingSpeed(1);
61
62 $this->em->expects($this->once())
63 ->method('persist')
64 ->will($this->returnValue($config));
65 $this->em->expects($this->once())
66 ->method('flush');
67
68 $this->dispatcher->dispatch(
69 FOSUserEvents::REGISTRATION_COMPLETED,
70 $event
71 );
72 }
73}
diff --git a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
index f670c925..441d6519 100644
--- a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
+++ b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
@@ -37,7 +37,7 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
37 ); 37 );
38 $this->mailer = new \Swift_Mailer($transport); 38 $this->mailer = new \Swift_Mailer($transport);
39 39
40 $twigTemplate = <<<TWIG 40 $twigTemplate = <<<'TWIG'
41{% block subject %}subject{% endblock %} 41{% block subject %}subject{% endblock %}
42{% block body_html %}html body {{ code }}{% endblock %} 42{% block body_html %}html body {{ code }}{% endblock %}
43{% block body_text %}text body {{ support_url }}{% endblock %} 43{% block body_text %}text body {{ support_url }}{% endblock %}