2016-03-20 04:55:26 +05:30
|
|
|
<?php
|
|
|
|
namespace tests\codeception\api\functional;
|
|
|
|
|
|
|
|
use Codeception\Scenario;
|
|
|
|
use Codeception\Specify;
|
|
|
|
use common\models\Account;
|
|
|
|
use tests\codeception\api\_pages\AccountsRoute;
|
|
|
|
use tests\codeception\api\_pages\LoginRoute;
|
|
|
|
use tests\codeception\api\functional\_steps\AccountSteps;
|
|
|
|
use tests\codeception\api\FunctionalTester;
|
|
|
|
|
|
|
|
class AccountsChangeUsernameCest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var AccountsRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
|
|
|
|
|
|
|
public function _before(FunctionalTester $I) {
|
|
|
|
$this->route = new AccountsRoute($I);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function _after(FunctionalTester $I) {
|
|
|
|
/** @var Account $account */
|
|
|
|
$account = Account::findOne(1);
|
|
|
|
$account->username = 'Admin';
|
|
|
|
$account->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testChangeUsername(FunctionalTester $I, Scenario $scenario) {
|
2016-04-15 04:31:01 +05:30
|
|
|
$I->wantTo('change my nickname');
|
2016-03-20 04:55:26 +05:30
|
|
|
$I = new AccountSteps($scenario);
|
|
|
|
$I->loggedInAsActiveAccount();
|
|
|
|
|
|
|
|
$this->route->changeUsername('password_0', 'bruce_wayne');
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-04-15 04:31:01 +05:30
|
|
|
public function testChangeUsernameNotAvailable(FunctionalTester $I, Scenario $scenario) {
|
|
|
|
$I->wantTo('see, that nickname "in use" is not available');
|
|
|
|
$I = new AccountSteps($scenario);
|
|
|
|
$I->loggedInAsActiveAccount();
|
|
|
|
|
|
|
|
$this->route->changeUsername('password_0', 'Jon');
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'username' => 'error.username_not_available',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-03-20 04:55:26 +05:30
|
|
|
}
|