64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\App\Models;
|
|
|
|
use Tests\Support\DBReset;
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
use App\Models\AttendanceDataModel;
|
|
|
|
class AttendanceDataModelTest extends CIUnitTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
DBReset::resetDatabase();
|
|
}
|
|
|
|
public function testCanInsertAndRetrieve()
|
|
{
|
|
$model = new AttendanceDataModel();
|
|
$id = $model->insert($this->validAttendanceRow());
|
|
|
|
$this->assertNotFalse($id);
|
|
|
|
$fetched = $model->find($id);
|
|
$this->assertSame((int) $id, (int) $fetched['id']);
|
|
}
|
|
|
|
public function testCanUpdate()
|
|
{
|
|
$model = new AttendanceDataModel();
|
|
$id = $model->insert($this->validAttendanceRow());
|
|
|
|
$this->assertTrue($model->update($id, ['updated_at' => date('Y-m-d H:i:s')]));
|
|
}
|
|
|
|
public function testCanDelete()
|
|
{
|
|
$model = new AttendanceDataModel();
|
|
$id = $model->insert($this->validAttendanceRow());
|
|
|
|
$model->delete($id);
|
|
|
|
$this->assertNull($model->find($id));
|
|
}
|
|
|
|
private function validAttendanceRow(): array
|
|
{
|
|
return [
|
|
'class_id' => 1,
|
|
'class_section_id' => 1,
|
|
'school_id' => 1,
|
|
'student_id' => 1,
|
|
'date' => '2026-01-01',
|
|
'status' => 'present',
|
|
'reason' => '',
|
|
'is_reported' => 'no',
|
|
'is_notified' => 'no',
|
|
'semester' => 'Fall',
|
|
'school_year' => '2025-2026',
|
|
'modified_by' => 1,
|
|
];
|
|
}
|
|
}
|