OSDN Git Service

Добавлен тест модели размещений.
[invent/invent.git] / tests / unit / models / LocationsTest.php
1 <?php
2
3 namespace tests\unit\models;
4
5 use app\models\Regions;
6 use app\models\Locations;
7
8 class LocationsTest extends \Codeception\Test\Unit
9 {
10     private $model;
11     /**
12      * @var \UnitTester
13      */
14     protected $tester;
15
16     protected function _before()
17     {
18         $this->model = new Locations();
19         $region = new Regions();
20         $region->name = '-- TEST REGION FOR LOCATION --';
21         $this->assertTrue($region->save());
22         $this->model->region_id = $region->id;
23     }
24
25     protected function _after()
26     {
27     }
28
29     // tests
30     public function testEnterNull()
31     {
32         // Пустое значение недопустимо
33         $this->model->name = NULL;
34         $this->assertFalse($this->model->validate([ 'name' ]));
35     }
36
37     public function testEnterAbove120()
38     {
39         // Больше 120 символов недопустимо
40         $this->model->name = '**** ' . str_repeat('a', 120) . ' ****';
41         $this->assertFalse($this->model->validate([ 'name' ]));
42     }
43
44     public function testEnterData()
45     {
46         $validName = '--TEST LOCATION--';
47         // Допустимая комбинация
48         $this->model->name = $validName;
49         $this->assertTrue($this->model->validate([ 'name' ]));
50
51         // Сохранение данных в базу
52         $this->assertTrue($this->model->save());
53         $count = count(Locations::find()->where([ 'name' => $validName ])->all());
54         $this->assertGreaterThan(0, $count);
55         $this->assertEquals(1, $count);
56     }
57 }