Skip to content

Commit

Permalink
Merge pull request #301 from creative-commoners/pulls/1.13/config
Browse files Browse the repository at this point in the history
ENH Allow File.keep_archived_assets to show files archive tab
  • Loading branch information
GuySartorelli authored Aug 8, 2023
2 parents 4a57298 + addd992 commit 546cb53
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Extensions/FileArchiveExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
51 changes: 51 additions & 0 deletions tests/Extensions/FileArchiveExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace SilverStripe\VersionedAdmin\Tests\Extensions;

use SilverStripe\Dev\SapphireTest;
use SilverStripe\Assets\AssetControlExtension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Assets\File;

class FileArchiveExtensionTest extends SapphireTest
{
/**
* @dataProvider provideIsArchiveFieldEnabled
*/
public function testIsArchiveFieldEnabled(
bool $assetControlExtension,
bool $file,
bool $expected
): void {
Config::modify()->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,
],
];
}
}

0 comments on commit 546cb53

Please sign in to comment.