[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
1 changed files with 21 additions and 20 deletions

View File

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