]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-500] Исправление конфигурации тестов
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 16 Jan 2026 12:59:36 +0000 (15:59 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 16 Jan 2026 12:59:36 +0000 (15:59 +0300)
- Исправлен CityFixture: namespace изменён с backend\models\City на yii_app\records\City
- Обновлены тестовые данные city.php под реальную структуру таблицы city
- Создан новый CityTest с правильными namespace и тестами валидации
- Исправлен test_db.php: переключён на PostgreSQL вместо MySQL
- Добавлены senderEmail/senderName в test.php для ContactForm

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
erp24/config/test.php
erp24/config/test_db.php
erp24/tests/_data/city.php
erp24/tests/fixtures/CityFixture.php
erp24/tests/unit/models/CityTest.php [new file with mode: 0644]

index 317bc1cb65ea65277aa63eed570202506377ebf1..6b7cf42ea5e2fffe07b1629f9703f12ff6d9b2b4 100644 (file)
@@ -42,5 +42,9 @@ return [
             */
         ],
     ],
-    'params' => $params,
+    'params' => array_merge($params, [
+        'senderEmail' => 'test@example.com',
+        'senderName' => 'Test Sender',
+        'adminEmail' => 'admin@example.com',
+    ]),
 ];
index f4290e0b0ca6b2d7d164e80fa6417cd70184faf5..33e780cfced5ff7154766d56b382987b9bf44e3d 100644 (file)
@@ -1,6 +1,24 @@
 <?php
-$db = require __DIR__ . '/db.php';
-// test database! Important not to run tests on production or development databases
-$db['dsn'] = 'mysql:host=localhost;dbname=yii2basic_test';
+/**
+ * Конфигурация тестовой базы данных.
+ * ВАЖНО: Не запускайте тесты на продакшен или девелоп базах данных!
+ */
 
