1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
namespace Wallabag\UserBundle\Tests\Controller;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
class ManageControllerTest extends WallabagCoreTestCase
{
public function testLogin()
{
$client = $this->getClient();
$client->request('GET', '/users/index');
$this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertContains('login', $client->getResponse()->headers->get('location'));
}
public function testCompleteScenario()
{
$this->logInAs('admin');
$client = $this->getClient();
// Create a new user in the database
$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());
// Fill in the form and submit it
$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',
));
$client->submit($form);
$client->followRedirect();
$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")');
// Edit the user
$crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link());
$form = $crawler->selectButton('user.form.save')->form(array(
'user[name]' => 'Foo User',
'user[username]' => 'test_user',
'user[email]' => 'test@test.io',
'user[enabled]' => true,
));
$client->submit($form);
$crawler = $client->followRedirect();
// 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->click($crawler->selectLink('user.list.edit_action')->last()->link());
// Delete the user
$client->submit($crawler->selectButton('user.form.delete')->form());
$crawler = $client->followRedirect();
// Check the user has been delete on the list
$this->assertNotRegExp('/Foo User/', $client->getResponse()->getContent());
}
public function testDeleteDisabledForLoggedUser()
{
$this->logInAs('admin');
$client = $this->getClient();
$crawler = $client->request('GET', '/users/'.$this->getLoggedInUserId().'/edit');
$disabled = $crawler->selectButton('user.form.delete')->extract('disabled');
$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
}
}
|