Exemple #1
0
<?php

use dektrium\user\tests\FunctionalTester;
use tests\codeception\_pages\LoginPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that login works');
$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->getFixture('user')->getModel('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->getFixture('user')->getModel('blocked');
$page->login($user->email, 'qwerty');
$I->see('Your account has been blocked');
$I->amGoingTo('try to login with wrong credentials');
$user = $I->getFixture('user')->getModel('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');
Exemple #2
0
<?php

use dektrium\user\tests\FunctionalTester;
use tests\codeception\_pages\CreatePage;
use tests\codeception\_pages\LoginPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that user creation works');
$loginPage = LoginPage::openBy($I);
$user = $I->getFixture('user')->getModel('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('toster', '*****@*****.**', 'toster');
$I->see('User has been created');
$I->see('toster');
$I->see('*****@*****.**');
Yii::$app->user->logout();
LoginPage::openBy($I)->login('*****@*****.**', 'toster');
$I->see('Logout');
Exemple #3
0
<?php

use dektrium\user\tests\FunctionalTester;
use tests\codeception\_pages\UpdatePage;
use tests\codeception\_pages\LoginPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that user update works');
$loginPage = LoginPage::openBy($I);
$user = $I->getFixture('user')->getModel('user');
$loginPage->login($user->email, 'qwerty');
$page = UpdatePage::openBy($I, ['id' => $user->id]);
$page->update('user', '*****@*****.**', 'new_pass');
$I->see('Account details have been updated');
Yii::$app->user->logout();
LoginPage::openBy($I)->login('*****@*****.**', 'new_pass');
$I->see('Logout');
<?php

use dektrium\user\tests\FunctionalTester;
use tests\codeception\_pages\RecoveryPage;
use tests\codeception\_pages\LoginPage;
use yii\helpers\Html;
use yii\helpers\Url;
use dektrium\user\models\User;
use dektrium\user\models\Token;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that password recovery works');
$page = RecoveryPage::openBy($I);
$I->amGoingTo('try to request recovery token for unconfirmed account');
$user = $I->getFixture('user')->getModel('unconfirmed');
$page->recover($user->email);
$I->see('You need to confirm your email address');
$I->amGoingTo('try to request recovery token');
$user = $I->getFixture('user')->getModel('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]);
$I->seeInEmail(Html::encode($token->getUrl()));
$I->seeInEmailRecipients($user->email);
$I->amGoingTo('reset password with invalid token');
$user = $I->getFixture('user')->getModel('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->getFixture('user')->getModel('user_with_recovery_token');
<?php

use dektrium\user\tests\FunctionalTester;
use dektrium\user\models\Token;
use dektrium\user\models\User;
use tests\codeception\_pages\RegistrationPage;
use yii\helpers\Html;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that registration works');
$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->getFixture('user')->getModel('user');
$page->register($user->username, $user->email, 'qwerty');
$I->see(Html::encode('This username has already been taken'));
$I->see(Html::encode('This email address has already been taken'));
$I->amGoingTo('try to register');
$page->register('tester', '*****@*****.**', 'tester');
$I->see('A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.');
$user = $I->grabRecord(User::className(), ['email' => '*****@*****.**']);
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_CONFIRMATION]);
$I->seeInEmail(Html::encode($token->url));
Exemple #6
0
<?php

use dektrium\user\tests\FunctionalTester;
use tests\codeception\_pages\ResendPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that resending of confirmation tokens works');
$page = ResendPage::openBy($I);
$I->amGoingTo('try to resend token to non-existent user');
$page->resend('*****@*****.**');
$I->see('Email is invalid');
$I->amGoingTo('try to resend token to already confirmed user');
$user = $I->getFixture('user')->getModel('user');
$page->resend($user->email);
$I->see('This account has already been confirmed');
$I->amGoingTo('try to resend token to unconfirmed user');
$user = $I->getFixture('user')->getModel('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.');
<?php

use dektrium\user\tests\FunctionalTester;
use yii\helpers\Url;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that confirmation works');
$I->amGoingTo('check that error is showed when token expired');
$token = $I->getFixture('token')->getModel('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->getFixture('token')->getModel('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');
<?php

use dektrium\user\tests\FunctionalTester;
use dektrium\user\models\Token;
use dektrium\user\models\User;
use tests\codeception\_pages\LoginPage;
use tests\codeception\_pages\SettingsPage;
use yii\helpers\Html;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that account settings page work');
$page = LoginPage::openBy($I);
$user = $I->getFixture('user')->getModel('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('*****@*****.**', $user->username, 'qwerty');
$I->seeRecord(User::className(), ['email' => $user->email, 'unconfirmed_email' => '*****@*****.**']);
$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]);
$I->seeInEmail(Html::encode($token->getUrl()));
$I->seeInEmailRecipients($user->unconfirmed_email);
Yii::$app->user->logout();
$I->amGoingTo('log in using new email address before clicking the confirmation link');
$page = LoginPage::openBy($I);
$page->login('*****@*****.**', 'qwerty');
$I->see('Invalid login or password');
$I->amGoingTo('log in using new email address after clicking the confirmation link');