Skip to content
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
13 changes: 7 additions & 6 deletions tests/MarkdownFieldTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Nimbus\Content\FieldTypeRegistry;
use Nimbus\Content\UnknownFieldType;
use Nimbus\Content\Validator;
use Nimbus\Plugin\PluginCapabilities;
use Nimbus\Plugin\PluginContext;
use NimbusCMS\Markdown\MarkdownFieldType;
use NimbusCMS\Markdown\MarkdownPlugin;
Expand All @@ -34,7 +35,7 @@ private function field(array $options = [], bool $required = false): Field
public function test_the_plugin_registers_its_field_type(): void
{
$registry = new FieldTypeRegistry();
(new MarkdownPlugin())->register(new PluginContext($registry, MarkdownPlugin::ID));
(new MarkdownPlugin())->register(new PluginContext(new PluginCapabilities(fieldTypes: $registry), MarkdownPlugin::ID));

self::assertTrue($registry->has('markdown'));
self::assertSame('markdown', $registry->get('markdown')->type());
Expand All @@ -44,7 +45,7 @@ public function test_the_plugin_registers_its_field_type(): void
public function test_the_type_appears_in_the_field_picker(): void
{
$registry = new FieldTypeRegistry();
(new MarkdownPlugin())->register(new PluginContext($registry, MarkdownPlugin::ID));
(new MarkdownPlugin())->register(new PluginContext(new PluginCapabilities(fieldTypes: $registry), MarkdownPlugin::ID));

self::assertArrayHasKey('markdown', $registry->choices());
self::assertSame('Markdown', $registry->choices()['markdown']);
Expand All @@ -62,10 +63,10 @@ public function test_the_plugin_id_matches_the_composer_manifest(): void
public function test_registering_twice_is_rejected_by_core(): void
{
$registry = new FieldTypeRegistry();
(new MarkdownPlugin())->register(new PluginContext($registry, MarkdownPlugin::ID));
(new MarkdownPlugin())->register(new PluginContext(new PluginCapabilities(fieldTypes: $registry), MarkdownPlugin::ID));

$this->expectException(\Nimbus\Content\DuplicateFieldType::class);
(new MarkdownPlugin())->register(new PluginContext($registry, MarkdownPlugin::ID));
(new MarkdownPlugin())->register(new PluginContext(new PluginCapabilities(fieldTypes: $registry), MarkdownPlugin::ID));
}

// -------------------------------------------------------- normalization
Expand Down Expand Up @@ -125,7 +126,7 @@ public function test_max_length_counts_characters_not_bytes(): void
public function test_required_empty_is_handled_by_core_not_here(): void
{
$registry = new FieldTypeRegistry();
(new MarkdownPlugin())->register(new PluginContext($registry, MarkdownPlugin::ID));
(new MarkdownPlugin())->register(new PluginContext(new PluginCapabilities(fieldTypes: $registry), MarkdownPlugin::ID));

$collection = new Collection(1, 'posts', 'Posts', '#', '', [$this->field(required: true)], ['kind' => 'collection']);
$errors = (new Validator($registry))->validate($collection, ['body' => $this->type->normalize('')]);
Expand All @@ -137,7 +138,7 @@ public function test_required_empty_is_handled_by_core_not_here(): void
public function test_a_valid_required_value_passes_through_core_validation(): void
{
$registry = new FieldTypeRegistry();
(new MarkdownPlugin())->register(new PluginContext($registry, MarkdownPlugin::ID));
(new MarkdownPlugin())->register(new PluginContext(new PluginCapabilities(fieldTypes: $registry), MarkdownPlugin::ID));

$collection = new Collection(1, 'posts', 'Posts', '#', '', [$this->field(required: true)], ['kind' => 'collection']);
$errors = (new Validator($registry))->validate($collection, ['body' => $this->type->normalize('# Hello')]);
Expand Down
15 changes: 8 additions & 7 deletions tests/PackageIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Nimbus\Content\Field;
use Nimbus\Content\FieldTypeRegistry;
use Nimbus\Content\UnknownFieldType;
use Nimbus\Plugin\PluginCapabilities;
use Nimbus\Plugin\PluginDiagnostic;
use Nimbus\Plugin\PluginLoader;
use NimbusCMS\Markdown\MarkdownPlugin;
Expand Down Expand Up @@ -91,7 +92,7 @@ public function test_composer_discovery_registers_the_field_type(): void
{
$registry = new FieldTypeRegistry();
$loader = new PluginLoader($this->installedAs());
$diagnostics = $loader->load($registry);
$diagnostics = $loader->load(new PluginCapabilities(fieldTypes: $registry));

self::assertSame([], $diagnostics, 'a correctly installed package must load cleanly');
self::assertSame(
Expand All @@ -108,7 +109,7 @@ public function test_composer_discovery_registers_the_field_type(): void
public function test_core_field_types_are_untouched_by_installation(): void
{
$registry = new FieldTypeRegistry();
(new PluginLoader($this->installedAs()))->load($registry);
(new PluginLoader($this->installedAs()))->load(new PluginCapabilities(fieldTypes: $registry));

foreach (['text', 'textarea', 'number', 'boolean', 'relation'] as $core) {
self::assertSame('core', $registry->providerOf($core));
Expand All @@ -121,7 +122,7 @@ public function test_disabling_the_package_leaves_the_type_unregistered(): void
{
$registry = new FieldTypeRegistry();
$loader = new PluginLoader($this->installedAs(), [MarkdownPlugin::ID => false]);
$diagnostics = $loader->load($registry);
$diagnostics = $loader->load(new PluginCapabilities(fieldTypes: $registry));

self::assertSame([], $loader->registered());
self::assertFalse($registry->has('markdown'));
Expand All @@ -133,7 +134,7 @@ public function test_disabling_the_package_leaves_the_type_unregistered(): void
public function test_with_the_package_disabled_writes_are_blocked_and_content_is_kept(): void
{
$registry = new FieldTypeRegistry();
(new PluginLoader($this->installedAs(), [MarkdownPlugin::ID => false]))->load($registry);
(new PluginLoader($this->installedAs(), [MarkdownPlugin::ID => false]))->load(new PluginCapabilities(fieldTypes: $registry));

$field = new Field('body', 'Body', 'markdown');
$stored = "# Still here\n\nWith **bold** text.";
Expand All @@ -160,11 +161,11 @@ public function test_re_enabling_restores_the_field_type(): void
$path = $this->installedAs();

$disabled = new FieldTypeRegistry();
(new PluginLoader($path, [MarkdownPlugin::ID => false]))->load($disabled);
(new PluginLoader($path, [MarkdownPlugin::ID => false]))->load(new PluginCapabilities(fieldTypes: $disabled));
self::assertFalse($disabled->has('markdown'));

$enabled = new FieldTypeRegistry();
(new PluginLoader($path, [MarkdownPlugin::ID => true]))->load($enabled);
(new PluginLoader($path, [MarkdownPlugin::ID => true]))->load(new PluginCapabilities(fieldTypes: $enabled));

self::assertTrue($enabled->has('markdown'), 'flipping the switch back is all it takes');
self::assertSame('markdown', $enabled->get('markdown')->type());
Expand All @@ -182,7 +183,7 @@ public function test_a_second_package_cannot_take_this_plugins_id(): void

$registry = new FieldTypeRegistry();
$loader = new PluginLoader($this->installedJson);
$diagnostics = $loader->load($registry);
$diagnostics = $loader->load(new PluginCapabilities(fieldTypes: $registry));

self::assertSame([MarkdownPlugin::ID => $manifest['name']], $loader->registered());
self::assertCount(1, $diagnostics);
Expand Down
Loading