diff --git a/src/Dev/TestAssetStore.php b/src/Dev/TestAssetStore.php index c4f354df..d78cdefa 100644 --- a/src/Dev/TestAssetStore.php +++ b/src/Dev/TestAssetStore.php @@ -90,8 +90,7 @@ public static function activate($basedir) Injector::inst()->registerService($generated, GeneratedAssetHandler::class); Requirements::backend()->setAssetHandler($generated); - // Disable legacy and set defaults - FlysystemAssetStore::config()->set('legacy_filenames', false); + // Set defaults Director::config()->set('alternate_base_url', '/'); DBFile::config()->set('force_resample', false); File::config()->set('force_resample', false); diff --git a/src/FileMigrationHelper.php b/src/FileMigrationHelper.php index bed8e6d0..9b28d17b 100644 --- a/src/FileMigrationHelper.php +++ b/src/FileMigrationHelper.php @@ -1,5 +1,9 @@ Versions($versionFilters, "", 1)->count(); + $oldVersionCount = $file->allVersions($versionFilters, "", 1)->count(); // Our hash was published at some other stage if ($oldVersionCount > 0) { return new ParsedFileID($file->getFilename(), $file->getHash(), $parsedFileID->getVariant()); diff --git a/src/Flysystem/FlysystemAssetStore.php b/src/Flysystem/FlysystemAssetStore.php index 0a9e7ebe..a11e0a5e 100644 --- a/src/Flysystem/FlysystemAssetStore.php +++ b/src/Flysystem/FlysystemAssetStore.php @@ -253,7 +253,6 @@ public function setProtectedResolutionStrategy(FileResolutionStrategy $protected * Return the store that contains the given fileID * * @param string $fileID Internal file identifier - * @deprecated 1.4.0 Use `applyToFileIDOnFilesystem()` instead * @return Filesystem */ protected function getFilesystemFor($fileID) diff --git a/src/ImageBackendFactory.php b/src/ImageBackendFactory.php index 8cea50b9..81738ff7 100644 --- a/src/ImageBackendFactory.php +++ b/src/ImageBackendFactory.php @@ -37,21 +37,21 @@ public function __construct(Factory $creator) */ public function create($service, array $params = []) { - /** @var AssetContainer */ - $store = reset($params); - if (!$store instanceof AssetContainer) { + /** @var AssetContainer $assetContainer */ + $assetContainer = reset($params); + if (!$assetContainer instanceof AssetContainer) { throw new BadMethodCallException("Can only create Image_Backend for " . AssetContainer::class); } // Check cache - $key = sha1($store->getHash().'-'.$store->getVariant()); + $key = sha1($assetContainer->getHash().'-'.$assetContainer->getVariant()); if (array_key_exists($key, $this->cache ?? [])) { return $this->cache[$key]; } // Verify file exists before creating backend $backend = null; - if ($store->exists() && $store->getIsImage()) { + if ($assetContainer->exists() && $assetContainer->getIsImage()) { $backend = $this->creator->create($service, $params); } diff --git a/src/Upload_Validator.php b/src/Upload_Validator.php index 67451b70..8ae0144c 100644 --- a/src/Upload_Validator.php +++ b/src/Upload_Validator.php @@ -121,8 +121,8 @@ public function getAllowedMaxFileSize($ext = null) $this->setAllowedMaxFileSize($fileSize); } else { // When no default is present, use maximum set by PHP - $maxUpload = File::ini2bytes(ini_get('upload_max_filesize')); - $maxPost = File::ini2bytes(ini_get('post_max_size')); + $maxUpload = Convert::memstring2bytes(ini_get('upload_max_filesize')); + $maxPost = Convert::memstring2bytes(ini_get('post_max_size')); $this->setAllowedMaxFileSize(min($maxUpload, $maxPost)); } } @@ -165,7 +165,7 @@ public function setAllowedMaxFileSize($rules) if (is_numeric($value)) { $tmpSize = $value; } else { - $tmpSize = File::ini2bytes($value); + $tmpSize = Convert::memstring2bytes($value); } $finalRules[$rule] = (int)$tmpSize; @@ -173,7 +173,7 @@ public function setAllowedMaxFileSize($rules) $this->allowedMaxFileSize = $finalRules; } elseif (is_string($rules)) { - $this->allowedMaxFileSize['*'] = File::ini2bytes($rules); + $this->allowedMaxFileSize['*'] = Convert::memstring2bytes($rules); } elseif ((int)$rules > 0) { $this->allowedMaxFileSize['*'] = (int)$rules; } diff --git a/tests/php/Dev/Tasks/FileMigrationHelperTest.php b/tests/php/Dev/Tasks/FileMigrationHelperTest.php index 6f4000cc..c59d9b33 100644 --- a/tests/php/Dev/Tasks/FileMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/FileMigrationHelperTest.php @@ -2,24 +2,25 @@ namespace SilverStripe\Assets\Tests\Dev\Tasks; -use Silverstripe\Assets\Dev\TestAssetStore; use SilverStripe\Assets\File; -use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper; -use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy; -use SilverStripe\Assets\FilenameParsing\HashFileIDHelper; -use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper; -use SilverStripe\Assets\Filesystem; -use SilverStripe\Assets\Flysystem\FlysystemAssetStore; -use SilverStripe\Assets\Folder; use SilverStripe\Assets\Image; -use SilverStripe\Assets\Storage\AssetStore; -use SilverStripe\Assets\Storage\FileHashingService; -use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension; -use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; -use SilverStripe\Core\Injector\Injector; +use SilverStripe\Assets\Folder; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Assets\Filesystem; +use SilverStripe\Core\Config\Config; use SilverStripe\ORM\Queries\SQLUpdate; +use SilverStripe\Core\Injector\Injector; +use Silverstripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\Storage\AssetStore; +use SilverStripe\Assets\Storage\FileHashingService; +use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper; +use SilverStripe\Assets\Flysystem\FlysystemAssetStore; +use SilverStripe\Assets\FilenameParsing\HashFileIDHelper; +use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper; +use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy; +use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension; /** * Ensures that File dataobjects can be safely migrated from 3.x @@ -428,6 +429,9 @@ private function missingFiles() */ public function testMigrationWithLegacyFilenames() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } Config::modify()->set(FlysystemAssetStore::class, 'legacy_filenames', true); $this->testMigration(); } diff --git a/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.php b/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.php index 341a50bc..2d339548 100644 --- a/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.php +++ b/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.php @@ -3,6 +3,7 @@ namespace SilverStripe\Assets\Tests\Dev\Tasks; use SilverStripe\Assets\Folder; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\Tasks\FixFolderPermissionsHelper; @@ -15,6 +16,9 @@ class FixFolderPermissionsHelperTest extends SapphireTest public function testTask() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $task = new FixFolderPermissionsHelper(); $updated = $task->run(); diff --git a/tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php b/tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php index f696442e..92117503 100644 --- a/tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php @@ -2,16 +2,17 @@ namespace SilverStripe\Assets\Tests\Dev\Tasks; -use Silverstripe\Assets\Dev\TestAssetStore; use SilverStripe\Assets\File; -use SilverStripe\Assets\Filesystem; -use SilverStripe\Assets\Folder; use SilverStripe\Assets\Image; -use SilverStripe\Assets\Dev\Tasks\LegacyThumbnailMigrationHelper; -use SilverStripe\Assets\Storage\AssetStore; -use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension; use SilverStripe\Core\Convert; +use SilverStripe\Assets\Folder; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Assets\Filesystem; +use Silverstripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\Storage\AssetStore; +use SilverStripe\Assets\Dev\Tasks\LegacyThumbnailMigrationHelper; +use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension; class LegacyThumbnailMigrationHelperTest extends SapphireTest { @@ -73,6 +74,9 @@ protected function tearDown(): void */ public function testMigratesWithExistingThumbnailInNewLocation($coreVersion) { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var TestAssetStore $store */ $store = singleton(AssetStore::class); // will use TestAssetStore @@ -105,6 +109,9 @@ public function testMigratesWithExistingThumbnailInNewLocation($coreVersion) */ public function testMigratesMultipleFilesInSameFolder($coreVersion) { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var TestAssetStore $store */ $store = singleton(AssetStore::class); // will use TestAssetStore @@ -148,6 +155,9 @@ public function testMigratesMultipleFilesInSameFolder($coreVersion) */ public function testMigrate($fixtureId, $formats, $coreVersion) { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var TestAssetStore $store */ $store = singleton(AssetStore::class); // will use TestAssetStore diff --git a/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php b/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php index baa41062..faaa048c 100644 --- a/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php @@ -2,23 +2,24 @@ namespace SilverStripe\Assets\Tests\Dev\Tasks; -use InvalidArgumentException; use LogicException; -use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use SilverStripe\Assets\Dev\Tasks\NormaliseAccessMigrationHelper as Helper; -use Silverstripe\Assets\Dev\TestAssetStore; +use Psr\Log\LoggerInterface; +use InvalidArgumentException; use SilverStripe\Assets\File; -use SilverStripe\Assets\Filesystem; -use SilverStripe\Assets\Flysystem\FlysystemAssetStore; -use SilverStripe\Assets\Folder; use SilverStripe\Assets\Image; -use SilverStripe\Assets\Storage\AssetStore; +use SilverStripe\Assets\Folder; +use SilverStripe\Dev\Deprecation; +use SilverStripe\Dev\SapphireTest; +use SilverStripe\Assets\Filesystem; use SilverStripe\Core\Config\Config; +use SilverStripe\Versioned\Versioned; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\SapphireTest; +use Silverstripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\Storage\AssetStore; use SilverStripe\Security\InheritedPermissions; -use SilverStripe\Versioned\Versioned; +use SilverStripe\Assets\Flysystem\FlysystemAssetStore; +use SilverStripe\Assets\Dev\Tasks\NormaliseAccessMigrationHelper as Helper; /** * Ensures that File dataobjects can be safely migrated from 3.x @@ -74,6 +75,9 @@ protected function tearDown(): void */ public function testSanityCheck() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); @@ -114,6 +118,9 @@ private function getHelper() public function testNeedToMoveWithFolder() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $this->expectException(\InvalidArgumentException::class); /** @var File $file */ $folder = Folder::find('Uploads'); @@ -123,6 +130,9 @@ public function testNeedToMoveWithFolder() public function testNeedToMovePublishedNoRestrictionFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::ANYONE; @@ -147,6 +157,9 @@ public function testNeedToMovePublishedNoRestrictionFile() public function testNeedToMovePublishedRestrictedFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::LOGGED_IN_USERS; @@ -171,6 +184,9 @@ public function testNeedToMovePublishedRestrictedFile() public function testNeedToMoveMetaChangedOnlyNoRestrictionFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::ANYONE; @@ -199,6 +215,9 @@ public function testNeedToMoveMetaChangedOnlyNoRestrictionFile() public function testNeedToMoveMetaChangedOnlyRestrictedFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::LOGGED_IN_USERS; @@ -227,6 +246,9 @@ public function testNeedToMoveMetaChangedOnlyRestrictedFile() public function testNeedToMoveDraftNoRestrictionFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->doUnpublish(); @@ -252,6 +274,9 @@ public function testNeedToMoveDraftNoRestrictionFile() public function testNeedToMoveDraftRestrictedFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->doUnpublish(); @@ -277,6 +302,9 @@ public function testNeedToMoveDraftRestrictedFile() public function testNeedToMoveUnrestrictedMixedDraftLiveFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::ANYONE; @@ -318,6 +346,9 @@ public function testNeedToMoveUnrestrictedMixedDraftLiveFile() public function testNeedToMoveRestrictedMixedDraftLiveFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::LOGGED_IN_USERS; @@ -358,6 +389,9 @@ public function testNeedToMoveRestrictedMixedDraftLiveFile() public function testNeedToMoveRestrictedLiveFileUnrestrictedDraft() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::LOGGED_IN_USERS; @@ -389,6 +423,9 @@ public function testNeedToMoveRestrictedLiveFileUnrestrictedDraft() */ public function testNeedToMoveUnrestrictedLiveFileRestrictedDraft() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::ANYONE; @@ -418,6 +455,9 @@ public function testNeedToMoveUnrestrictedLiveFileRestrictedDraft() */ public function testNeedToMoveRestrictedLiveUnrestrictedDraft() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::LOGGED_IN_USERS; @@ -443,6 +483,9 @@ public function testNeedToMoveRestrictedLiveUnrestrictedDraft() public function testNeedToMoveFileInProtectedFolder() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'secret'); $file->doUnpublish(); @@ -479,6 +522,9 @@ public function testNeedToMoveFileInProtectedFolder() public function testNeedToMoveRenamedFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::ANYONE; @@ -503,6 +549,9 @@ public function testNeedToMoveRenamedFile() public function testNeedToMoveReplacedRenamedFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::ANYONE; @@ -536,6 +585,9 @@ public function testNeedToMoveReplacedRenamedFile() public function testFindBadFilesWithProtectedDraft() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ foreach (File::get()->exclude('ClassName', Folder::class) as $file) { $file->protectFile(); @@ -549,6 +601,9 @@ public function testFindBadFilesWithProtectedDraft() public function testFindBadFilesWithPublishedDraft() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ foreach (File::get()->exclude('ClassName', Folder::class) as $file) { $file->publishFile(); @@ -568,6 +623,9 @@ public function testFindBadFilesWithPublishedDraft() public function testFindBadFilesWithProtectedLive() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ foreach (File::get()->exclude('ClassName', Folder::class) as $file) { $file->publishSingle(); @@ -583,6 +641,9 @@ public function testFindBadFilesWithProtectedLive() public function testFindBadFilesWithPublishedLive() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ foreach (File::get()->exclude('ClassName', Folder::class) as $file) { $file->publishSingle(); @@ -602,6 +663,9 @@ public function testFindBadFilesWithPublishedLive() public function testFindBadFilesWithMultiPublishedVersions() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ foreach (File::get()->exclude('ClassName', Folder::class) as $file) { $file->publishSingle(); @@ -630,6 +694,9 @@ public function testFindBadFilesWithMultiPublishedVersions() public function testNeedToMoveNonExistentFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $this->expectException(\LogicException::class); /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); @@ -644,6 +711,9 @@ public function testNeedToMoveNonExistentFile() public function testRun() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ foreach (File::get()->exclude('ClassName', Folder::class) as $file) { $file->publishFile(); @@ -676,6 +746,9 @@ public function testRun() */ public function testRunWithLotsOfFiles() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } // Create a two hundred good files for ($i = 0; $i < 200; $i++) { $file = new File(); @@ -724,6 +797,9 @@ public function testRunWithLotsOfFiles() public function testFixWithProtectedDraftFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->protectFile(); @@ -739,6 +815,9 @@ public function testFixWithProtectedDraftFile() public function testFixWithPublicDraftFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->publishFile(); @@ -754,6 +833,9 @@ public function testFixWithPublicDraftFile() public function testFixWithPublicLiveFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->publishSingle(); @@ -770,6 +852,9 @@ public function testFixWithPublicLiveFile() public function testFixWithProtectedLiveFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->publishSingle(); @@ -786,6 +871,9 @@ public function testFixWithProtectedLiveFile() public function testFixWithPublicRestrictedLiveFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::LOGGED_IN_USERS; @@ -803,6 +891,9 @@ public function testFixWithPublicRestrictedLiveFile() public function testFixWithProtectedRestrictedLiveFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->CanViewType = InheritedPermissions::LOGGED_IN_USERS; @@ -820,6 +911,9 @@ public function testFixWithProtectedRestrictedLiveFile() public function testFixWithUpdatedDraftMetadataFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->publishSingle(); @@ -844,6 +938,9 @@ public function testFixWithUpdatedDraftMetadataFile() public function testFixWithUpdatedDraftFile() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); $file->publishSingle(); @@ -874,6 +971,9 @@ public function testFixWithUpdatedDraftFile() public function testFixWithImageVariants() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var FlysystemAssetStore $store */ $store = Injector::inst()->get(AssetStore::class); $public = $store->getPublicFilesystem(); diff --git a/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperWithHashPathTest.php b/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperWithHashPathTest.php index 3fe3cccb..01c082b6 100644 --- a/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperWithHashPathTest.php +++ b/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperWithHashPathTest.php @@ -2,31 +2,32 @@ namespace SilverStripe\Assets\Tests\Dev\Tasks; -use InvalidArgumentException; use LogicException; -use SilverStripe\Assets\Dev\Tasks\NormaliseAccessMigrationHelper as Helper; -use Silverstripe\Assets\Dev\TestAssetStore; +use InvalidArgumentException; use SilverStripe\Assets\File; -use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper; -use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy; -use SilverStripe\Assets\FilenameParsing\FileResolutionStrategy; -use SilverStripe\Assets\FilenameParsing\HashFileIDHelper; -use SilverStripe\Assets\FilenameParsing\LegacyFileIDHelper; -use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper; -use SilverStripe\Assets\Filesystem; -use SilverStripe\Assets\Flysystem\FlysystemAssetStore; -use SilverStripe\Assets\Folder; use SilverStripe\Assets\Image; -use SilverStripe\Assets\Storage\AssetStore; -use SilverStripe\Assets\Storage\FileHashingService; -use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension; -use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; -use SilverStripe\Core\Injector\Injector; +use SilverStripe\Assets\Folder; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Assets\Filesystem; +use SilverStripe\Core\Config\Config; +use SilverStripe\Versioned\Versioned; use SilverStripe\ORM\Queries\SQLUpdate; +use SilverStripe\Core\Injector\Injector; +use Silverstripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\Storage\AssetStore; use SilverStripe\Security\InheritedPermissions; -use SilverStripe\Versioned\Versioned; +use SilverStripe\Assets\Storage\FileHashingService; +use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper; +use SilverStripe\Assets\Flysystem\FlysystemAssetStore; +use SilverStripe\Assets\FilenameParsing\HashFileIDHelper; +use SilverStripe\Assets\FilenameParsing\LegacyFileIDHelper; +use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper; +use SilverStripe\Assets\FilenameParsing\FileResolutionStrategy; +use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy; +use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension; +use SilverStripe\Assets\Dev\Tasks\NormaliseAccessMigrationHelper as Helper; /** * Ensures that File dataobjects can be safely migrated from 3.x @@ -54,6 +55,9 @@ protected function setUpAssetStore() */ public function testSanityCheck() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); @@ -89,6 +93,9 @@ public function testSanityCheck() public function testFixWithImageVariants() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var FlysystemAssetStore $store */ $store = Injector::inst()->get(AssetStore::class); $public = $store->getPublicFilesystem(); diff --git a/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperWithKeepArchivedTest.php b/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperWithKeepArchivedTest.php index d724faf7..9ae02afe 100644 --- a/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperWithKeepArchivedTest.php +++ b/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperWithKeepArchivedTest.php @@ -2,32 +2,33 @@ namespace SilverStripe\Assets\Tests\Dev\Tasks; -use InvalidArgumentException; use LogicException; -use SilverStripe\Assets\AssetControlExtension; -use SilverStripe\Assets\Dev\Tasks\NormaliseAccessMigrationHelper as Helper; -use Silverstripe\Assets\Dev\TestAssetStore; +use InvalidArgumentException; use SilverStripe\Assets\File; -use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper; -use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy; -use SilverStripe\Assets\FilenameParsing\FileResolutionStrategy; -use SilverStripe\Assets\FilenameParsing\HashFileIDHelper; -use SilverStripe\Assets\FilenameParsing\LegacyFileIDHelper; -use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper; -use SilverStripe\Assets\Filesystem; -use SilverStripe\Assets\Flysystem\FlysystemAssetStore; -use SilverStripe\Assets\Folder; use SilverStripe\Assets\Image; -use SilverStripe\Assets\Storage\AssetStore; -use SilverStripe\Assets\Storage\FileHashingService; -use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension; -use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; -use SilverStripe\Core\Injector\Injector; +use SilverStripe\Assets\Folder; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Assets\Filesystem; +use SilverStripe\Core\Config\Config; +use SilverStripe\Versioned\Versioned; use SilverStripe\ORM\Queries\SQLUpdate; +use SilverStripe\Core\Injector\Injector; +use Silverstripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\Storage\AssetStore; +use SilverStripe\Assets\AssetControlExtension; use SilverStripe\Security\InheritedPermissions; -use SilverStripe\Versioned\Versioned; +use SilverStripe\Assets\Storage\FileHashingService; +use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper; +use SilverStripe\Assets\Flysystem\FlysystemAssetStore; +use SilverStripe\Assets\FilenameParsing\HashFileIDHelper; +use SilverStripe\Assets\FilenameParsing\LegacyFileIDHelper; +use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper; +use SilverStripe\Assets\FilenameParsing\FileResolutionStrategy; +use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy; +use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension; +use SilverStripe\Assets\Dev\Tasks\NormaliseAccessMigrationHelper as Helper; /** * Ensures that File dataobjects can be safely migrated from 3.x @@ -50,6 +51,9 @@ protected function setUpAssetStore() */ public function testSanityCheck() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var File $file */ $file = $this->objFromFixture(File::class, 'file1'); diff --git a/tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php b/tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php index f74c1bf6..5e872f2e 100644 --- a/tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php @@ -2,13 +2,14 @@ namespace SilverStripe\Assets\Tests\Dev\Tasks; -use Silverstripe\Assets\Dev\TestAssetStore; use SilverStripe\Assets\File; -use SilverStripe\Assets\Filesystem; use SilverStripe\Assets\Folder; -use SilverStripe\Assets\Dev\Tasks\SecureAssetsMigrationHelper; -use SilverStripe\Assets\Storage\AssetStore; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Assets\Filesystem; +use Silverstripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\Storage\AssetStore; +use SilverStripe\Assets\Dev\Tasks\SecureAssetsMigrationHelper; class SecureAssetsMigrationHelperTest extends SapphireTest { @@ -64,6 +65,9 @@ protected function tearDown(): void */ public function testMigrate($fixture, $htaccess, $expected) { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $helper = new SecureAssetsMigrationHelper(); /** @var TestAssetStore $store */ @@ -125,6 +129,9 @@ public function dataMigrate() public function testHtaccessMatchesExact() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $htaccess = <<markTestSkipped('Test calls deprecated code'); + } $htaccess = <<markTestSkipped('Test calls deprecated code'); + } $htaccess = <<markTestSkipped('Test calls deprecated code'); + } $htaccess = <<markTestSkipped('Test calls deprecated code'); + } $tagsToShortcodeHelper = new TagsToShortcodeHelper(); $tagsToShortcodeHelper->run(); @@ -105,6 +109,9 @@ public function testRewrite() public function testPublishedFileRewrite() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $document = $this->objFromFixture(File::class, 'document'); $image = $this->objFromFixture(Image::class, 'image1'); @@ -116,6 +123,9 @@ public function testPublishedFileRewrite() public function testLivePageRewrite() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var PseudoPage $newPage */ $newPage = $this->objFromFixture(PseudoPage::class, 'page1'); $newPage->publishSingle(); @@ -158,6 +168,9 @@ public function testLivePageRewrite() public function testRewriteRegularObject() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $tagsToShortcodeHelper = new TagsToShortcodeHelper(); $tagsToShortcodeHelper->run(); @@ -183,6 +196,9 @@ public function testRewriteRegularObject() public function testRewriteSubclassObject() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $tagsToShortcodeHelper = new TagsToShortcodeHelper(); $tagsToShortcodeHelper->run(); @@ -209,6 +225,9 @@ public function testRewriteSubclassObject() public function testStagelessVersionedObject() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } // This is just here to make sure that the logic for converting live content doesn't fall on its face when // encountering a versioned object that does not support stages. @@ -235,6 +254,9 @@ public function testStagelessVersionedObject() */ public function testNewContent($input, $output = false) { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $tagsToShortcodeHelper = new TagsToShortcodeHelper(); $actual = $tagsToShortcodeHelper->getNewContent($input); $this->assertEquals($output ?: $input, $actual); @@ -484,6 +506,9 @@ public function newContentEasyFixDataProvider() */ public function testAmbigiousCleanedName() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $underscoreFile = 3; $trippleUnderscore = 4; diff --git a/tests/php/FileTest.php b/tests/php/FileTest.php index 294635a2..8ca4fe1b 100644 --- a/tests/php/FileTest.php +++ b/tests/php/FileTest.php @@ -3,26 +3,27 @@ namespace SilverStripe\Assets\Tests; use Generator; -use League\Flysystem\Filesystem; -use PHPUnit\Framework\MockObject\MockObject; -use SilverStripe\Assets\AssetControlExtension; -use Silverstripe\Assets\Dev\TestAssetStore; use SilverStripe\Assets\File; -use SilverStripe\Assets\Flysystem\FlysystemAssetStore; -use SilverStripe\Assets\Folder; use SilverStripe\Assets\Image; -use SilverStripe\Assets\Storage\AssetStore; -use SilverStripe\Assets\Tests\FileTest\MyCustomFile; +use SilverStripe\Assets\Folder; +use League\Flysystem\Filesystem; +use SilverStripe\ORM\DataObject; +use SilverStripe\Dev\Deprecation; +use SilverStripe\Security\Member; use SilverStripe\Control\Director; -use SilverStripe\Core\Config\Config; -use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Core\Config\Config; use SilverStripe\ErrorPage\ErrorPage; -use SilverStripe\ORM\DataObject; +use SilverStripe\Versioned\Versioned; +use SilverStripe\Core\Injector\Injector; use SilverStripe\ORM\ValidationException; -use SilverStripe\Security\Member; +use Silverstripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\Storage\AssetStore; +use PHPUnit\Framework\MockObject\MockObject; use SilverStripe\Security\PermissionChecker; -use SilverStripe\Versioned\Versioned; +use SilverStripe\Assets\AssetControlExtension; +use SilverStripe\Assets\Tests\FileTest\MyCustomFile; +use SilverStripe\Assets\Flysystem\FlysystemAssetStore; /** * Tests for the File class @@ -763,6 +764,9 @@ public function testJoinPaths() */ public function testIni2Bytes($iniValue, $expected) { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $this->assertSame($expected, File::ini2bytes($iniValue)); } diff --git a/tests/php/FilenameParsing/LegacyFileIDHelperTest.php b/tests/php/FilenameParsing/LegacyFileIDHelperTest.php index a176423a..667db997 100644 --- a/tests/php/FilenameParsing/LegacyFileIDHelperTest.php +++ b/tests/php/FilenameParsing/LegacyFileIDHelperTest.php @@ -1,11 +1,19 @@ markTestSkipped('Test calls deprecated code'); + } + parent::setUp(); + } protected function getHelper() { diff --git a/tests/php/FilenameParsing/MigrationLegacyFileIDHelperTest.php b/tests/php/FilenameParsing/MigrationLegacyFileIDHelperTest.php index f279f594..34d79e15 100644 --- a/tests/php/FilenameParsing/MigrationLegacyFileIDHelperTest.php +++ b/tests/php/FilenameParsing/MigrationLegacyFileIDHelperTest.php @@ -1,11 +1,19 @@ markTestSkipped('Test calls deprecated code'); + } + parent::setUp(); + } protected function getHelper() { diff --git a/tests/php/RedirectKeepArchiveFileControllerTest.php b/tests/php/RedirectKeepArchiveFileControllerTest.php index 9562e4eb..3321ace1 100644 --- a/tests/php/RedirectKeepArchiveFileControllerTest.php +++ b/tests/php/RedirectKeepArchiveFileControllerTest.php @@ -11,7 +11,6 @@ use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Control\HTTPResponse; -use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore; /** * We rerun all the same test in `RedirectFileControllerTest` but with keep_archived_assets on diff --git a/tests/php/Shortcodes/FileShortcodeProviderTest.php b/tests/php/Shortcodes/FileShortcodeProviderTest.php index 05b0ff9e..90c79c5e 100644 --- a/tests/php/Shortcodes/FileShortcodeProviderTest.php +++ b/tests/php/Shortcodes/FileShortcodeProviderTest.php @@ -44,7 +44,7 @@ protected function setUp(): void // Conditional fixture creation in case the 'cms' and 'errorpage' modules are installed if (class_exists(ErrorPage::class)) { - Config::inst()->update(SiteTree::class, 'create_default_pages', true); + Config::inst()->set(SiteTree::class, 'create_default_pages', true); ErrorPage::singleton()->requireDefaultRecords(); } } diff --git a/tests/php/Storage/AssetStoreTest.php b/tests/php/Storage/AssetStoreTest.php index ca36f9da..78869b26 100644 --- a/tests/php/Storage/AssetStoreTest.php +++ b/tests/php/Storage/AssetStoreTest.php @@ -4,19 +4,20 @@ use Exception; use InvalidArgumentException; +use SilverStripe\Assets\File; use League\Flysystem\Filesystem; +use SilverStripe\Dev\Deprecation; +use SilverStripe\Dev\SapphireTest; +use SilverStripe\Core\Config\Config; +use SilverStripe\Core\Injector\Injector; use Silverstripe\Assets\Dev\TestAssetStore; -use SilverStripe\Assets\File; +use SilverStripe\Assets\Storage\AssetStore; use SilverStripe\Assets\FilenameParsing\FileIDHelper; +use SilverStripe\Assets\FilenameParsing\ParsedFileID; +use SilverStripe\Assets\Flysystem\FlysystemAssetStore; use SilverStripe\Assets\FilenameParsing\HashFileIDHelper; use SilverStripe\Assets\FilenameParsing\LegacyFileIDHelper; use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper; -use SilverStripe\Assets\FilenameParsing\ParsedFileID; -use SilverStripe\Assets\Flysystem\FlysystemAssetStore; -use SilverStripe\Assets\Storage\AssetStore; -use SilverStripe\Core\Config\Config; -use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\SapphireTest; class AssetStoreTest extends SapphireTest { @@ -237,6 +238,9 @@ public function testConflictResolution() */ public function testGetOriginalFilename() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $store = new TestAssetStore(); $this->assertEquals( 'directory/lovely-fish.jpg', @@ -395,6 +399,9 @@ public function testGetFileID($fileID, $tuple) */ public function testParseFileID($fileID, $tuple) { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $store = new TestAssetStore(); $result = $store->parseFileID($fileID); if (is_null($tuple)) { @@ -441,6 +448,9 @@ public function testGetMetadata() */ public function testLegacyFilenames() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } Config::modify()->set(FlysystemAssetStore::class, 'legacy_filenames', true); $backend = $this->getBackend(); @@ -555,10 +565,19 @@ public function testDefaultConflictResolution() { $store = $this->getBackend(); - // Disable legacy filenames - Config::modify()->set(FlysystemAssetStore::class, 'legacy_filenames', false); $this->assertEquals(AssetStore::CONFLICT_OVERWRITE, $store->getDefaultConflictResolution(null)); $this->assertEquals(AssetStore::CONFLICT_OVERWRITE, $store->getDefaultConflictResolution('somevariant')); + } + + /** + * Test default conflict resolution for legacy filenames + */ + public function testDefaultConflictResolutionLegacy() + { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } + $store = $this->getBackend(); // Enable legacy filenames -- legacy filename used to have different conflict resolution prior to 1.4.0 Config::modify()->set(FlysystemAssetStore::class, 'legacy_filenames', true); @@ -775,6 +794,9 @@ public function testStoreLocationWritingLogic() public function testGetFilesystemFor() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $store = $this->getBackend(); $publicFs = $store->getPublicFilesystem(); @@ -899,6 +921,98 @@ public function listOfFilesToNormalise() $public = AssetStore::VISIBILITY_PUBLIC; $protected = AssetStore::VISIBILITY_PROTECTED; + /** @var FileIDHelper $hashHelper */ + $hashHelper = new HashFileIDHelper(); + $naturalHelper = new NaturalFileIDHelper(); + + $content = "The quick brown fox jumps over the lazy dog."; + $hash = sha1($content ?? ''); + $filename = 'folder/file.txt'; + $hashPath = $hashHelper->buildFileID($filename, $hash); + + $variant = 'uppercase'; + $vContent = strtoupper($content ?? ''); + $vNatural = $naturalHelper->buildFileID($filename, $hash, $variant); + $vHash = $hashHelper->buildFileID($filename, $hash, $variant); + + return [ + // Main file only + [$public, [$filename => $content], $filename, $hash, [$filename], [$hashPath, dirname($hashPath ?? '')]], + [$public, [$hashPath => $content], $filename, $hash, [$filename], [$hashPath, dirname($hashPath ?? '')]], + [$protected, [$filename => $content], $filename, $hash, [$hashPath], [$filename]], + [$protected, [$hashPath => $content], $filename, $hash, [$hashPath], [$filename]], + + // Main File with variant + [ + $public, + [$filename => $content, $vNatural => $vContent], + $filename, + $hash, + [$filename, $vNatural], + [$hashPath, $vHash, dirname($hashPath ?? '')] + ], + [ + $public, + [$hashPath => $content, $vHash => $vContent], + $filename, + $hash, + [$filename, $vNatural], + [$hashPath, $vHash, dirname($hashPath ?? '')] + ], + [ + $protected, + [$filename => $content, $vNatural => $vContent], + $filename, + $hash, + [$hashPath, $vHash], + [$filename, $vNatural] + ], + [ + $protected, + [$hashPath => $content, $vHash => $vContent], + $filename, + $hash, + [$hashPath, $vHash], + [$filename, $vNatural] + ], + ]; + } + + /** + * @dataProvider listOfFilesToNormalise + * @param string $fsName + * @param array $contents + * @param string $filename + * @param string $hash + * @param array $expected + * @param array $notExpected + */ + public function testNormalise($fsName, array $contents, $filename, $hash, array $expected, array $notExpected = []) + { + $this->writeDummyFiles($fsName, $contents); + + $results = $this->getBackend()->normalise($filename, $hash); + + $this->assertEquals($filename, $results['Filename']); + $this->assertEquals($hash, $results['Hash']); + + $fs = $this->getFilesystem($fsName); + + foreach ($expected as $expectedFile) { + $this->assertTrue($fs->has($expectedFile), "$expectedFile should exists"); + $this->assertNotEmpty($fs->read($expectedFile), "$expectedFile should be non empty"); + } + + foreach ($notExpected as $notExpectedFile) { + $this->assertFalse($fs->has($notExpectedFile), "$notExpectedFile should NOT exists"); + } + } + + public function listOfFilesToNormaliseWithLegacy() + { + $public = AssetStore::VISIBILITY_PUBLIC; + $protected = AssetStore::VISIBILITY_PROTECTED; + /** @var FileIDHelper $hashHelper */ $hashHelper = new HashFileIDHelper(); $naturalHelper = new NaturalFileIDHelper(); @@ -970,7 +1084,7 @@ public function listOfFilesToNormalise() } /** - * @dataProvider listOfFilesToNormalise + * @dataProvider listOfFilesToNormaliseWithLegacy * @param string $fsName * @param array $contents * @param string $filename @@ -978,8 +1092,14 @@ public function listOfFilesToNormalise() * @param array $expected * @param array $notExpected */ - public function testNormalise($fsName, array $contents, $filename, $hash, array $expected, array $notExpected = []) + public function testNormaliseWithLegacy($fsName, array $contents, $filename, $hash, array $expected, array $notExpected = []) { + // This is a duplicate of testNormalise that a dataprovider + // with the deprecated class LegacyFileIDHelper + // Delete the dataprovider at the same time as deleting this test + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $this->writeDummyFiles($fsName, $contents); $results = $this->getBackend()->normalise($filename, $hash); @@ -1004,6 +1124,135 @@ public function listOfFileIDsToNormalise() $public = AssetStore::VISIBILITY_PUBLIC; $protected = AssetStore::VISIBILITY_PROTECTED; + /** @var FileIDHelper $hashHelper */ + $hashHelper = new HashFileIDHelper(); + $naturalHelper = new NaturalFileIDHelper(); + + $content = "The quick brown fox jumps over the lazy dog."; + $hash = sha1($content ?? ''); + $filename = 'folder/file.txt'; + $hashPath = $hashHelper->buildFileID($filename, $hash); + + $variant = 'uppercase'; + $vContent = strtoupper($content ?? ''); + $vNatural = $naturalHelper->buildFileID($filename, $hash, $variant); + $vHash = $hashHelper->buildFileID($filename, $hash, $variant); + + return [ + // Main file only + [$public, [$filename => $content], $filename, [$filename], [$hashPath, dirname($hashPath ?? '')]], + [$public, [$hashPath => $content], $hashPath, [$filename], [$hashPath, dirname($hashPath ?? '')]], + [$protected, [$filename => $content], $filename, [$hashPath], [$filename]], + [$protected, [$hashPath => $content], $hashPath, [$hashPath], [$filename]], + + // Main File with variant + [ + $public, + [$filename => $content, $vNatural => $vContent], + $filename, + [$filename, $vNatural], + [$hashPath, $vHash, dirname($hashPath ?? '')] + ], + [ + $public, + [$hashPath => $content, $vHash => $vContent], + $hashPath, + [$filename, $vNatural], + [$hashPath, $vHash, dirname($hashPath ?? '')] + ], + [ + $protected, + [$filename => $content, $vNatural => $vContent], + $filename, + [$hashPath, $vHash], + [$filename, $vNatural] + ], + [ + $protected, + [$hashPath => $content, $vHash => $vContent], + $hashPath, + [$hashPath, $vHash], + [$filename, $vNatural] + ], + + // Test files with a parent folder that could be confused for an hash folder + 'natural path in public store with 10-char folder' => [ + $public, + ['multimedia/video.mp4' => $content], + 'multimedia/video.mp4', + ['multimedia/video.mp4'], + [], + 'multimedia/video.mp4' + ], + 'natural path in protected store with 10-char folder' => [ + $protected, + ['multimedia/video.mp4' => $content], + 'multimedia/video.mp4', + [$hashHelper->buildFileID('multimedia/video.mp4', $hash)], + [], + 'multimedia/video.mp4' + ], + 'natural path in public store with 10-hexadecimal-char folder' => [ + $public, + ['0123456789/video.mp4' => $content], + '0123456789/video.mp4', + ['0123456789/video.mp4'], + [], + '0123456789/video.mp4' + ], + 'natural path in protected store with 10-hexadecimal-char folder' => [ + $protected, + ['abcdef7890/video.mp4' => $content], + 'abcdef7890/video.mp4', + [$hashHelper->buildFileID('abcdef7890/video.mp4', $hash)], + [], + 'abcdef7890/video.mp4' + ], + ]; + } + + /** + * @dataProvider listOfFileIDsToNormalise + * @param string $fsName + * @param array $contents + * @param string $fileID + * @param array $expected + * @param array $notExpected + */ + public function testNormalisePath( + $fsName, + array $contents, + $fileID, + array $expected, + array $notExpected = [], + $expectedFilename = 'folder/file.txt' + ) { + $this->writeDummyFiles($fsName, $contents); + + $results = $this->getBackend()->normalisePath($fileID); + + $this->assertEquals($expectedFilename, $results['Filename']); + $this->assertTrue( + strpos(sha1("The quick brown fox jumps over the lazy dog."), $results['Hash'] ?? '') === 0 + ); + + $fs = $this->getFilesystem($fsName); + + foreach ($expected as $expectedFile) { + $this->assertTrue($fs->has($expectedFile), "$expectedFile should exists"); + $this->assertNotEmpty($fs->read($expectedFile), "$expectedFile should be non empty"); + } + + foreach ($notExpected as $notExpectedFile) { + $this->assertFalse($fs->has($notExpectedFile), "$notExpectedFile should NOT exists"); + } + } + + public function listOfFileIDsToNormaliseWithLegacy() + { + $public = AssetStore::VISIBILITY_PUBLIC; + $protected = AssetStore::VISIBILITY_PROTECTED; + /** @var FileIDHelper $hashHelper */ $hashHelper = new HashFileIDHelper(); $naturalHelper = new NaturalFileIDHelper(); @@ -1104,14 +1353,14 @@ public function listOfFileIDsToNormalise() } /** - * @dataProvider listOfFileIDsToNormalise + * @dataProvider listOfFileIDsToNormaliseWithLegacy * @param string $fsName * @param array $contents * @param string $fileID * @param array $expected * @param array $notExpected */ - public function testNormalisePath( + public function testNormalisePathWithLegacy( $fsName, array $contents, $fileID, @@ -1119,6 +1368,12 @@ public function testNormalisePath( array $notExpected = [], $expectedFilename = 'folder/file.txt' ) { + // This is a duplicate of testNormalise that a dataprovider + // with the deprecated class LegacyFileIDHelper + // Delete the dataprovider at the same time as deleting this test + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $this->writeDummyFiles($fsName, $contents); $results = $this->getBackend()->normalisePath($fileID); diff --git a/tests/php/Storage/DBFileTest.php b/tests/php/Storage/DBFileTest.php index f382badd..c23137cd 100644 --- a/tests/php/Storage/DBFileTest.php +++ b/tests/php/Storage/DBFileTest.php @@ -27,7 +27,7 @@ protected function setUp(): void // Set backend TestAssetStore::activate('DBFileTest'); - Director::config()->update('alternate_base_url', '/mysite/'); + Director::config()->set('alternate_base_url', '/mysite/'); } protected function tearDown(): void diff --git a/tests/php/VersionedFilesMigratorTest.php b/tests/php/VersionedFilesMigratorTest.php index 794f4050..a6041a18 100644 --- a/tests/php/VersionedFilesMigratorTest.php +++ b/tests/php/VersionedFilesMigratorTest.php @@ -2,19 +2,20 @@ namespace SilverStripe\Assets\Tests; -use SilverStripe\Assets\Dev\Tasks\VersionedFilesMigrationTask; -use Silverstripe\Assets\Dev\TestAssetStore; -use SilverStripe\Assets\Dev\VersionedFilesMigrator; +use SilverStripe\Core\Path; use SilverStripe\Assets\File; -use SilverStripe\Assets\FileMigrationHelper; +use SilverStripe\Assets\Folder; +use SilverStripe\Dev\Deprecation; +use SilverStripe\Dev\SapphireTest; use SilverStripe\Assets\Filesystem; +use SilverStripe\Core\Config\Config; +use SilverStripe\Control\HTTPRequest; +use Silverstripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\FileMigrationHelper; +use SilverStripe\Assets\Dev\VersionedFilesMigrator; use SilverStripe\Assets\Flysystem\FlysystemAssetStore; -use SilverStripe\Assets\Folder; +use SilverStripe\Assets\Dev\Tasks\VersionedFilesMigrationTask; use SilverStripe\Assets\Tests\FileMigrationHelperTest\Extension; -use SilverStripe\Control\HTTPRequest; -use SilverStripe\Core\Config\Config; -use SilverStripe\Core\Path; -use SilverStripe\Dev\SapphireTest; class VersionedFilesMigratorTest extends SapphireTest { @@ -57,6 +58,9 @@ protected function tearDown(): void */ public function testMigrationDeletes() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $migrator = VersionedFilesMigrator::create( VersionedFilesMigrator::STRATEGY_DELETE, TestAssetStore::base_path(), @@ -75,6 +79,9 @@ public function testMigrationDeletes() */ public function testMigrationProtects() { + if (Deprecation::get_is_enabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $migrator = VersionedFilesMigrator::create( VersionedFilesMigrator::STRATEGY_PROTECT, TestAssetStore::base_path(),