From e96ffa1ca9240390b695933076a175fe70630159 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Mon, 19 Jan 2026 08:29:56 +0700 Subject: [PATCH] refactor(test): remove legacy v2 master tests and cleanup HealthTest - Deleted obsolete v2 master test files and support classes: - tests/_support/v2/MasterTestCase.php - tests/unit/v2/master/TestDef/TestDefSiteModelTest.php - tests/unit/v2/master/TestDef/TestDefTechModelTest.php - tests/unit/v2/master/TestDef/TestMapModelTest.php - tests/feature/v2/master/TestDef/TestDefSiteTest.php - Cleaned up formatting and logic in tests/unit/HealthTest.php. --- tests/_support/v2/MasterTestCase.php | 325 --------------- .../v2/master/TestDef/TestDefCalcTest.php | 328 --------------- .../v2/master/TestDef/TestDefGroupTest.php | 291 -------------- .../v2/master/TestDef/TestDefParamTest.php | 288 -------------- .../v2/master/TestDef/TestDefSiteTest.php | 375 ------------------ tests/unit/HealthTest.php | 6 +- .../v2/master/TestDef/TestDefCalModelTest.php | 145 ------- .../v2/master/TestDef/TestDefGrpModelTest.php | 132 ------ .../TestDef/TestDefSiteModelMasterTest.php | 220 ---------- .../master/TestDef/TestDefSiteModelTest.php | 137 ------- .../master/TestDef/TestDefTechModelTest.php | 160 -------- .../v2/master/TestDef/TestMapModelTest.php | 155 -------- 12 files changed, 2 insertions(+), 2560 deletions(-) delete mode 100644 tests/_support/v2/MasterTestCase.php delete mode 100644 tests/feature/v2/master/TestDef/TestDefCalcTest.php delete mode 100644 tests/feature/v2/master/TestDef/TestDefGroupTest.php delete mode 100644 tests/feature/v2/master/TestDef/TestDefParamTest.php delete mode 100644 tests/feature/v2/master/TestDef/TestDefSiteTest.php delete mode 100644 tests/unit/v2/master/TestDef/TestDefCalModelTest.php delete mode 100644 tests/unit/v2/master/TestDef/TestDefGrpModelTest.php delete mode 100644 tests/unit/v2/master/TestDef/TestDefSiteModelMasterTest.php delete mode 100644 tests/unit/v2/master/TestDef/TestDefSiteModelTest.php delete mode 100644 tests/unit/v2/master/TestDef/TestDefTechModelTest.php delete mode 100644 tests/unit/v2/master/TestDef/TestMapModelTest.php diff --git a/tests/_support/v2/MasterTestCase.php b/tests/_support/v2/MasterTestCase.php deleted file mode 100644 index 5b33d69..0000000 --- a/tests/_support/v2/MasterTestCase.php +++ /dev/null @@ -1,325 +0,0 @@ -token = $this->generateTestToken(); - } - - /** - * Cleanup after test - */ - protected function tearDown(): void - { - parent::tearDown(); - } - - /** - * Generate JWT token for testing - */ - protected function generateTestToken(): string - { - $key = getenv('JWT_SECRET') ?: 'my-secret-key'; - $payload = [ - 'iss' => 'localhost', - 'aud' => 'localhost', - 'iat' => time(), - 'nbf' => time(), - 'exp' => time() + 3600, - 'uid' => 1, - 'email' => 'admin@admin.com' - ]; - return JWT::encode($payload, $key, 'HS256'); - } - - /** - * Make authenticated GET request - */ - protected function get(string $path, array $options = []) - { - $this->withHeaders(['Authorization' => 'Bearer ' . $this->token]); - return $this->call('get', $path, $options); - } - - /** - * Make authenticated POST request - */ - protected function post(string $path, array $options = []) - { - $this->withHeaders(['Authorization' => 'Bearer ' . $this->token]); - return $this->call('post', $path, $options); - } - - /** - * Make authenticated PUT request - */ - protected function put(string $path, array $options = []) - { - $this->withHeaders(['Authorization' => 'Bearer ' . $this->token]); - return $this->call('put', $path, $options); - } - - /** - * Make authenticated DELETE request - */ - protected function delete(string $path, array $options = []) - { - $this->withHeaders(['Authorization' => 'Bearer ' . $this->token]); - return $this->call('delete', $path, $options); - } - - /** - * Create a TEST type test definition - */ - protected function createTestData(): array - { - return [ - 'SiteID' => 1, - 'TestSiteCode' => $this->testSiteCode, - 'TestSiteName' => 'Test Definition ' . time(), - 'TestType' => self::TEST_TYPE_TEST, - 'Description' => 'Test description', - 'SeqScr' => 10, - 'SeqRpt' => 10, - 'IndentLeft' => 0, - 'VisibleScr' => 1, - 'VisibleRpt' => 1, - 'CountStat' => 1, - 'details' => [ - 'DisciplineID' => 1, - 'DepartmentID' => 1, - 'ResultType' => 1, // Numeric - 'RefType' => 1, // NMRC - 'Unit1' => 'mg/dL', - 'Decimal' => 2, - 'Method' => 'Test Method', - 'ExpectedTAT' => 60 - ], - 'testmap' => [ - [ - 'HostType' => 'HIS', - 'HostID' => 'TEST001', - 'HostTestCode' => 'TEST001', - 'HostTestName' => 'Test (HIS)' - ] - ] - ]; - } - - /** - * Create a PARAM type test definition - */ - protected function createParamData(): array - { - return [ - 'SiteID' => 1, - 'TestSiteCode' => 'PARM' . substr(time(), -4), - 'TestSiteName' => 'Parameter Test ' . time(), - 'TestType' => self::TEST_TYPE_PARAM, - 'Description' => 'Parameter test description', - 'SeqScr' => 5, - 'SeqRpt' => 5, - 'VisibleScr' => 1, - 'VisibleRpt' => 1, - 'CountStat' => 1, - 'details' => [ - 'DisciplineID' => 1, - 'DepartmentID' => 1, - 'ResultType' => 1, - 'RefType' => 1, - 'Unit1' => 'unit', - 'Decimal' => 1, - 'Method' => 'Parameter Method' - ] - ]; - } - - /** - * Create a GROUP type test definition with members - */ - protected function createGroupData(array $memberIds = []): array - { - return [ - 'SiteID' => 1, - 'TestSiteCode' => 'GRUP' . substr(time(), -4), - 'TestSiteName' => 'Group Test ' . time(), - 'TestType' => self::TEST_TYPE_GROUP, - 'Description' => 'Group test description', - 'SeqScr' => 100, - 'SeqRpt' => 100, - 'VisibleScr' => 1, - 'VisibleRpt' => 1, - 'CountStat' => 1, - 'Members' => $memberIds ?: [1, 2], - 'testmap' => [ - [ - 'HostType' => 'LIS', - 'HostID' => 'LIS001', - 'HostTestCode' => 'PANEL', - 'HostTestName' => 'Test Panel (LIS)' - ] - ] - ]; - } - - /** - * Create a CALC type test definition - */ - protected function createCalcData(): array - { - return [ - 'SiteID' => 1, - 'TestSiteCode' => 'CALC' . substr(time(), -4), - 'TestSiteName' => 'Calculated Test ' . time(), - 'TestType' => self::TEST_TYPE_CALC, - 'Description' => 'Calculated test description', - 'SeqScr' => 50, - 'SeqRpt' => 50, - 'VisibleScr' => 1, - 'VisibleRpt' => 1, - 'CountStat' => 1, - 'details' => [ - 'DisciplineID' => 1, - 'DepartmentID' => 1, - 'FormulaInput' => '["TEST1", "TEST2"]', - 'FormulaCode' => 'TEST1 + TEST2', - 'FormulaLang' => 'SQL', - 'RefType' => 1, - 'Unit1' => 'mg/dL', - 'Decimal' => 0, - 'Method' => 'Calculation Method' - ], - 'testmap' => [ - [ - 'HostType' => 'LIS', - 'HostID' => 'LIS001', - 'HostTestCode' => 'CALCR', - 'HostTestName' => 'Calculated Result (LIS)' - ] - ] - ]; - } - - /** - * Assert API response has success status - */ - protected function assertSuccessResponse($response, string $message = 'Response should be successful'): void - { - $body = json_decode($response->response()->getBody(), true); - $this->assertArrayHasKey('status', $body, $message); - $this->assertEquals('success', $body['status'], $message); - } - - /** - * Assert API response has error status - */ - protected function assertErrorResponse($response, string $message = 'Response should be an error'): void - { - $body = json_decode($response->response()->getBody(), true); - $this->assertArrayHasKey('status', $body, $message); - $this->assertNotEquals('success', $body['status'], $message); - } - - /** - * Assert response has data key - */ - protected function assertHasData($response, string $message = 'Response should have data'): void - { - $body = json_decode($response->response()->getBody(), true); - $this->assertArrayHasKey('data', $body, $message); - } - - /** - * Get test type name from VID - */ - protected function getTestTypeName(int $vid): string - { - return match ($vid) { - self::TEST_TYPE_TEST => 'TEST', - self::TEST_TYPE_PARAM => 'PARAM', - self::TEST_TYPE_CALC => 'CALC', - self::TEST_TYPE_GROUP => 'GROUP', - self::TEST_TYPE_TITLE => 'TITLE', - default => 'UNKNOWN' - }; - } - - /** - * Skip test if database not available - */ - protected function requireDatabase(): void - { - $db = \Config\Database::connect(); - try { - $db->connect(); - } catch (\Exception $e) { - $this->markTestSkipped('Database not available: ' . $e->getMessage()); - } - } - - /** - * Skip test if required seeded data not found - */ - protected function requireSeededData(): void - { - $db = \Config\Database::connect(); - $count = $db->table('valueset') - ->where('VSetID', self::VALUESET_TEST_TYPE) - ->countAllResults(); - - if ($count === 0) { - $this->markTestSkipped('Test type valuesets not seeded'); - } - } -} diff --git a/tests/feature/v2/master/TestDef/TestDefCalcTest.php b/tests/feature/v2/master/TestDef/TestDefCalcTest.php deleted file mode 100644 index 985b216..0000000 --- a/tests/feature/v2/master/TestDef/TestDefCalcTest.php +++ /dev/null @@ -1,328 +0,0 @@ - 1, - 'TestSiteCode' => 'CALC' . substr(time(), -4), - 'TestSiteName' => 'Calculated Test ' . time(), - 'TestType' => $this::TEST_TYPE_CALC, - 'Description' => 'Calculated test with formula', - 'SeqScr' => 50, - 'SeqRpt' => 50, - 'VisibleScr' => 1, - 'VisibleRpt' => 1, - 'CountStat' => 1, - 'details' => [ - 'DisciplineID' => 1, - 'DepartmentID' => 1, - 'FormulaInput' => '["CHOL", "HDL", "TG"]', - 'FormulaCode' => 'CHOL - HDL - (TG / 5)', - 'FormulaLang' => 'SQL', - 'RefType' => 1, // NMRC - 'Unit1' => 'mg/dL', - 'Decimal' => 0, - 'Method' => 'Friedewald Formula' - ] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($calcData)]); - - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - - if ($status === 201) { - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('created', $body['status']); - - // Verify calc details were created - $calcId = $body['data']['TestSiteId']; - $showResult = $this->get($this->endpoint . '/' . $calcId); - $showBody = json_decode($showResult->response()->getBody(), true); - - if ($showBody['data'] !== null) { - $this->assertArrayHasKey('testdefcal', $showBody['data']); - } - } - } - - /** - * Test CALC with different formula languages - */ - public function testCalcWithDifferentFormulaLanguages(): void - { - $languages = ['Phyton', 'CQL', 'FHIRP', 'SQL']; - - foreach ($languages as $lang) { - $calcData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'C' . substr(time(), -5) . strtoupper(substr($lang, 0, 1)), - 'TestSiteName' => "Calc with $lang", - 'TestType' => $this::TEST_TYPE_CALC, - 'details' => [ - 'FormulaInput' => '["TEST1"]', - 'FormulaCode' => 'TEST1 * 2', - 'FormulaLang' => $lang - ] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($calcData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [201, 400, 500]), - "CALC with $lang: Expected 201, 400, or 500, got $status" - ); - } - } - - /** - * Test CALC with JSON formula input - */ - public function testCalcWithJsonFormulaInput(): void - { - $calcData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'CJSN' . substr(time(), -3), - 'TestSiteName' => 'Calc with JSON Input', - 'TestType' => $this::TEST_TYPE_CALC, - 'details' => [ - 'FormulaInput' => '["parameter1", "parameter2", "parameter3"]', - 'FormulaCode' => '(param1 + param2) / param3', - 'FormulaLang' => 'FHIRP' - ] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($calcData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - } - - /** - * Test CALC with complex formula - */ - public function testCalcWithComplexFormula(): void - { - $calcData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'CCMP' . substr(time(), -3), - 'TestSiteName' => 'Calc with Complex Formula', - 'TestType' => $this::TEST_TYPE_CALC, - 'details' => [ - 'FormulaInput' => '["WBC", "NEUT", "LYMPH", "MONO", "EOS", "BASO"]', - 'FormulaCode' => 'if WBC > 0 then (NEUT + LYMPH + MONO + EOS + BASO) / WBC * 100 else 0', - 'FormulaLang' => 'Phyton' - ] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($calcData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - } - - /** - * Test update CALC formula - */ - public function testUpdateCalcFormula(): void - { - // Create a CALC first - $calcData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'UPCL' . substr(time(), -4), - 'TestSiteName' => 'Update Calc Test', - 'TestType' => $this::TEST_TYPE_CALC, - 'details' => [ - 'FormulaInput' => '["A", "B"]', - 'FormulaCode' => 'A + B', - 'FormulaLang' => 'SQL' - ] - ]; - - $createResult = $this->post($this->endpoint, ['body' => json_encode($calcData)]); - $createStatus = $createResult->response()->getStatusCode(); - - if ($createStatus === 201) { - $createBody = json_decode($createResult->response()->getBody(), true); - $calcId = $createBody['data']['TestSiteId'] ?? null; - - if ($calcId) { - // Update formula - $updateData = [ - 'TestSiteName' => 'Updated Calc Test Name', - 'details' => [ - 'FormulaInput' => '["A", "B", "C"]', - 'FormulaCode' => 'A + B + C' - ] - ]; - - $updateResult = $this->put($this->endpoint . '/' . $calcId, ['body' => json_encode($updateData)]); - $updateStatus = $updateResult->response()->getStatusCode(); - - $this->assertTrue( - in_array($updateStatus, [200, 400, 500]), - "Expected 200, 400, or 500, got $updateStatus" - ); - } - } - } - - /** - * Test CALC has correct TypeCode in response - */ - public function testCalcTypeCodeInResponse(): void - { - $indexResult = $this->get($this->endpoint . '?TestType=CALC'); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $calc = $indexBody['data'][0]; - - // Verify TypeCode is CALC - $this->assertEquals('CALC', $calc['TypeCode'] ?? ''); - } - } - - /** - * Test CALC details structure - */ - public function testCalcDetailsStructure(): void - { - $indexResult = $this->get($this->endpoint . '?TestType=CALC'); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $calc = $indexBody['data'][0]; - $calcId = $calc['TestSiteID'] ?? null; - - if ($calcId) { - $showResult = $this->get($this->endpoint . '/' . $calcId); - $showBody = json_decode($showResult->response()->getBody(), true); - - if ($showBody['data'] !== null && isset($showBody['data']['testdefcal'])) { - $calcDetails = $showBody['data']['testdefcal']; - - if (is_array($calcDetails) && !empty($calcDetails)) { - $firstDetail = $calcDetails[0]; - - // Check required fields in calc structure - $this->assertArrayHasKey('TestCalID', $firstDetail); - $this->assertArrayHasKey('TestSiteID', $firstDetail); - $this->assertArrayHasKey('FormulaInput', $firstDetail); - $this->assertArrayHasKey('FormulaCode', $firstDetail); - - // Check for joined discipline/department - if (isset($firstDetail['DisciplineName'])) { - $this->assertArrayHasKey('DepartmentName', $firstDetail); - } - } - } - } - } - } - - /** - * Test CALC delete cascades to details - */ - public function testCalcDeleteCascadesToDetails(): void - { - // Create a CALC - $calcData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'CDEL' . substr(time(), -4), - 'TestSiteName' => 'Calc to Delete', - 'TestType' => $this::TEST_TYPE_CALC, - 'details' => [ - 'FormulaInput' => '["TEST1"]', - 'FormulaCode' => 'TEST1 * 2' - ] - ]; - - $createResult = $this->post($this->endpoint, ['body' => json_encode($calcData)]); - $createStatus = $createResult->response()->getStatusCode(); - - if ($createStatus === 201) { - $createBody = json_decode($createResult->response()->getBody(), true); - $calcId = $createBody['data']['TestSiteId'] ?? null; - - if ($calcId) { - // Delete the CALC - $deleteResult = $this->delete($this->endpoint . '/' . $calcId); - $deleteStatus = $deleteResult->response()->getStatusCode(); - - $this->assertTrue( - in_array($deleteStatus, [200, 404, 500]), - "Expected 200, 404, or 500, got $deleteStatus" - ); - - if ($deleteStatus === 200) { - // Verify CALC details are also soft deleted - $showResult = $this->get($this->endpoint . '/' . $calcId); - $showBody = json_decode($showResult->response()->getBody(), true); - - // CALC should show EndDate set - if ($showBody['data'] !== null) { - $this->assertNotNull($showBody['data']['EndDate']); - } - } - } - } - } - - /** - * Test CALC with result unit configuration - */ - public function testCalcWithResultUnit(): void - { - $units = ['mg/dL', 'g/L', 'mmol/L', '%', 'IU/L']; - - foreach ($units as $unit) { - $calcData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'CUNT' . substr(time(), -3) . substr($unit, 0, 1), - 'TestSiteName' => "Calc with $unit", - 'TestType' => $this::TEST_TYPE_CALC, - 'details' => [ - 'Unit1' => $unit, - 'Decimal' => 2, - 'FormulaInput' => '["TEST1"]', - 'FormulaCode' => 'TEST1' - ] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($calcData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [201, 400, 500]), - "CALC with unit $unit: Expected 201, 400, or 500, got $status" - ); - } - } -} diff --git a/tests/feature/v2/master/TestDef/TestDefGroupTest.php b/tests/feature/v2/master/TestDef/TestDefGroupTest.php deleted file mode 100644 index 81d70bc..0000000 --- a/tests/feature/v2/master/TestDef/TestDefGroupTest.php +++ /dev/null @@ -1,291 +0,0 @@ -getExistingTestIds(); - - $groupData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'GRUP' . substr(time(), -4), - 'TestSiteName' => 'Test Group ' . time(), - 'TestType' => $this::TEST_TYPE_GROUP, - 'Description' => 'Group test with members', - 'SeqScr' => 100, - 'SeqRpt' => 100, - 'VisibleScr' => 1, - 'VisibleRpt' => 1, - 'CountStat' => 1, - 'Members' => $memberIds - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($groupData)]); - - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - - if ($status === 201) { - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('created', $body['status']); - - // Verify members were created - $groupId = $body['data']['TestSiteId']; - $showResult = $this->get($this->endpoint . '/' . $groupId); - $showBody = json_decode($showResult->response()->getBody(), true); - - if ($showBody['data'] !== null) { - $this->assertArrayHasKey('testdefgrp', $showBody['data']); - } - } - } - - /** - * Test create GROUP without members - */ - public function testCreateGroupWithoutMembers(): void - { - $groupData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'GREM' . substr(time(), -4), - 'TestSiteName' => 'Empty Group ' . time(), - 'TestType' => $this::TEST_TYPE_GROUP, - 'Members' => [] // Empty members - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($groupData)]); - - // Should still succeed but with warning or empty members - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [201, 400]), - "Expected 201 or 400, got $status" - ); - } - - /** - * Test update GROUP members - */ - public function testUpdateGroupMembers(): void - { - // Create a group first - $memberIds = $this->getExistingTestIds(); - $groupData = $this->createGroupData($memberIds); - $groupData['TestSiteCode'] = 'UPMB' . substr(time(), -4); - - $createResult = $this->post($this->endpoint, ['body' => json_encode($groupData)]); - $createStatus = $createResult->response()->getStatusCode(); - - if ($createStatus === 201) { - $createBody = json_decode($createResult->response()->getBody(), true); - $groupId = $createBody['data']['TestSiteId'] ?? null; - - if ($groupId) { - // Update with new members - $updateData = [ - 'Members' => array_slice($memberIds, 0, 1) // Only one member - ]; - - $updateResult = $this->put($this->endpoint . '/' . $groupId, ['body' => json_encode($updateData)]); - $updateStatus = $updateResult->response()->getStatusCode(); - - $this->assertTrue( - in_array($updateStatus, [200, 400, 500]), - "Expected 200, 400, or 500, got $updateStatus" - ); - } - } - } - - /** - * Test add member to existing GROUP - */ - public function testAddMemberToGroup(): void - { - // Get existing test - $indexResult = $this->get($this->endpoint . '?TestType=GROUP'); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $group = $indexBody['data'][0]; - $groupId = $group['TestSiteID'] ?? null; - - if ($groupId) { - // Get a test ID to add - $testIds = $this->getExistingTestIds(); - $newMemberId = $testIds[0] ?? 1; - - $updateData = [ - 'Members' => [$newMemberId] - ]; - - $result = $this->put($this->endpoint . '/' . $groupId, ['body' => json_encode($updateData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [200, 400, 500]), - "Expected 200, 400, or 500, got $status" - ); - } - } - } - - /** - * Test GROUP with single member - */ - public function testGroupWithSingleMember(): void - { - $memberIds = $this->getExistingTestIds(); - - $groupData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'GSGL' . substr(time(), -4), - 'TestSiteName' => 'Single Member Group ' . time(), - 'TestType' => $this::TEST_TYPE_GROUP, - 'Members' => [array_slice($memberIds, 0, 1)[0] ?? 1] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($groupData)]); - - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - } - - /** - * Test GROUP members have correct structure - */ - public function testGroupMembersStructure(): void - { - $indexResult = $this->get($this->endpoint . '?TestType=GROUP'); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $group = $indexBody['data'][0]; - $groupId = $group['TestSiteID'] ?? null; - - if ($groupId) { - $showResult = $this->get($this->endpoint . '/' . $groupId); - $showBody = json_decode($showResult->response()->getBody(), true); - - if ($showBody['data'] !== null && isset($showBody['data']['testdefgrp'])) { - $members = $showBody['data']['testdefgrp']; - - if (is_array($members) && !empty($members)) { - $firstMember = $members[0]; - - // Check required fields in member structure - $this->assertArrayHasKey('TestGrpID', $firstMember); - $this->assertArrayHasKey('TestSiteID', $firstMember); - $this->assertArrayHasKey('Member', $firstMember); - - // Check for joined test details (if loaded) - if (isset($firstMember['TestSiteCode'])) { - $this->assertArrayHasKey('TestSiteName', $firstMember); - } - } - } - } - } - } - - /** - * Test GROUP delete cascades to members - */ - public function testGroupDeleteCascadesToMembers(): void - { - // Create a group - $memberIds = $this->getExistingTestIds(); - $groupData = $this->createGroupData($memberIds); - $groupData['TestSiteCode'] = 'GDEL' . substr(time(), -4); - - $createResult = $this->post($this->endpoint, ['body' => json_encode($groupData)]); - $createStatus = $createResult->response()->getStatusCode(); - - if ($createStatus === 201) { - $createBody = json_decode($createResult->response()->getBody(), true); - $groupId = $createBody['data']['TestSiteId'] ?? null; - - if ($groupId) { - // Delete the group - $deleteResult = $this->delete($this->endpoint . '/' . $groupId); - $deleteStatus = $deleteResult->response()->getStatusCode(); - - $this->assertTrue( - in_array($deleteStatus, [200, 404, 500]), - "Expected 200, 404, or 500, got $deleteStatus" - ); - - if ($deleteStatus === 200) { - // Verify group members are also soft deleted - $showResult = $this->get($this->endpoint . '/' . $groupId); - $showBody = json_decode($showResult->response()->getBody(), true); - - // Group should show EndDate set - if ($showBody['data'] !== null) { - $this->assertNotNull($showBody['data']['EndDate']); - } - } - } - } - } - - /** - * Test GROUP type has correct TypeCode in response - */ - public function testGroupTypeCodeInResponse(): void - { - $indexResult = $this->get($this->endpoint . '?TestType=GROUP'); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $group = $indexBody['data'][0]; - - // Verify TypeCode is GROUP - $this->assertEquals('GROUP', $group['TypeCode'] ?? ''); - } - } - - /** - * Helper to get existing test IDs - */ - private function getExistingTestIds(): array - { - $indexResult = $this->get($this->endpoint); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - $ids = []; - if (isset($indexBody['data']) && is_array($indexBody['data'])) { - foreach ($indexBody['data'] as $item) { - if (isset($item['TestSiteID'])) { - $ids[] = $item['TestSiteID']; - } - if (count($ids) >= 3) { - break; - } - } - } - - return $ids ?: [1, 2, 3]; - } -} diff --git a/tests/feature/v2/master/TestDef/TestDefParamTest.php b/tests/feature/v2/master/TestDef/TestDefParamTest.php deleted file mode 100644 index 96b5e2c..0000000 --- a/tests/feature/v2/master/TestDef/TestDefParamTest.php +++ /dev/null @@ -1,288 +0,0 @@ - 1, - 'TestSiteCode' => 'PARM' . substr(time(), -4), - 'TestSiteName' => 'Parameter Test ' . time(), - 'TestType' => $this::TEST_TYPE_PARAM, - 'Description' => 'Parameter/sub-test description', - 'SeqScr' => 5, - 'SeqRpt' => 5, - 'VisibleScr' => 1, - 'VisibleRpt' => 1, - 'CountStat' => 1, - 'details' => [ - 'DisciplineID' => 1, - 'DepartmentID' => 1, - 'ResultType' => 1, // Numeric - 'RefType' => 1, // NMRC - 'Unit1' => 'unit', - 'Decimal' => 1, - 'Method' => 'Parameter Method' - ] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($paramData)]); - - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - - if ($status === 201) { - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('created', $body['status']); - - // Verify tech details were created - $paramId = $body['data']['TestSiteId']; - $showResult = $this->get($this->endpoint . '/' . $paramId); - $showBody = json_decode($showResult->response()->getBody(), true); - - if ($showBody['data'] !== null) { - $this->assertArrayHasKey('testdeftech', $showBody['data']); - } - } - } - - /** - * Test PARAM has correct TypeCode in response - */ - public function testParamTypeCodeInResponse(): void - { - $indexResult = $this->get($this->endpoint . '?TestType=PARAM'); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $param = $indexBody['data'][0]; - - // Verify TypeCode is PARAM - $this->assertEquals('PARAM', $param['TypeCode'] ?? ''); - } - } - - /** - * Test PARAM details structure - */ - public function testParamDetailsStructure(): void - { - $indexResult = $this->get($this->endpoint . '?TestType=PARAM'); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $param = $indexBody['data'][0]; - $paramId = $param['TestSiteID'] ?? null; - - if ($paramId) { - $showResult = $this->get($this->endpoint . '/' . $paramId); - $showBody = json_decode($showResult->response()->getBody(), true); - - if ($showBody['data'] !== null && isset($showBody['data']['testdeftech'])) { - $techDetails = $showBody['data']['testdeftech']; - - if (is_array($techDetails) && !empty($techDetails)) { - $firstDetail = $techDetails[0]; - - // Check required fields in tech structure - $this->assertArrayHasKey('TestTechID', $firstDetail); - $this->assertArrayHasKey('TestSiteID', $firstDetail); - $this->assertArrayHasKey('ResultType', $firstDetail); - $this->assertArrayHasKey('RefType', $firstDetail); - - // Check for joined discipline/department - if (isset($firstDetail['DisciplineName'])) { - $this->assertArrayHasKey('DepartmentName', $firstDetail); - } - } - } - } - } - } - - /** - * Test PARAM with different result types - */ - public function testParamWithDifferentResultTypes(): void - { - $resultTypes = [ - 1 => 'NMRIC', // Numeric - 2 => 'RANGE', // Range - 3 => 'TEXT', // Text - 4 => 'VSET' // Value Set - ]; - - foreach ($resultTypes as $resultTypeId => $resultTypeName) { - $paramData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'PR' . substr(time(), -4) . substr($resultTypeName, 0, 1), - 'TestSiteName' => "Param with $resultTypeName", - 'TestType' => $this::TEST_TYPE_PARAM, - 'details' => [ - 'ResultType' => $resultTypeId, - 'RefType' => 1 - ] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($paramData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [201, 400, 500]), - "PARAM with ResultType $resultTypeName: Expected 201, 400, or 500, got $status" - ); - } - } - - /** - * Test PARAM with different reference types - */ - public function testParamWithDifferentRefTypes(): void - { - $refTypes = [ - 1 => 'NMRC', // Numeric - 2 => 'TEXT' // Text - ]; - - foreach ($refTypes as $refTypeId => $refTypeName) { - $paramData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'PR' . substr(time(), -4) . 'R' . substr($refTypeName, 0, 1), - 'TestSiteName' => "Param with RefType $refTypeName", - 'TestType' => $this::TEST_TYPE_PARAM, - 'details' => [ - 'ResultType' => 1, - 'RefType' => $refTypeId - ] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($paramData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [201, 400, 500]), - "PARAM with RefType $refTypeName: Expected 201, 400, or 500, got $status" - ); - } - } - - /** - * Test PARAM delete cascades to details - */ - public function testParamDeleteCascadesToDetails(): void - { - // Create a PARAM - $paramData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'PDEL' . substr(time(), -4), - 'TestSiteName' => 'Param to Delete', - 'TestType' => $this::TEST_TYPE_PARAM, - 'details' => [ - 'ResultType' => 1, - 'RefType' => 1 - ] - ]; - - $createResult = $this->post($this->endpoint, ['body' => json_encode($paramData)]); - $createStatus = $createResult->response()->getStatusCode(); - - if ($createStatus === 201) { - $createBody = json_decode($createResult->response()->getBody(), true); - $paramId = $createBody['data']['TestSiteId'] ?? null; - - if ($paramId) { - // Delete the PARAM - $deleteResult = $this->delete($this->endpoint . '/' . $paramId); - $deleteStatus = $deleteResult->response()->getStatusCode(); - - $this->assertTrue( - in_array($deleteStatus, [200, 404, 500]), - "Expected 200, 404, or 500, got $deleteStatus" - ); - - if ($deleteStatus === 200) { - // Verify PARAM details are also soft deleted - $showResult = $this->get($this->endpoint . '/' . $paramId); - $showBody = json_decode($showResult->response()->getBody(), true); - - // PARAM should show EndDate set - if ($showBody['data'] !== null) { - $this->assertNotNull($showBody['data']['EndDate']); - } - } - } - } - } - - /** - * Test PARAM visibility settings - */ - public function testParamVisibilitySettings(): void - { - $visibilityCombinations = [ - ['VisibleScr' => 1, 'VisibleRpt' => 1], - ['VisibleScr' => 1, 'VisibleRpt' => 0], - ['VisibleScr' => 0, 'VisibleRpt' => 1], - ['VisibleScr' => 0, 'VisibleRpt' => 0] - ]; - - foreach ($visibilityCombinations as $vis) { - $paramData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'PVIS' . substr(time(), -4), - 'TestSiteName' => 'Visibility Test', - 'TestType' => $this::TEST_TYPE_PARAM, - 'VisibleScr' => $vis['VisibleScr'], - 'VisibleRpt' => $vis['VisibleRpt'] - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($paramData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [201, 400, 500]), - "PARAM visibility ({$vis['VisibleScr']}, {$vis['VisibleRpt']}): Expected 201, 400, or 500, got $status" - ); - } - } - - /** - * Test PARAM sequence ordering - */ - public function testParamSequenceOrdering(): void - { - $paramData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'PSEQ' . substr(time(), -4), - 'TestSiteName' => 'Sequenced Param', - 'TestType' => $this::TEST_TYPE_PARAM, - 'SeqScr' => 25, - 'SeqRpt' => 30 - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($paramData)]); - $status = $result->response()->getStatusCode(); - - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - } -} diff --git a/tests/feature/v2/master/TestDef/TestDefSiteTest.php b/tests/feature/v2/master/TestDef/TestDefSiteTest.php deleted file mode 100644 index 2d635f1..0000000 --- a/tests/feature/v2/master/TestDef/TestDefSiteTest.php +++ /dev/null @@ -1,375 +0,0 @@ -get($this->endpoint); - $result->assertStatus(200); - - $body = json_decode($result->response()->getBody(), true); - $this->assertArrayHasKey('status', $body); - $this->assertArrayHasKey('data', $body); - $this->assertArrayHasKey('message', $body); - } - - /** - * Test index with SiteID filter - */ - public function testIndexWithSiteFilter(): void - { - $result = $this->get($this->endpoint . '?SiteID=1'); - $result->assertStatus(200); - - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('success', $body['status']); - } - - /** - * Test index with TestType filter - */ - public function testIndexWithTestTypeFilter(): void - { - // Filter by TEST type - $result = $this->get($this->endpoint . '?TestType=TEST'); - $result->assertStatus(200); - - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('success', $body['status']); - } - - /** - * Test index with Visibility filter - */ - public function testIndexWithVisibilityFilter(): void - { - $result = $this->get($this->endpoint . '?VisibleScr=1&VisibleRpt=1'); - $result->assertStatus(200); - - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('success', $body['status']); - } - - /** - * Test index with keyword search - */ - public function testIndexWithKeywordSearch(): void - { - $result = $this->get($this->endpoint . '?TestSiteName=hemoglobin'); - $result->assertStatus(200); - - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('success', $body['status']); - } - - /** - * Test show endpoint returns single test - */ - public function testShowReturnsSingleTest(): void - { - // First get the list to find a valid ID - $indexResult = $this->get($this->endpoint); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $firstItem = $indexBody['data'][0]; - $testSiteID = $firstItem['TestSiteID'] ?? null; - - if ($testSiteID) { - $showResult = $this->get($this->endpoint . '/' . $testSiteID); - $showResult->assertStatus(200); - - $body = json_decode($showResult->response()->getBody(), true); - $this->assertArrayHasKey('data', $body); - $this->assertEquals('success', $body['status']); - - // Check that related details are loaded based on TestType - if ($body['data'] !== null) { - $typeCode = $body['data']['TypeCode'] ?? ''; - if ($typeCode === 'CALC') { - $this->assertArrayHasKey('testdefcal', $body['data']); - } elseif ($typeCode === 'GROUP') { - $this->assertArrayHasKey('testdefgrp', $body['data']); - } elseif (in_array($typeCode, ['TEST', 'PARAM'])) { - $this->assertArrayHasKey('testdeftech', $body['data']); - } - // All types should have testmap - $this->assertArrayHasKey('testmap', $body['data']); - } - } - } - } - - /** - * Test show with non-existent ID returns null data - */ - public function testShowWithInvalidIDReturnsNull(): void - { - $result = $this->get($this->endpoint . '/9999999'); - $result->assertStatus(200); - - $body = json_decode($result->response()->getBody(), true); - $this->assertArrayHasKey('data', $body); - $this->assertNull($body['data']); - } - - /** - * Test create new TEST type test definition - */ - public function testCreateTestTypeTest(): void - { - $testData = $this->createTestData(); - - $result = $this->post($this->endpoint, ['body' => json_encode($testData)]); - - $status = $result->response()->getStatusCode(); - // Expect 201 (created) or 400 (validation error) or 500 (server error) - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - - if ($status === 201) { - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('created', $body['status']); - $this->assertArrayHasKey('TestSiteId', $body['data']); - } - } - - /** - * Test create new PARAM type test definition - */ - public function testCreateParamTypeTest(): void - { - $paramData = $this->createParamData(); - - $result = $this->post($this->endpoint, ['body' => json_encode($paramData)]); - - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - } - - /** - * Test create new GROUP type test definition - */ - public function testCreateGroupTypeTest(): void - { - // First create some member tests - $memberIds = $this->getExistingTestIds(); - - $groupData = $this->createGroupData($memberIds); - - $result = $this->post($this->endpoint, ['body' => json_encode($groupData)]); - - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - } - - /** - * Test create new CALC type test definition - */ - public function testCreateCalcTypeTest(): void - { - $calcData = $this->createCalcData(); - - $result = $this->post($this->endpoint, ['body' => json_encode($calcData)]); - - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [201, 400, 500]), - "Expected 201, 400, or 500, got $status" - ); - } - - /** - * Test update existing test - */ - public function testUpdateTest(): void - { - $indexResult = $this->get($this->endpoint); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - if (isset($indexBody['data']) && is_array($indexBody['data']) && !empty($indexBody['data'])) { - $firstItem = $indexBody['data'][0]; - $testSiteID = $firstItem['TestSiteID'] ?? null; - - if ($testSiteID) { - $updateData = [ - 'TestSiteName' => 'Updated Test Name ' . time(), - 'Description' => 'Updated description' - ]; - - $result = $this->put($this->endpoint . '/' . $testSiteID, ['body' => json_encode($updateData)]); - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [200, 404, 500]), - "Expected 200, 404, or 500, got $status" - ); - - if ($status === 200) { - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('success', $body['status']); - } - } - } - } - - /** - * Test soft delete (disable) test - */ - public function testDeleteTest(): void - { - // Create a test first to delete - $testData = $this->createTestData(); - $testData['TestSiteCode'] = 'DEL' . substr(time(), -4); - - $createResult = $this->post($this->endpoint, ['body' => json_encode($testData)]); - $createStatus = $createResult->response()->getStatusCode(); - - if ($createStatus === 201) { - $createBody = json_decode($createResult->response()->getBody(), true); - $testSiteID = $createBody['data']['TestSiteId'] ?? null; - - if ($testSiteID) { - $deleteResult = $this->delete($this->endpoint . '/' . $testSiteID); - $deleteStatus = $deleteResult->response()->getStatusCode(); - - $this->assertTrue( - in_array($deleteStatus, [200, 404, 500]), - "Expected 200, 404, or 500, got $deleteStatus" - ); - - if ($deleteStatus === 200) { - $deleteBody = json_decode($deleteResult->response()->getBody(), true); - $this->assertEquals('success', $deleteBody['status']); - $this->assertArrayHasKey('EndDate', $deleteBody['data']); - } - } - } - } - - /** - * Test validation - missing required fields - */ - public function testCreateValidationRequiredFields(): void - { - $invalidData = [ - 'TestSiteName' => 'Test without required fields' - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($invalidData)]); - $result->assertStatus(400); - } - - /** - * Test that TestSiteCode is max 6 characters - */ - public function testTestSiteCodeLength(): void - { - $invalidData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'HB123456', // 8 characters - invalid - 'TestSiteName' => 'Test with too long code', - 'TestType' => $this::TEST_TYPE_TEST - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($invalidData)]); - $result->assertStatus(400); - } - - /** - * Test that TestSiteCode is at least 3 characters - */ - public function testTestSiteCodeMinLength(): void - { - $invalidData = [ - 'SiteID' => 1, - 'TestSiteCode' => 'HB', // 2 characters - invalid - 'TestSiteName' => 'Test with too short code', - 'TestType' => $this::TEST_TYPE_TEST - ]; - - $result = $this->post($this->endpoint, ['body' => json_encode($invalidData)]); - $result->assertStatus(400); - } - - /** - * Test that duplicate TestSiteCode is rejected - */ - public function testDuplicateTestSiteCode(): void - { - // First create a test - $testData = $this->createTestData(); - $testData['TestSiteCode'] = 'DUP' . substr(time(), -3); - - $this->post($this->endpoint, ['body' => json_encode($testData)]); - - // Try to create another test with the same code - $duplicateData = $testData; - $duplicateData['TestSiteName'] = 'Different Name'; - - $result = $this->post($this->endpoint, ['body' => json_encode($duplicateData)]); - - // Should fail with 400 or 500 - $status = $result->response()->getStatusCode(); - $this->assertTrue( - in_array($status, [400, 500]), - "Expected 400 or 500 for duplicate, got $status" - ); - } - - /** - * Test filtering by multiple parameters - */ - public function testIndexWithMultipleFilters(): void - { - $result = $this->get($this->endpoint . '?SiteID=1&TestType=TEST&VisibleScr=1'); - $result->assertStatus(200); - - $body = json_decode($result->response()->getBody(), true); - $this->assertEquals('success', $body['status']); - } - - /** - * Helper method to get existing test IDs for group members - */ - private function getExistingTestIds(): array - { - $indexResult = $this->get($this->endpoint); - $indexBody = json_decode($indexResult->response()->getBody(), true); - - $ids = []; - if (isset($indexBody['data']) && is_array($indexBody['data'])) { - foreach ($indexBody['data'] as $item) { - if (isset($item['TestSiteID'])) { - $ids[] = $item['TestSiteID']; - } - if (count($ids) >= 2) { - break; - } - } - } - - return $ids ?: [1, 2]; - } -} diff --git a/tests/unit/HealthTest.php b/tests/unit/HealthTest.php index b3e480f..75f2016 100644 --- a/tests/unit/HealthTest.php +++ b/tests/unit/HealthTest.php @@ -34,13 +34,11 @@ final class HealthTest extends CIUnitTestCase $validation->check($config->baseURL, 'valid_url'), 'baseURL "' . $config->baseURL . '" in .env is not valid URL', ); + return; } - // Get the baseURL in app/Config/App.php - // You can't use Config\App, because phpunit.xml.dist sets app.baseURL + // If no baseURL in .env, check app/Config/App.php $reader = new ConfigReader(); - - // BaseURL in app/Config/App.php is a valid URL? $this->assertTrue( $validation->check($reader->baseURL, 'valid_url'), 'baseURL "' . $reader->baseURL . '" in app/Config/App.php is not valid URL', diff --git a/tests/unit/v2/master/TestDef/TestDefCalModelTest.php b/tests/unit/v2/master/TestDef/TestDefCalModelTest.php deleted file mode 100644 index a7bf3ed..0000000 --- a/tests/unit/v2/master/TestDef/TestDefCalModelTest.php +++ /dev/null @@ -1,145 +0,0 @@ -model = new TestDefCalModel(); - } - - /** - * Test model has correct table name - */ - public function testModelHasCorrectTableName(): void - { - $this->assertEquals('testdefcal', $this->model->table); - } - - /** - * Test model has correct primary key - */ - public function testModelHasCorrectPrimaryKey(): void - { - $this->assertEquals('TestCalID', $this->model->primaryKey); - } - - /** - * Test model uses soft deletes - */ - public function testModelUsesSoftDeletes(): void - { - $this->assertTrue($this->model->useSoftDeletes); - $this->assertEquals('EndDate', $this->model->deletedField); - } - - /** - * Test model has correct allowed fields - */ - public function testModelHasCorrectAllowedFields(): void - { - $allowedFields = $this->model->allowedFields; - - // Foreign key - $this->assertContains('TestSiteID', $allowedFields); - - // Calculation fields - $this->assertContains('DisciplineID', $allowedFields); - $this->assertContains('DepartmentID', $allowedFields); - $this->assertContains('FormulaInput', $allowedFields); - $this->assertContains('FormulaCode', $allowedFields); - - // Result fields - $this->assertContains('RefType', $allowedFields); - $this->assertContains('Unit1', $allowedFields); - $this->assertContains('Factor', $allowedFields); - $this->assertContains('Unit2', $allowedFields); - $this->assertContains('Decimal', $allowedFields); - $this->assertContains('Method', $allowedFields); - - // Timestamp fields - $this->assertContains('CreateDate', $allowedFields); - $this->assertContains('EndDate', $allowedFields); - } - - /** - * Test model uses timestamps - */ - public function testModelUsesTimestamps(): void - { - $this->assertTrue($this->model->useTimestamps); - $this->assertEquals('CreateDate', $this->model->createdField); - } - - /** - * Test model return type is array - */ - public function testModelReturnTypeIsArray(): void - { - $this->assertEquals('array', $this->model->returnType); - } - - /** - * Test model has correct skip validation - */ - public function testModelSkipValidation(): void - { - $this->assertFalse($this->model->skipValidation); - } - - /** - * Test model has correct useAutoIncrement - */ - public function testModelUseAutoIncrement(): void - { - $this->assertTrue($this->model->useAutoIncrement); - } - - /** - * Test FormulaInput field is in allowed fields - */ - public function testFormulaInputFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('FormulaInput', $allowedFields); - } - - /** - * Test FormulaCode field is in allowed fields - */ - public function testFormulaCodeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('FormulaCode', $allowedFields); - } - - /** - * Test RefType field is in allowed fields - */ - public function testRefTypeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('RefType', $allowedFields); - } - - /** - * Test Method field is in allowed fields - */ - public function testMethodFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('Method', $allowedFields); - } -} diff --git a/tests/unit/v2/master/TestDef/TestDefGrpModelTest.php b/tests/unit/v2/master/TestDef/TestDefGrpModelTest.php deleted file mode 100644 index 5951120..0000000 --- a/tests/unit/v2/master/TestDef/TestDefGrpModelTest.php +++ /dev/null @@ -1,132 +0,0 @@ -model = new TestDefGrpModel(); - } - - /** - * Test model has correct table name - */ - public function testModelHasCorrectTableName(): void - { - $this->assertEquals('testdefgrp', $this->model->table); - } - - /** - * Test model has correct primary key - */ - public function testModelHasCorrectPrimaryKey(): void - { - $this->assertEquals('TestGrpID', $this->model->primaryKey); - } - - /** - * Test model uses soft deletes - */ - public function testModelUsesSoftDeletes(): void - { - $this->assertTrue($this->model->useSoftDeletes); - $this->assertEquals('EndDate', $this->model->deletedField); - } - - /** - * Test model has correct allowed fields - */ - public function testModelHasCorrectAllowedFields(): void - { - $allowedFields = $this->model->allowedFields; - - // Foreign keys - $this->assertContains('TestSiteID', $allowedFields); - $this->assertContains('Member', $allowedFields); - - // Timestamp fields - $this->assertContains('CreateDate', $allowedFields); - $this->assertContains('EndDate', $allowedFields); - } - - /** - * Test model uses timestamps - */ - public function testModelUsesTimestamps(): void - { - $this->assertTrue($this->model->useTimestamps); - $this->assertEquals('CreateDate', $this->model->createdField); - } - - /** - * Test model return type is array - */ - public function testModelReturnTypeIsArray(): void - { - $this->assertEquals('array', $this->model->returnType); - } - - /** - * Test model has correct skip validation - */ - public function testModelSkipValidation(): void - { - $this->assertFalse($this->model->skipValidation); - } - - /** - * Test model has correct useAutoIncrement - */ - public function testModelUseAutoIncrement(): void - { - $this->assertTrue($this->model->useAutoIncrement); - } - - /** - * Test TestSiteID field is in allowed fields - */ - public function testTestSiteIDFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestSiteID', $allowedFields); - } - - /** - * Test Member field is in allowed fields - */ - public function testMemberFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('Member', $allowedFields); - } - - /** - * Test CreateDate field is in allowed fields - */ - public function testCreateDateFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('CreateDate', $allowedFields); - } - - /** - * Test EndDate field is in allowed fields - */ - public function testEndDateFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('EndDate', $allowedFields); - } -} diff --git a/tests/unit/v2/master/TestDef/TestDefSiteModelMasterTest.php b/tests/unit/v2/master/TestDef/TestDefSiteModelMasterTest.php deleted file mode 100644 index 528feb0..0000000 --- a/tests/unit/v2/master/TestDef/TestDefSiteModelMasterTest.php +++ /dev/null @@ -1,220 +0,0 @@ -model = new TestDefSiteModel(); - } - - /** - * Test model has correct table name - */ - public function testModelHasCorrectTableName(): void - { - $this->assertEquals('testdefsite', $this->model->table); - } - - /** - * Test model has correct primary key - */ - public function testModelHasCorrectPrimaryKey(): void - { - $this->assertEquals('TestSiteID', $this->model->primaryKey); - } - - /** - * Test model uses soft deletes - */ - public function testModelUsesSoftDeletes(): void - { - $this->assertTrue($this->model->useSoftDeletes); - $this->assertEquals('EndDate', $this->model->deletedField); - } - - /** - * Test model has correct allowed fields for master data - */ - public function testModelHasCorrectAllowedFields(): void - { - $allowedFields = $this->model->allowedFields; - - // Core required fields - $this->assertContains('SiteID', $allowedFields); - $this->assertContains('TestSiteCode', $allowedFields); - $this->assertContains('TestSiteName', $allowedFields); - $this->assertContains('TestType', $allowedFields); - - // Display and ordering fields - $this->assertContains('Description', $allowedFields); - $this->assertContains('SeqScr', $allowedFields); - $this->assertContains('SeqRpt', $allowedFields); - $this->assertContains('IndentLeft', $allowedFields); - $this->assertContains('FontStyle', $allowedFields); - - // Visibility fields - $this->assertContains('VisibleScr', $allowedFields); - $this->assertContains('VisibleRpt', $allowedFields); - $this->assertContains('CountStat', $allowedFields); - - // Timestamp fields - $this->assertContains('CreateDate', $allowedFields); - $this->assertContains('StartDate', $allowedFields); - $this->assertContains('EndDate', $allowedFields); - } - - /** - * Test model uses timestamps - */ - public function testModelUsesTimestamps(): void - { - $this->assertTrue($this->model->useTimestamps); - $this->assertEquals('CreateDate', $this->model->createdField); - $this->assertEquals('StartDate', $this->model->updatedField); - } - - /** - * Test model return type is array - */ - public function testModelReturnTypeIsArray(): void - { - $this->assertEquals('array', $this->model->returnType); - } - - /** - * Test model has correct skip validation - */ - public function testModelSkipValidation(): void - { - $this->assertFalse($this->model->skipValidation); - } - - /** - * Test model has correct useAutoIncrement - */ - public function testModelUseAutoIncrement(): void - { - $this->assertTrue($this->model->useAutoIncrement); - } - - /** - * Test TestSiteCode field is in allowed fields - */ - public function testTestSiteCodeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestSiteCode', $allowedFields); - } - - /** - * Test TestSiteName field is in allowed fields - */ - public function testTestSiteNameFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestSiteName', $allowedFields); - } - - /** - * Test TestType field is in allowed fields - */ - public function testTestTypeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestType', $allowedFields); - } - - /** - * Test SiteID field is in allowed fields - */ - public function testSiteIDFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('SiteID', $allowedFields); - } - - /** - * Test Description field is in allowed fields - */ - public function testDescriptionFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('Description', $allowedFields); - } - - /** - * Test SeqScr field is in allowed fields - */ - public function testSeqScrFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('SeqScr', $allowedFields); - } - - /** - * Test SeqRpt field is in allowed fields - */ - public function testSeqRptFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('SeqRpt', $allowedFields); - } - - /** - * Test VisibleScr field is in allowed fields - */ - public function testVisibleScrFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('VisibleScr', $allowedFields); - } - - /** - * Test VisibleRpt field is in allowed fields - */ - public function testVisibleRptFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('VisibleRpt', $allowedFields); - } - - /** - * Test CountStat field is in allowed fields - */ - public function testCountStatFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('CountStat', $allowedFields); - } - - /** - * Test getTests method exists and is callable - */ - public function testGetTestsMethodExists(): void - { - $this->assertTrue(method_exists($this->model, 'getTests')); - $this->assertIsCallable([$this->model, 'getTests']); - } - - /** - * Test getTest method exists and is callable - */ - public function testGetTestMethodExists(): void - { - $this->assertTrue(method_exists($this->model, 'getTest')); - $this->assertIsCallable([$this->model, 'getTest']); - } -} diff --git a/tests/unit/v2/master/TestDef/TestDefSiteModelTest.php b/tests/unit/v2/master/TestDef/TestDefSiteModelTest.php deleted file mode 100644 index 241ccec..0000000 --- a/tests/unit/v2/master/TestDef/TestDefSiteModelTest.php +++ /dev/null @@ -1,137 +0,0 @@ -model = new TestDefSiteModel(); - } - - /** - * Test model has correct table name - */ - public function testModelHasCorrectTableName(): void - { - $this->assertEquals('testdefsite', $this->model->table); - } - - /** - * Test model has correct primary key - */ - public function testModelHasCorrectPrimaryKey(): void - { - $this->assertEquals('TestSiteID', $this->model->primaryKey); - } - - /** - * Test model uses soft deletes - */ - public function testModelUsesSoftDeletes(): void - { - $this->assertTrue($this->model->useSoftDeletes); - $this->assertEquals('EndDate', $this->model->deletedField); - } - - /** - * Test model has correct allowed fields - */ - public function testModelHasCorrectAllowedFields(): void - { - $allowedFields = $this->model->allowedFields; - - // Core required fields - $this->assertContains('SiteID', $allowedFields); - $this->assertContains('TestSiteCode', $allowedFields); - $this->assertContains('TestSiteName', $allowedFields); - $this->assertContains('TestType', $allowedFields); - - // Optional fields - $this->assertContains('Description', $allowedFields); - $this->assertContains('SeqScr', $allowedFields); - $this->assertContains('SeqRpt', $allowedFields); - $this->assertContains('IndentLeft', $allowedFields); - $this->assertContains('FontStyle', $allowedFields); - $this->assertContains('VisibleScr', $allowedFields); - $this->assertContains('VisibleRpt', $allowedFields); - $this->assertContains('CountStat', $allowedFields); - - // Timestamp fields - $this->assertContains('CreateDate', $allowedFields); - $this->assertContains('StartDate', $allowedFields); - $this->assertContains('EndDate', $allowedFields); - } - - /** - * Test model uses timestamps - */ - public function testModelUsesTimestamps(): void - { - $this->assertTrue($this->model->useTimestamps); - $this->assertEquals('CreateDate', $this->model->createdField); - $this->assertEquals('StartDate', $this->model->updatedField); - } - - /** - * Test model return type is array - */ - public function testModelReturnTypeIsArray(): void - { - $this->assertEquals('array', $this->model->returnType); - } - - /** - * Test model has correct skip validation - */ - public function testModelSkipValidation(): void - { - $this->assertFalse($this->model->skipValidation); - } - - /** - * Test model has correct useAutoIncrement - */ - public function testModelUseAutoIncrement(): void - { - $this->assertTrue($this->model->useAutoIncrement); - } - - /** - * Test TestSiteCode field is in allowed fields - */ - public function testTestSiteCodeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestSiteCode', $allowedFields); - } - - /** - * Test TestSiteName field is in allowed fields - */ - public function testTestSiteNameFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestSiteName', $allowedFields); - } - - /** - * Test TestType field is in allowed fields - */ - public function testTestTypeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestType', $allowedFields); - } -} diff --git a/tests/unit/v2/master/TestDef/TestDefTechModelTest.php b/tests/unit/v2/master/TestDef/TestDefTechModelTest.php deleted file mode 100644 index 296a28b..0000000 --- a/tests/unit/v2/master/TestDef/TestDefTechModelTest.php +++ /dev/null @@ -1,160 +0,0 @@ -model = new TestDefTechModel(); - } - - /** - * Test model has correct table name - */ - public function testModelHasCorrectTableName(): void - { - $this->assertEquals('testdeftech', $this->model->table); - } - - /** - * Test model has correct primary key - */ - public function testModelHasCorrectPrimaryKey(): void - { - $this->assertEquals('TestTechID', $this->model->primaryKey); - } - - /** - * Test model uses soft deletes - */ - public function testModelUsesSoftDeletes(): void - { - $this->assertTrue($this->model->useSoftDeletes); - $this->assertEquals('EndDate', $this->model->deletedField); - } - - /** - * Test model has correct allowed fields - */ - public function testModelHasCorrectAllowedFields(): void - { - $allowedFields = $this->model->allowedFields; - - // Foreign key - $this->assertContains('TestSiteID', $allowedFields); - - // Technical fields - $this->assertContains('DisciplineID', $allowedFields); - $this->assertContains('DepartmentID', $allowedFields); - $this->assertContains('ResultType', $allowedFields); - $this->assertContains('RefType', $allowedFields); - $this->assertContains('VSet', $allowedFields); - - // Quantity and units - $this->assertContains('ReqQty', $allowedFields); - $this->assertContains('ReqQtyUnit', $allowedFields); - $this->assertContains('Unit1', $allowedFields); - $this->assertContains('Factor', $allowedFields); - $this->assertContains('Unit2', $allowedFields); - $this->assertContains('Decimal', $allowedFields); - - // Collection and method - $this->assertContains('CollReq', $allowedFields); - $this->assertContains('Method', $allowedFields); - $this->assertContains('ExpectedTAT', $allowedFields); - - // Timestamp fields - $this->assertContains('CreateDate', $allowedFields); - $this->assertContains('EndDate', $allowedFields); - } - - /** - * Test model uses timestamps - */ - public function testModelUsesTimestamps(): void - { - $this->assertTrue($this->model->useTimestamps); - $this->assertEquals('CreateDate', $this->model->createdField); - } - - /** - * Test model return type is array - */ - public function testModelReturnTypeIsArray(): void - { - $this->assertEquals('array', $this->model->returnType); - } - - /** - * Test model has correct skip validation - */ - public function testModelSkipValidation(): void - { - $this->assertFalse($this->model->skipValidation); - } - - /** - * Test model has correct useAutoIncrement - */ - public function testModelUseAutoIncrement(): void - { - $this->assertTrue($this->model->useAutoIncrement); - } - - /** - * Test TestSiteID field is in allowed fields - */ - public function testTestSiteIDFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestSiteID', $allowedFields); - } - - /** - * Test ResultType field is in allowed fields - */ - public function testResultTypeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('ResultType', $allowedFields); - } - - /** - * Test RefType field is in allowed fields - */ - public function testRefTypeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('RefType', $allowedFields); - } - - /** - * Test Unit1 field is in allowed fields - */ - public function testUnit1FieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('Unit1', $allowedFields); - } - - /** - * Test Method field is in allowed fields - */ - public function testMethodFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('Method', $allowedFields); - } -} diff --git a/tests/unit/v2/master/TestDef/TestMapModelTest.php b/tests/unit/v2/master/TestDef/TestMapModelTest.php deleted file mode 100644 index 64f3d4c..0000000 --- a/tests/unit/v2/master/TestDef/TestMapModelTest.php +++ /dev/null @@ -1,155 +0,0 @@ -model = new TestMapModel(); - } - - /** - * Test model has correct table name - */ - public function testModelHasCorrectTableName(): void - { - $this->assertEquals('testmap', $this->model->table); - } - - /** - * Test model has correct primary key - */ - public function testModelHasCorrectPrimaryKey(): void - { - $this->assertEquals('TestMapID', $this->model->primaryKey); - } - - /** - * Test model uses soft deletes - */ - public function testModelUsesSoftDeletes(): void - { - $this->assertTrue($this->model->useSoftDeletes); - $this->assertEquals('EndDate', $this->model->deletedField); - } - - /** - * Test model has correct allowed fields - */ - public function testModelHasCorrectAllowedFields(): void - { - $allowedFields = $this->model->allowedFields; - - // Foreign key - $this->assertContains('TestSiteID', $allowedFields); - - // Host system mapping - $this->assertContains('HostType', $allowedFields); - $this->assertContains('HostID', $allowedFields); - $this->assertContains('HostDataSource', $allowedFields); - $this->assertContains('HostTestCode', $allowedFields); - $this->assertContains('HostTestName', $allowedFields); - - // Client system mapping - $this->assertContains('ClientType', $allowedFields); - $this->assertContains('ClientID', $allowedFields); - $this->assertContains('ClientDataSource', $allowedFields); - $this->assertContains('ConDefID', $allowedFields); - $this->assertContains('ClientTestCode', $allowedFields); - $this->assertContains('ClientTestName', $allowedFields); - - // Timestamp fields - $this->assertContains('CreateDate', $allowedFields); - $this->assertContains('EndDate', $allowedFields); - } - - /** - * Test model uses timestamps - */ - public function testModelUsesTimestamps(): void - { - $this->assertTrue($this->model->useTimestamps); - $this->assertEquals('CreateDate', $this->model->createdField); - } - - /** - * Test model return type is array - */ - public function testModelReturnTypeIsArray(): void - { - $this->assertEquals('array', $this->model->returnType); - } - - /** - * Test model has correct skip validation - */ - public function testModelSkipValidation(): void - { - $this->assertFalse($this->model->skipValidation); - } - - /** - * Test model has correct useAutoIncrement - */ - public function testModelUseAutoIncrement(): void - { - $this->assertTrue($this->model->useAutoIncrement); - } - - /** - * Test HostType field is in allowed fields - */ - public function testHostTypeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('HostType', $allowedFields); - } - - /** - * Test HostID field is in allowed fields - */ - public function testHostIDFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('HostID', $allowedFields); - } - - /** - * Test HostTestCode field is in allowed fields - */ - public function testHostTestCodeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('HostTestCode', $allowedFields); - } - - /** - * Test ClientType field is in allowed fields - */ - public function testClientTypeFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('ClientType', $allowedFields); - } - - /** - * Test TestSiteID field is in allowed fields - */ - public function testTestSiteIDFieldExists(): void - { - $allowedFields = $this->model->allowedFields; - $this->assertContains('TestSiteID', $allowedFields); - } -}