Esempio n. 1
0
 /**
  * Tests whether the page entity config schema is valid.
  */
 public function testValidPageConfigSchema()
 {
     $id = strtolower($this->randomMachineName());
     /** @var $page \Drupal\page_manager\PageInterface */
     $page = Page::create(['id' => $id, 'label' => $this->randomMachineName(), 'path' => '/node/{node}']);
     // Add an access condition.
     $page->addAccessCondition(['id' => 'node_type', 'bundles' => ['article' => 'article'], 'negate' => TRUE, 'context_mapping' => ['node' => 'node']]);
     // Add a block display variant.
     $display_variant_id = $page->addVariant(['id' => 'block_display', 'label' => 'Block page']);
     /** @var $display_variant \Drupal\page_manager\Plugin\DisplayVariant\BlockDisplayVariant */
     $display_variant = $page->getVariant($display_variant_id);
     // Add a selection condition.
     $display_variant->addSelectionCondition(['id' => 'node_type', 'bundles' => ['page' => 'page'], 'context_mapping' => ['node' => 'node']]);
     // Add a block.
     $display_variant->addBlock(['id' => 'entity_view:node', 'label' => 'View the node', 'provider' => 'page_manager', 'label_display' => 'visible', 'view_mode' => 'default']);
     $page->save();
     $config = \Drupal::config("page_manager.page.{$id}");
     $this->assertEqual($config->get('id'), $id);
     $this->assertConfigSchema(\Drupal::service('config.typed'), $config->getName(), $config->get());
 }
 /**
  * Tests that a node bundle condition controls the node view page.
  */
 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.
     $http_status_variant = PageVariant::create(['variant' => 'http_status_code', 'label' => 'HTTP status code', 'id' => 'http_status_code', 'page' => 'placeholder']);
     $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);
 }