add controllers, servoices
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Assignment;
|
||||
|
||||
use App\Models\Configuration;
|
||||
use App\Services\Assignment\AssignmentContextService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssignmentContextServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_get_current_term_values(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
$service = new AssignmentContextService(new Configuration());
|
||||
|
||||
$this->assertSame('Fall', $service->getCurrentSemester());
|
||||
$this->assertSame('2025-2026', $service->getCurrentSchoolYear());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Assignment;
|
||||
|
||||
use App\Models\StudentClass;
|
||||
use App\Models\TeacherClass;
|
||||
use App\Services\Assignment\AssignmentDataLoaderService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssignmentDataLoaderServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_load_teacher_classes_includes_teacher_name(): void
|
||||
{
|
||||
$this->seedTeacherData();
|
||||
|
||||
$service = new AssignmentDataLoaderService(new TeacherClass(), new StudentClass());
|
||||
$rows = $service->loadTeacherClasses('2025-2026');
|
||||
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertSame('Teacher One', $rows->first()->teacher_full_name);
|
||||
}
|
||||
|
||||
public function test_load_student_classes_filters_inactive(): void
|
||||
{
|
||||
$this->seedStudentData();
|
||||
|
||||
$service = new AssignmentDataLoaderService(new TeacherClass(), new StudentClass());
|
||||
$rows = $service->loadStudentClasses('2025-2026');
|
||||
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertSame(1, $rows->first()->student_id);
|
||||
}
|
||||
|
||||
private function seedTeacherData(): void
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'One',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('teacher_class')->insert([
|
||||
'teacher_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'position' => 'main',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedStudentData(): void
|
||||
{
|
||||
DB::table('students')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'school_id' => 'S-1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'Active',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'school_id' => 'S-2',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'Inactive',
|
||||
'age' => 9,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 0,
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'student_id' => 2,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Assignment;
|
||||
|
||||
use App\Services\Assignment\AssignmentMetaService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssignmentMetaServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_get_school_years_uses_fallback(): void
|
||||
{
|
||||
$service = new AssignmentMetaService();
|
||||
$years = $service->getSchoolYears('2025-2026');
|
||||
|
||||
$this->assertSame(['2025-2026'], $years);
|
||||
}
|
||||
|
||||
public function test_get_school_years_returns_distinct_sorted(): void
|
||||
{
|
||||
DB::table('teacher_class')->insert([
|
||||
['class_section_id' => 101, 'teacher_id' => 1, 'position' => 'main', 'school_year' => '2024-2025'],
|
||||
['class_section_id' => 102, 'teacher_id' => 2, 'position' => 'main', 'school_year' => '2025-2026'],
|
||||
['class_section_id' => 103, 'teacher_id' => 3, 'position' => 'main', 'school_year' => '2025-2026'],
|
||||
]);
|
||||
|
||||
$service = new AssignmentMetaService();
|
||||
$years = $service->getSchoolYears();
|
||||
|
||||
$this->assertSame(['2025-2026', '2024-2025'], $years);
|
||||
}
|
||||
|
||||
public function test_first_non_empty_returns_first_value(): void
|
||||
{
|
||||
$service = new AssignmentMetaService();
|
||||
$value = $service->firstNonEmpty([null, '', 'Fall', 'Spring']);
|
||||
|
||||
$this->assertSame('Fall', $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Assignment;
|
||||
|
||||
use App\Models\ClassSection;
|
||||
use App\Services\Assignment\AssignmentSectionService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssignmentSectionServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_get_section_names_map(): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new AssignmentSectionService(new ClassSection());
|
||||
$map = $service->getSectionNamesMap([1]);
|
||||
|
||||
$this->assertSame('1-A', $map[1]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user