From cc1d4a4454905acc36282cd173f3312e122ff19b Mon Sep 17 00:00:00 2001 From: Dmitry Dobryshin Date: Tue, 24 Nov 2020 08:34:29 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=20=D1=82=D0=B5=D1=81=D1=82=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB?= =?utf8?q?=D0=B8=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tests/unit/models/LocationsTest.php | 57 +++++++++++++++++++++++++++++++++++++ tests/unit/models/RegionsTest.php | 52 +++++++++++++++++++++++++++++++++ tests/unit/models/StatusTest.php | 4 +-- tests/unit/models/TypesTest.php | 14 +++------ 4 files changed, 115 insertions(+), 12 deletions(-) create mode 100644 tests/unit/models/LocationsTest.php create mode 100644 tests/unit/models/RegionsTest.php diff --git a/tests/unit/models/LocationsTest.php b/tests/unit/models/LocationsTest.php new file mode 100644 index 0000000..240af06 --- /dev/null +++ b/tests/unit/models/LocationsTest.php @@ -0,0 +1,57 @@ +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 diff --git a/tests/unit/models/RegionsTest.php b/tests/unit/models/RegionsTest.php new file mode 100644 index 0000000..4de102b --- /dev/null +++ b/tests/unit/models/RegionsTest.php @@ -0,0 +1,52 @@ +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 diff --git a/tests/unit/models/StatusTest.php b/tests/unit/models/StatusTest.php index 019a94b..4dc92ce 100644 --- a/tests/unit/models/StatusTest.php +++ b/tests/unit/models/StatusTest.php @@ -31,12 +31,12 @@ class StatusTest extends \Codeception\Test\Unit $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' ])); } diff --git a/tests/unit/models/TypesTest.php b/tests/unit/models/TypesTest.php index 86ea793..2d78c4a 100644 --- a/tests/unit/models/TypesTest.php +++ b/tests/unit/models/TypesTest.php @@ -14,7 +14,7 @@ class TypesTest extends \Codeception\Test\Unit protected function _before() { - + $this->types = new Types(); } protected function _after() @@ -23,27 +23,21 @@ class TypesTest extends \Codeception\Test\Unit 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; -- 2.11.0