mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-24 22:12:06 +02:00
Update & Complete tests
This commit is contained in:
parent
4ab56d74ed
commit
7ddb4276a6
@ -12,8 +12,10 @@ use Illuminate\Http\UploadedFile;
|
|||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProviderExternal;
|
||||||
use PHPUnit\Framework\Attributes\Test;
|
use PHPUnit\Framework\Attributes\Test;
|
||||||
use Tests\Classes\LocalFile;
|
use Tests\Classes\LocalFile;
|
||||||
|
use Tests\Data\CommonDataProvider;
|
||||||
use Tests\Data\HttpRequestTestData;
|
use Tests\Data\HttpRequestTestData;
|
||||||
use Tests\Data\OtpTestData;
|
use Tests\Data\OtpTestData;
|
||||||
use Tests\FeatureTestCase;
|
use Tests\FeatureTestCase;
|
||||||
@ -38,7 +40,9 @@ class IconControllerTest extends FeatureTestCase
|
|||||||
|
|
||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
Http::fake([
|
Http::fake([
|
||||||
TfaLogoLib::IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
'https://raw.githubusercontent.com/2factorauth/twofactorauth/master/img/*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
|
'https://cdn.jsdelivr.net/gh/selfhst/icons/*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
|
'https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
TfalogoLib::TFA_URL => Http::response(HttpRequestTestData::TFA_JSON_BODY, 200),
|
TfalogoLib::TFA_URL => Http::response(HttpRequestTestData::TFA_JSON_BODY, 200),
|
||||||
]);
|
]);
|
||||||
Http::fake([
|
Http::fake([
|
||||||
@ -101,11 +105,13 @@ class IconControllerTest extends FeatureTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function test_fetch_logo_returns_filename()
|
#[DataProviderExternal(CommonDataProvider::class, 'iconsCollectionProvider')]
|
||||||
|
public function test_fetch_logo_returns_filename($iconCollection)
|
||||||
{
|
{
|
||||||
$response = $this->actingAs($this->user, 'api-guard')
|
$response = $this->actingAs($this->user, 'api-guard')
|
||||||
->json('POST', '/api/v1/icons/default', [
|
->json('POST', '/api/v1/icons/default', [
|
||||||
'service' => 'service',
|
'service' => 'service',
|
||||||
|
'iconCollection' => $iconCollection,
|
||||||
])
|
])
|
||||||
->assertStatus(201)
|
->assertStatus(201)
|
||||||
->assertJsonStructure([
|
->assertJsonStructure([
|
||||||
@ -119,6 +125,7 @@ class IconControllerTest extends FeatureTestCase
|
|||||||
$response = $this->actingAs($this->user, 'api-guard')
|
$response = $this->actingAs($this->user, 'api-guard')
|
||||||
->json('POST', '/api/v1/icons/default', [
|
->json('POST', '/api/v1/icons/default', [
|
||||||
'service' => 'service',
|
'service' => 'service',
|
||||||
|
'iconCollection' => 'tfa',
|
||||||
])
|
])
|
||||||
->assertStatus(201)
|
->assertStatus(201)
|
||||||
->assertJsonStructure([
|
->assertJsonStructure([
|
||||||
|
24
tests/Data/CommonDataProvider.php
Normal file
24
tests/Data/CommonDataProvider.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Data;
|
||||||
|
|
||||||
|
final class CommonDataProvider
|
||||||
|
{
|
||||||
|
public static function iconsCollectionProvider() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'TFA' => [
|
||||||
|
'tfa',
|
||||||
|
],
|
||||||
|
'SELFH' => [
|
||||||
|
'selfh',
|
||||||
|
],
|
||||||
|
'DASHBOARDICONS' => [
|
||||||
|
'dashboardicons',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,6 +15,7 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
|||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
use PHPUnit\Framework\Attributes\DataProviderExternal;
|
use PHPUnit\Framework\Attributes\DataProviderExternal;
|
||||||
use PHPUnit\Framework\Attributes\Test;
|
use PHPUnit\Framework\Attributes\Test;
|
||||||
|
use Tests\Data\CommonDataProvider;
|
||||||
use Tests\Data\HttpRequestTestData;
|
use Tests\Data\HttpRequestTestData;
|
||||||
use Tests\Data\OtpTestData;
|
use Tests\Data\OtpTestData;
|
||||||
use Tests\FeatureTestCase;
|
use Tests\FeatureTestCase;
|
||||||
@ -39,7 +40,9 @@ class IconServiceTest extends FeatureTestCase
|
|||||||
|
|
||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
Http::fake([
|
Http::fake([
|
||||||
TfaLogoLib::IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
'https://raw.githubusercontent.com/2factorauth/twofactorauth/master/img/*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
|
'https://cdn.jsdelivr.net/gh/selfhst/icons/*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
|
'https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
|
||||||
TfaLogoLib::TFA_URL => Http::response(HttpRequestTestData::TFA_JSON_BODY, 200),
|
TfaLogoLib::TFA_URL => Http::response(HttpRequestTestData::TFA_JSON_BODY, 200),
|
||||||
]);
|
]);
|
||||||
Http::fake([
|
Http::fake([
|
||||||
@ -50,7 +53,6 @@ class IconServiceTest extends FeatureTestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_buildFromOfficialLogo_calls_logoLib_to_get_the_icon()
|
public function test_buildFromOfficialLogo_calls_logoLib_to_get_the_icon()
|
||||||
{
|
{
|
||||||
// LogoLib::spy();
|
|
||||||
LogoLib::shouldReceive('driver->getIcon')
|
LogoLib::shouldReceive('driver->getIcon')
|
||||||
->once()
|
->once()
|
||||||
->with('fakeService')
|
->with('fakeService')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user