@@ -16,25 +16,48 @@ class AttendanceDataModelTest extends CIUnitTestCase
|
||||
|
||||
public function testCanInsertAndRetrieve()
|
||||
{
|
||||
$record = fake(AttendanceDataModel::class);
|
||||
$this->assertNotNull($record->id);
|
||||
$fetched = (new AttendanceDataModel())->find($record->id);
|
||||
$this->assertEquals($record->id, $fetched->id);
|
||||
$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()
|
||||
{
|
||||
$record = fake(AttendanceDataModel::class);
|
||||
$model = new AttendanceDataModel();
|
||||
$model->update($record->id, ['updated_at' => date('Y-m-d H:i:s')]);
|
||||
$this->assertTrue(true); // simple test to verify no exception thrown
|
||||
$id = $model->insert($this->validAttendanceRow());
|
||||
|
||||
$this->assertTrue($model->update($id, ['updated_at' => date('Y-m-d H:i:s')]));
|
||||
}
|
||||
|
||||
public function testCanDelete()
|
||||
{
|
||||
$record = fake(AttendanceDataModel::class);
|
||||
$model = new AttendanceDataModel();
|
||||
$model->delete($record->id);
|
||||
$this->assertNull($model->find($record->id));
|
||||
$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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user