From addd992bc242d3b0817797920508eb1f46e16466 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 8 Aug 2023 09:54:46 +1200 Subject: [PATCH] ENH Allow File.keep_archived_assets to show files archive tab --- src/Extensions/FileArchiveExtension.php | 5 +- tests/Extensions/FileArchiveExtensionTest.php | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/Extensions/FileArchiveExtensionTest.php diff --git a/src/Extensions/FileArchiveExtension.php b/src/Extensions/FileArchiveExtension.php index 6f85a31f..8c212ec4 100644 --- a/src/Extensions/FileArchiveExtension.php +++ b/src/Extensions/FileArchiveExtension.php @@ -77,6 +77,9 @@ public function getArchiveField() */ public function isArchiveFieldEnabled() { - return Config::inst()->get(AssetControlExtension::class, 'keep_archived_assets'); + // This should really only check File.keep_archived_assets, though it was originally + // only checking AssetControlExtension.keep_archived_assets, so keeping that for BC + return Config::inst()->get(AssetControlExtension::class, 'keep_archived_assets') + || Config::inst()->get(File::class, 'keep_archived_assets'); } } diff --git a/tests/Extensions/FileArchiveExtensionTest.php b/tests/Extensions/FileArchiveExtensionTest.php new file mode 100644 index 00000000..02004895 --- /dev/null +++ b/tests/Extensions/FileArchiveExtensionTest.php @@ -0,0 +1,51 @@ +set(AssetControlExtension::class, 'keep_archived_assets', $assetControlExtension); + Config::modify()->set(File::class, 'keep_archived_assets', $file); + $actual = File::singleton()->isArchiveFieldEnabled(); + $this->assertSame($expected, $actual); + } + + public function provideIsArchiveFieldEnabled(): array + { + return [ + [ + 'assetControlExtension' => false, + 'file' => false, + 'expected' => false, + ], + [ + 'assetControlExtension' => true, + 'file' => false, + 'expected' => true, + ], + [ + 'assetControlExtension' => false, + 'file' => true, + 'expected' => true, + ], + [ + 'assetControlExtension' => true, + 'file' => true, + 'expected' => true, + ], + ]; + } +}