-return $db;
+return [
+    'class' => yii\db\Connection::class,
+    'dsn' => strtr('pgsql:host={host};port={port};dbname={dbname}', [
+        '{host}' => getenv('POSTGRES_HOSTNAME') ?: '127.0.0.1',
+        '{port}' => getenv('POSTGRES_PORT') ?: 5432,
+        '{dbname}' => getenv('POSTGRES_SCHEMA_TEST') ?: 'erp24_test',
+    ]),
+    'username' => getenv('POSTGRES_USER') ?: 'bazacvetov24',
+    'password' => getenv('POSTGRES_PASSWORD') ?: '',
+    'schemaMap' => [
+        'pgsql' => [
+            'class' => 'yii\db\pgsql\Schema',
+            'defaultSchema' => 'erp24'
+        ]
+    ],
+    'charset' => 'utf8',
+    'enableSchemaCache' => false,
+];
index 966a63d70a76f805473cd6b464cd90e9580bf9ce..53d36ceae0f9e20eb4ca38394913d281716ed5a1 100755 (executable)
@@ -1,15 +1,52 @@
 <?php
 
 return [
-    [
-        'name' => 'Город тест',
-        'code' => 'city-test',
-        'social' => 'socialsocial',
-        'phone' => '+7 (232) 4-335-647',
-           'email' => 'nicole.paucek@schultz.info',
-           'phone_support' => '8 800 770 70 22',
-        'active' => '1',
-        'created_at' => '1402312317',
-        'updated_at' => '1402312317',
+    'city1' => [
+        'id_region' => 1,
+        'id_country' => 1,
+        'oid' => 1,
+        'city_name_ru' => 'Тестовый город',
+        'city_name_ru_sklon' => 'Тестового города',
+        'city_name_en' => 'Test City',
+        'city_url' => 'test-city',
+        'h1' => 'Тестовый город',
+        'seo_title' => 'Тестовый город - заголовок',
+        'seo_description_ru' => 'Описание тестового города',
+        'seo_description_eng' => 'Test city description',
+        'seo_content' => 'Контент для SEO',
+        'region_name' => 'Тестовый регион',
+        'dop' => '',
+        'visible' => '1',
+        'generate' => '1',
+        'main' => '0',
+        'naselenie' => 100000.00,
+        'gps_center' => '55.7558,37.6173',
+        'org_id' => 1,
+        'work_time' => '09:00-18:00',
+        'work_time_sklad' => '08:00-20:00',
+    ],
+    'city2' => [
+        'id_region' => 2,
+        'id_country' => 1,
+        'oid' => 2,
+        'city_name_ru' => 'Второй город',
+        'city_name_ru_sklon' => 'Второго города',
+        'city_name_en' => 'Second City',
+        'city_url' => 'second-city',
+        'h1' => 'Второй город',
+        'seo_title' => 'Второй город - заголовок',
+        'seo_description_ru' => 'Описание второго города',
+        'seo_description_eng' => 'Second city description',
+        'seo_content' => 'Контент для SEO второго города',
+        'region_name' => 'Второй регион',
+        'dop' => '',
+        'visible' => '1',
+        'generate' => '1',
+        'main' => '0',
+        'naselenie' => 50000.00,
+        'gps_center' => '59.9343,30.3351',
+        'org_id' => 1,
+        'work_time' => '10:00-19:00',
+        'work_time_sklad' => '09:00-21:00',
     ],
 ];
index 5bcb4070a7af91303050814652691713f09bd504..b5adbe6ff92a429a06ad03f9bb2541bff0357855 100755 (executable)
@@ -1,9 +1,11 @@
 <?php
+
 namespace tests\fixtures;
 
 use yii\test\ActiveFixture;
 
 class CityFixture extends ActiveFixture
 {
-    public $modelClass = 'backend\models\City';
+    public $modelClass = 'yii_app\\records\\City';
+    public $dataFile = __DIR__ . '/../_data/city.php';
 }
\ No newline at end of file
diff --git a/erp24/tests/unit/models/CityTest.php b/erp24/tests/unit/models/CityTest.php
new file mode 100644 (file)
index 0000000..9e565a8
--- /dev/null
@@ -0,0 +1,147 @@
+<?php
+
+namespace tests\unit\models;
+
+use Codeception\Test\Unit;
+use tests\fixtures\CityFixture;
+use yii_app\records\City;
+
+/**
+ * City model test
+ */
+class CityTest extends Unit
+{
+    /**
+     * @var \tests\UnitTester
+     */
+    protected $tester;
+
+    /**
+     * @return array
+     */
+    public function _fixtures(): array
+    {
+        return [
+            'city' => [
+                'class' => CityFixture::class,
+                'dataFile' => '@app/tests/_data/city.php',
+            ],
+        ];
+    }
+
+    /**
+     * Тест: пустые обязательные поля не проходят валидацию
+     */
+    public function testEmptyRequiredFields(): void
+    {
+        $city = new City();
+
+        $this->assertFalse($city->validate());
+        $this->assertArrayHasKey('id_region', $city->getErrors());
+        $this->assertArrayHasKey('id_country', $city->getErrors());
+        $this->assertArrayHasKey('oid', $city->getErrors());
+    }
+
+    /**
+     * Тест: валидные данные проходят валидацию
+     */
+    public function testValidData(): void
+    {
+        $city = new City();
+        $city->id_region = 1;
+        $city->id_country = 1;
+        $city->oid = 1;
+        $city->city_name_ru = 'Новый город';
+        $city->city_name_ru_sklon = 'Нового города';
+        $city->city_name_en = 'New City';
+        $city->city_url = 'new-city';
+        $city->h1 = 'Новый город';
+        $city->seo_title = 'Новый город - заголовок';
+        $city->seo_description_ru = 'Описание';
+        $city->seo_description_eng = 'Description';
+        $city->seo_content = 'Content';
+        $city->region_name = 'Регион';
+        $city->naselenie = 10000.00;
+        $city->gps_center = '55.0000,37.0000';
+        $city->org_id = 1;
+        $city->work_time = '09:00-18:00';
+        $city->work_time_sklad = '08:00-20:00';
+
+        $this->assertTrue($city->validate(), 'Валидация должна пройти с корректными данными');
+    }
+
+    /**
+     * Тест: некорректные типы данных
+     */
+    public function testInvalidIntegerFields(): void
+    {
+        $city = new City();
+        $city->id_region = 'not_integer';
+        $city->id_country = 'not_integer';
+        $city->oid = 'not_integer';
+        $city->org_id = 'not_integer';
+
+        $this->assertFalse($city->validate());
+        $this->assertArrayHasKey('id_region', $city->getErrors());
+        $this->assertArrayHasKey('id_country', $city->getErrors());
+        $this->assertArrayHasKey('oid', $city->getErrors());
+        $this->assertArrayHasKey('org_id', $city->getErrors());
+    }
+
+    /**
+     * Тест: слишком длинное название города (>255 символов)
+     */
+    public function testLongCityName(): void
+    {
+        $city = new City();
+        $city->city_name_ru = str_repeat('а', 300);
+
+        $this->assertFalse($city->validate(['city_name_ru']));
+        $this->assertArrayHasKey('city_name_ru', $city->getErrors());
+    }
+
+    /**
+     * Тест: корректная длина gps_center (max 35)
+     */
+    public function testGpsCenterLength(): void
+    {
+        $city = new City();
+        $city->gps_center = str_repeat('1', 40);
+
+        $this->assertFalse($city->validate(['gps_center']));
+        $this->assertArrayHasKey('gps_center', $city->getErrors());
+    }
+
+    /**
+     * Тест: поле main максимум 1 символ
+     */
+    public function testMainFieldLength(): void
+    {
+        $city = new City();
+        $city->main = 'abc';
+
+        $this->assertFalse($city->validate(['main']));
+        $this->assertArrayHasKey('main', $city->getErrors());
+    }
+
+    /**
+     * Тест: получение названия таблицы
+     */
+    public function testTableName(): void
+    {
+        $this->assertEquals('city', City::tableName());
+    }
+
+    /**
+     * Тест: наличие attributeLabels
+     */
+    public function testAttributeLabels(): void
+    {
+        $city = new City();
+        $labels = $city->attributeLabels();
+
+        $this->assertIsArray($labels);
+        $this->assertArrayHasKey('id_city', $labels);
+        $this->assertArrayHasKey('city_name_ru', $labels);
+    }
+}