Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add full testing and update setting() helper to accept default #7

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
collision: 7.*
exclude:
- laravel: 11.*
php: 8.1
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
steps:
- name: Checkout Code
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Contracts/SettingHold.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class SettingHold

public int $order = 1;

public static function make(): static
public static function make(): self
{
return new static;
return new self;
}

public function toArray(): array
Expand Down
20 changes: 13 additions & 7 deletions src/Traits/UseShield.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BezhanSalleh\FilamentShield\Support\Utils;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
use Illuminate\Support\Str;

trait UseShield
Expand Down Expand Up @@ -48,13 +49,18 @@ protected function getShieldRedirectPath(): string

protected static function getPermissionName(): string
{
return Str::of(class_basename(static::class))
->prepend(
Str::of(Utils::getPagePermissionPrefix())
->append('_')
->toString()
)
->toString();
if(class_exists('BezhanSalleh\FilamentShield\Support\Utils')) {
return Str::of(class_basename(static::class))
->prepend(
Str::of(Utils::getPagePermissionPrefix())
->append('_')
->toString()
)
->toString();
}
else {
return "";
}
}

public static function canAccess(): bool
Expand Down
Binary file modified tests/database/database.sqlite
Binary file not shown.
19 changes: 14 additions & 5 deletions tests/src/LocationSettingsPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,38 @@
actingAs(User::factory()->create());
});

function checkLocationSettingExists($setting, $name): void
{
assertDatabaseHas(\TomatoPHP\FilamentSettingsHub\Models\Setting::class, [
'name' => $name,
'group' => 'sites',
'payload' => is_null($setting->{$name}) ? json_encode(null) : json_encode($setting->{$name}),
]);
}

it('has site site_address exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_address');
checkLocationSettingExists($siteSettings, 'site_address');
});

it('has site site_phone_code exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_phone_code');
checkLocationSettingExists($siteSettings, 'site_phone_code');
});

it('has site site_location exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_location');
checkLocationSettingExists($siteSettings, 'site_location');
});

it('has site site_currency exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_currency');
checkLocationSettingExists($siteSettings, 'site_currency');
});

it('has site site_language exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_language');
checkLocationSettingExists($siteSettings, 'site_language');
});

it('can render location settings page resource', function () {
Expand Down
6 changes: 5 additions & 1 deletion tests/src/MenuSettingsPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

it('has site site_social exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_social');
assertDatabaseHas(\TomatoPHP\FilamentSettingsHub\Models\Setting::class, [
'name' => 'site_social',
'group' => 'sites',
'payload' => is_null($siteSettings->site_social) ? json_encode(null) : json_encode($siteSettings->site_social),
]);
});

it('can render social menu settings page resource', function () {
Expand Down
26 changes: 18 additions & 8 deletions tests/src/SiteSettingsPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,50 @@
actingAs(User::factory()->create());
});


function checkSiteSettingExists($setting, $name): void
{
assertDatabaseHas(\TomatoPHP\FilamentSettingsHub\Models\Setting::class, [
'name' => $name,
'group' => 'sites',
'payload' => is_null($setting->{$name}) ? json_encode(null) : json_encode($setting->{$name}),
]);
}

it('has site site_name exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_name');
checkSiteSettingExists($siteSettings, 'site_name');
});

it('has site_description exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_description');
checkSiteSettingExists($siteSettings, 'site_description');

});

it('has site_keywords exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_keywords');
checkSiteSettingExists($siteSettings, 'site_keywords');
});

it('has site_phone exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;

$this->checkSettingExists($siteSettings, 'site_phone');
checkSiteSettingExists($siteSettings, 'site_phone');
});

it('has site_profile exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_profile');
checkSiteSettingExists($siteSettings, 'site_profile');
});

it('has site_author exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_author');
checkSiteSettingExists($siteSettings, 'site_author');
});

it('has site_email exists', function () {
$siteSettings = new \TomatoPHP\FilamentSettingsHub\Settings\SitesSettings;
$this->checkSettingExists($siteSettings, 'site_email');
checkSiteSettingExists($siteSettings, 'site_email');
});

it('can render site settings page resource', function () {
Expand Down
9 changes: 0 additions & 9 deletions tests/src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,4 @@ public function getEnvironmentSetUp($app): void
__DIR__ . '/../resources/views',
]);
}

public function checkSettingExists($setting, $name): void
{
assertDatabaseHas(\TomatoPHP\FilamentSettingsHub\Models\Setting::class, [
'name' => $name,
'group' => 'sites',
'payload' => is_null($setting->{$name}) ? json_encode(null) : json_encode($setting->{$name}),
]);
}
}