fixing some tests
This commit is contained in:
23
tests/functional/ConfirmationCept.php
Normal file
23
tests/functional/ConfirmationCept.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var Codeception\Scenario $scenario
|
||||
*/
|
||||
|
||||
use tests\_fixtures\TokenFixture;
|
||||
use yii\helpers\Url;
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that confirmation works');
|
||||
$I->haveFixtures(['token' => TokenFixture::className()]);
|
||||
|
||||
$I->amGoingTo('check that error is showed when token expired');
|
||||
$token = $I->grabFixture('token', 'expired_confirmation');
|
||||
$I->amOnPage(Url::toRoute(['/user/registration/confirm', 'id' => $token->user_id, 'code' => $token->code]));
|
||||
$I->see('The confirmation link is invalid or expired. Please try requesting a new one.');
|
||||
|
||||
$I->amGoingTo('check that user get confirmed');
|
||||
$token = $I->grabFixture('token', 'confirmation');
|
||||
$I->amOnPage(Url::toRoute(['/user/registration/confirm', 'id' => $token->user_id, 'code' => $token->code]));
|
||||
$I->see('Thank you, registration is now complete.');
|
||||
$I->see('Logout');
|
||||
32
tests/functional/CreateCept.php
Normal file
32
tests/functional/CreateCept.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var Codeception\Scenario $scenario
|
||||
*/
|
||||
|
||||
use tests\_fixtures\UserFixture;
|
||||
use tests\_pages\CreatePage;
|
||||
use tests\_pages\LoginPage;
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that user creation works');
|
||||
$I->haveFixtures(['user' => UserFixture::className()]);
|
||||
|
||||
$loginPage = LoginPage::openBy($I);
|
||||
$user = $I->grabFixture('user', 'user');
|
||||
$loginPage->login($user->email, 'qwerty');
|
||||
|
||||
$page = CreatePage::openBy($I);
|
||||
|
||||
$I->amGoingTo('try to create user with empty fields');
|
||||
$page->create('', '', '');
|
||||
$I->expectTo('see validations errors');
|
||||
$I->see('Username cannot be blank.');
|
||||
$I->see('Email cannot be blank.');
|
||||
|
||||
$page->create('foobar', 'foobar@example.com', 'foobar');
|
||||
$I->see('User has been created');
|
||||
|
||||
Yii::$app->user->logout();
|
||||
LoginPage::openBy($I)->login('foobar@example.com', 'foobar');
|
||||
$I->see('Logout');
|
||||
41
tests/functional/LoginCept.php
Normal file
41
tests/functional/LoginCept.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var Codeception\Scenario $scenario
|
||||
*/
|
||||
|
||||
use tests\_fixtures\UserFixture;
|
||||
use tests\_pages\LoginPage;
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that login works');
|
||||
$I->haveFixtures(['user' => UserFixture::className()]);
|
||||
|
||||
$page = LoginPage::openBy($I);
|
||||
|
||||
$I->amGoingTo('try to login with empty credentials');
|
||||
$page->login('', '');
|
||||
$I->expectTo('see validations errors');
|
||||
$I->see('Login cannot be blank.');
|
||||
$I->see('Password cannot be blank.');
|
||||
|
||||
$I->amGoingTo('try to login with unconfirmed account');
|
||||
$user = $I->grabFixture('user', 'unconfirmed');
|
||||
$page->login($user->email, 'qwerty');
|
||||
$I->see('You need to confirm your email address');
|
||||
|
||||
$I->amGoingTo('try to login with blocked account');
|
||||
$user = $I->grabFixture('user', 'blocked');
|
||||
$page->login($user->email, 'qwerty');
|
||||
$I->see('Your account has been blocked');
|
||||
|
||||
$I->amGoingTo('try to login with wrong credentials');
|
||||
$user = $I->grabFixture('user', 'user');
|
||||
$page->login($user->email, 'wrong');
|
||||
$I->expectTo('see validations errors');
|
||||
$I->see('Invalid login or password');
|
||||
|
||||
$I->amGoingTo('try to login with correct credentials');
|
||||
$page->login($user->email, 'qwerty');
|
||||
$I->dontSee('Login');
|
||||
$I->see('Logout');
|
||||
56
tests/functional/RecoveryCept.php
Normal file
56
tests/functional/RecoveryCept.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var Codeception\Scenario $scenario
|
||||
*/
|
||||
|
||||
use tests\_fixtures\TokenFixture;
|
||||
use tests\_fixtures\UserFixture;
|
||||
use tests\_pages\RecoveryPage;
|
||||
use tests\_pages\LoginPage;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Model\Token;
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that password recovery works');
|
||||
$I->haveFixtures(['user' => UserFixture::className(), 'token' => TokenFixture::className()]);
|
||||
|
||||
$I->amGoingTo('try to request recovery token for unconfirmed account');
|
||||
$page = RecoveryPage::openBy($I);
|
||||
$user = $I->grabFixture('user', 'unconfirmed');
|
||||
$page->recover($user->email);
|
||||
$I->see('An email has been sent with instructions for resetting your password');
|
||||
|
||||
$I->amGoingTo('try to request recovery token');
|
||||
$page = RecoveryPage::openBy($I);
|
||||
$user = $I->grabFixture('user', 'user');
|
||||
$page->recover($user->email);
|
||||
$I->see('An email has been sent with instructions for resetting your password');
|
||||
$user = $I->grabRecord(User::className(), ['email' => $user->email]);
|
||||
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
|
||||
/** @var yii\swiftmailer\Message $message */
|
||||
$message = $I->grabLastSentEmail();
|
||||
$I->assertArrayHasKey($user->email, $message->getTo());
|
||||
$I->assertContains(Html::encode($token->getUrl()), utf8_encode(quoted_printable_decode($message->getSwiftMessage()->toString())));
|
||||
|
||||
$I->amGoingTo('reset password with invalid token');
|
||||
$user = $I->grabFixture('user', 'user_with_expired_recovery_token');
|
||||
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
|
||||
$I->amOnPage(Url::toRoute(['/user/recovery/reset', 'id' => $user->id, 'code' => $token->code]));
|
||||
$I->see('Recovery link is invalid or expired. Please try requesting a new one.');
|
||||
|
||||
$I->amGoingTo('reset password');
|
||||
$user = $I->grabFixture('user', 'user_with_recovery_token');
|
||||
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
|
||||
$I->amOnPage(Url::toRoute(['/user/recovery/reset', 'id' => $user->id, 'code' => $token->code]));
|
||||
$I->fillField('#recovery-form-password', 'newpass');
|
||||
$I->click('Finish');
|
||||
$I->see('Your password has been changed successfully.');
|
||||
|
||||
$page = LoginPage::openBy($I);
|
||||
$page->login($user->email, 'qwerty');
|
||||
$I->see('Invalid login or password');
|
||||
$page->login($user->email, 'newpass');
|
||||
$I->dontSee('Invalid login or password');
|
||||
104
tests/functional/RegistrationCest.php
Normal file
104
tests/functional/RegistrationCest.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Da\User\Model\Token;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Module;
|
||||
use tests\_fixtures\UserFixture;
|
||||
use tests\_pages\LoginPage;
|
||||
use tests\_pages\RegistrationPage;
|
||||
use yii\helpers\Html;
|
||||
|
||||
class RegistrationCest
|
||||
{
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->haveFixtures(['user' => UserFixture::className()]);
|
||||
}
|
||||
|
||||
public function _after(FunctionalTester $I)
|
||||
{
|
||||
\Yii::$container->set(Module::className(), [
|
||||
'enableConfirmation' => true,
|
||||
'enableGeneratingPassword' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests registration with email, username and password without any confirmation.
|
||||
* @param FunctionalTester $I
|
||||
*/
|
||||
public function testRegistration(FunctionalTester $I)
|
||||
{
|
||||
\Yii::$container->set(Module::className(), [
|
||||
'enableConfirmation' => false,
|
||||
'enableGeneratingPassword' => false,
|
||||
]);
|
||||
|
||||
$page = RegistrationPage::openBy($I);
|
||||
|
||||
$I->amGoingTo('try to register with empty credentials');
|
||||
$page->register('', '', '');
|
||||
$I->see('Username cannot be blank');
|
||||
$I->see('Email cannot be blank');
|
||||
$I->see('Password cannot be blank');
|
||||
|
||||
$I->amGoingTo('try to register with already used email and username');
|
||||
$user = $I->grabFixture('user', 'user');
|
||||
|
||||
$page->register($user->email, $user->username, 'qwerty');
|
||||
$I->see(Html::encode('This username has already been taken'));
|
||||
$I->see(Html::encode('This email address has already been taken'));
|
||||
|
||||
$page->register('tester@example.com', 'tester', 'tester');
|
||||
$I->see('Your account has been created and a message with further instructions has been sent to your email');
|
||||
$user = $I->grabRecord(User::className(), ['email' => 'tester@example.com']);
|
||||
$I->assertTrue($user->isConfirmed);
|
||||
|
||||
$page = LoginPage::openBy($I);
|
||||
$page->login('tester', 'tester');
|
||||
$I->see('Logout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests registration when confirmation message is sent.
|
||||
* @param FunctionalTester $I
|
||||
*/
|
||||
public function testRegistrationWithConfirmation(FunctionalTester $I)
|
||||
{
|
||||
\Yii::$container->set(Module::className(), [
|
||||
'enableConfirmation' => true,
|
||||
]);
|
||||
$page = RegistrationPage::openBy($I);
|
||||
$page->register('tester@example.com', 'tester', 'tester');
|
||||
$I->see('Your account has been created and a message with further instructions has been sent to your email');
|
||||
$user = $I->grabRecord(User::className(), ['email' => 'tester@example.com']);
|
||||
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_CONFIRMATION]);
|
||||
/** @var yii\swiftmailer\Message $message */
|
||||
$message = $I->grabLastSentEmail();
|
||||
$I->assertArrayHasKey($user->email, $message->getTo());
|
||||
$I->assertContains(Html::encode($token->getUrl()), utf8_encode(quoted_printable_decode($message->getSwiftMessage()->toString())));
|
||||
$I->assertFalse($user->isConfirmed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests registration when password is generated automatically and sent to user.
|
||||
* @param FunctionalTester $I
|
||||
*/
|
||||
public function testRegistrationWithoutPassword(FunctionalTester $I)
|
||||
{
|
||||
\Yii::$container->set(Module::className(), [
|
||||
'enableConfirmation' => false,
|
||||
'enableGeneratingPassword' => true,
|
||||
]);
|
||||
$page = RegistrationPage::openBy($I);
|
||||
$page->register('tester@example.com', 'tester');
|
||||
$I->see('Your account has been created and a message with further instructions has been sent to your email');
|
||||
$user = $I->grabRecord(User::className(), ['email' => 'tester@example.com']);
|
||||
$I->assertEquals('tester', $user->username);
|
||||
/** @var yii\swiftmailer\Message $message */
|
||||
$message = $I->grabLastSentEmail();
|
||||
$I->assertArrayHasKey($user->email, $message->getTo());
|
||||
$I->assertContains('We have generated a password for you', utf8_encode(quoted_printable_decode($message->getSwiftMessage()->toString())));
|
||||
}
|
||||
}
|
||||
29
tests/functional/ResendCept.php
Normal file
29
tests/functional/ResendCept.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var Codeception\Scenario $scenario
|
||||
*/
|
||||
|
||||
use tests\_fixtures\UserFixture;
|
||||
use tests\_pages\ResendPage;
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that resending of confirmation tokens works');
|
||||
$I->haveFixtures(['user' => UserFixture::className()]);
|
||||
|
||||
$I->amGoingTo('try to resend token to non-existent user');
|
||||
$page = ResendPage::openBy($I);
|
||||
$page->resend('foo@example.com');
|
||||
$I->see('A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.');
|
||||
|
||||
$I->amGoingTo('try to resend token to already confirmed user');
|
||||
$page = ResendPage::openBy($I);
|
||||
$user = $I->grabFixture('user', 'user');
|
||||
$page->resend($user->email);
|
||||
$I->see('A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.');
|
||||
|
||||
$I->amGoingTo('try to resend token to unconfirmed user');
|
||||
$page = ResendPage::openBy($I);
|
||||
$user = $I->grabFixture('user', 'unconfirmed');
|
||||
$page->resend($user->email);
|
||||
$I->see('A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.');
|
||||
86
tests/functional/SettingsCept.php
Normal file
86
tests/functional/SettingsCept.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var Codeception\Scenario $scenario
|
||||
*/
|
||||
|
||||
use Da\User\Model\Token;
|
||||
use Da\User\Model\User;
|
||||
use tests\_fixtures\ProfileFixture;
|
||||
use tests\_fixtures\UserFixture;
|
||||
use tests\_pages\LoginPage;
|
||||
use tests\_pages\SettingsPage;
|
||||
use yii\helpers\Html;
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that account settings page work');
|
||||
$I->haveFixtures(['user' => UserFixture::className(), 'profile' => ProfileFixture::className()]);
|
||||
|
||||
$page = LoginPage::openBy($I);
|
||||
$user = $I->grabFixture('user', 'user');
|
||||
$page->login($user->username, 'qwerty');
|
||||
|
||||
$page = SettingsPage::openBy($I);
|
||||
|
||||
$I->amGoingTo('check that current password is required and must be valid');
|
||||
$page->update($user->email, $user->username, 'wrong');
|
||||
$I->see('Current password is not valid');
|
||||
|
||||
$I->amGoingTo('check that email is changing properly');
|
||||
$page->update('new_user@example.com', $user->username, 'qwerty');
|
||||
$I->seeRecord(User::className(), ['email' => $user->email, 'unconfirmed_email' => 'new_user@example.com']);
|
||||
$I->see('A confirmation message has been sent to your new email address');
|
||||
$user = $I->grabRecord(User::className(), ['id' => $user->id]);
|
||||
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_CONFIRM_NEW_EMAIL]);
|
||||
/** @var yii\swiftmailer\Message $message */
|
||||
$message = $I->grabLastSentEmail();
|
||||
$I->assertArrayHasKey($user->unconfirmed_email, $message->getTo());
|
||||
$I->assertContains(Html::encode($token->getUrl()), utf8_encode(quoted_printable_decode($message->getSwiftMessage()->toString())));
|
||||
|
||||
Yii::$app->user->logout();
|
||||
|
||||
$I->amGoingTo('log in using new email address before clicking the confirmation link');
|
||||
$page = LoginPage::openBy($I);
|
||||
$page->login('new_user@example.com', 'qwerty');
|
||||
$I->see('Invalid login or password');
|
||||
|
||||
$I->amGoingTo('log in using new email address after clicking the confirmation link');
|
||||
$user->attemptEmailChange($token->code);
|
||||
$page->login('new_user@example.com', 'qwerty');
|
||||
$I->see('Logout');
|
||||
$I->seeRecord(User::className(), [
|
||||
'id' => 1,
|
||||
'email' => 'new_user@example.com',
|
||||
'unconfirmed_email' => null,
|
||||
]);
|
||||
|
||||
$I->amGoingTo('reset email changing process');
|
||||
$page = SettingsPage::openBy($I);
|
||||
$page->update('user@example.com', $user->username, 'qwerty');
|
||||
$I->see('A confirmation message has been sent to your new email address');
|
||||
$I->seeRecord(User::className(), [
|
||||
'id' => 1,
|
||||
'email' => 'new_user@example.com',
|
||||
'unconfirmed_email' => 'user@example.com',
|
||||
]);
|
||||
$page->update('new_user@example.com', $user->username, 'qwerty');
|
||||
$I->see('Your account details have been updated');
|
||||
$I->seeRecord(User::className(), [
|
||||
'id' => 1,
|
||||
'email' => 'new_user@example.com',
|
||||
'unconfirmed_email' => null,
|
||||
]);
|
||||
$I->amGoingTo('change username and password');
|
||||
$page->update('new_user@example.com', 'nickname', 'qwerty', '123654');
|
||||
$I->see('Your account details have been updated');
|
||||
$I->seeRecord(User::className(), [
|
||||
'username' => 'nickname',
|
||||
'email' => 'new_user@example.com',
|
||||
]);
|
||||
|
||||
Yii::$app->user->logout();
|
||||
|
||||
$I->amGoingTo('login with new credentials');
|
||||
$page = LoginPage::openBy($I);
|
||||
$page->login('nickname', '123654');
|
||||
$I->see('Logout');
|
||||
26
tests/functional/UpdateCept.php
Normal file
26
tests/functional/UpdateCept.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var Codeception\Scenario $scenario
|
||||
*/
|
||||
|
||||
use tests\_fixtures\UserFixture;
|
||||
use tests\_pages\UpdatePage;
|
||||
use tests\_pages\LoginPage;
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that user update works');
|
||||
$I->haveFixtures(['user' => UserFixture::className()]);
|
||||
|
||||
$loginPage = LoginPage::openBy($I);
|
||||
$user = $I->grabFixture('user', 'user');
|
||||
$loginPage->login($user->email, 'qwerty');
|
||||
|
||||
$page = UpdatePage::openBy($I, ['id' => $user->id]);
|
||||
|
||||
$page->update('user', 'updated_user@example.com', 'new_pass');
|
||||
$I->see('Account details have been updated');
|
||||
|
||||
Yii::$app->user->logout();
|
||||
LoginPage::openBy($I)->login('updated_user@example.com', 'new_pass');
|
||||
$I->see('Logout');
|
||||
1
tests/functional/_bootstrap.php
Normal file
1
tests/functional/_bootstrap.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
|
||||
Reference in New Issue
Block a user