3 namespace tests\unit\models;
5 use app\models\Regions;
7 class RegionsTest extends \Codeception\Test\Unit
15 protected function _before()
17 $this->model = new Regions();
20 protected function _after()
25 public function testEnterNull()
27 // Пустое значение недопустимо
28 $this->model->name = NULL;
29 $this->assertFalse($this->model->validate([ 'name' ]));
32 public function testEnterAbove120()
34 // Больше 120 символов недопустимо
35 $this->model->name = '**** ' . str_repeat('a', 120) . ' ****';
36 $this->assertFalse($this->model->validate([ 'name' ]));
39 public function testEnterData()
41 $validName = '--TEST REGION--';
42 // Допустимая комбинация
43 $this->model->name = $validName;
44 $this->assertTrue($this->model->validate([ 'name' ]));
46 // Сохранение данных в базу
47 $this->assertTrue($this->model->save());
48 $count = count(Regions::find()->where([ 'name' => $validName ])->all());
49 $this->assertGreaterThan(0, $count);
50 $this->assertEquals(1, $count);