From f6746914c928fe7b515cfa01d940dab8b193de20 Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Fri, 16 Jan 2026 17:36:15 +0300 Subject: [PATCH] =?utf8?q?[ERP-500]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?utf8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20unit-=D1=82=D0=B5=D1=81=D1=82?= =?utf8?q?=D0=BE=D0=B2=20CityTest=20=D0=B8=20UserTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Удалено поле dop из фикстуры city.php (PostgreSQL enum не принимает пустую строку) - Переписан UserTest для тестирования mock User модели без зависимости от БД Co-Authored-By: Claude Opus 4.5 --- erp24/tests/_data/city.php | 2 - erp24/tests/unit/models/UserTest.php | 99 ++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 31 deletions(-) diff --git a/erp24/tests/_data/city.php b/erp24/tests/_data/city.php index 53d36cea..bff8d8ee 100755 --- a/erp24/tests/_data/city.php +++ b/erp24/tests/_data/city.php @@ -15,7 +15,6 @@ return [ 'seo_description_eng' => 'Test city description', 'seo_content' => 'Контент для SEO', 'region_name' => 'Тестовый регион', - 'dop' => '', 'visible' => '1', 'generate' => '1', 'main' => '0', @@ -39,7 +38,6 @@ return [ 'seo_description_eng' => 'Second city description', 'seo_content' => 'Контент для SEO второго города', 'region_name' => 'Второй регион', - 'dop' => '', 'visible' => '1', 'generate' => '1', 'main' => '0', diff --git a/erp24/tests/unit/models/UserTest.php b/erp24/tests/unit/models/UserTest.php index 0ebb10a7..2a3f21ec 100644 --- a/erp24/tests/unit/models/UserTest.php +++ b/erp24/tests/unit/models/UserTest.php @@ -3,59 +3,100 @@ namespace tests\unit\models; use app\models\User; -use Yii; -use yii_app\records\Admin; /** - * Tests for User model - * - * @group database + * Tests for mock User model (in-memory user data) + * This tests the basic Yii2 IdentityInterface implementation */ class UserTest extends \Codeception\Test\Unit { - protected function _before(): void + /** + * Test finding user by ID + */ + public function testFindUserById(): void { - // Skip tests if database is not available - try { - Yii::$app->db->open(); - } catch (\Exception $e) { - $this->markTestSkipped('Database connection not available: ' . $e->getMessage()); - } + // Test existing user + $user = User::findIdentity('100'); + $this->assertNotNull($user); + $this->assertEquals('admin', $user->username); + + // Test non-existing user + $this->assertNull(User::findIdentity('999')); } - public function testFindUserById() + /** + * Test finding user by access token + */ + public function testFindUserByAccessToken(): void { - verify($user = Admin::findIdentity(1))->notEmpty(); - verify($user->login_user)->equals('root'); + // Test existing token + $user = User::findIdentityByAccessToken('100-token'); + $this->assertNotNull($user); + $this->assertEquals('admin', $user->username); - verify(User::findIdentity(999))->empty(); + // Test non-existing token + $this->assertNull(User::findIdentityByAccessToken('non-existing')); } - public function testFindUserByAccessToken() + /** + * Test finding user by username + */ + public function testFindUserByUsername(): void { - verify($user = User::findIdentityByAccessToken('100-token'))->notEmpty(); - verify($user->username)->equals('admin'); + // Test existing username + $user = User::findByUsername('admin'); + $this->assertNotNull($user); + $this->assertEquals('100', $user->id); - verify(User::findIdentityByAccessToken('non-existing'))->empty(); + // Test non-existing username + $this->assertNull(User::findByUsername('not-admin')); } - public function testFindUserByUsername() + /** + * Test auth key validation + */ + public function testValidateAuthKey(): void { - verify($user = User::findByUsername('admin'))->notEmpty(); - verify(User::findByUsername('not-admin'))->empty(); + $user = User::findByUsername('admin'); + $this->assertNotNull($user); + + // Valid auth key + $this->assertTrue($user->validateAuthKey('test100key')); + + // Invalid auth key + $this->assertFalse($user->validateAuthKey('wrong-key')); } /** - * @depends testFindUserByUsername + * Test password validation */ - public function testValidateUser() + public function testValidatePassword(): void { $user = User::findByUsername('admin'); - verify($user->validateAuthKey('test100key'))->notEmpty(); - verify($user->validateAuthKey('test102key'))->empty(); + $this->assertNotNull($user); + + // Valid password + $this->assertTrue($user->validatePassword('admin')); - verify($user->validatePassword('admin'))->notEmpty(); - verify($user->validatePassword('123456'))->empty(); + // Invalid password + $this->assertFalse($user->validatePassword('wrong-password')); } + /** + * Test getId method + */ + public function testGetId(): void + { + $user = User::findIdentity('100'); + $this->assertEquals('100', $user->getId()); + } + + /** + * Test getAuthKey method + */ + public function testGetAuthKey(): void + { + $user = User::findIdentity('100'); + $this->assertEquals('test100key', $user->getAuthKey()); + } } -- 2.39.5