Skip to content

Commit

Permalink
Add tests to cover importing single fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Nov 12, 2024
1 parent a41f757 commit 24f962e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 9 deletions.
60 changes: 55 additions & 5 deletions tests/Transformers/BardTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function it_doesnt_handles_images_without_base_url()
}

#[Test]
public function is_enables_buttons_on_bard_field()
public function it_enables_buttons_on_bard_field()
{
$transformer = new BardTransformer(
import: $this->import,
Expand Down Expand Up @@ -192,10 +192,60 @@ public function is_enables_buttons_on_bard_field()
}

#[Test]
public function is_enables_buttons_on_bard_field_in_fieldset()
public function it_enables_buttons_on_imported_bard_field()
{
Fieldset::make('content_stuff')->setContents(['fields' => [
['handle' => 'bard_basic', 'field' => ['type' => 'bard']],
['handle' => 'bard_field', 'field' => ['type' => 'bard']],
]])->save();

$blueprint = $this->collection->entryBlueprint();

$this->blueprint->setContents([
'sections' => [
'main' => [
'fields' => [
['handle' => 'bard_field', 'field' => 'content_stuff.bard_field'],
],
],
],
])->save();

$transformer = new BardTransformer(
import: $this->import,
blueprint: $blueprint,
field: $blueprint->field('bard_field'),
config: []
);

$transformer->transform('<p>Hello world!</p>');

$fieldset = Fieldset::find('content_stuff');

$this->assertEquals([
'h1',
'h2',
'h3',
'bold',
'italic',
'unorderedlist',
'orderedlist',
'removeformat',
'quote',
'anchor',
'image',
'table',
'horizontalrule',
'codeblock',
'underline',
'superscript',
], $fieldset->field('bard_field')->get('buttons'));
}

#[Test]
public function it_enables_buttons_on_imported_bard_field_with_prefix()
{
Fieldset::make('content_stuff')->setContents(['fields' => [
['handle' => 'bard_field', 'field' => ['type' => 'bard']],
]])->save();

$blueprint = $this->collection->entryBlueprint();
Expand All @@ -213,7 +263,7 @@ public function is_enables_buttons_on_bard_field_in_fieldset()
$transformer = new BardTransformer(
import: $this->import,
blueprint: $blueprint,
field: $blueprint->field('resources_bard_basic'),
field: $blueprint->field('resources_bard_field'),
config: []
);

Expand All @@ -238,6 +288,6 @@ public function is_enables_buttons_on_bard_field_in_fieldset()
'codeblock',
'underline',
'superscript',
], $fieldset->field('bard_basic')->get('buttons'));
], $fieldset->field('bard_field')->get('buttons'));
}
}
41 changes: 37 additions & 4 deletions tests/WordPress/GutenbergTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,43 @@ public function it_transforms_spacer_blocks()
}

#[Test]
public function it_append_sets_to_bard_field_in_fieldset()
public function it_append_sets_to_imported_bard_field()
{
Fieldset::make('content_stuff')->setContents(['fields' => [
['handle' => 'bard_basic', 'field' => ['type' => 'bard']],
['handle' => 'bard_field', 'field' => ['type' => 'bard']],
]])->save();

$this->blueprint->setContents([
'sections' => [
'main' => [
'fields' => [
['handle' => 'bard_field', 'field' => 'content_stuff.bard_field'],
],
],
],
])->save();

Gutenberg::toBard(
config: [],
blueprint: $this->blueprint,
field: $this->blueprint->field('bard_field'),
value: <<<'HTML'
<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
HTML
);

$fieldset = Fieldset::find('content_stuff');

$this->assertSetExists('spacer', $fieldset->field('bard_field'));
}

#[Test]
public function it_append_sets_to_imported_bard_field_with_prefix()
{
Fieldset::make('content_stuff')->setContents(['fields' => [
['handle' => 'bard_field', 'field' => ['type' => 'bard']],
]])->save();

$this->blueprint->setContents([
Expand All @@ -788,7 +821,7 @@ public function it_append_sets_to_bard_field_in_fieldset()
Gutenberg::toBard(
config: [],
blueprint: $this->blueprint,
field: $this->blueprint->field('resources_bard_basic'),
field: $this->blueprint->field('resources_bard_field'),
value: <<<'HTML'
<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
Expand All @@ -798,7 +831,7 @@ public function it_append_sets_to_bard_field_in_fieldset()

$fieldset = Fieldset::find('content_stuff');

$this->assertSetExists('spacer', $fieldset->field('bard_basic'));
$this->assertSetExists('spacer', $fieldset->field('bard_field'));
}

#[Test]
Expand Down

0 comments on commit 24f962e

Please sign in to comment.