From c88db95791c17b1a8b8dd7df28552639f9a3e2db Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Mon, 8 Apr 2024 14:54:24 +1200 Subject: [PATCH] Fixes. --- .../Extension/FluentSiteTreeExtensionTest.php | 203 +++++++----------- 1 file changed, 78 insertions(+), 125 deletions(-) diff --git a/tests/php/Extension/FluentSiteTreeExtensionTest.php b/tests/php/Extension/FluentSiteTreeExtensionTest.php index aa0e1d97..c93634d4 100644 --- a/tests/php/Extension/FluentSiteTreeExtensionTest.php +++ b/tests/php/Extension/FluentSiteTreeExtensionTest.php @@ -10,7 +10,6 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\CompositeField; -use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; @@ -334,140 +333,94 @@ function (FluentState $newState) use ($localeCode, $fixture, $expected) { ); } - public function testHomeVisibleOnFrontendBothConfigAny() - { - Config::modify()->set(DataObject::class, 'cms_localisation_required', FluentExtension::INHERITANCE_MODE_ANY); - Config::modify()->set(DataObject::class, 'frontend_publish_required', FluentExtension::INHERITANCE_MODE_ANY); - - FluentState::singleton()->withState(function (FluentState $newState) { - $newState - ->setLocale('de_DE') - ->setIsDomainMode(false) - ->setIsFrontend(true); - - $page = Page::get()->filter('URLSegment', 'home')->first(); - - $this->assertNotNull($page); - }); - } - - public function testHomeVisibleOnFrontendOneConfigAny() - { - Config::modify()->set(DataObject::class, 'cms_localisation_required', FluentExtension::INHERITANCE_MODE_EXACT); - Config::modify()->set(DataObject::class, 'frontend_publish_required', FluentExtension::INHERITANCE_MODE_ANY); - - FluentState::singleton()->withState(function (FluentState $newState) { - $newState - ->setLocale('de_DE') - ->setIsDomainMode(false) - ->setIsFrontend(true); - - $page = Page::get()->filter('URLSegment', 'home')->first(); - - $this->assertNotNull($page); - }); - } - - public function testHomeNotVisibleOnFrontendBothConfigExact() - { - Config::modify()->set(DataObject::class, 'cms_localisation_required', FluentExtension::INHERITANCE_MODE_EXACT); - Config::modify()->set(DataObject::class, 'frontend_publish_required', FluentExtension::INHERITANCE_MODE_EXACT); - - FluentState::singleton()->withState(function (FluentState $newState) { - $newState - ->setLocale('de_DE') - ->setIsDomainMode(false) - ->setIsFrontend(true); - - $page = Page::get()->filter('URLSegment', 'home')->first(); - - $this->assertNull($page); - }); - } - - public function testHomeNotVisibleOnFrontendOneConfigExact() - { - Config::modify()->set(DataObject::class, 'cms_localisation_required', FluentExtension::INHERITANCE_MODE_ANY); - Config::modify()->set(DataObject::class, 'frontend_publish_required', FluentExtension::INHERITANCE_MODE_EXACT); - - FluentState::singleton()->withState(function (FluentState $newState) { - $newState - ->setLocale('de_DE') - ->setIsDomainMode(false) - ->setIsFrontend(true); - - $page = Page::get()->filter('URLSegment', 'home')->first(); - - $this->assertNull($page); - }); - } - - public function testHomeVisibleInCMSBothConfigAny() - { - Config::modify()->set(DataObject::class, 'cms_localisation_required', FluentExtension::INHERITANCE_MODE_ANY); - Config::modify()->set(DataObject::class, 'frontend_publish_required', FluentExtension::INHERITANCE_MODE_ANY); - - FluentState::singleton()->withState(function (FluentState $newState) { - $newState - ->setLocale('de_DE') - ->setIsDomainMode(false) - ->setIsFrontend(false); - - $page = Page::get()->filter('URLSegment', 'home')->first(); - - $this->assertNotNull($page); - }); - } - - public function testHomeVisibleInCMSOneConfigAny() - { - Config::modify()->set(DataObject::class, 'cms_localisation_required', FluentExtension::INHERITANCE_MODE_ANY); - Config::modify()->set(DataObject::class, 'frontend_publish_required', FluentExtension::INHERITANCE_MODE_EXACT); - - FluentState::singleton()->withState(function (FluentState $newState) { - $newState + /** + * @param string $cmsInheritanceMode + * @param string $frontendInheritanceMode + * @param bool $frontendContext + * @param bool $expected + * @return void + * @dataProvider localeInheritanceModeCasesProvider + */ + public function testLocaleInheritanceMode( + string $cmsInheritanceMode, + string $frontendInheritanceMode, + bool $frontendContext, + bool $expected + ): void { + Page::config() + ->set('cms_localisation_required', $cmsInheritanceMode) + ->set('frontend_publish_required', $frontendInheritanceMode); + + FluentState::singleton()->withState(function (FluentState $state) use ($frontendContext, $expected) { + $state ->setLocale('de_DE') ->setIsDomainMode(false) - ->setIsFrontend(false); + ->setIsFrontend($frontendContext); - $page = Page::get()->filter('URLSegment', 'home')->first(); + $page = Page::get()->find('URLSegment', 'home'); - $this->assertNotNull($page); - }); - } + if ($expected) { + $this->assertNotNull($page, 'We expect the page model to have content available'); - public function testHomeNotVisibleInCMSBothConfigExact() - { - Config::modify()->set(DataObject::class, 'cms_localisation_required', FluentExtension::INHERITANCE_MODE_EXACT); - Config::modify()->set(DataObject::class, 'frontend_publish_required', FluentExtension::INHERITANCE_MODE_EXACT); - - FluentState::singleton()->withState(function (FluentState $newState) { - $newState - ->setLocale('de_DE') - ->setIsDomainMode(false) - ->setIsFrontend(false); - - $page = Page::get()->filter('URLSegment', 'home')->first(); + return; + } - $this->assertNull($page); + $this->assertNull($page, 'We expect the page model to not have any content available'); }); } - public function testHomeNotVisibleInCMSOneConfigExact() + public function localeInheritanceModeCasesProvider(): array { - Config::modify()->set(DataObject::class, 'cms_localisation_required', FluentExtension::INHERITANCE_MODE_EXACT); - Config::modify()->set(DataObject::class, 'frontend_publish_required', FluentExtension::INHERITANCE_MODE_ANY); - - FluentState::singleton()->withState(function (FluentState $newState) { - $newState - ->setLocale('de_DE') - ->setIsDomainMode(false) - ->setIsFrontend(false); - - $page = Page::get()->filter('URLSegment', 'home')->first(); - - $this->assertNull($page); - }); + return [ + 'cms with any mode, frontend with any mode, frontend context' => [ + FluentExtension::INHERITANCE_MODE_ANY, + FluentExtension::INHERITANCE_MODE_ANY, + true, + true, + ], + 'cms with exact mode, frontend with any mode, frontend context' => [ + FluentExtension::INHERITANCE_MODE_EXACT, + FluentExtension::INHERITANCE_MODE_ANY, + true, + true, + ], + 'cms with exact mode, frontend with exact mode, frontend context' => [ + FluentExtension::INHERITANCE_MODE_EXACT, + FluentExtension::INHERITANCE_MODE_EXACT, + true, + false, + ], + 'cms with any mode, frontend with exact mode, frontend context' => [ + FluentExtension::INHERITANCE_MODE_ANY, + FluentExtension::INHERITANCE_MODE_EXACT, + true, + false, + ], + 'cms with any mode, frontend with any mode, cms context' => [ + FluentExtension::INHERITANCE_MODE_ANY, + FluentExtension::INHERITANCE_MODE_ANY, + false, + true, + ], + 'cms with any mode, frontend with exact mode, cms context' => [ + FluentExtension::INHERITANCE_MODE_ANY, + FluentExtension::INHERITANCE_MODE_EXACT, + false, + true, + ], + 'cms with exact mode, frontend with exact mode, cms context' => [ + FluentExtension::INHERITANCE_MODE_EXACT, + FluentExtension::INHERITANCE_MODE_EXACT, + false, + false, + ], + 'cms with exact mode, frontend with any mode, cms context' => [ + FluentExtension::INHERITANCE_MODE_EXACT, + FluentExtension::INHERITANCE_MODE_ANY, + false, + false, + ], + ]; } /**