68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\App\Controllers\View;
|
|
|
|
use App\Controllers\View\ParentController;
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
use ReflectionMethod;
|
|
|
|
final class ParentControllerEnrollmentContactTest extends CIUnitTestCase
|
|
{
|
|
public function testNormalizeEnrollmentParentContactAcceptsValidAddressAndPhone(): void
|
|
{
|
|
$result = $this->normalize([
|
|
'cellphone' => '(203) 555-1212',
|
|
'address_street' => '12 Oak Street',
|
|
'apt' => '2B',
|
|
'city' => 'bridgeport',
|
|
'state' => 'ct',
|
|
'zip' => '06604',
|
|
]);
|
|
|
|
$this->assertSame([], $result['errors']);
|
|
$this->assertSame('203-555-1212', $result['data']['cellphone']);
|
|
$this->assertSame('12 Oak Street', $result['data']['address_street']);
|
|
$this->assertSame('2B', $result['data']['apt']);
|
|
$this->assertSame('Bridgeport', $result['data']['city']);
|
|
$this->assertSame('CT', $result['data']['state']);
|
|
$this->assertSame('06604', $result['data']['zip']);
|
|
}
|
|
|
|
public function testNormalizeEnrollmentParentContactRejectsMissingPhoneAndAddress(): void
|
|
{
|
|
$result = $this->normalize([
|
|
'cellphone' => '12345',
|
|
'address_street' => '12',
|
|
'city' => '',
|
|
'state' => '',
|
|
'zip' => 'abc',
|
|
]);
|
|
|
|
$this->assertNotSame([], $result['errors']);
|
|
$this->assertSame([], $result['data']);
|
|
$this->assertStringContainsString('phone', strtolower(implode(' ', $result['errors'])));
|
|
$this->assertStringContainsString('street address', strtolower(implode(' ', $result['errors'])));
|
|
$this->assertStringContainsString('city', strtolower(implode(' ', $result['errors'])));
|
|
$this->assertStringContainsString('state', strtolower(implode(' ', $result['errors'])));
|
|
$this->assertStringContainsString('zip', strtolower(implode(' ', $result['errors'])));
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $fields
|
|
* @return array{errors: list<string>, data: array<string, string>}
|
|
*/
|
|
private function normalize(array $fields): array
|
|
{
|
|
$controller = new class extends ParentController {
|
|
public function __construct()
|
|
{
|
|
}
|
|
};
|
|
|
|
$method = new ReflectionMethod(ParentController::class, 'normalizeEnrollmentParentContact');
|
|
$method->setAccessible(true);
|
|
|
|
return $method->invoke($controller, $fields);
|
|
}
|
|
}
|