clqms-be/tests/unit/v2/master/TestDef/TestDefSiteModelMasterTest.php
mahdahar cd65e91db1 refactor: Rename controllers to follow CodeIgniter 4 naming convention
- Rename all controllers from X.php to XController.php format
- Add new RefTxtModel for text-based reference ranges
- Rename group_dialog.php to grp_dialog.php and remove title_dialog.php
- Add comprehensive test suite for v2/master/TestDef module
- Update Routes.php to reflect controller renames
- Remove obsolete data files (clqms_v2.sql, lab.dbml)
2026-01-05 16:55:34 +07:00

221 lines
5.6 KiB
PHP

<?php
namespace Tests\Unit\v2\master\TestDef;
use CodeIgniter\Test\CIUnitTestCase;
use App\Models\Test\TestDefSiteModel;
/**
* Unit tests for TestDefSiteModel - Master Data Tests CRUD operations
*
* Tests the model configuration and behavior for test definition management
*/
class TestDefSiteModelMasterTest extends CIUnitTestCase
{
protected TestDefSiteModel $model;
protected function setUp(): void
{
parent::setUp();
$this->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']);
}
}