Skip to content

Commit

Permalink
FIX HTML showing in inline preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Jul 10, 2023
1 parent 2b293b8 commit 4129d16
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
14 changes: 11 additions & 3 deletions src/Block/FileBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/behat/features/elemental-fileblock.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "test1" in the ".element-editor-summary__content" element

# Assert that it saved
And I click on the ".element-editor-header__title" element
Expand Down
30 changes: 15 additions & 15 deletions tests/php/Block/FileBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
}

Expand Down

0 comments on commit 4129d16

Please sign in to comment.