add controllers, servoices
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\BroadcastEmail;
|
||||
|
||||
use App\Services\BroadcastEmail\BroadcastEmailComposerService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BroadcastEmailComposerServiceTest extends TestCase
|
||||
{
|
||||
public function test_sanitize_removes_script_and_events(): void
|
||||
{
|
||||
$service = new BroadcastEmailComposerService();
|
||||
$html = '<p onclick="alert(1)">Hi</p><script>alert(2)</script>';
|
||||
|
||||
$clean = $service->sanitizeHtml($html);
|
||||
|
||||
$this->assertStringNotContainsString('script', $clean);
|
||||
$this->assertStringNotContainsString('onclick', $clean);
|
||||
}
|
||||
|
||||
public function test_compose_replaces_name_when_personalized(): void
|
||||
{
|
||||
$service = new BroadcastEmailComposerService();
|
||||
$html = '<p>Hello {{name}}</p>';
|
||||
|
||||
$rendered = $service->compose(false, 'Subject', $html, 'Parent', '', '', '', true);
|
||||
|
||||
$this->assertSame('<p>Hello Parent</p>', $rendered);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\BroadcastEmail;
|
||||
|
||||
use App\Services\BroadcastEmail\BroadcastEmailRecipientService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BroadcastEmailRecipientServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_parents_with_emails_filters_missing_email(): void
|
||||
{
|
||||
$this->seedParentData();
|
||||
|
||||
$service = new BroadcastEmailRecipientService();
|
||||
$parents = $service->parentsWithEmails();
|
||||
|
||||
$this->assertCount(1, $parents);
|
||||
$this->assertSame('parent@example.com', $parents[0]['email']);
|
||||
}
|
||||
|
||||
public function test_recipients_by_ids_returns_names(): void
|
||||
{
|
||||
$this->seedParentData();
|
||||
|
||||
$service = new BroadcastEmailRecipientService();
|
||||
$recipients = $service->recipientsByIds([10]);
|
||||
|
||||
$this->assertCount(1, $recipients);
|
||||
$this->assertSame('Parent User', $recipients[0]['name']);
|
||||
}
|
||||
|
||||
private function seedParentData(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
'id' => 1,
|
||||
'name' => 'parent',
|
||||
'slug' => 'parent',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
[
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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',
|
||||
],
|
||||
[
|
||||
'id' => 11,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'No',
|
||||
'lastname' => 'Email',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => '',
|
||||
'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('user_roles')->insert([
|
||||
['user_id' => 10, 'role_id' => 1],
|
||||
['user_id' => 11, 'role_id' => 1],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\BroadcastEmail;
|
||||
|
||||
use App\Services\BroadcastEmail\BroadcastEmailSenderOptionsService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BroadcastEmailSenderOptionsServiceTest extends TestCase
|
||||
{
|
||||
public function test_list_options_from_env(): void
|
||||
{
|
||||
$old = getenv('MAIL_SENDERS') ?: '';
|
||||
putenv('MAIL_SENDERS={"general":{"name":"Office","email":"office@example.com"}}');
|
||||
|
||||
$service = new BroadcastEmailSenderOptionsService();
|
||||
$options = $service->listOptions();
|
||||
|
||||
$this->assertSame('general', $options[0]['key']);
|
||||
$this->assertSame('Office <office@example.com>', $options[0]['label']);
|
||||
|
||||
putenv('MAIL_SENDERS=' . $old);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user