mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Базовые модели перенесены в отдельное простраинство имён
Поправлены именования классов (хз, почему оно прежде работало)
This commit is contained in:
		
							
								
								
									
										32
									
								
								tests/codeception/api/unit/models/base/ApiFormTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								tests/codeception/api/unit/models/base/ApiFormTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| <?php | ||||
| namespace tests\codeception\api\models\base; | ||||
|  | ||||
| use api\models\base\ApiForm; | ||||
| use Codeception\Specify; | ||||
| use tests\codeception\api\unit\TestCase; | ||||
|  | ||||
| class ApiFormTest extends TestCase { | ||||
|  | ||||
|     use Specify; | ||||
|  | ||||
|     public function testLoad() { | ||||
|         $model = new DummyApiForm(); | ||||
|         $this->specify('model should load data without ModelName array scope', function () use ($model) { | ||||
|             expect('model successful load data without prefix', $model->load(['field' => 'test-data']))->true(); | ||||
|             expect('field is set as passed data', $model->field)->equals('test-data'); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| class DummyApiForm extends ApiForm { | ||||
|  | ||||
|     public $field; | ||||
|  | ||||
|     public function rules() { | ||||
|         return [ | ||||
|             ['field', 'safe'], | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,38 @@ | ||||
| <?php | ||||
| namespace tests\codeception\api\models\base; | ||||
|  | ||||
| use api\models\base\PasswordProtectedForm; | ||||
| use Codeception\Specify; | ||||
| use common\models\Account; | ||||
| use tests\codeception\api\unit\TestCase; | ||||
|  | ||||
| class PasswordProtectedFormTest extends TestCase { | ||||
|     use Specify; | ||||
|  | ||||
|     public function testValidatePassword() { | ||||
|         $this->specify('error.password_invalid on passing invalid account password', function() { | ||||
|             $model = new DummyBasePasswordProtectedForm(); | ||||
|             $model->password = 'some-invalid-password'; | ||||
|             $model->validatePassword(); | ||||
|             expect($model->getErrors('password'))->equals(['error.password_invalid']); | ||||
|         }); | ||||
|  | ||||
|         $this->specify('no errors on passing valid account password', function() { | ||||
|             $model = new DummyBasePasswordProtectedForm(); | ||||
|             $model->password = 'password_0'; | ||||
|             $model->validatePassword(); | ||||
|             expect($model->getErrors('password'))->isEmpty(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| class DummyBasePasswordProtectedForm extends PasswordProtectedForm { | ||||
|  | ||||
|     protected function getAccount() { | ||||
|         return new Account([ | ||||
|             'password' => 'password_0', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,62 @@ | ||||
| <?php | ||||
| namespace tests\codeception\api\models\base; | ||||
|  | ||||
| use api\models\base\KeyConfirmationForm; | ||||
| use Codeception\Specify; | ||||
| use tests\codeception\api\unit\DbTestCase; | ||||
| use tests\codeception\common\fixtures\EmailActivationFixture; | ||||
| use Yii; | ||||
|  | ||||
| /** | ||||
|  * @property array $emailActivations | ||||
|  */ | ||||
| class KeyConfirmationFormTest extends DbTestCase { | ||||
|     use Specify; | ||||
|  | ||||
|     public function fixtures() { | ||||
|         return [ | ||||
|             'emailActivations' => [ | ||||
|                 'class' => EmailActivationFixture::class, | ||||
|                 'dataFile' => '@tests/codeception/common/fixtures/data/email-activations.php', | ||||
|             ], | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     protected function createModel($key = null) { | ||||
|         return new KeyConfirmationForm([ | ||||
|             'key' => $key, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function testEmptyKey() { | ||||
|         $model = $this->createModel(); | ||||
|         $this->specify('get error.key_is_required with validating empty key field', function () use ($model) { | ||||
|             expect('model should don\'t pass validation', $model->validate())->false(); | ||||
|             expect('error messages should be set', $model->errors)->equals([ | ||||
|                 'key' => [ | ||||
|                     'error.key_is_required', | ||||
|                 ], | ||||
|             ]); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     public function testIncorrectKey() { | ||||
|         $model = $this->createModel('not-exists-key'); | ||||
|         $this->specify('get error.key_not_exists with validation wrong key', function () use ($model) { | ||||
|             expect('model should don\'t pass validation', $model->validate())->false(); | ||||
|             expect('error messages should be set', $model->errors)->equals([ | ||||
|                 'key' => [ | ||||
|                     'error.key_not_exists', | ||||
|                 ], | ||||
|             ]); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     public function testCorrectKey() { | ||||
|         $model = $this->createModel($this->emailActivations[0]['key']); | ||||
|         $this->specify('no errors if key exists', function () use ($model) { | ||||
|             expect('model should pass validation', $model->validate())->true(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user