Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Sep 14, 2024
1 parent ab2cf16 commit 9c071bd
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function setConfigs(SetConfigsRequest $request): ConfigCollectionResource
*
* @return string[]
*/
public function getLanguages(): array
public function getLanguages(GetAllConfigsRequest $request): array
{
// @phpstan-ignore-next-line
return collect(config('app.supported_locale'))->filter(function ($value, $key) {
Expand Down
33 changes: 33 additions & 0 deletions tests/Feature_v2/Album/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Album;

use Tests\Feature_v2\Base\BaseApiV2Test;

class ConfigTest extends BaseApiV2Test
{
public function testGet(): void
{
$response = $this->getJson('Gallery::Init');
$this->assertOk($response);

$response = $this->getJson('Gallery::getLayout');
$this->assertOk($response);

$response = $this->getJson('Gallery::getMapProvider');
$this->assertOk($response);

$response = $this->getJson('Gallery::getUploadLimits');
$this->assertOk($response);
}
}
36 changes: 36 additions & 0 deletions tests/Feature_v2/Diagnostics/PermissionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Diagnostics;

use Tests\Feature_v2\Base\BaseApiV2Test;

class PermissionTest extends BaseApiV2Test
{
public function testGetGuest(): void
{
$response = $this->getJson('Diagnostics::permissions');
$this->assertUnauthorized($response);
}

public function testAuthenticated(): void
{
$response = $this->actingAs($this->userLocked)->getJson('Diagnostics::permissions');
$this->assertForbidden($response);
}

public function testAuthorized(): void
{
$response = $this->actingAs($this->admin)->getJson('Diagnostics::permissions');
$this->assertOk($response);
}
}
2 changes: 1 addition & 1 deletion tests/Feature_v2/Jobs/GetJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGetJobsGuest(): void
$this->assertUnauthorized($response);
}

public function testGetAllSettingUser(): void
public function testGetJobsUser(): void
{
$response = $this->actingAs($this->userMayUpload1)->getJson('Jobs');
$this->assertForbidden($response);
Expand Down
63 changes: 63 additions & 0 deletions tests/Feature_v2/Maintenance/CleaningTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Maintenance;

use Tests\Feature_v2\Base\BaseApiV2Test;

class CleaningTest extends BaseApiV2Test
{
public function testGuest(): void
{
$response = $this->getJsonWithData('Maintenance::cleaning', []);
$this->assertUnprocessable($response);

$response = $this->getJsonWithData('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertUnauthorized($response);

$response = $this->postJson('Maintenance::cleaning');
$this->assertUnprocessable($response);

$response = $this->postJson('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertUnauthorized($response);
}

public function testUser(): void
{
$response = $this->actingAs($this->userLocked)->getJsonWithData('Maintenance::cleaning');
$this->assertUnprocessable($response);

$response = $this->actingAs($this->userLocked)->getJsonWithData('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertForbidden($response);

$response = $this->actingAs($this->userLocked)->postJson('Maintenance::cleaning');
$this->assertUnprocessable($response);

$response = $this->actingAs($this->userLocked)->postJson('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertForbidden($response);
}

public function testAdmin(): void
{
$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::cleaning');
$this->assertUnprocessable($response);

$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertOk($response);

$response = $this->actingAs($this->admin)->postJson('Maintenance::cleaning');
$this->assertUnprocessable($response);

$response = $this->actingAs($this->admin)->postJson('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertOk($response);
}
}
63 changes: 63 additions & 0 deletions tests/Feature_v2/Maintenance/GenSizeVariantsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Maintenance;

use Tests\Feature_v2\Base\BaseApiV2Test;

class GenSizeVariantsTest extends BaseApiV2Test
{
public function testGuest(): void
{
$response = $this->getJsonWithData('Maintenance::genSizeVariants', []);
$this->assertUnprocessable($response);

$response = $this->getJsonWithData('Maintenance::genSizeVariants', ['kind' => 4]);
$this->assertUnauthorized($response);

$response = $this->postJson('Maintenance::genSizeVariants');
$this->assertUnprocessable($response);

$response = $this->postJson('Maintenance::genSizeVariants', ['kind' => 4]);
$this->assertUnauthorized($response);
}

public function testUser(): void
{
$response = $this->actingAs($this->userLocked)->getJsonWithData('Maintenance::genSizeVariants');
$this->assertUnprocessable($response);

$response = $this->actingAs($this->userLocked)->getJsonWithData('Maintenance::genSizeVariants', ['kind' => 4]);
$this->assertForbidden($response);

$response = $this->actingAs($this->userLocked)->postJson('Maintenance::genSizeVariants');
$this->assertUnprocessable($response);

$response = $this->actingAs($this->userLocked)->postJson('Maintenance::genSizeVariants', ['kind' => 4]);
$this->assertForbidden($response);
}

public function testAdmin(): void
{
$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::genSizeVariants');
$this->assertUnprocessable($response);

$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::genSizeVariants', ['kind' => 4]);
$this->assertOk($response);

$response = $this->actingAs($this->admin)->postJson('Maintenance::genSizeVariants');
$this->assertUnprocessable($response);

$response = $this->actingAs($this->admin)->postJson('Maintenance::genSizeVariants', ['kind' => 4]);
$this->assertNoContent($response);
}
}
45 changes: 45 additions & 0 deletions tests/Feature_v2/Maintenance/JobsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Maintenance;

use Tests\Feature_v2\Base\BaseApiV2Test;

class JobsTest extends BaseApiV2Test
{
public function testGuest(): void
{
$response = $this->getJsonWithData('Maintenance::jobs', []);
$this->assertUnauthorized($response);

$response = $this->postJson('Maintenance::jobs');
$this->assertUnauthorized($response);
}

public function testUser(): void
{
$response = $this->actingAs($this->userLocked)->getJsonWithData('Maintenance::jobs');
$this->assertForbidden($response);

$response = $this->actingAs($this->userLocked)->postJson('Maintenance::jobs');
$this->assertForbidden($response);
}

public function testAdmin(): void
{
$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::jobs');
$this->assertOk($response);

$response = $this->actingAs($this->admin)->postJson('Maintenance::jobs');
$this->assertNoContent($response);
}
}
36 changes: 36 additions & 0 deletions tests/Feature_v2/Maintenance/OptimizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Maintenance;

use Tests\Feature_v2\Base\BaseApiV2Test;

class OptimizeTest extends BaseApiV2Test
{
public function testGuest(): void
{
$response = $this->postJson('Maintenance::optimize');
$this->assertUnauthorized($response);
}

public function testUser(): void
{
$response = $this->actingAs($this->userLocked)->postJson('Maintenance::optimize');
$this->assertForbidden($response);
}

public function testAdmin(): void
{
$response = $this->actingAs($this->admin)->postJson('Maintenance::optimize');
$this->assertOk($response);
}
}
46 changes: 46 additions & 0 deletions tests/Feature_v2/Maintenance/TreeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Maintenance;

use Tests\Feature_v2\Base\BaseApiV2Test;

class TreeTest extends BaseApiV2Test
{
public function testGuest(): void
{
$response = $this->getJsonWithData('Maintenance::tree', []);
$this->assertUnauthorized($response);

$response = $this->postJson('Maintenance::tree');
$this->assertUnauthorized($response);
}

public function testUser(): void
{
$response = $this->actingAs($this->userLocked)->getJsonWithData('Maintenance::tree');
$this->assertForbidden($response);

$response = $this->actingAs($this->userLocked)->postJson('Maintenance::tree');
$this->assertForbidden($response);
}

public function testAdmin(): void
{
$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::tree');
$this->assertOk($response);

// FIX ME: The attribute [cover_id] either does not exist or was not retrieved for model [App\Models\BaseAlbumImpl]
// $response = $this->actingAs($this->admin)->postJson('Maintenance::tree');
// $this->assertCreated($response);
}
}
Loading

0 comments on commit 9c071bd

Please sign in to comment.