Skip to content

Commit

Permalink
Fix test for later revision of file helper implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Apr 30, 2019
1 parent c457db9 commit 9b74fa1
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy;
use SilverStripe\Assets\FilenameParsing\LegacyFileIDHelper;
use SilverStripe\Assets\FilenameParsing\ParsedFileID;
use SilverStripe\Assets\Filesystem;
use SilverStripe\Assets\Folder;
Expand Down Expand Up @@ -66,21 +67,48 @@ public function tearDown()
parent::tearDown();
}

/**
* Tests cases where files have already been migrated to 4.3 or older,
* and some images have since been unpublished or otherwise marked protected.
* The previously orphaned thumbnails wouldn't have been moved to the protected store in this case.
* The migration task should find those orphans, and reunite them with the original image.
* And they lived happily ever after.
*/
public function testMigratesThumbnailsForProtectedFiles()
{
/** @var TestAssetStore $store */
$store = singleton(AssetStore::class); // will use TestAssetStore

// Remove the legacy helper, otherwise it'll move the _resampled files as well,
// which "pollutes" our test case.
/** @var FileIDHelperResolutionStrategy $strategy */
$publicStrategy = $store->getPublicResolutionStrategy();
$helpers = $publicStrategy->getResolutionFileIDHelpers();
$origHelpers = [];
foreach ($helpers as $i => $helper) {
$origHelpers[] = clone $helper;
if ($helper instanceof LegacyFileIDHelper) {
unset($helpers[$i]);
}
}
$publicStrategy->setResolutionFileIDHelpers($helpers);
$store->setPublicResolutionStrategy($publicStrategy);

/** @var Image $image */
$image = $this->objFromFixture(Image::class, 'nested');

$formats = ['ResizedImage' => [60,60]];
$expectedLegacyPath = $this->createLegacyResampledImageFixture($store, $image, $formats);

// Protect file *after* creating legacy fixture
// Protect file *after* creating legacy fixture,
// but without moving the _resampled "orphan"
$image->protectFile();
$image->write();

// We need to retain the legacy helper for later assertions.
$publicStrategy->setResolutionFileIDHelpers($origHelpers);
$store->setPublicResolutionStrategy($publicStrategy);

$helper = new LegacyThumbnailMigrationHelper();
$moved = $helper->run($store);

Expand All @@ -98,7 +126,10 @@ public function testMigratesThumbnailsForProtectedFiles()
new ParsedFileID($image->Filename, $image->Hash),
$store->getProtectedFilesystem()
);
$this->assertCount(1, $protectedVariants);

// findVariants() returns *both* the original file and the variant
// See FileIDHelperResolutionStrategyTest->testFindVariant()
$this->assertCount(2, $protectedVariants);
}

public function testMigratesWithExistingThumbnailInNewLocation()
Expand Down

0 comments on commit 9b74fa1

Please sign in to comment.