]>
Commit | Line | Data |
---|---|---|
152fcccd JB |
1 | <?php |
2 | ||
3 | namespace Wallabag\UserBundle\Tests\Controller; | |
4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |
6 | ||
7 | class ManageControllerTest extends WallabagCoreTestCase | |
8 | { | |
9 | public function testLogin() | |
10 | { | |
11 | $client = $this->getClient(); | |
12 | ||
d01dc5a8 | 13 | $client->request('GET', '/users/list'); |
152fcccd | 14 | |
f808b016 | 15 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
152fcccd JB |
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 | |
d01dc5a8 | 25 | $crawler = $client->request('GET', '/users/list'); |
f808b016 | 26 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 'Unexpected HTTP status code for GET /users/'); |
152fcccd JB |
27 | $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link()); |
28 | ||
29 | // Fill in the form and submit it | |
f808b016 | 30 | $form = $crawler->selectButton('user.form.save')->form([ |
152fcccd JB |
31 | 'new_user[username]' => 'test_user', |
32 | 'new_user[email]' => 'test@test.io', | |
d069bff4 JB |
33 | 'new_user[plainPassword][first]' => 'testtest', |
34 | 'new_user[plainPassword][second]' => 'testtest', | |
f808b016 | 35 | ]); |
152fcccd JB |
36 | |
37 | $client->submit($form); | |
38 | $client->followRedirect(); | |
d01dc5a8 | 39 | $crawler = $client->request('GET', '/users/list'); |
152fcccd JB |
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 | ||
f808b016 | 47 | $form = $crawler->selectButton('user.form.save')->form([ |
152fcccd JB |
48 | 'user[name]' => 'Foo User', |
49 | 'user[username]' => 'test_user', | |
50 | 'user[email]' => 'test@test.io', | |
51 | 'user[enabled]' => true, | |
f808b016 | 52 | ]); |
152fcccd JB |
53 | |
54 | $client->submit($form); | |
55 | $crawler = $client->followRedirect(); | |
56 | ||
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"]'); | |
59 | ||
d01dc5a8 | 60 | $crawler = $client->request('GET', '/users/list'); |
152fcccd JB |
61 | $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); |
62 | ||
63 | // Delete the user | |
64 | $client->submit($crawler->selectButton('user.form.delete')->form()); | |
65 | $crawler = $client->followRedirect(); | |
66 | ||
67 | // Check the user has been delete on the list | |
68 | $this->assertNotRegExp('/Foo User/', $client->getResponse()->getContent()); | |
69 | } | |
ccc7faec JB |
70 | |
71 | public function testDeleteDisabledForLoggedUser() | |
72 | { | |
73 | $this->logInAs('admin'); | |
74 | $client = $this->getClient(); | |
75 | ||
f808b016 | 76 | $crawler = $client->request('GET', '/users/' . $this->getLoggedInUserId() . '/edit'); |
ccc7faec JB |
77 | $disabled = $crawler->selectButton('user.form.delete')->extract('disabled'); |
78 | ||
f808b016 | 79 | $this->assertSame('disabled', $disabled[0]); |
ccc7faec | 80 | } |
a2daa32d TC |
81 | |
82 | public function testUserSearch() | |
83 | { | |
84 | $this->logInAs('admin'); | |
85 | $client = $this->getClient(); | |
86 | ||
87 | // Search on unread list | |
d01dc5a8 | 88 | $crawler = $client->request('GET', '/users/list'); |
a2daa32d TC |
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 | } | |
152fcccd | 99 | } |