Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Apr 8, 2024
1 parent c88db95 commit 0576ad2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/Extension/FluentFilteredExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class FluentFilteredExtension extends DataExtension
*/
const SUFFIX = 'FilteredLocales';

/**
* Allow the filtered locale behaviour to be skipped for draft stage only
*
* @var bool
* @config
*/
private static bool $apply_filtered_locales_to_stage = false;

private static $many_many = [
'FilteredLocales' => Locale::class,
];
Expand Down
20 changes: 9 additions & 11 deletions tests/php/Extension/FluentFilteredExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use Page;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use TractorCow\Fluent\Extension\FluentFilteredExtension;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
Expand Down Expand Up @@ -44,14 +42,14 @@ protected function setUp(): void
public function testAugmentSQLFrontend()
{
// Specifically set this config value so that filtered locales ARE required in stage=Stage.
Config::modify()->set(DataObject::class, 'apply_filtered_locales_to_stage', true);
SiteTree::config()->set('apply_filtered_locales_to_stage', true);

$currentStage = Versioned::get_stage();

Versioned::set_stage(Versioned::DRAFT);

FluentState::singleton()->withState(function (FluentState $newState) {
$newState
FluentState::singleton()->withState(function (FluentState $state) {
$state
->setLocale('en_NZ')
->setIsFrontend(true)
->setIsDomainMode(false);
Expand All @@ -72,14 +70,14 @@ public function testAugmentSQLFrontend()
public function testAugmentSQLFrontendLive()
{
// Specifically set this config value so that filtered locales ARE required in stage=Stage.
Config::modify()->set(DataObject::class, 'apply_filtered_locales_to_stage', true);
SiteTree::config()->set('apply_filtered_locales_to_stage', true);

$currentStage = Versioned::get_stage();

Versioned::set_stage(Versioned::LIVE);

FluentState::singleton()->withState(function (FluentState $newState) {
$newState
FluentState::singleton()->withState(function (FluentState $state) {
$state
->setLocale('en_NZ')
->setIsFrontend(true);

Expand All @@ -99,15 +97,15 @@ public function testAugmentSQLFrontendLive()
public function testAugmentSQLStage()
{
// Specifically set this config value so that filtered locales are NOT required in stage=Stage.
Config::modify()->set(DataObject::class, 'apply_filtered_locales_to_stage', false);
SiteTree::config()->set('apply_filtered_locales_to_stage', false);

$currentStage = Versioned::get_stage();

Versioned::set_stage(Versioned::DRAFT);

// Run test
FluentState::singleton()->withState(function (FluentState $newState) {
$newState
FluentState::singleton()->withState(function (FluentState $state) {
$state
->setLocale('en_NZ')
->setIsFrontend(true);

Expand Down
15 changes: 9 additions & 6 deletions tests/php/Extension/FluentSiteTreeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Versioned\Versioned;
use TractorCow\Fluent\Extension\FluentDirectorExtension;
Expand Down Expand Up @@ -443,11 +442,15 @@ public function localePrefixUrlProvider()
* @throws ValidationException
* @dataProvider localeFallbackProvider
*/
public function testPageVisibilityWithFallback($cmsMode, $frontendMode, bool $isFrontend, int $expected)
{
Config::modify()
->set(DataObject::class, 'cms_localisation_required', $cmsMode)
->set(DataObject::class, 'frontend_publish_required', $frontendMode);
public function testPageVisibilityWithFallback(
string|bool $cmsMode,
string|bool $frontendMode,
bool $isFrontend,
int $expected
): void {
Page::config()
->set('cms_localisation_required', $cmsMode)
->set('frontend_publish_required', $frontendMode);

$pageId = FluentState::singleton()->withState(function (FluentState $state): int {
$state
Expand Down

0 comments on commit 0576ad2

Please sign in to comment.