add stickers logic
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Reports\Stickers;
|
||||
|
||||
use App\Services\Reports\Stickers\StickerPresetService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StickerPresetServiceTest extends TestCase
|
||||
{
|
||||
public function test_presets_include_alias_fields(): void
|
||||
{
|
||||
$service = new StickerPresetService();
|
||||
$presets = $service->presets();
|
||||
|
||||
$this->assertNotEmpty($presets);
|
||||
$this->assertArrayHasKey('title', $presets[0]);
|
||||
$this->assertArrayHasKey('text', $presets[0]);
|
||||
$this->assertArrayHasKey('per_page', $presets[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Reports\Stickers;
|
||||
|
||||
use App\Services\Reports\Stickers\StickerContextService;
|
||||
use App\Services\Reports\Stickers\StickerPrintService;
|
||||
use App\Services\Reports\Stickers\StickerQueryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StickerPrintServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_generate_returns_pdf_content(): void
|
||||
{
|
||||
$this->seedData();
|
||||
$service = new StickerPrintService(new StickerQueryService(new StickerContextService()));
|
||||
|
||||
$result = $service->generate([
|
||||
'student_id' => 100,
|
||||
'school_year' => '2025-2026',
|
||||
'sticker_size' => '102x34',
|
||||
]);
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertNotEmpty($result['pdf']);
|
||||
}
|
||||
|
||||
public function test_generate_returns_error_when_no_students(): void
|
||||
{
|
||||
$service = new StickerPrintService(new StickerQueryService(new StickerContextService()));
|
||||
|
||||
$result = $service->generate([
|
||||
'class_section_id' => 999,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$this->assertFalse($result['ok']);
|
||||
$this->assertSame('No students found in this class.', $result['message']);
|
||||
}
|
||||
|
||||
private function seedData(): void
|
||||
{
|
||||
DB::table('classes')->insert([
|
||||
['id' => 1, 'class_name' => 'Grade 1', 'created_at' => now(), 'updated_at' => now()],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 200,
|
||||
'class_section_name' => 'Grade 1',
|
||||
'class_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'parent_id' => 10,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'is_active' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 200,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_event_only' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Reports\Stickers;
|
||||
|
||||
use App\Services\Reports\Stickers\StickerContextService;
|
||||
use App\Services\Reports\Stickers\StickerQueryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StickerQueryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_students_by_class_returns_rows(): void
|
||||
{
|
||||
$this->seedData();
|
||||
$service = new StickerQueryService(new StickerContextService());
|
||||
|
||||
$students = $service->listStudentsByClass(200, '2025-2026');
|
||||
|
||||
$this->assertCount(1, $students);
|
||||
$this->assertSame(100, $students[0]['id']);
|
||||
}
|
||||
|
||||
public function test_list_students_for_print_all_excludes_youth_and_kg(): void
|
||||
{
|
||||
$this->seedData();
|
||||
$this->seedYouthClass();
|
||||
|
||||
$service = new StickerQueryService(new StickerContextService());
|
||||
$students = $service->listStudentsForPrintAll('2025-2026');
|
||||
|
||||
$this->assertCount(1, $students);
|
||||
$this->assertSame('Grade 1', $students[0]['class_section_name']);
|
||||
}
|
||||
|
||||
private function seedData(): void
|
||||
{
|
||||
DB::table('classes')->insert([
|
||||
['id' => 1, 'class_name' => 'Grade 1', 'created_at' => now(), 'updated_at' => now()],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 200,
|
||||
'class_section_name' => 'Grade 1',
|
||||
'class_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'parent_id' => 10,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'is_active' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 200,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_event_only' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedYouthClass(): void
|
||||
{
|
||||
DB::table('classes')->insert([
|
||||
['id' => 2, 'class_name' => 'Youth', 'created_at' => now(), 'updated_at' => now()],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 201,
|
||||
'class_section_name' => 'Youth',
|
||||
'class_id' => 2,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 101,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Youth',
|
||||
'lastname' => 'Student',
|
||||
'parent_id' => 11,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'is_active' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 101,
|
||||
'class_section_id' => 201,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_event_only' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user