Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Allow File.keep_archived_assets to show files archive tab #301

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
|| 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,
],
];
}
}