Skip to content

Commit

Permalink
Support for Statamic v5
Browse files Browse the repository at this point in the history
  • Loading branch information
martyf committed May 9, 2024
1 parent 9604599 commit c9c1919
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- statamic:hide -->

![Statamic 4+](https://img.shields.io/badge/Statamic-4.0-FF269E?style=for-the-badge&link=https://statamic.com)
![Statamic 5](https://img.shields.io/badge/Statamic-5.0-FF269E?style=for-the-badge&link=https://statamic.com)
[![Variable Number Fieldtype for Statamic on Packagist](https://img.shields.io/packagist/v/mitydigital/statamic-variable-number-fieldtype?style=for-the-badge)](https://packagist.org/packages/mitydigital/statamic-variable-number-fieldtype/stats)

---
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"require": {
"php": "^8.2",
"statamic/cms": "^4.25.0",
"statamic/cms": "^5.0",
"ext-intl": "*"
},
"require-dev": {
Expand Down
3 changes: 2 additions & 1 deletion src/Fieldtypes/VariableNumberFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MityDigital\StatamicVariableNumberFieldtype\Fieldtypes;

use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
use MityDigital\StatamicVariableNumberFieldtype\Facades\VariableNumber;
use Statamic\Facades\Folder;
use Statamic\Fields\Fieldtype;
Expand Down Expand Up @@ -337,7 +338,7 @@ protected function configFieldItems(): array

'options' => collect(Folder::disk('resources')
->getFilesRecursively('views'))
->map(fn ($view) => str_replace_first('views/', '', str_before($view, '.')))
->map(fn ($view) => Str::replaceFirst('views/', '', Str::before($view, '.')))
->filter(fn ($view) => (
$view &&
! str_starts_with($view, 'vendor/') &&
Expand Down
56 changes: 26 additions & 30 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
use Facades\Statamic\Version;
use Illuminate\Support\Facades\File;
use MityDigital\StatamicVariableNumberFieldtype\ServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Statamic\Console\Processes\Composer;
use Statamic\Extend\Manifest;
use Statamic\Facades\Blueprint;
use Statamic\Providers\StatamicServiceProvider;
use Statamic\Facades\Site;
use Statamic\Statamic;
use Statamic\Testing\AddonTestCase;

abstract class TestCase extends OrchestraTestCase
abstract class TestCase extends AddonTestCase
{
protected $shouldFakeVersion = true;

protected function setUp(): void
protected string $addonServiceProvider = ServiceProvider::class;

protected function set2Up(): void
{
parent::setUp();

Expand All @@ -28,31 +29,21 @@ protected function setUp(): void
}
}

protected function getPackageProviders($app)
{
return [
StatamicServiceProvider::class,
ServiceProvider::class,
];
}

protected function getPackageAliases($app)
{
return [
'Statamic' => Statamic::class,
];
}

protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);

$app->make(Manifest::class)->manifest = [
'mitydigital/statamic-variable-number-fieldtype' => [
'id' => 'mitydigital/statamic-variable-number-fieldtype',
'namespace' => 'MityDigital\\StatamicVariableNumberFieldtype',
config()->set('filesystems.disks', array_merge(
config('filesystems.disks'),
[
'fonts' => [
'driver' => 'local',
'root' => __DIR__.'/fonts',
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
],
];
));
}

protected function resolveApplicationConfiguration($app)
Expand All @@ -61,24 +52,29 @@ protected function resolveApplicationConfiguration($app)

$configs = [
'forms',
'sites',
];

foreach ($configs as $config) {
$app['config']->set(
"statamic.$config",
require(__DIR__."/../vendor/statamic/cms/config/{$config}.php")
require (__DIR__."/../vendor/statamic/cms/config/{$config}.php")
);
}

// set the forms folder
$app['config']->set('statamic.forms.forms', __DIR__.'/__fixtures__/forms');

// configure to be an AU site
$app['config']->set('statamic.sites.sites.default.locale', 'en_AU');

Statamic::booted(function () {
Blueprint::setDirectory(__DIR__.'/__fixtures__/blueprints');

// configure to be an AU site
Site::setSites([
'default' => [
'name' => config('app.name'),
'locale' => 'en_AU',
'url' => '/',
],
]);
});
}

Expand Down

0 comments on commit c9c1919

Please sign in to comment.