Source of file FileBlockTest.php
Size: 3,026 Bytes - Last Modified: 2021-12-23T10:29:57+00:00
/var/www/docs.ssmods.com/process/src/tests/php/Block/FileBlockTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | <?php namespace SilverStripe\ElementalFileBlock\Tests\Block; use SilverStripe\AssetAdmin\Forms\UploadField; use SilverStripe\Assets\File; use SilverStripe\Assets\Folder; use SilverStripe\Assets\Image; use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore; use SilverStripe\Dev\SapphireTest; use SilverStripe\ElementalFileBlock\Block\FileBlock; class FileBlockTest extends SapphireTest { protected static $fixture_file = 'FileBlockTest.yml'; protected function setUp(): void { parent::setUp(); TestAssetStore::activate('FileBlockTest'); // Copy test images for each of the fixture references /** @var File $image */ $files = File::get()->exclude('ClassName', Folder::class); foreach ($files as $image) { $sourcePath = __DIR__ . '/FileBlockTest/' . $image->Name; $image->setFromLocalFile($sourcePath, $image->Filename); $image->write(); } } protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); } public function testGetSummaryReturnsStringWithoutAssociatedFile() { $block = new FileBlock; $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); } public function testImageIsAddedToSchemaData() { /** @var FileBlock $block */ $block = $this->objFromFixture(FileBlock::class, 'with_image'); $schemaData = $block->getBlockSchema(); $this->assertNotEmpty($schemaData['fileURL'], 'File URL is added to schema'); $this->assertNotEmpty($schemaData['fileTitle'], 'File title is added to schema'); } public function testUploadFieldShouldNotAllowMultipleFiles() { /** @var FileBlock $block */ $block = $this->objFromFixture(FileBlock::class, 'with_image'); /** @var UploadField $field */ $field = $block->getCMSFields()->fieldByName('Root.Main.File'); $this->assertInstanceOf(UploadField::class, $field, 'Field should be an UploadField'); $this->assertFalse($field->getIsMultiUpload(), 'Field should not allow multiple uploads'); } } |