mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Инициализировано Yii2 приложение, выпилены лишние части, накинуты чуточку нужных
This commit is contained in:
11
tests/codeception/api/unit/DbTestCase.php
Normal file
11
tests/codeception/api/unit/DbTestCase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
class DbTestCase extends \yii\codeception\DbTestCase
|
||||
{
|
||||
public $appConfig = '@tests/codeception/config/api/unit.php';
|
||||
}
|
11
tests/codeception/api/unit/TestCase.php
Normal file
11
tests/codeception/api/unit/TestCase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
class TestCase extends \yii\codeception\TestCase
|
||||
{
|
||||
public $appConfig = '@tests/codeception/config/api/unit.php';
|
||||
}
|
2
tests/codeception/api/unit/_bootstrap.php
Normal file
2
tests/codeception/api/unit/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will for your tests
|
23
tests/codeception/api/unit/fixtures/data/models/user.php
Normal file
23
tests/codeception/api/unit/fixtures/data/models/user.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'username' => 'okirlin',
|
||||
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
|
||||
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
|
||||
'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'email' => 'brady.renner@rutherford.com',
|
||||
],
|
||||
[
|
||||
'username' => 'troy.becker',
|
||||
'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
|
||||
'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
|
||||
'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'status' => '0',
|
||||
],
|
||||
];
|
59
tests/codeception/api/unit/models/ContactFormTest.php
Normal file
59
tests/codeception/api/unit/models/ContactFormTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit\models;
|
||||
|
||||
use Yii;
|
||||
use tests\codeception\api\unit\TestCase;
|
||||
use api\models\ContactForm;
|
||||
|
||||
class ContactFormTest extends TestCase
|
||||
{
|
||||
|
||||
use \Codeception\Specify;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) {
|
||||
return 'testing_message.eml';
|
||||
};
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
unlink($this->getMessageFile());
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testContact()
|
||||
{
|
||||
$model = new ContactForm();
|
||||
|
||||
$model->attributes = [
|
||||
'name' => 'Tester',
|
||||
'email' => 'tester@example.com',
|
||||
'subject' => 'very important letter subject',
|
||||
'body' => 'body of current message',
|
||||
];
|
||||
|
||||
$model->sendEmail('admin@example.com');
|
||||
|
||||
$this->specify('email should be send', function () {
|
||||
expect('email file should exist', file_exists($this->getMessageFile()))->true();
|
||||
});
|
||||
|
||||
$this->specify('message should contain correct data', function () use ($model) {
|
||||
$emailMessage = file_get_contents($this->getMessageFile());
|
||||
|
||||
expect('email should contain user name', $emailMessage)->contains($model->name);
|
||||
expect('email should contain sender email', $emailMessage)->contains($model->email);
|
||||
expect('email should contain subject', $emailMessage)->contains($model->subject);
|
||||
expect('email should contain body', $emailMessage)->contains($model->body);
|
||||
});
|
||||
}
|
||||
|
||||
private function getMessageFile()
|
||||
{
|
||||
return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\models;
|
||||
|
||||
use Yii;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use api\models\PasswordResetRequestForm;
|
||||
use tests\codeception\common\fixtures\UserFixture;
|
||||
use common\models\User;
|
||||
use Codeception\Specify;
|
||||
|
||||
class PasswordResetRequestFormTest extends DbTestCase
|
||||
{
|
||||
use Specify;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) {
|
||||
return 'testing_message.eml';
|
||||
};
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
@unlink($this->getMessageFile());
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testSendEmailWrongUser()
|
||||
{
|
||||
$this->specify('no user with such email, message should not be sent', function () {
|
||||
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = 'not-existing-email@example.com';
|
||||
|
||||
expect('email not sent', $model->sendEmail())->false();
|
||||
|
||||
});
|
||||
|
||||
$this->specify('user is not active, message should not be sent', function () {
|
||||
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $this->user[1]['email'];
|
||||
|
||||
expect('email not sent', $model->sendEmail())->false();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public function testSendEmailCorrectUser()
|
||||
{
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $this->user[0]['email'];
|
||||
$user = User::findOne(['password_reset_token' => $this->user[0]['password_reset_token']]);
|
||||
|
||||
expect('email sent', $model->sendEmail())->true();
|
||||
expect('user has valid token', $user->password_reset_token)->notNull();
|
||||
|
||||
$this->specify('message has correct format', function () use ($model) {
|
||||
|
||||
expect('message file exists', file_exists($this->getMessageFile()))->true();
|
||||
|
||||
$message = file_get_contents($this->getMessageFile());
|
||||
expect('message "from" is correct', $message)->contains(Yii::$app->params['supportEmail']);
|
||||
expect('message "to" is correct', $message)->contains($model->email);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public function fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => '@tests/codeception/api/unit/fixtures/data/models/user.php'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function getMessageFile()
|
||||
{
|
||||
return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
|
||||
}
|
||||
}
|
43
tests/codeception/api/unit/models/ResetPasswordFormTest.php
Normal file
43
tests/codeception/api/unit/models/ResetPasswordFormTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit\models;
|
||||
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\UserFixture;
|
||||
use api\models\ResetPasswordForm;
|
||||
|
||||
class ResetPasswordFormTest extends DbTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @expectedException \yii\base\InvalidParamException
|
||||
*/
|
||||
public function testResetWrongToken()
|
||||
{
|
||||
new ResetPasswordForm('notexistingtoken_1391882543');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \yii\base\InvalidParamException
|
||||
*/
|
||||
public function testResetEmptyToken()
|
||||
{
|
||||
new ResetPasswordForm('');
|
||||
}
|
||||
|
||||
public function testResetCorrectToken()
|
||||
{
|
||||
$form = new ResetPasswordForm($this->user[0]['password_reset_token']);
|
||||
expect('password should be resetted', $form->resetPassword())->true();
|
||||
}
|
||||
|
||||
public function fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => '@tests/codeception/api/unit/fixtures/data/models/user.php'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
52
tests/codeception/api/unit/models/SignupFormTest.php
Normal file
52
tests/codeception/api/unit/models/SignupFormTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit\models;
|
||||
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\UserFixture;
|
||||
use Codeception\Specify;
|
||||
use api\models\SignupForm;
|
||||
|
||||
class SignupFormTest extends DbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testCorrectSignup()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'username' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
$user = $model->signup();
|
||||
|
||||
$this->assertInstanceOf('common\models\User', $user, 'user should be valid');
|
||||
|
||||
expect('username should be correct', $user->username)->equals('some_username');
|
||||
expect('email should be correct', $user->email)->equals('some_email@example.com');
|
||||
expect('password should be correct', $user->validatePassword('some_password'))->true();
|
||||
}
|
||||
|
||||
public function testNotCorrectSignup()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'username' => 'troy.becker',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
expect('username and email are in use, user should not be created', $model->signup())->null();
|
||||
}
|
||||
|
||||
public function fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => '@tests/codeception/api/unit/fixtures/data/models/user.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user