2FAuth/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php
2023-12-20 16:55:58 +01:00

89 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature\Http\Requests;
use App\Http\Requests\WebauthnRenameRequest;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
/**
* WebauthnRenameRequestTest test class
*/
#[CoversClass(WebauthnRenameRequest::class)]
class WebauthnRenameRequestTest extends TestCase
{
use WithoutMiddleware;
/**
* @test
*/
public function test_user_is_authorized()
{
Auth::shouldReceive('check')
->once()
->andReturn(true);
$request = new WebauthnRenameRequest();
$this->assertTrue($request->authorize());
}
/**
* @test
*/
#[DataProvider('provideValidData')]
public function test_valid_data(array $data) : void
{
$request = new WebauthnRenameRequest();
$validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails());
}
/**
* Provide Valid data for validation test
*/
public static function provideValidData() : array
{
return [
[[
'name' => 'Yubikey',
]],
];
}
/**
* @test
*/
#[DataProvider('provideInvalidData')]
public function test_invalid_data(array $data) : void
{
$request = new WebauthnRenameRequest();
$validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails());
}
/**
* Provide invalid data for validation test
*/
public static function provideInvalidData() : array
{
return [
[[
'name' => '', // required
]],
[[
'name' => true, // string
]],
[[
'name' => 0, // string
]],
];
}
}