|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace DNADesign\Populate\Tests; |
| 4 | + |
| 5 | +use DNADesign\Populate\PopulateFactory; |
| 6 | +use DNADesign\Populate\Tests\PopulateFactoryTest\PopulateFactoryTestObject; |
| 7 | +use DNADesign\Populate\Tests\PopulateFactoryTest\PopulateFactoryTestVersionedObject; |
| 8 | +use SilverStripe\Assets\Image; |
| 9 | +use SilverStripe\Dev\SapphireTest; |
| 10 | +use SilverStripe\Dev\TestOnly; |
| 11 | +use SilverStripe\Versioned\Versioned; |
| 12 | + |
| 13 | +/** |
| 14 | + * Test populating files into assets folder. |
| 15 | + */ |
| 16 | +class PopulateAssetFactoryTest extends SapphireTest implements TestOnly |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var PopulateFactory |
| 20 | + */ |
| 21 | + protected $factory; |
| 22 | + |
| 23 | + protected $usesDatabase = true; |
| 24 | + |
| 25 | + public function setUp() |
| 26 | + { |
| 27 | + parent::setUp(); |
| 28 | + $this->factory = new PopulateFactory(); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Assert that a file is loaded into the expected path within assets directory (Root path). |
| 33 | + */ |
| 34 | + public function testLoadingFileToRootAssetsDirectory() |
| 35 | + { |
| 36 | + // Load a file using populate factory |
| 37 | + $obj = $this->factory->createObject(Image::class, 'image1', [ |
| 38 | + 'Filename' => 'image1.png', |
| 39 | + 'PopulateFileFrom' => 'tests/php/fixture/assets/image1.png', |
| 40 | + ]); |
| 41 | + |
| 42 | + // Assert that the file is created and exists in expected root directory of assets |
| 43 | + $this->assertEquals('./image1.png', $obj->getFilename()); |
| 44 | + $this->assertFileExists(__DIR__ . '/../../assets/image1.png'); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Assert that a file is loaded into the expected path within assets directory (Within folder) |
| 49 | + */ |
| 50 | + public function testLoadingFileToFolderInAssetsDirectory() |
| 51 | + { |
| 52 | + // Load a file using populate factory |
| 53 | + $obj = $this->factory->createObject(Image::class, 'image1', [ |
| 54 | + 'Filename' => 'fixture/image1.png', |
| 55 | + 'PopulateFileFrom' => 'tests/php/fixture/assets/image1.png', |
| 56 | + ]); |
| 57 | + |
| 58 | + // Assert that the file is created and exists in expected root directory of assets |
| 59 | + $this->assertEquals('fixture/image1.png', $obj->getFilename()); |
| 60 | + $this->assertFileExists(__DIR__ . '/../../assets/fixture/image1.png'); |
| 61 | + } |
| 62 | +} |
0 commit comments