Add form request validation tests for various client and admin requests
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Requests\Client\Auth;
|
||||
|
||||
use App\Http\Requests\Client\Auth\UserRegistrationRequest;
|
||||
use Tests\Concerns\ValidatesFormRequests;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserRegistrationRequestTest extends TestCase
|
||||
{
|
||||
use ValidatesFormRequests;
|
||||
|
||||
protected function valid(array $overrides = []): array
|
||||
{
|
||||
return array_merge(['phone' => '09120000000', 'national_code' => '0012345678'], $overrides);
|
||||
}
|
||||
|
||||
public function test_passes_with_phone_and_national_code(): void
|
||||
{
|
||||
$this->assertPasses(UserRegistrationRequest::class, $this->valid());
|
||||
}
|
||||
|
||||
public function test_passes_with_all_optional_fields(): void
|
||||
{
|
||||
$this->assertPasses(UserRegistrationRequest::class, $this->valid([
|
||||
'fullname' => 'f', 'specialty' => 's', 'clinic_name' => 'c', 'clinic_phone' => '021', 'province' => 'p', 'city' => 'c', 'address' => 'a', 'level' => 'دانپزشک',
|
||||
]));
|
||||
}
|
||||
|
||||
public function test_accepts_international_and_persian_digit_phones(): void
|
||||
{
|
||||
$this->assertPasses(UserRegistrationRequest::class, $this->valid(['phone' => '+989120000000']));
|
||||
$this->assertPasses(UserRegistrationRequest::class, $this->valid(['phone' => '۰۹۱۲۰۰۰۰۰۰۰']));
|
||||
}
|
||||
|
||||
public function test_fails_without_phone_or_national_code(): void
|
||||
{
|
||||
$errors = $this->formRequestErrors(UserRegistrationRequest::class, []);
|
||||
|
||||
$this->assertArrayHasKey('phone', $errors);
|
||||
$this->assertArrayHasKey('national_code', $errors);
|
||||
}
|
||||
|
||||
public function test_fails_with_invalid_phone(): void
|
||||
{
|
||||
$this->assertFailsOn('phone', UserRegistrationRequest::class, $this->valid(['phone' => 'abc']));
|
||||
$this->assertFailsOn('phone', UserRegistrationRequest::class, $this->valid(['phone' => '123']));
|
||||
$this->assertFailsOn('phone', UserRegistrationRequest::class, $this->valid(['phone' => '+9999120000000']));
|
||||
}
|
||||
|
||||
public function test_fails_when_level_exceeds_limit(): void
|
||||
{
|
||||
$this->assertFailsOn('level', UserRegistrationRequest::class, $this->valid(['level' => str_repeat('a', 51)]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user