Compare commits
3 Commits
d2873ebcc1
...
f31f87aaf6
| Author | SHA1 | Date | |
|---|---|---|---|
| f31f87aaf6 | |||
| ac11fbeaa6 | |||
| 84fe0e5d18 |
@@ -28,11 +28,13 @@ class UserForm
|
||||
->tel()
|
||||
->helperText('مثال درست: 09123456789')
|
||||
->dehydrateStateUsing(fn (?string $state): ?string => Mobile::normalize($state))
|
||||
->rules([static function (string $attribute, mixed $value, \Closure $fail): void {
|
||||
if (filled($value) && ! preg_match(Mobile::REGEX, (string) Mobile::normalize((string) $value))) {
|
||||
$fail('فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789');
|
||||
}
|
||||
}])
|
||||
->rules([
|
||||
fn (): \Closure => function (string $attribute, mixed $value, \Closure $fail): void {
|
||||
if (filled($value) && ! preg_match(Mobile::REGEX, (string) Mobile::normalize((string) $value))) {
|
||||
$fail('فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789');
|
||||
}
|
||||
},
|
||||
])
|
||||
->unique(ignoreRecord: true)
|
||||
->maxLength(20),
|
||||
TextInput::make('password')
|
||||
|
||||
48
tests/Feature/UserFormMobileTest.php
Normal file
48
tests/Feature/UserFormMobileTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use App\Filament\Resources\Users\Pages\CreateUser;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
use function Pest\Laravel\actingAs;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function (): void {
|
||||
Filament::setCurrentPanel(Filament::getDefaultPanel());
|
||||
$admin = User::factory()->create();
|
||||
$role = Role::query()->firstOrCreate(['slug' => 'admin'], ['name' => 'مدیر']);
|
||||
$admin->roles()->sync([$role->id]);
|
||||
actingAs($admin);
|
||||
});
|
||||
|
||||
it('opens the create user form without the unresolvable-closure error', function (): void {
|
||||
Livewire\Livewire::test(CreateUser::class)
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
it('accepts a +98 mobile and normalizes it, rejects a malformed one', function (): void {
|
||||
Livewire\Livewire::test(CreateUser::class)
|
||||
->fillForm([
|
||||
'name' => 'کاربر تست',
|
||||
'email' => 'ok@example.com',
|
||||
'mobile' => '+98 912 345 6789',
|
||||
'password' => 'password12',
|
||||
])
|
||||
->call('create')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
expect(User::query()->where('email', 'ok@example.com')->value('mobile'))->toBe('09123456789');
|
||||
|
||||
Livewire\Livewire::test(CreateUser::class)
|
||||
->fillForm([
|
||||
'name' => 'کاربر بد',
|
||||
'email' => 'bad@example.com',
|
||||
'mobile' => '123',
|
||||
'password' => 'password12',
|
||||
])
|
||||
->call('create')
|
||||
->assertHasFormErrors(['mobile']);
|
||||
});
|
||||
Reference in New Issue
Block a user