| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SilverStripe\ElementalFileBlock\Tests\Block; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SilverStripe\AssetAdmin\Forms\UploadField; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SilverStripe\Assets\File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\Assets\Folder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Assets\Image; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SilverStripe\Dev\SapphireTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SilverStripe\ElementalFileBlock\Block\FileBlock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class FileBlockTest extends SapphireTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     protected static $fixture_file = 'FileBlockTest.yml'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         TestAssetStore::activate('FileBlockTest'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         // Copy test images for each of the fixture references | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         /** @var File $image */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $files = File::get()->exclude('ClassName', Folder::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         foreach ($files as $image) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             $sourcePath = __DIR__ . '/FileBlockTest/' . $image->Name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             $image->setFromLocalFile($sourcePath, $image->Filename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             $image->write(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     protected function tearDown() | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         TestAssetStore::reset(); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         parent::tearDown(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     public function testGetSummaryReturnsStringWithoutAssociatedFile() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $block = new FileBlock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->assertSame('', $block->getSummary()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function testGetSummaryReturnsThumbnailAndFileTitle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         /** @var FileBlock $block */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $block = $this->objFromFixture(FileBlock::class, 'with_image'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $summary = $block->getSummary(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertContains('elemental-preview__thumbnail-image', $summary); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->assertContains('Some image', $summary); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function testGetSummaryReturnsFileTitleWhenLinkedToFile() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         /** @var FileBlock $block */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $block = $this->objFromFixture(FileBlock::class, 'with_file'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $summary = $block->getSummary(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->assertContains('elemental-preview__thumbnail-image', $summary); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->assertContains('elemental-preview__thumbnail-image--placeholder', $summary); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->assertContains('Some file', $summary); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function testImageIsAddedToSchemaData() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         /** @var FileBlock $block */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $block = $this->objFromFixture(FileBlock::class, 'with_image'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $schemaData = $block->getBlockSchema(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->assertNotEmpty($schemaData['fileURL'], 'File URL is added to schema'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->assertNotEmpty($schemaData['fileTitle'], 'File title is added to schema'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     public function testUploadFieldShouldNotAllowMultipleFiles() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         /** @var FileBlock $block */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $block = $this->objFromFixture(FileBlock::class, 'with_image'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         /** @var UploadField $field */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $field = $block->getCMSFields()->fieldByName('Root.Main.File'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $this->assertInstanceOf(UploadField::class, $field, 'Field should be an UploadField'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $this->assertFalse($field->getIsMultiUpload(), 'Field should not allow multiple uploads'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 89 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths