Passed
Pull Request — master (#4)
by Robbie
01:29
created

FileBlockTest::testImageIsAddedToSchemaData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ElementalFileBlock\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\ElementalFileBlock\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
        /** @var FileBlock $block */
46
        $block = $this->objFromFixture(FileBlock::class, 'with_image');
47
48
        $summary = $block->getSummary();
49
50
        $this->assertContains('elemental-preview__thumbnail-image', $summary);
51
        $this->assertContains('Some image', $summary);
52
    }
53
54
    public function testGetSummaryReturnsFileTitleWhenLinkedToFile()
55
    {
56
        /** @var FileBlock $block */
57
        $block = $this->objFromFixture(FileBlock::class, 'with_file');
58
59
        $summary = $block->getSummary();
60
61
        $this->assertContains('elemental-preview__thumbnail-image', $summary);
62
        $this->assertContains('elemental-preview__thumbnail-image--placeholder', $summary);
63
        $this->assertContains('Some file', $summary);
64
    }
65
66
    public function testImageIsAddedToSchemaData()
67
    {
68
        /** @var FileBlock $block */
69
        $block = $this->objFromFixture(FileBlock::class, 'with_image');
70
71
        $schemaData = $block->getBlockSchema();
72
73
        $this->assertNotEmpty($schemaData['fileURL'], 'File URL is added to schema');
74
        $this->assertNotEmpty($schemaData['fileTitle'], 'File title is added to schema');
75
    }
76
}
77