1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ElementalBlocks\Tests\Block; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Assets\File; |
6
|
|
|
use SilverStripe\Assets\Folder; |
7
|
|
|
use SilverStripe\Assets\Image; |
8
|
|
|
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore; |
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
10
|
|
|
use SilverStripe\ElementalBlocks\Block\FileBlock; |
11
|
|
|
|
12
|
|
|
class FileBlockTest extends SapphireTest |
13
|
|
|
{ |
14
|
|
|
protected static $fixture_file = 'FileBlockTest.yml'; |
15
|
|
|
|
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
TestAssetStore::activate('FileBlockTest'); |
20
|
|
|
|
21
|
|
|
// Copy test images for each of the fixture references |
22
|
|
|
/** @var File $image */ |
23
|
|
|
$files = File::get()->exclude('ClassName', Folder::class); |
24
|
|
|
foreach ($files as $image) { |
25
|
|
|
$sourcePath = __DIR__ . '/FileBlockTest/' . $image->Name; |
26
|
|
|
$image->setFromLocalFile($sourcePath, $image->Filename); |
27
|
|
|
$image->write(); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function tearDown() |
32
|
|
|
{ |
33
|
|
|
TestAssetStore::reset(); |
34
|
|
|
parent::tearDown(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGetSummaryReturnsStringWithoutAssociatedFile() |
38
|
|
|
{ |
39
|
|
|
$block = new FileBlock; |
40
|
|
|
$this->assertSame('', $block->getSummary()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetSummaryReturnsThumbnailAndFileTitle() |
44
|
|
|
{ |
45
|
|
|
$block = $this->objFromFixture(FileBlock::class, 'with_image'); |
46
|
|
|
|
47
|
|
|
$summary = $block->getSummary(); |
48
|
|
|
|
49
|
|
|
$this->assertContains('elemental-preview__thumbnail-image', $summary); |
50
|
|
|
$this->assertContains('Some image', $summary); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testGetSummaryReturnsFileTitleWhenLinkedToFile() |
54
|
|
|
{ |
55
|
|
|
$block = $this->objFromFixture(FileBlock::class, 'with_file'); |
56
|
|
|
|
57
|
|
|
$summary = $block->getSummary(); |
58
|
|
|
|
59
|
|
|
$this->assertContains('elemental-preview__thumbnail-image', $summary); |
60
|
|
|
$this->assertContains('elemental-preview__thumbnail-image--placeholder', $summary); |
61
|
|
|
$this->assertContains('Some file', $summary); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|