2016-05-11 01:10:06 +05:30
|
|
|
<?php
|
|
|
|
namespace codeception\common\unit\models;
|
|
|
|
|
|
|
|
use Codeception\Specify;
|
2016-05-11 01:58:04 +05:30
|
|
|
use common\models\confirmations\ForgotPassword;
|
2016-05-11 01:10:06 +05:30
|
|
|
use common\models\confirmations\RegistrationConfirmation;
|
|
|
|
use common\models\EmailActivation;
|
|
|
|
use tests\codeception\common\fixtures\EmailActivationFixture;
|
|
|
|
use tests\codeception\console\unit\DbTestCase;
|
|
|
|
|
|
|
|
class EmailActivationTest extends DbTestCase {
|
|
|
|
use Specify;
|
|
|
|
|
|
|
|
public function fixtures() {
|
|
|
|
return [
|
2016-05-16 04:03:19 +05:30
|
|
|
'emailActivations' => EmailActivationFixture::class,
|
2016-05-11 01:10:06 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInstantiate() {
|
|
|
|
$this->specify('return valid model type', function() {
|
|
|
|
expect(EmailActivation::findOne([
|
|
|
|
'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION,
|
|
|
|
]))->isInstanceOf(RegistrationConfirmation::class);
|
|
|
|
expect(EmailActivation::findOne([
|
|
|
|
'type' => EmailActivation::TYPE_FORGOT_PASSWORD_KEY,
|
2016-05-11 01:58:04 +05:30
|
|
|
]))->isInstanceOf(ForgotPassword::class);
|
2016-05-11 01:10:06 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-27 04:28:06 +05:30
|
|
|
public function testBeforeSave() {
|
|
|
|
$this->specify('method should generate value for key field if it empty', function() {
|
|
|
|
$model = new EmailActivation();
|
|
|
|
$model->beforeSave(true);
|
|
|
|
expect($model->key)->notNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->specify('method should repeat code generation if code duplicate with exists', function() {
|
|
|
|
/** @var EmailActivation|\PHPUnit_Framework_MockObject_MockObject $model */
|
|
|
|
$model = $this->getMockBuilder(EmailActivation::class)
|
|
|
|
->setMethods(['generateKey', 'isKeyExists'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$model->expects($this->exactly(3))
|
|
|
|
->method('generateKey')
|
|
|
|
->will($this->onConsecutiveCalls('1', '2', '3'));
|
|
|
|
|
|
|
|
$model->expects($this->exactly(3))
|
|
|
|
->method('isKeyExists')
|
|
|
|
->will($this->onConsecutiveCalls(true, true, false));
|
|
|
|
|
|
|
|
$model->beforeSave(true);
|
|
|
|
expect($model->key)->equals('3');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-11 01:10:06 +05:30
|
|
|
}
|