From: Aleksey Filippov Date: Fri, 16 Jan 2026 12:59:36 +0000 (+0300) Subject: [ERP-500] Исправление конфигурации тестов X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=6420d034a84987739918332b4ead3c96c0a33033;p=erp24_rep%2Fyii-erp24%2F.git [ERP-500] Исправление конфигурации тестов - Исправлен 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 --- diff --git a/erp24/config/test.php b/erp24/config/test.php index 317bc1cb..6b7cf42e 100644 --- a/erp24/config/test.php +++ b/erp24/config/test.php @@ -42,5 +42,9 @@ return [ */ ], ], - 'params' => $params, + 'params' => array_merge($params, [ + 'senderEmail' => 'test@example.com', + 'senderName' => 'Test Sender', + 'adminEmail' => 'admin@example.com', + ]), ]; diff --git a/erp24/config/test_db.php b/erp24/config/test_db.php index f4290e0b..33e780cf 100644 --- a/erp24/config/test_db.php +++ b/erp24/config/test_db.php @@ -1,6 +1,24 @@ 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, +]; diff --git a/erp24/tests/_data/city.php b/erp24/tests/_data/city.php index 966a63d7..53d36cea 100755 --- a/erp24/tests/_data/city.php +++ b/erp24/tests/_data/city.php @@ -1,15 +1,52 @@ 'Город тест', - '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', ], ]; diff --git a/erp24/tests/fixtures/CityFixture.php b/erp24/tests/fixtures/CityFixture.php index 5bcb4070..b5adbe6f 100755 --- a/erp24/tests/fixtures/CityFixture.php +++ b/erp24/tests/fixtures/CityFixture.php @@ -1,9 +1,11 @@ [ + '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); + } +}