--- /dev/null
+<?php
+
+namespace tests\unit\models;
+
+use app\models\Regions;
+use app\models\Locations;
+
+class LocationsTest extends \Codeception\Test\Unit
+{
+ private $model;
+ /**
+ * @var \UnitTester
+ */
+ protected $tester;
+
+ protected function _before()
+ {
+ $this->model = new Locations();
+ $region = new Regions();
+ $region->name = '-- TEST REGION FOR LOCATION --';
+ $this->assertTrue($region->save());
+ $this->model->region_id = $region->id;
+ }
+
+ protected function _after()
+ {
+ }
+
+ // tests
+ public function testEnterNull()
+ {
+ // Пустое значение недопустимо
+ $this->model->name = NULL;
+ $this->assertFalse($this->model->validate([ 'name' ]));
+ }
+
+ public function testEnterAbove120()
+ {
+ // Больше 120 символов недопустимо
+ $this->model->name = '**** ' . str_repeat('a', 120) . ' ****';
+ $this->assertFalse($this->model->validate([ 'name' ]));
+ }
+
+ public function testEnterData()
+ {
+ $validName = '--TEST LOCATION--';
+ // Допустимая комбинация
+ $this->model->name = $validName;
+ $this->assertTrue($this->model->validate([ 'name' ]));
+
+ // Сохранение данных в базу
+ $this->assertTrue($this->model->save());
+ $count = count(Locations::find()->where([ 'name' => $validName ])->all());
+ $this->assertGreaterThan(0, $count);
+ $this->assertEquals(1, $count);
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+namespace tests\unit\models;
+
+use app\models\Regions;
+
+class RegionsTest extends \Codeception\Test\Unit
+{
+ private $model;
+ /**
+ * @var \UnitTester
+ */
+ protected $tester;
+
+ protected function _before()
+ {
+ $this->model = new Regions();
+ }
+
+ protected function _after()
+ {
+ }
+
+ // tests
+ public function testEnterNull()
+ {
+ // Пустое значение недопустимо
+ $this->model->name = NULL;
+ $this->assertFalse($this->model->validate([ 'name' ]));
+ }
+
+ public function testEnterAbove120()
+ {
+ // Больше 120 символов недопустимо
+ $this->model->name = '**** ' . str_repeat('a', 120) . ' ****';
+ $this->assertFalse($this->model->validate([ 'name' ]));
+ }
+
+ public function testEnterData()
+ {
+ $validName = '--TEST REGION--';
+ // Допустимая комбинация
+ $this->model->name = $validName;
+ $this->assertTrue($this->model->validate([ 'name' ]));
+
+ // Сохранение данных в базу
+ $this->assertTrue($this->model->save());
+ $count = count(Regions::find()->where([ 'name' => $validName ])->all());
+ $this->assertGreaterThan(0, $count);
+ $this->assertEquals(1, $count);
+ }
+}
\ No newline at end of file
$this->assertFalse($this->model->validate([ 'name' ]));
}
- public function testEnterLong()
+ public function testEnterAbove100()
{
$this->model = new Status();
// Больше 100 символов недопустимо
- $this->model->name = '**** aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrsssss ****';
+ $this->model->name = '**** ' . str_repeat('a', 100) . ' ****';
$this->assertFalse($this->model->validate([ 'name' ]));
}
protected function _before()
{
-
+ $this->types = new Types();
}
protected function _after()
public function testEnterNull()
{
- $this->types = new Types();
-
// Пустое значение недопустимо
$this->types->name = NULL;
$this->assertFalse($this->types->validate([ 'name' ]));
}
-
- public function testEnterLong()
+
+ public function testEnterAbove100()
{
- $this->types = new Types();
-
// Больше 100 символов недопустимо
- $this->types->name = '**** aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrsssss ****';
+ $this->types->name = '**** ' . str_repeat('a', 100) . ' ****';
$this->assertFalse($this->types->validate([ 'name' ]));
}
// tests
public function testEnterData()
{
- $this->types = new Types();
-
$validName = '--TEST TYPE--';
// Допустимая комбинация
$this->types->name = $validName;