mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Реализована логика oAuth авторизации приложений, добавлен Redis, удалены лишние тесты, пофикшены старые.
This commit is contained in:
@ -1,59 +0,0 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
<?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\Account;
|
||||
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 = Account::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';
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
<?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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user