added email verification for unit and functional tests
This commit is contained in:
parent
95bd8f4409
commit
b7526436aa
@ -7,3 +7,4 @@ modules:
|
||||
- Yii2:
|
||||
part: orm
|
||||
entryScript: index-test.php
|
||||
cleanup: false
|
||||
|
@ -49,6 +49,7 @@ class ContactFormCest
|
||||
'ContactForm[body]' => 'test content',
|
||||
'ContactForm[verifyCode]' => 'testme',
|
||||
]);
|
||||
$I->seeEmailIsSent();
|
||||
$I->dontSeeElement('#contact-form');
|
||||
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ class LoginFormCest
|
||||
{
|
||||
public function _before(\FunctionalTester $I)
|
||||
{
|
||||
$I->amOnPage(['site/login']);
|
||||
$I->amOnRoute('site/login');
|
||||
}
|
||||
|
||||
public function openLoginPage(\FunctionalTester $I)
|
||||
@ -12,18 +12,18 @@ class LoginFormCest
|
||||
|
||||
}
|
||||
|
||||
// demonstrates `amLoggedAs` method
|
||||
// demonstrates `amLoggedInAs` method
|
||||
public function internalLoginById(\FunctionalTester $I)
|
||||
{
|
||||
$I->amLoggedAs(100);
|
||||
$I->amLoggedInAs(100);
|
||||
$I->amOnPage('/');
|
||||
$I->see('Logout (admin)');
|
||||
}
|
||||
|
||||
// demonstrates `amLoggedAs` method
|
||||
public function internalLoginBy(\FunctionalTester $I)
|
||||
// demonstrates `amLoggedInAs` method
|
||||
public function internalLoginByInstance(\FunctionalTester $I)
|
||||
{
|
||||
$I->amLoggedAs(\app\models\User::findByUsername('admin'));
|
||||
$I->amLoggedInAs(\app\models\User::findByUsername('admin'));
|
||||
$I->amOnPage('/');
|
||||
$I->see('Logout (admin)');
|
||||
}
|
||||
@ -36,7 +36,7 @@ class LoginFormCest
|
||||
$I->see('Password cannot be blank.');
|
||||
}
|
||||
|
||||
public function loginWithWringCredentials(\FunctionalTester $I)
|
||||
public function loginWithWrongCredentials(\FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', [
|
||||
'LoginForm[username]' => 'admin',
|
||||
|
@ -8,4 +8,4 @@ modules:
|
||||
enabled:
|
||||
- Asserts
|
||||
- Yii2:
|
||||
part: orm
|
||||
part: [orm, email]
|
@ -7,18 +7,10 @@ use app\models\ContactForm;
|
||||
class ContactFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
private $model;
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
\Yii::$app->mailer->fileTransportCallback = function () {
|
||||
return 'testing_message.eml';
|
||||
};
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
unlink($this->getMessageFile());
|
||||
}
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
public $tester;
|
||||
|
||||
public function testEmailIsSentOnContact()
|
||||
{
|
||||
@ -39,18 +31,15 @@ class ContactFormTest extends \Codeception\Test\Unit
|
||||
];
|
||||
|
||||
expect_that($this->model->contact('admin@example.com'));
|
||||
expect_that(file_exists($this->getMessageFile()));
|
||||
|
||||
$emailMessage = file_get_contents($this->getMessageFile());
|
||||
// using Yii2 module actions to check email was sent
|
||||
$this->tester->seeEmailIsSent();
|
||||
|
||||
expect($emailMessage)->contains($this->model->name);
|
||||
expect($emailMessage)->contains($this->model->email);
|
||||
expect($emailMessage)->contains($this->model->subject);
|
||||
expect($emailMessage)->contains($this->model->body);
|
||||
}
|
||||
|
||||
private function getMessageFile()
|
||||
{
|
||||
return \Yii::getAlias(\Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
|
||||
$emailMessage = $this->tester->grabLastSentEmail();
|
||||
expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
|
||||
expect($emailMessage->getTo())->hasKey('admin@example.com');
|
||||
expect($emailMessage->getFrom())->hasKey('tester@example.com');
|
||||
expect($emailMessage->getSubject())->equals('very important letter subject');
|
||||
expect($emailMessage->toString())->contains('body of current message');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user