[TESTS] Fix Controller/SecurityTest

This commit is contained in:
Diogo Peralta Cordeiro 2022-03-06 23:06:12 +00:00
parent a37ce86d05
commit 9c9e86649a
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0

View File

@ -47,11 +47,11 @@ class SecurityTest extends GNUsocialTestCase
public function testLoginSuccess()
{
[, $crawler] = self::testLogin($nickname = 'taken_user', 'foobar');
$this->assertResponseIsSuccessful();
$this->assertSelectorNotExists('.alert');
[$client, $crawler] = self::testLogin($nickname = 'taken_user', 'foobar');
$this->assertRouteSame('root');
$this->assertSelectorTextContains('.profile-info .profile-info-nickname', $nickname);
$client->followRedirect();
$this->assertSelectorNotExists('.alert');
$this->assertSelectorTextContains('.profile-info-url-nickname', $nickname);
}
public function testLoginAttemptAlreadyLoggedIn()
@ -72,11 +72,11 @@ class SecurityTest extends GNUsocialTestCase
public function testLoginEmail()
{
self::testLogin('email@provider', 'foobar');
$this->assertResponseIsSuccessful();
$this->assertSelectorNotExists('.alert');
[$client, $crawler] = self::testLogin('taken_user@provider.any', 'foobar');
$this->assertRouteSame('root');
$this->assertSelectorTextContains('.profile-info .profile-info-nickname', 'taken_user');
$client->followRedirect();
$this->assertSelectorNotExists('.alert');
$this->assertSelectorTextContains('.profile-info-url-nickname', 'taken_user');
}
// --------- Register --------------
@ -97,13 +97,14 @@ class SecurityTest extends GNUsocialTestCase
public function testRegisterSuccess()
{
[$client,] = self::testRegister('new_nickname', 'new_email@email_provider', 'foobar');
[$client,] = self::testRegister('new_nickname', 'new_email@provider.any', 'foobar');
$this->assertResponseStatusCodeSame(302);
$crawler = $client->followRedirect();
$this->assertRouteSame('root');
$client->followRedirect();
$this->assertResponseIsSuccessful();
$this->assertSelectorNotExists('.alert');
$this->assertRouteSame('root');
$this->assertSelectorTextContains('.profile-info .profile-info-nickname', 'new_nickname');
$this->assertSelectorTextContains('.profile-info-url-nickname', 'new_nickname');
}
public function testRegisterDifferentPassword()
@ -113,7 +114,7 @@ class SecurityTest extends GNUsocialTestCase
$this->assertResponseIsSuccessful();
$crawler = $client->submitForm('Register', [
'register[nickname]' => 'new_user',
'register[email]' => 'new_email@provider',
'register[email]' => 'new_email@provider.any',
'register[password][first]' => 'fooobar',
'register[password][second]' => 'barquux',
]);
@ -124,9 +125,9 @@ class SecurityTest extends GNUsocialTestCase
private function testRegisterPasswordLength(string $password, string $error)
{
self::testRegister('new_nickname', 'email@provider', $password);
[$client, ] = self::testRegister('new_nickname', 'email@provider.any', $password);
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('.help-block > ul > li', $error);
$this->assertSelectorTextContains('.form-error', $error);
$this->assertRouteSame('security_register');
}
@ -147,17 +148,17 @@ class SecurityTest extends GNUsocialTestCase
private function testRegisterNoEmail()
{
self::testRegister('new_nickname', '', 'foobar');
[$client, ] = self::testRegister('new_nickname', '', 'foobar');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('.help-block > ul > li', 'Please enter an email');
$this->assertSelectorTextContains('.form-error', 'Please enter an email');
$this->assertRouteSame('security_register');
}
private function testRegisterNicknameLength(string $nickname, string $error)
{
self::testRegister($nickname, 'email@provider', 'foobar');
[$client, ] = self::testRegister($nickname, 'email@provider.any', 'foobar');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('.help-block > ul > li', $error);
$this->assertSelectorTextContains('.form-error', $error);
$this->assertRouteSame('security_register');
}
@ -173,13 +174,13 @@ class SecurityTest extends GNUsocialTestCase
public function testRegisterExistingNickname()
{
[$client, $crawler] = self::testRegister('taken_user', 'new_new_email@email_provider', 'foobar');
[$client, ] = self::testRegister('taken_user', 'new_new_email@provider.any', 'foobar');
$this->assertSelectorTextContains('.stacktrace', 'App\Util\Exception\NicknameTakenException');
}
public function testRegisterExistingEmail()
{
[$client, $crawler] = self::testRegister('other_new_nickname', 'email@provider', 'foobar');
[$client, ] = self::testRegister('other_new_nickname', 'email@provider.any', 'foobar');
$this->assertSelectorTextContains('.stacktrace', 'App\Util\Exception\EmailTakenException');
}
}