PanelsEverywhereTest.php in Panels Everywhere 8.4
File
tests/src/Functional/PanelsEverywhereTest.php
View source
<?php
namespace Drupal\Tests\panels_everywhere\Functional;
use Drupal\page_manager\Entity\PageVariant;
use Drupal\Tests\BrowserTestBase;
class PanelsEverywhereTest extends PanelsEverywhereBrowserTestBase {
public function testFrontPage() {
$siteTemplate = $this
->loadSiteTemplate();
$this
->assertEquals(FALSE, $siteTemplate
->status(), 'Expect the site_template to be disabled by default');
$this
->checkFrontPageWorks();
}
public function testOtherPages() {
$this
->drupalGet('/some/page/that/should/not/exist');
$this
->assertSession()
->statusCodeEquals(404);
$this
->drupalGet('/user/login');
$this
->assertSession()
->statusCodeEquals(200);
$this
->loadSiteTemplate()
->setStatus(TRUE)
->save();
drupal_flush_all_caches();
$this
->drupalGet('/some/page/that/should/not/exist');
$this
->assertSession()
->statusCodeEquals(404);
$this
->drupalGet('/user/login');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testSiteTemplate() {
$pageText = 'No front page content has been created yet.';
$siteTemplate = $this
->loadSiteTemplate();
$this
->assertEquals(FALSE, $siteTemplate
->status(), 'Expect the site_template to be disabled by default');
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextContains($pageText);
$this
->enableSiteTemplate();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextNotContains($pageText);
$this
->loadSiteTemplate()
->setStatus(FALSE)
->save();
drupal_flush_all_caches();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextContains($pageText);
}
public function testBlockPlacement() {
$this
->enableSiteTemplate();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextNotContains('Powered by');
$siteTemplate = $this
->loadSiteTemplate();
$defaultVariant = $siteTemplate
->getVariant('panels_everywhere');
$this
->placeBlockOnVariant($defaultVariant, 'system_powered_by_block', 'content');
$defaultVariant
->save();
drupal_flush_all_caches();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextContains('Powered by');
$this
->assertSession()
->pageTextNotContains('No front page content has been created yet.');
$siteTemplate = $this
->loadSiteTemplate();
$defaultVariant = $siteTemplate
->getVariant('panels_everywhere');
$this
->placeBlockOnVariant($defaultVariant, 'system_main_block', 'content');
$defaultVariant
->save();
drupal_flush_all_caches();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextContains('No front page content has been created yet.');
}
public function testMixingRegularAndPanelsEverywherePages() {
$this
->enableSiteTemplate();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextNotContains('No front page content has been created yet.');
$siteTemplate = $this
->loadSiteTemplate();
$defaultVariant = $siteTemplate
->getVariant('panels_everywhere');
$this
->addPathCondition($defaultVariant, '<front>', TRUE);
$defaultVariant
->save();
drupal_flush_all_caches();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextContains('No front page content has been created yet.');
$this
->drupalGet('/user/login');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains('Create new account');
}
public function testCustomVariants() {
$this
->enableSiteTemplate();
$siteTemplate = $this
->loadSiteTemplate();
$defaultVariant = $siteTemplate
->getVariant('panels_everywhere');
$this
->addPathCondition($defaultVariant, '<front>', TRUE);
$defaultVariant
->save();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextContains('No front page content has been created yet.');
$customVariant = $this->pageVariantStorage
->create([
'id' => 'this-is-a-custom-variant',
'variant' => 'panels_everywhere_variant',
'variant_settings' => [
'id' => 'panels_everywhere_variant',
'layout' => 'layout_onecol',
'builder' => 'standard',
],
]);
$customVariant
->setPageEntity($siteTemplate);
$customVariant
->save();
$this
->addPathCondition($customVariant, '<front>');
drupal_flush_all_caches();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextNotContains('No front page content has been created yet.');
$this->pageVariantStorage
->delete([
$customVariant,
]);
drupal_flush_all_caches();
$this
->checkFrontPageWorks();
$this
->assertSession()
->pageTextContains('No front page content has been created yet.');
}
public function testCallingSiteTemplateConfigurationPath() {
$this
->enableSiteTemplate();
$siteTemplate = $this
->loadSiteTemplate();
$this
->drupalGet($siteTemplate
->getPath());
$this
->assertSession()
->statusCodeEquals(404);
$defaultVariant = $siteTemplate
->getVariant('panels_everywhere');
$this
->placeBlockOnVariant($defaultVariant, 'system_main_block', 'content');
$defaultVariant
->save();
drupal_flush_all_caches();
$this
->drupalGet($siteTemplate
->getPath());
$this
->assertSession()
->statusCodeEquals(404);
}
protected function loadSiteTemplate() {
$this->pageStorage
->resetCache([
'site_template',
]);
$site_template = $this->pageStorage
->load('site_template');
return $site_template;
}
protected function enableSiteTemplate() {
$this
->loadSiteTemplate()
->setStatus(TRUE)
->save();
drupal_flush_all_caches();
}
protected function checkFrontPageWorks() {
$this
->drupalGet('<front>');
$this
->assertSession()
->statusCodeEquals(200);
}
}