Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX HTML showing in inline preview #42

Merged
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
14 changes: 11 additions & 3 deletions src/Block/FileBlock.php
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
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 see "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