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 02336e6 commit c88db95
Showing 1 changed file with 78 additions and 125 deletions.
203 changes: 78 additions & 125 deletions tests/php/Extension/FluentSiteTreeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
],
];
}

/**
Expand Down

0 comments on commit c88db95

Please sign in to comment.