コミットメタ情報

リビジョンcc1d4a4454905acc36282cd173f3312e122ff19b (tree)
日時2020-11-24 14:34:29
作者Dmitry Dobryshin <dimkainc@mail...>
コミッターDmitry Dobryshin

ログメッセージ

Добавлен тест модели размещений.

変更サマリ

差分

--- /dev/null
+++ b/tests/unit/models/LocationsTest.php
@@ -0,0 +1,57 @@
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+}
\ No newline at end of file
--- /dev/null
+++ b/tests/unit/models/RegionsTest.php
@@ -0,0 +1,52 @@
1+<?php
2+
3+namespace tests\unit\models;
4+
5+use app\models\Regions;
6+
7+class RegionsTest extends \Codeception\Test\Unit
8+{
9+ private $model;
10+ /**
11+ * @var \UnitTester
12+ */
13+ protected $tester;
14+
15+ protected function _before()
16+ {
17+ $this->model = new Regions();
18+ }
19+
20+ protected function _after()
21+ {
22+ }
23+
24+ // tests
25+ public function testEnterNull()
26+ {
27+ // Пустое значение недопустимо
28+ $this->model->name = NULL;
29+ $this->assertFalse($this->model->validate([ 'name' ]));
30+ }
31+
32+ public function testEnterAbove120()
33+ {
34+ // Больше 120 символов недопустимо
35+ $this->model->name = '**** ' . str_repeat('a', 120) . ' ****';
36+ $this->assertFalse($this->model->validate([ 'name' ]));
37+ }
38+
39+ public function testEnterData()
40+ {
41+ $validName = '--TEST REGION--';
42+ // Допустимая комбинация
43+ $this->model->name = $validName;
44+ $this->assertTrue($this->model->validate([ 'name' ]));
45+
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);
51+ }
52+}
\ No newline at end of file
--- a/tests/unit/models/StatusTest.php
+++ b/tests/unit/models/StatusTest.php
@@ -31,12 +31,12 @@ class StatusTest extends \Codeception\Test\Unit
3131 $this->assertFalse($this->model->validate([ 'name' ]));
3232 }
3333
34- public function testEnterLong()
34+ public function testEnterAbove100()
3535 {
3636 $this->model = new Status();
3737
3838 // Больше 100 символов недопустимо
39- $this->model->name = '**** aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrsssss ****';
39+ $this->model->name = '**** ' . str_repeat('a', 100) . ' ****';
4040 $this->assertFalse($this->model->validate([ 'name' ]));
4141 }
4242
--- a/tests/unit/models/TypesTest.php
+++ b/tests/unit/models/TypesTest.php
@@ -14,7 +14,7 @@ class TypesTest extends \Codeception\Test\Unit
1414
1515 protected function _before()
1616 {
17-
17+ $this->types = new Types();
1818 }
1919
2020 protected function _after()
@@ -23,27 +23,21 @@ class TypesTest extends \Codeception\Test\Unit
2323
2424 public function testEnterNull()
2525 {
26- $this->types = new Types();
27-
2826 // Пустое значение недопустимо
2927 $this->types->name = NULL;
3028 $this->assertFalse($this->types->validate([ 'name' ]));
3129 }
32-
33- public function testEnterLong()
30+
31+ public function testEnterAbove100()
3432 {
35- $this->types = new Types();
36-
3733 // Больше 100 символов недопустимо
38- $this->types->name = '**** aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrsssss ****';
34+ $this->types->name = '**** ' . str_repeat('a', 100) . ' ****';
3935 $this->assertFalse($this->types->validate([ 'name' ]));
4036 }
4137
4238 // tests
4339 public function testEnterData()
4440 {
45- $this->types = new Types();
46-
4741 $validName = '--TEST TYPE--';
4842 // Допустимая комбинация
4943 $this->types->name = $validName;
旧リポジトリブラウザで表示