aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-10-02 15:00:02 +0200
committerGitHub <noreply@github.com>2016-10-02 15:00:02 +0200
commit1dc3bee6b916b228c596a45d20dc6ae14ac555cb (patch)
tree2d3573ebc6e6fbd71dd63f15653f3347cde8164e /tests/Wallabag
parent18b8dc0e9984fce01b231810347fef7d32c06ac7 (diff)
parentccc7faec094387681a59faa5ca79a86e33f06972 (diff)
downloadwallabag-1dc3bee6b916b228c596a45d20dc6ae14ac555cb.tar.gz
wallabag-1dc3bee6b916b228c596a45d20dc6ae14ac555cb.tar.zst
wallabag-1dc3bee6b916b228c596a45d20dc6ae14ac555cb.zip
Merge pull request #2327 from wallabag/user-management
Add users management UI
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php114
-rw-r--r--tests/Wallabag/UserBundle/Controller/ManageControllerTest.php82
2 files changed, 82 insertions, 114 deletions
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
28 $this->assertCount(1, $crawler->filter('button[id=config_save]')); 28 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); 29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
30 $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); 30 $this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
31 $this->assertCount(1, $crawler->filter('button[id=new_user_save]'));
32 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); 31 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]'));
33 } 32 }
34 33
@@ -283,119 +282,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
283 $this->assertContains('flashes.config.notice.user_updated', $alert[0]); 282 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
284 } 283 }
285 284
286 public function dataForNewUserFailed()
287 {
288 return [
289 [
290 [
291 'new_user[username]' => '',
292 'new_user[plainPassword][first]' => '',
293 'new_user[plainPassword][second]' => '',
294 'new_user[email]' => '',
295 ],
296 'fos_user.username.blank',
297 ],
298 [
299 [
300 'new_user[username]' => 'a',
301 'new_user[plainPassword][first]' => 'mypassword',
302 'new_user[plainPassword][second]' => 'mypassword',
303 'new_user[email]' => '',
304 ],
305 'fos_user.username.short',
306 ],
307 [
308 [
309 'new_user[username]' => 'wallace',
310 'new_user[plainPassword][first]' => 'mypassword',
311 'new_user[plainPassword][second]' => 'mypassword',
312 'new_user[email]' => 'test',
313 ],
314 'fos_user.email.invalid',
315 ],
316 [
317 [
318 'new_user[username]' => 'admin',
319 'new_user[plainPassword][first]' => 'wallacewallace',
320 'new_user[plainPassword][second]' => 'wallacewallace',
321 'new_user[email]' => 'wallace@wallace.me',
322 ],
323 'fos_user.username.already_used',
324 ],
325 [
326 [
327 'new_user[username]' => 'wallace',
328 'new_user[plainPassword][first]' => 'mypassword1',
329 'new_user[plainPassword][second]' => 'mypassword2',
330 'new_user[email]' => 'wallace@wallace.me',
331 ],
332 'validator.password_must_match',
333 ],
334 ];
335 }
336
337 /**
338 * @dataProvider dataForNewUserFailed
339 */
340 public function testNewUserFailed($data, $expectedMessage)
341 {
342 $this->logInAs('admin');
343 $client = $this->getClient();
344
345 $crawler = $client->request('GET', '/config');
346
347 $this->assertEquals(200, $client->getResponse()->getStatusCode());
348
349 $form = $crawler->filter('button[id=new_user_save]')->form();
350
351 $crawler = $client->submit($form, $data);
352
353 $this->assertEquals(200, $client->getResponse()->getStatusCode());
354
355 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
356 $this->assertContains($expectedMessage, $alert[0]);
357 }
358
359 public function testNewUserCreated()
360 {
361 $this->logInAs('admin');
362 $client = $this->getClient();
363
364 $crawler = $client->request('GET', '/config');
365
366 $this->assertEquals(200, $client->getResponse()->getStatusCode());
367
368 $form = $crawler->filter('button[id=new_user_save]')->form();
369
370 $data = [
371 'new_user[username]' => 'wallace',
372 'new_user[plainPassword][first]' => 'wallace1',
373 'new_user[plainPassword][second]' => 'wallace1',
374 'new_user[email]' => 'wallace@wallace.me',
375 ];
376
377 $client->submit($form, $data);
378
379 $this->assertEquals(302, $client->getResponse()->getStatusCode());
380
381 $crawler = $client->followRedirect();
382
383 $this->assertContains('flashes.config.notice.user_added', $crawler->filter('body')->extract(['_text'])[0]);
384
385 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
386 $user = $em
387 ->getRepository('WallabagUserBundle:User')
388 ->findOneByUsername('wallace');
389
390 $this->assertTrue(false !== $user);
391 $this->assertTrue($user->isEnabled());
392 $this->assertEquals('material', $user->getConfig()->getTheme());
393 $this->assertEquals(12, $user->getConfig()->getItemsPerPage());
394 $this->assertEquals(50, $user->getConfig()->getRssLimit());
395 $this->assertEquals('en', $user->getConfig()->getLanguage());
396 $this->assertEquals(1, $user->getConfig()->getReadingSpeed());
397 }
398
399 public function testRssUpdateResetToken() 285 public function testRssUpdateResetToken()
400 { 286 {
401 $this->logInAs('admin'); 287 $this->logInAs('admin');
diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
new file mode 100644
index 00000000..19b824b8
--- /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}