3 namespace tests\unit\models;
5 use app\models\Regions;
6 use app\models\Locations;
8 class LocationsTest extends \Codeception\Test\Unit
16 protected function _before()
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;
25 protected function _after()
30 public function testEnterNull()
32 // Пустое значение недопустимо
33 $this->model->name = NULL;
34 $this->assertFalse($this->model->validate([ 'name' ]));
37 public function testEnterAbove120()
39 // Больше 120 символов недопустимо
40 $this->model->name = '**** ' . str_repeat('a', 120) . ' ****';
41 $this->assertFalse($this->model->validate([ 'name' ]));
44 public function testEnterData()
46 $validName = '--TEST LOCATION--';
47 // Допустимая комбинация
48 $this->model->name = $validName;
49 $this->assertTrue($this->model->validate([ 'name' ]));
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);