71 lines
2.4 KiB
PHP
71 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Auth;
|
|
|
|
use App\Services\Auth\RegistrationFormatterService;
|
|
use App\Services\PhoneFormatterService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class RegistrationFormatterServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_format_normalizes_parent_fields(): void
|
|
{
|
|
$formatter = new RegistrationFormatterService(new PhoneFormatterService);
|
|
|
|
$result = $formatter->format([
|
|
'firstname' => 'john',
|
|
'lastname' => 'doe',
|
|
'email' => 'USER@EXAMPLE.COM',
|
|
'gender' => 'Male',
|
|
'city' => 'new haven',
|
|
'cellphone' => '(203) 555-1234',
|
|
'address_street' => '123 main st',
|
|
'apt' => 'a1',
|
|
'state' => 'ct',
|
|
'zip' => '06510',
|
|
'accept_school_policy' => 1,
|
|
'no_second_parent_info' => 1,
|
|
]);
|
|
|
|
$this->assertSame('John', $result['firstname']);
|
|
$this->assertSame('Doe', $result['lastname']);
|
|
$this->assertSame('user@example.com', $result['email']);
|
|
$this->assertSame('New Haven', $result['city']);
|
|
$this->assertSame('203-555-1234', $result['cellphone']);
|
|
$this->assertSame('CT', $result['state']);
|
|
$this->assertArrayNotHasKey('second_firstname', $result);
|
|
}
|
|
|
|
public function test_format_includes_second_parent_when_present(): void
|
|
{
|
|
$formatter = new RegistrationFormatterService(new PhoneFormatterService);
|
|
|
|
$result = $formatter->format([
|
|
'firstname' => 'john',
|
|
'lastname' => 'doe',
|
|
'email' => 'user@example.com',
|
|
'gender' => 'Male',
|
|
'city' => 'new haven',
|
|
'cellphone' => '2035551234',
|
|
'address_street' => '123 main st',
|
|
'apt' => 'a1',
|
|
'state' => 'ct',
|
|
'zip' => '06510',
|
|
'accept_school_policy' => 1,
|
|
'second_firstname' => 'jane',
|
|
'second_lastname' => 'doe',
|
|
'second_gender' => 'Female',
|
|
'second_email' => 'jane@example.com',
|
|
'second_cellphone' => '2035559876',
|
|
]);
|
|
|
|
$this->assertSame('Jane', $result['second_firstname']);
|
|
$this->assertSame('Doe', $result['second_lastname']);
|
|
$this->assertSame('jane@example.com', $result['second_email']);
|
|
$this->assertSame('203-555-9876', $result['second_cellphone']);
|
|
}
|
|
}
|