From 2f06274d2978d7a80b7f375199f6ef82a618ba01 Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Mon, 10 Jul 2023 13:24:11 +1200 Subject: [PATCH] FIX HTML showing in inline preview --- src/Block/FileBlock.php | 14 +++++++-- .../features/elemental-fileblock.feature | 3 ++ tests/php/Block/FileBlockTest.php | 30 +++++++++---------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Block/FileBlock.php b/src/Block/FileBlock.php index 65ff1d9..6a3a8b0 100644 --- a/src/Block/FileBlock.php +++ b/src/Block/FileBlock.php @@ -47,7 +47,7 @@ public function getType() public function getSummary() { if ($this->File() && $this->File()->exists()) { - return $this->getSummaryThumbnail() . $this->File()->Title; + return $this->File()->Title; } return ''; } @@ -60,10 +60,18 @@ public function getSummary() protected function provideBlockSchema() { $blockSchema = parent::provideBlockSchema(); - if ($this->File() && $this->File()->exists() && $this->File()->getIsImage()) { - $blockSchema['fileURL'] = $this->File()->CMSThumbnail()->getURL(); + if ($this->File() && $this->File()->exists()) { $blockSchema['fileTitle'] = $this->File()->getTitle(); + + if ($this->File()->getIsImage()) { + $blockSchema['fileURL'] = $this->File()->CMSThumbnail()->getURL(); + } else { + $blockSchema['fileURL'] = ModuleResourceLoader::resourceURL( + 'silverstripe/framework:client/images/app_icons/document_92.png' + ); + } } + return $blockSchema; } diff --git a/tests/behat/features/elemental-fileblock.feature b/tests/behat/features/elemental-fileblock.feature index 39e1654..185d90e 100644 --- a/tests/behat/features/elemental-fileblock.feature +++ b/tests/behat/features/elemental-fileblock.feature @@ -32,6 +32,9 @@ Feature: Use elemental fileblock And I click on the ".gallery-item__thumbnail" element And I press the "Insert" button And I press the "Publish" button + And I wait for 1 seconds + And I should see a ".element-editor-summary__thumbnail-image" element + And I should see "test1" in the ".element-editor-summary__content" element # Assert that it saved And I click on the ".element-editor-header__title" element diff --git a/tests/php/Block/FileBlockTest.php b/tests/php/Block/FileBlockTest.php index cb4828c..a7a3a52 100644 --- a/tests/php/Block/FileBlockTest.php +++ b/tests/php/Block/FileBlockTest.php @@ -41,27 +41,13 @@ public function testGetSummaryReturnsStringWithoutAssociatedFile() $this->assertSame('', $block->getSummary()); } - public function testGetSummaryReturnsThumbnailAndFileTitle() - { - /** @var FileBlock $block */ - $block = $this->objFromFixture(FileBlock::class, 'with_image'); - - $summary = $block->getSummary(); - - $this->assertStringContainsString('elemental-preview__thumbnail-image', $summary); - $this->assertStringContainsString('Some image', $summary); - } - public function testGetSummaryReturnsFileTitleWhenLinkedToFile() { /** @var FileBlock $block */ $block = $this->objFromFixture(FileBlock::class, 'with_file'); $summary = $block->getSummary(); - - $this->assertStringContainsString('elemental-preview__thumbnail-image', $summary); - $this->assertStringContainsString('elemental-preview__thumbnail-image--placeholder', $summary); - $this->assertStringContainsString('Some file', $summary); + $this->assertEquals('Some file', $summary); } public function testImageIsAddedToSchemaData() @@ -72,6 +58,20 @@ public function testImageIsAddedToSchemaData() $schemaData = $block->getBlockSchema(); $this->assertNotEmpty($schemaData['fileURL'], 'File URL is added to schema'); + $this->assertStringContainsString('ss-logo', $schemaData['fileURL'], 'File URL contains image name'); + $this->assertNotEmpty($schemaData['fileTitle'], 'File title is added to schema'); + + /** @var FileBlock $block */ + $block2 = $this->objFromFixture(FileBlock::class, 'with_file'); + + $schemaData = $block2->getBlockSchema(); + + $this->assertNotEmpty($schemaData['fileURL'], 'File URL is added to schema'); + $this->assertStringContainsString( + 'document_92.png', + $schemaData['fileURL'], + 'File URL contains placeholder file name' + ); $this->assertNotEmpty($schemaData['fileTitle'], 'File title is added to schema'); }