Skip to content

Commit

Permalink
ENH Allow File.keep_archived_assets to show files archive tab
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 7, 2023
1 parent 4a57298 commit bcc4ffb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Extensions/FileArchiveExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ public function getArchiveField()
* The files archive is only useful if archived assets are stored
* so this checks if this option is enabled
*
* 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 boolean
*/
public function isArchiveFieldEnabled()
{
return Config::inst()->get(AssetControlExtension::class, 'keep_archived_assets');
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 bcc4ffb

Please sign in to comment.