mirror of
https://github.com/janickiy/yii2-nomer
synced 2025-03-09 15:39:59 +00:00
add files to project
This commit is contained in:
commit
5cac498444
3729 changed files with 836998 additions and 0 deletions
45
tests/unit/models/ContactFormTest.php
Normal file
45
tests/unit/models/ContactFormTest.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace tests\models;
|
||||
|
||||
use app\models\ContactForm;
|
||||
|
||||
class ContactFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
private $model;
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
public $tester;
|
||||
|
||||
public function testEmailIsSentOnContact()
|
||||
{
|
||||
/** @var ContactForm $model */
|
||||
$this->model = $this->getMockBuilder('app\models\ContactForm')
|
||||
->setMethods(['validate'])
|
||||
->getMock();
|
||||
|
||||
$this->model->expects($this->once())
|
||||
->method('validate')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->model->attributes = [
|
||||
'name' => 'Tester',
|
||||
'email' => 'tester@example.com',
|
||||
'subject' => 'very important letter subject',
|
||||
'body' => 'body of current message',
|
||||
];
|
||||
|
||||
expect_that($this->model->contact('admin@example.com'));
|
||||
|
||||
// using Yii2 module actions to check email was sent
|
||||
$this->tester->seeEmailIsSent();
|
||||
|
||||
$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');
|
||||
}
|
||||
}
|
52
tests/unit/models/LoginFormTest.php
Normal file
52
tests/unit/models/LoginFormTest.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace tests\models;
|
||||
|
||||
use app\models\LoginForm;
|
||||
use Codeception\Specify;
|
||||
|
||||
class LoginFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
private $model;
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
\Yii::$app->user->logout();
|
||||
}
|
||||
|
||||
public function testLoginNoUser()
|
||||
{
|
||||
$this->model = new LoginForm([
|
||||
'username' => 'not_existing_username',
|
||||
'password' => 'not_existing_password',
|
||||
]);
|
||||
|
||||
expect_not($this->model->login());
|
||||
expect_that(\Yii::$app->user->isGuest);
|
||||
}
|
||||
|
||||
public function testLoginWrongPassword()
|
||||
{
|
||||
$this->model = new LoginForm([
|
||||
'username' => 'demo',
|
||||
'password' => 'wrong_password',
|
||||
]);
|
||||
|
||||
expect_not($this->model->login());
|
||||
expect_that(\Yii::$app->user->isGuest);
|
||||
expect($this->model->errors)->hasKey('password');
|
||||
}
|
||||
|
||||
public function testLoginCorrect()
|
||||
{
|
||||
$this->model = new LoginForm([
|
||||
'username' => 'demo',
|
||||
'password' => 'demo',
|
||||
]);
|
||||
|
||||
expect_that($this->model->login());
|
||||
expect_not(\Yii::$app->user->isGuest);
|
||||
expect($this->model->errors)->hasntKey('password');
|
||||
}
|
||||
|
||||
}
|
42
tests/unit/models/UserTest.php
Normal file
42
tests/unit/models/UserTest.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
namespace tests\models;
|
||||
use app\models\User;
|
||||
|
||||
class UserTest extends \Codeception\Test\Unit
|
||||
{
|
||||
public function testFindUserById()
|
||||
{
|
||||
expect_that($user = User::findIdentity(100));
|
||||
expect($user->username)->equals('admin');
|
||||
|
||||
expect_not(User::findIdentity(999));
|
||||
}
|
||||
|
||||
public function testFindUserByAccessToken()
|
||||
{
|
||||
expect_that($user = User::findIdentityByAccessToken('100-token'));
|
||||
expect($user->username)->equals('admin');
|
||||
|
||||
expect_not(User::findIdentityByAccessToken('non-existing'));
|
||||
}
|
||||
|
||||
public function testFindUserByUsername()
|
||||
{
|
||||
expect_that($user = User::findByUsername('admin'));
|
||||
expect_not(User::findByUsername('not-admin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testFindUserByUsername
|
||||
*/
|
||||
public function testValidateUser($user)
|
||||
{
|
||||
$user = User::findByUsername('admin');
|
||||
expect_that($user->validateAuthKey('test100key'));
|
||||
expect_not($user->validateAuthKey('test102key'));
|
||||
|
||||
expect_that($user->validatePassword('admin'));
|
||||
expect_not($user->validatePassword('123456'));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue