Skip to content

Commit cd84074

Browse files
committed
Theme System: Split & organised tests, changed module version to string
1 parent 4949520 commit cd84074

File tree

5 files changed

+278
-258
lines changed

5 files changed

+278
-258
lines changed

app/Theming/ThemeModule.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ThemeModule
99
protected string $name;
1010
protected string $description;
1111
protected string $folderName;
12-
protected int $version;
12+
protected string $version;
1313

1414
/**
1515
* Create a ThemeModule instance from JSON data.
@@ -26,10 +26,14 @@ public static function fromJson(array $data, string $folderName): static
2626
throw new ThemeException("Module in folder \"{$folderName}\" is missing a valid 'description' property");
2727
}
2828

29-
if (!isset($data['version']) || !is_int($data['version']) || $data['version'] < 1) {
29+
if (!isset($data['version']) || !is_string($data['version'])) {
3030
throw new ThemeException("Module in folder \"{$folderName}\" is missing a valid 'version' property");
3131
}
3232

33+
if (!preg_match('/^v?\d+\.\d+\.\d+(-.*)?$/', $data['version'])) {
34+
throw new ThemeException("Module in folder \"{$folderName}\" has an invalid 'version' format. Expected semantic version format like '1.0.0' or 'v1.0.0'");
35+
}
36+
3337
$module = new static();
3438
$module->name = $data['name'];
3539
$module->description = $data['description'];

tests/TestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Http\JsonResponse;
1414
use Illuminate\Support\Env;
1515
use Illuminate\Support\Facades\DB;
16+
use Illuminate\Support\Facades\File;
1617
use Illuminate\Support\Facades\Log;
1718
use Illuminate\Testing\Assert as PHPUnit;
1819
use Illuminate\Testing\Constraints\HasInDatabase;
@@ -157,6 +158,23 @@ protected function runWithEnv(array $valuesByKey, callable $callback, bool $hand
157158
}
158159
}
159160

161+
protected function usingThemeFolder(callable $callback): void
162+
{
163+
// Create a folder and configure a theme
164+
$themeFolderName = 'testing_theme_' . str_shuffle(rtrim(base64_encode(time()), '='));
165+
config()->set('view.theme', $themeFolderName);
166+
$themeFolderPath = theme_path('');
167+
168+
// Create a theme folder and clean it up on application tear-down
169+
File::makeDirectory($themeFolderPath);
170+
$this->beforeApplicationDestroyed(fn() => File::deleteDirectory($themeFolderPath));
171+
172+
// Run provided callback with the theme env option set
173+
$this->runWithEnv(['APP_THEME' => $themeFolderName], function () use ($callback, $themeFolderName) {
174+
call_user_func($callback, $themeFolderName);
175+
});
176+
}
177+
160178
/**
161179
* Check the keys and properties in the given map to include
162180
* exist, albeit not exclusively, within the map to check.

0 commit comments

Comments
 (0)