diff --git a/src/Tests/PanelsTest.php b/src/Tests/PanelsTest.php index b83ab4b..9f8c4da 100644 --- a/src/Tests/PanelsTest.php +++ b/src/Tests/PanelsTest.php @@ -7,6 +7,7 @@ namespace Drupal\panels\Tests; +use Drupal\Component\Render\FormattableMarkup; use Drupal\simpletest\WebTestBase; /** @@ -24,7 +25,7 @@ class PanelsTest extends WebTestBase { /** * {@inheritdoc} */ - public static $modules = ['block', 'page_manager', 'page_manager_ui', 'panels_test', 'layout_plugin_example']; + public static $modules = ['block', 'page_manager_ui', 'panels_test', 'layout_plugin_example', 'node']; /** * {@inheritdoc} @@ -32,6 +33,8 @@ class PanelsTest extends WebTestBase { protected function setUp() { parent::setUp(); + $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); + $this->drupalPlaceBlock('local_tasks_block'); $this->drupalPlaceBlock('local_actions_block'); $this->drupalPlaceBlock('system_branding_block'); @@ -40,7 +43,12 @@ class PanelsTest extends WebTestBase { \Drupal::service('theme_handler')->install(['bartik', 'classy']); $this->config('system.theme')->set('admin', 'classy')->save(); - $this->drupalLogin($this->drupalCreateUser(['administer pages', 'access administration pages', 'view the administration theme'])); + $this->drupalLogin($this->drupalCreateUser([ + 'administer pages', + 'access administration pages', + 'view the administration theme', + 'create article content', + ])); } /** @@ -48,33 +56,57 @@ class PanelsTest extends WebTestBase { */ public function testLayoutSettings() { // Create new page. - $this->drupalGet('admin/structure/page_manager/add'); $edit = [ 'id' => 'foo', - 'label' => 'foo', - 'path' => 'testing', + 'label' => 'Foo', + 'path' => 'foo/{node}', + 'variant_plugin_id' => 'panels_variant', + 'use_admin_theme' => TRUE, + 'description' => 'This is our first test page.', ]; - $this->drupalPostForm(NULL, $edit, 'Save'); + $this->drupalPostForm('admin/structure/page_manager/add', $edit, 'Next'); + + // Map the parameter with the Node entity. + $this->clickLink('Edit'); + $edit = [ + 'type' => 'entity:node', + ]; + $this->drupalPostForm(NULL, $edit, 'Update parameter'); + $this->assertText('The Node parameter has been updated.'); + $this->drupalPostForm(NULL, [], 'Next'); - // Add variant with a layout that has settings. - $this->clickLink('Add new variant'); - $this->clickLink('Panels'); + // Configure the variant. $edit = [ - 'id' => 'panels_1', - 'label' => 'Default', + 'variant_settings[page_title]' => 'Sample Panels page', 'variant_settings[layout]' => 'layout_example_test', ]; - $this->drupalPostForm(NULL, $edit, 'Save'); + $this->drupalPostForm(NULL, $edit, 'Next'); + + // Skip the layout step. + // @TODO We should remove this step since the layout can be selected + // at the previous step. + $this->drupalPostForm(NULL, [], 'Next'); - // Add a block. + // Place the Node entity display block within the layout. $this->clickLink('Add new block'); - $this->clickLink('Powered by Drupal'); + $this->clickLink('Entity view (Content)'); $edit = [ 'region' => 'top', ]; $this->drupalPostForm(NULL, $edit, 'Add block'); + // Finish the wizard. + $this->drupalPostForm(NULL, [], 'Finish'); + $this->assertRaw(new FormattableMarkup('Saved the %label Page.', ['%label' => 'Foo'])); + + // Test the page. + $node = $this->drupalCreateNode(['type' => 'article']); + $this->drupalGet('foo/' . $node->id()); + $this->assertResponse(200); + $this->assertText($node->getTitle()); + // Check the default value and change a layout setting. + $this->drupalGet('admin/structure/page_manager/manage/foo/page_variant__foo-panels_variant-0__general'); $this->assertText('Blah'); $this->assertFieldByName("variant_settings[layout_settings][setting_1]", "Default"); $edit = [ @@ -83,14 +115,13 @@ class PanelsTest extends WebTestBase { $this->drupalPostForm(NULL, $edit, 'Save'); // Go back to the variant edit form and see that the setting stuck. - $this->drupalGet('admin/structure/page_manager/manage/foo/variant/panels_1'); + $this->drupalGet('admin/structure/page_manager/manage/foo/page_variant__foo-panels_variant-0__general'); $this->assertFieldByName("variant_settings[layout_settings][setting_1]", "Abracadabra"); // View the page and make sure the setting is present. - $this->drupalGet('testing'); + $this->drupalGet('foo/' . $node->id()); $this->assertText('Blah:'); $this->assertText('Abracadabra'); - $this->assertText('Powered by Drupal'); } }