You are here

public function PagePlaceholderTest::testPagePlaceHolder in Page Manager 8

Tests that a node bundle condition controls the node view page.

File

src/Tests/PagePlaceholderTest.php, line 39
Contains \Drupal\page_manager\Tests\PageNodeSelectionTest.

Class

PagePlaceholderTest
Tests selecting page variants based on nodes.

Namespace

Drupal\page_manager\Tests

Code

public function testPagePlaceHolder() {

  // Access the page callback and check whether string is printed.
  $page_string = 'test-page';
  $this
    ->drupalGet('page-manager-test/' . $page_string);
  $this
    ->assertResponse(200);
  $this
    ->assertCacheTag('page_manager_route_name:page_manager_test.page_view');
  $this
    ->assertText('Hello World! Page ' . $page_string);

  // Create a new page entity with the same path as in the test module.
  $page = Page::create([
    'label' => 'Placeholder test',
    'id' => 'placeholder',
    'path' => '/page-manager-test/%',
  ]);
  $page
    ->save();

  // Create a new variant.

  /* @var $http_status_variant \Drupal\page_manager\Entity\PageVariant */
  $http_status_variant = PageVariant::create([
    'label' => 'HTTP status code',
    'id' => 'http_status_code',
    'page' => 'placeholder',
  ]);

  // Test setting variant post create works.
  $http_status_variant
    ->setVariantPluginId('http_status_code');
  $http_status_variant
    ->getVariantPlugin()
    ->setConfiguration([
    'status_code' => 200,
  ]);
  $http_status_variant
    ->save();
  $this
    ->triggerRouterRebuild();

  // Access the page callback again and check that now the text is not there.
  $this
    ->drupalGet('page-manager-test/' . $page_string);
  $this
    ->assertResponse(200);
  $this
    ->assertCacheTag('page_manager_route_name:page_manager_test.page_view');
  $this
    ->assertNoText('Hello World! Page ' . $page_string);
}