1 layout.test LayoutInterfaceTest::testOverriddenPaths()

Test the overriding of paths.

File

core/modules/layout/tests/layout.test, line 1152
Tests for the Layout module.

Class

LayoutInterfaceTest
Tests the interface for adding, removing, and moving blocks.

Code

function testOverriddenPaths() {
  // Make a new layout that creates a custom path with placeholders.
  $layout_name = 'node';
  $layout_title = 'Generic Node';
  $layout_path = 'node/%';
  $edit = array(
    'title' => $layout_title,
    'name' => $layout_name,
    'layout_template' => 'moscone_flipped',
    'path' => $layout_path,
  );
  // Save directly without checking contexts.
  $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));

  // Add a block to the sidebar.
  $this->clickLink(t('Add block'), 3);
  $this->clickLink(t('Node title test'));
  $this->backdropPost(NULL, array(), t('Add block'));

  // Record the UUID for the newly added block.
  $last_block = $this->xpath('(//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
    ':region' => 'l-sidebar',
  ));
  //$block_uuid = (string) $last_block[0]['data-block-id'];

  // Change the title type to custom.
  $edit = array(
    'title_display' => LAYOUT_TITLE_CUSTOM,
    'title' => 'Generic node title',
  );
  $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/edit-title/editor/title', $edit, t('Save configuration'));
  $this->backdropPost('admin/structure/layouts/manage/' . $layout_name, array(), t('Save layout'));

  // Visit the sample node page and check that the block is visible.
  $this->backdropGet('node/1');
  $block_element = $this->xpath('//*[contains(@class,:region)]//*[contains(@class,:block)]', array(
    ':region' => 'l-sidebar',
    ':block' => 'block-layout-test-test-node-title',
  ));
  $this->assertEqual(count($block_element), 1, 'The block is shown on the overridden path.');
  $this->assertText($this->test_node1->body[LANGUAGE_NONE][0]['value'], 'Current page content is still shown on the overridden path.');

  // Clone the layout and make a second overriding item at the same path.
  $clone_layout_name = 'node_post';
  $edit = array(
    'name' => $clone_layout_name,
    'title' => 'Post node',
  );
  $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/clone', $edit, t('Clone layout'));
  $this->assertText('You may now configure the cloned layout.', 'Layout cloned and landed on settings page.');
  $this->backdropPost(NULL, array(), t('Add visibility condition'));
  $edit = array(
    'condition' => 'node_type',
  );
  $this->backdropPost(NULL, $edit, t('Load condition'));
  $edit = array(
    'bundles[post]' => TRUE,
  );
  $this->backdropPost(NULL, $edit, t('Add visibility condition'));
  $this->backdropPost(NULL, array(), t('Save layout'));

  // Record the UUID for the same block in this layout.
  $last_block = $this->xpath('(//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
    ':region' => 'l-sidebar',
  ));
  $block_uuid = (string) $last_block[0]['data-block-id'];

  $edit = array(
    'title_display' => LAYOUT_TITLE_BLOCK,
    'title_block' => $block_uuid,
  );
  $this->backdropPost('admin/structure/layouts/manage/' . $clone_layout_name . '/edit-title/editor/title', $edit, t('Save configuration'));
  $this->backdropPost('admin/structure/layouts/manage/' . $clone_layout_name, array(), t('Save layout'));

  $this->backdropGet('node/' . $this->test_node1->nid);
  $this->assertText('Node title', 'The node-type specific layout is used over the generic layout, and the page title is copied from the block title.');

  $this->backdropGet('node/' . $this->test_node2->nid);
  $this->assertText('Generic node title', 'The generic layout is used when there is not a more specific layout.');

  // Check the weights of the layout to ensure they have the correct defaults,
  // then rearrange and check the paths again.
  $this->backdropGet('admin/structure/layouts/reorder', array('query' => array('layouts' => array('node_post', 'node'))));
  $this->assertFieldByXPath('//select[@name="layouts[' . $clone_layout_name . '][weight]"]', '-1');
  $this->assertFieldByXPath('//select[@name="layouts[' . $layout_name . '][weight]"]', '0');

  $edit = array(
    'layouts[node_post][weight]' => 1,
  );
  $this->backdropPost(NULL, $edit, t('Save order'));

  // Now both layouts should use the generic layout.
  $this->backdropGet('node/' . $this->test_node1->nid);
  $this->assertText('Generic node title', 'The generic layout is used on post content.');
  $this->backdropGet('node/' . $this->test_node2->nid);
  $this->assertText('Generic node title', 'The generic layout is used on generic content.');

  // Delete these layouts and ensure it goes back to the default layout.
  $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/delete', array(), t('Delete layout'));
  $this->backdropPost('admin/structure/layouts/manage/' . $clone_layout_name . '/delete', array(), t('Delete layout'));

  $this->backdropGet('node/' . $this->test_node1->nid);
  $this->assertNoText('Generic node title', 'The generic node layout has been deleted.');
  $this->assertNoText('Post node title', 'The post node layout has been deleted.');
  $this->assertRaw(check_markup($this->test_node1->body[LANGUAGE_NONE][0]['value'], $this->test_node1->body[LANGUAGE_NONE][0]['format']), 'The default layout is now displaying the node.');
}