-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix populating file when path is assets folder
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace DNADesign\Populate\Tests; | ||
|
||
use DNADesign\Populate\PopulateFactory; | ||
use DNADesign\Populate\Tests\PopulateFactoryTest\PopulateFactoryTestObject; | ||
use DNADesign\Populate\Tests\PopulateFactoryTest\PopulateFactoryTestVersionedObject; | ||
use SilverStripe\Assets\Image; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
/** | ||
* Test populating files into assets folder. | ||
*/ | ||
class PopulateAssetFactoryTest extends SapphireTest implements TestOnly | ||
{ | ||
/** | ||
* @var PopulateFactory | ||
*/ | ||
protected $factory; | ||
|
||
protected $usesDatabase = true; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->factory = new PopulateFactory(); | ||
} | ||
|
||
/** | ||
* Assert that a file is loaded into the expected path within assets directory (Root path). | ||
*/ | ||
public function testLoadingFileToRootAssetsDirectory() | ||
{ | ||
// Load a file using populate factory | ||
$obj = $this->factory->createObject(Image::class, 'image1', [ | ||
'Filename' => 'image1.png', | ||
'PopulateFileFrom' => 'tests/php/fixture/assets/image1.png', | ||
]); | ||
|
||
// Assert that the file is created and exists in expected root directory of assets | ||
$this->assertEquals('./image1.png', $obj->getFilename()); | ||
$this->assertFileExists(__DIR__ . '/../../assets/image1.png'); | ||
} | ||
|
||
/** | ||
* Assert that a file is loaded into the expected path within assets directory (Within folder) | ||
*/ | ||
public function testLoadingFileToFolderInAssetsDirectory() | ||
{ | ||
// Load a file using populate factory | ||
$obj = $this->factory->createObject(Image::class, 'image1', [ | ||
'Filename' => 'fixture/image1.png', | ||
'PopulateFileFrom' => 'tests/php/fixture/assets/image1.png', | ||
]); | ||
|
||
// Assert that the file is created and exists in expected root directory of assets | ||
$this->assertEquals('fixture/image1.png', $obj->getFilename()); | ||
$this->assertFileExists(__DIR__ . '/../../assets/fixture/image1.png'); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.