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