Skip to content

Commit

Permalink
Merge branch '2.0' into 2
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 18, 2023
2 parents e770339 + 85831ce commit 5feb8de
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 5feb8de

Please sign in to comment.