Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Oct 31, 2024
1 parent 8e7abce commit f7d16ce
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/Transformers/BardTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\AssetContainer;
use Statamic\Facades\Collection;
use Statamic\Facades\Fieldset;
use Statamic\Importer\Tests\TestCase;
use Statamic\Importer\Transformers\BardTransformer;
use Statamic\Testing\Concerns\PreventsSavingStacheItemsToDisk;
Expand Down Expand Up @@ -136,4 +137,78 @@ public function it_doesnt_handles_images_without_base_url()
],
], $output);
}

#[Test]
public function is_enables_buttons_on_bard_field()
{
$transformer = new BardTransformer($this->blueprint, $this->field, []);

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

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

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

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

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

$this->blueprint->setContents([
'sections' => [
'main' => [
'fields' => [
['import' => 'content_stuff', 'prefix' => 'resources_'],
],
],
],
])->save();

$transformer = new BardTransformer($blueprint, $blueprint->field('resources_bard_basic'), []);

$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_basic')->get('buttons'));
}
}
34 changes: 34 additions & 0 deletions tests/WordPress/GutenbergTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Statamic\Facades\AssetContainer;
use Statamic\Facades\Blueprint;
use Statamic\Facades\Collection;
use Statamic\Facades\Fieldset;
use Statamic\Importer\Tests\TestCase;
use Statamic\Importer\WordPress\Gutenberg;
use Statamic\Testing\Concerns\PreventsSavingStacheItemsToDisk;
Expand Down Expand Up @@ -767,6 +768,39 @@ public function it_transforms_spacer_blocks()
], $output);
}

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

$this->blueprint->setContents([
'sections' => [
'main' => [
'fields' => [
['import' => 'content_stuff', 'prefix' => 'resources_'],
],
],
],
])->save();

Gutenberg::toBard(
config: [],
blueprint: $this->blueprint,
field: $this->blueprint->field('resources_bard_basic'),
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_basic'));
}

#[Test]
public function it_returns_hook_output()
{
Expand Down

0 comments on commit f7d16ce

Please sign in to comment.