clqms-be/tests/unit/v2/master/TestDef/TestDefCalModelTest.php

146 lines
3.5 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Unit\v2\master\TestDef;
use CodeIgniter\Test\CIUnitTestCase;
use App\Models\Test\TestDefCalModel;
/**
* Unit tests for TestDefCalModel
*
* Tests the calculation definition model for CALC type tests
*/
class TestDefCalModelTest extends CIUnitTestCase
{
protected TestDefCalModel $model;
protected function setUp(): void
{
parent::setUp();
$this->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);
}
}