2016-09-30 18:09:06 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Tests\Wallabag\Controller;
|
2016-09-30 18:09:06 +00:00
|
|
|
|
2024-02-24 19:24:51 +00:00
|
|
|
use Tests\Wallabag\WallabagTestCase;
|
2016-09-30 18:09:06 +00:00
|
|
|
|
2024-02-24 19:24:51 +00:00
|
|
|
class UserControllerTest extends WallabagTestCase
|
2016-09-30 18:09:06 +00:00
|
|
|
{
|
|
|
|
public function testLogin()
|
|
|
|
{
|
2022-11-23 16:09:32 +00:00
|
|
|
$client = $this->getTestClient();
|
2016-09-30 18:09:06 +00:00
|
|
|
|
2017-04-29 17:39:51 +00:00
|
|
|
$client->request('GET', '/users/list');
|
2016-09-30 18:09:06 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('login', $client->getResponse()->headers->get('location'));
|
2016-09-30 18:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCompleteScenario()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
2022-11-23 16:09:32 +00:00
|
|
|
$client = $this->getTestClient();
|
2016-09-30 18:09:06 +00:00
|
|
|
|
|
|
|
// Create a new user in the database
|
2017-04-29 17:39:51 +00:00
|
|
|
$crawler = $client->request('GET', '/users/list');
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode(), 'Unexpected HTTP status code for GET /users/');
|
2016-09-30 18:09:06 +00:00
|
|
|
$crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link());
|
|
|
|
|
|
|
|
// Fill in the form and submit it
|
2017-07-01 07:52:38 +00:00
|
|
|
$form = $crawler->selectButton('user.form.save')->form([
|
2016-09-30 18:09:06 +00:00
|
|
|
'new_user[username]' => 'test_user',
|
|
|
|
'new_user[email]' => 'test@test.io',
|
2017-05-30 05:56:41 +00:00
|
|
|
'new_user[plainPassword][first]' => 'testtest',
|
|
|
|
'new_user[plainPassword][second]' => 'testtest',
|
2017-07-01 07:52:38 +00:00
|
|
|
]);
|
2016-09-30 18:09:06 +00:00
|
|
|
|
|
|
|
$client->submit($form);
|
|
|
|
$client->followRedirect();
|
2017-04-29 17:39:51 +00:00
|
|
|
$crawler = $client->request('GET', '/users/list');
|
2016-09-30 18:09:06 +00:00
|
|
|
|
|
|
|
// 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());
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$form = $crawler->selectButton('user.form.save')->form([
|
2016-09-30 18:09:06 +00:00
|
|
|
'user[name]' => 'Foo User',
|
|
|
|
'user[username]' => 'test_user',
|
|
|
|
'user[email]' => 'test@test.io',
|
|
|
|
'user[enabled]' => true,
|
2017-07-01 07:52:38 +00:00
|
|
|
]);
|
2016-09-30 18:09:06 +00:00
|
|
|
|
|
|
|
$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"]');
|
|
|
|
|
2017-04-29 17:39:51 +00:00
|
|
|
$crawler = $client->request('GET', '/users/list');
|
2016-09-30 18:09:06 +00:00
|
|
|
$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
|
2022-01-31 08:27:20 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/Foo User/', $client->getResponse()->getContent());
|
2016-09-30 18:09:06 +00:00
|
|
|
}
|
2016-10-02 11:21:45 +00:00
|
|
|
|
|
|
|
public function testDeleteDisabledForLoggedUser()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
2022-11-23 16:09:32 +00:00
|
|
|
$client = $this->getTestClient();
|
2016-10-02 11:21:45 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$crawler = $client->request('GET', '/users/' . $this->getLoggedInUserId() . '/edit');
|
2023-08-07 21:40:16 +00:00
|
|
|
$disabled = $crawler->selectButton('user.form.delete')->extract(['disabled']);
|
2016-10-02 11:21:45 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame('disabled', $disabled[0]);
|
2016-10-02 11:21:45 +00:00
|
|
|
}
|
2017-04-27 14:40:18 +00:00
|
|
|
|
|
|
|
public function testUserSearch()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
2022-11-23 16:09:32 +00:00
|
|
|
$client = $this->getTestClient();
|
2017-04-27 14:40:18 +00:00
|
|
|
|
|
|
|
// Search on unread list
|
2017-04-29 17:39:51 +00:00
|
|
|
$crawler = $client->request('GET', '/users/list');
|
2017-04-27 14:40:18 +00:00
|
|
|
|
|
|
|
$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
|
|
|
|
}
|
2016-09-30 18:09:06 +00:00
|
|
|
}
|