add all controllers logic
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Services\Email\EmailDispatchService;
|
||||
use App\Services\Frontend\ContactSubmissionService;
|
||||
use App\Services\System\GlobalConfigService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ContactSubmissionServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_submit_creates_contact_record(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
$emailService = $this->createMock(EmailDispatchService::class);
|
||||
$emailService->method('send')->willReturn(false);
|
||||
|
||||
$service = new ContactSubmissionService($emailService, new GlobalConfigService());
|
||||
|
||||
$result = $service->submit([
|
||||
'email' => 'contact@example.com',
|
||||
'message' => 'Hello from unit test',
|
||||
]);
|
||||
|
||||
$this->assertNotNull($result['record']);
|
||||
$this->assertDatabaseHas('contactus', [
|
||||
'subject' => 'Contact Us Form Submission',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Services\Frontend\FrontendPageService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FrontendPageServiceTest extends TestCase
|
||||
{
|
||||
public function test_page_returns_payload(): void
|
||||
{
|
||||
$service = new FrontendPageService();
|
||||
$payload = $service->page('index');
|
||||
|
||||
$this->assertSame('index', $payload['page']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Services\Frontend\LandingPageContextService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LandingPageContextServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_context_returns_config_values(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
['config_key' => 'enrollment_deadline', 'config_value' => '2025-09-01'],
|
||||
['config_key' => 'refund_deadline', 'config_value' => '2025-10-01'],
|
||||
]);
|
||||
|
||||
$service = app(LandingPageContextService::class);
|
||||
$context = $service->context();
|
||||
|
||||
$this->assertSame('2025-2026', $context['school_year']);
|
||||
$this->assertSame('Fall', $context['semester']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Services\Frontend\LandingPageParentDashboardService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LandingPageParentDashboardServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_summary_returns_parent_payload(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 'S-1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = app(LandingPageParentDashboardService::class);
|
||||
$payload = $service->summary(1, 'primary');
|
||||
|
||||
$this->assertTrue($payload['ok']);
|
||||
$this->assertCount(1, $payload['students']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Frontend\LandingPageRoleService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LandingPageRoleServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_resolve_role_returns_guest_when_missing(): void
|
||||
{
|
||||
$service = app(LandingPageRoleService::class);
|
||||
$this->assertSame('guest', $service->resolveRole(null));
|
||||
}
|
||||
|
||||
public function test_resolve_role_returns_first_role(): void
|
||||
{
|
||||
$roleId = DB::table('roles')->insertGetId([
|
||||
'name' => 'teacher',
|
||||
'priority' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
$user = User::query()->create([
|
||||
'firstname' => 'Teach',
|
||||
'lastname' => 'Er',
|
||||
'email' => 'teacher@example.com',
|
||||
'cellphone' => '5555555555',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'status' => 'Active',
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => $user->id,
|
||||
'role_id' => $roleId,
|
||||
]);
|
||||
|
||||
$service = app(LandingPageRoleService::class);
|
||||
$this->assertSame('teacher', $service->resolveRole($user));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Frontend\LandingPageService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LandingPageServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_dashboard_for_user_returns_guest(): void
|
||||
{
|
||||
$service = app(LandingPageService::class);
|
||||
$payload = $service->dashboardForUser(null);
|
||||
|
||||
$this->assertSame('guest', $payload['role']);
|
||||
}
|
||||
|
||||
public function test_dashboard_for_user_returns_admin(): void
|
||||
{
|
||||
$roleId = DB::table('roles')->insertGetId([
|
||||
'name' => 'admin',
|
||||
'priority' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
$user = User::query()->create([
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'email' => 'admin@example.com',
|
||||
'cellphone' => '5555555555',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'status' => 'Active',
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => $user->id,
|
||||
'role_id' => $roleId,
|
||||
]);
|
||||
|
||||
$service = app(LandingPageService::class);
|
||||
$payload = $service->dashboardForUser($user);
|
||||
|
||||
$this->assertSame('admin', $payload['role']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Services\Frontend\LandingPageTeacherSummaryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LandingPageTeacherSummaryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_summary_returns_dashboard_payload(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('teacher_class')->insert([
|
||||
'teacher_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'position' => 'main',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = app(LandingPageTeacherSummaryService::class);
|
||||
$payload = $service->summary(1);
|
||||
|
||||
$this->assertSame(101, $payload['class_section_id']);
|
||||
$this->assertArrayHasKey('scoreSummary', $payload);
|
||||
$this->assertArrayHasKey('attendanceSummary', $payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Frontend\ProfileIconService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProfileIconServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_build_for_user_returns_initials(): void
|
||||
{
|
||||
$user = User::query()->create([
|
||||
'firstname' => 'Jane',
|
||||
'lastname' => 'Smith',
|
||||
'email' => 'jane@example.com',
|
||||
'cellphone' => '5555555555',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'status' => 'Active',
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = app(ProfileIconService::class);
|
||||
$payload = $service->buildForUser($user->id);
|
||||
|
||||
$this->assertSame('JS', $payload['userInitials']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Frontend;
|
||||
|
||||
use App\Services\Frontend\StaticPageService;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StaticPageServiceTest extends TestCase
|
||||
{
|
||||
public function test_load_returns_content(): void
|
||||
{
|
||||
$dir = public_path('html');
|
||||
File::ensureDirectoryExists($dir);
|
||||
File::put($dir . '/terms_of_service.html', '<h1>Terms</h1>');
|
||||
|
||||
$service = new StaticPageService();
|
||||
$result = $service->load('terms_of_service.html', 'terms_of_service');
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertSame('terms_of_service', $result['type']);
|
||||
$this->assertStringContainsString('Terms', $result['content']);
|
||||
}
|
||||
|
||||
public function test_load_missing_returns_error(): void
|
||||
{
|
||||
$service = new StaticPageService();
|
||||
$result = $service->load('missing.html', 'missing');
|
||||
|
||||
$this->assertFalse($result['ok']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user