- <?php
- * @file
- * Tests for the Layout module.
- */
- require_once BACKDROP_ROOT . '/core/modules/simpletest/tests/upgrade/upgrade.test';
-
- * Tests the interface for adding, removing, and moving blocks.
- */
- class LayoutInterfaceTest extends BackdropWebTestCase {
- protected $profile = 'minimal';
- protected $admin_user;
- protected $web_user;
- protected $test_node1;
- protected $test_node2;
- protected $orphaned_blocks = FALSE;
-
- function setUp() {
- parent::setUp('layout_test');
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access user profiles',
- 'access administration pages',
- 'administer site configuration',
- 'administer modules',
- 'administer layouts',
- 'administer nodes',
- ));
- $this->backdropLogin($this->admin_user);
-
-
- $this->web_user = $this->backdropCreateUser(array(
- 'access user profiles',
- 'access content',
- 'administer nodes',
- ));
-
-
- $this->backdropCreateContentType(array('type' => 'page', 'name' => 'Page'));
- $this->backdropCreateContentType(array('type' => 'post', 'name' => 'Post'));
-
- $this->test_node1 = $this->backdropCreateNode(array(
- 'type' => 'post',
- 'title' => $this->randomString(),
- 'uid' => $this->admin_user->uid,
- ));
-
- $this->test_node2 = $this->backdropCreateNode(array(
- 'type' => 'page',
- 'title' => $this->randomString(),
- 'uid' => $this->web_user->uid,
- ));
- }
-
-
- * Test the support for contexts within conditions and blocks.
- */
- function testRelationships() {
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_path = 'node/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_path,
- );
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Check path'));
-
-
- $edit = array();
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Add relationship'));
-
- $edit = array(
- 'relationship' => 'author_from_node:relationship',
- );
- $this->backdropPost(NULL, $edit, t('Load relationship'));
- $this->backdropPost(NULL, array(), t('Add relationship'));
-
- $this->backdropPost(NULL, array(), t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->assertText(t('A testing block for layouts with contexts.'));
- $this->clickLink(t('Layout bar block'));
- $select_options = $this->xpath('//*[@id=:select]//option', array(
- ':select' => 'edit-contexts-my-user',
- ));
- $this->assertEqual(count($select_options), 2, 'Two options are found in the select list.');
- $relationship_option = (string) $select_options[0]['value'];
- $this->assertTrue(strpos($relationship_option, 'relationship') === 0, 'First select list option is the user context from the author relationship.');
-
- $edit = array(
- 'contexts[my_user]' => $relationship_option,
- );
- $this->backdropPost(NULL, $edit, t('Add 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'];
- $block_edit_url = 'admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid;
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
-
-
- $this->backdropGet('node/' . $this->test_node2->nid);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->web_user->mail, '@title' => $this->test_node2->title)));
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
-
-
-
- $edit = array(
- 'contexts[my_user]' => 'current_user',
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('node/' . $this->test_node2->nid);
- $this->assertNoText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->web_user->mail, '@title' => $this->test_node2->title)));
-
-
-
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->admin_user->mail, '@title' => $this->test_node1->title)));
-
-
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', array(), t('Remove'));
- }
-
-
- * Test that layout templates may be enabled and disabled.
- */
- function testLayoutTemplates() {
-
- $this->backdropGet('admin/structure/layouts/settings');
- $edit = array(
- 'templates[boxton]' => FALSE,
- 'templates[moscone]' => TRUE,
- 'templates[moscone_flipped]' => TRUE,
- 'templates[simmons]' => TRUE,
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
- $this->assertText(t('The "Boxton" layout template is currently in use and may not be disabled.'));
-
-
- $this->backdropGet('admin/structure/layouts/manage/default/configure');
- $this->assertText('Simmons');
-
-
- $edit = array(
- 'templates[boxton]' => TRUE,
- 'templates[moscone]' => TRUE,
- 'templates[moscone_flipped]' => TRUE,
- 'templates[simmons]' => FALSE,
- );
- $this->backdropPost('admin/structure/layouts/settings', $edit, t('Save configuration'));
- $this->assertText(t('Your configuration has been saved.'));
-
-
- $this->backdropGet('admin/structure/layouts/manage/default/configure');
- $this->assertNoText('Simmons');
-
-
- $this->assertNoText('3/3/4 columns');
-
-
- config_set('layout.settings', 'excluded_templates', array());
-
-
- $this->backdropGet('admin/structure/layouts/manage/default/configure');
- $this->assertText('3/3/4 columns');
- $this->backdropGet('admin/structure/layouts/settings');
- $this->assertText('3/3/4 columns');
-
-
- $edit = array(
- 'templates[three_three_four_column]' => FALSE,
- );
- $this->backdropPost('admin/structure/layouts/settings', $edit, t('Save configuration'));
- $this->assertNoText('3/3/4 columns');
-
-
- $this->backdropPost('admin/structure/layouts/settings', array(), t('Save configuration'));
- $this->assertNoText('3/3/4 columns');
- }
-
-
- * Test the path view page link.
- */
- function testViewPageLink() {
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
-
-
- $this->assertFieldByXPath('//input[@name="layout_template"][@checked="checked"]', TRUE, 'The Layout template default value is set.');
- $default_layout_template = config_get('layout.layout.default', 'layout_template');
- $field_id = 'edit-layout-template-' . str_replace('_', '-', $default_layout_template);
- $this->assertFieldChecked($field_id, 'The Layout template default value is the same as the default layout.');
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'a-menu-item-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- layout_reset_caches();
-
-
- $this->assertLinkByHref($layout_url, 0, 'View page link found.');
- $this->assertLink('View page', 0, 'View page link text found.');
- $this->clickLink(t('View page'));
- $this->assertResponse(200, 'View page link goes to path.');
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'node/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $this->assertNoLinkByHref($layout_url, 0, 'View page link found.');
- $this->assertNoLink('View page', 1, 'View page link text found.');
- }
-
-
- * Add and remove blocks from a custom layout path.
- */
- function testBlockBasics() {
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'layout-test-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
-
-
- $this->assertText(t('Layout created. Blocks may now be added to this layout.'));
-
-
- $this->assertNoLink(t('Main page content'));
- $this->assertNoLink(t('Layout bar block'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 5,
- );
- $this->backdropPost(NULL, $edit, t('Add 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'];
- $block_edit_url = 'admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid;
-
-
- $elements = $this->xpath('//*[contains(@id,:id)]//*[contains(@class,:class)]//span[normalize-space()=:title]', array(
- ':id' => 'layout-editor-block-' .$block_uuid,
- ':class' => 'layout-editor-block-title',
- ':title' => t('Layout foo block'),
- ));
- $this->assertEqual(count($elements), 1, 'The sample block label was found.');
- $elements = $this->xpath('//*[contains(@id,:id)]//*[contains(@class,:class)]//*[normalize-space()=:description]', array(
- ':id' => 'layout-editor-block-' .$block_uuid,
- ':class' => 'layout-editor-block-content',
- ':description' => t('A testing block for layouts.'),
- ));
- $this->assertEqual(count($elements), 1, 'The sample block description was found.');
-
-
- $block_new_label = $this->randomName();
- $block_new_description = $this->randomName();
- $edit = array(
- 'admin_label' => $block_new_label,
- 'admin_description' => $block_new_description,
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
-
-
- $elements = $this->xpath('//*[contains(@id,:id)]//*[contains(@class,:class)]//span[normalize-space()=:title]', array(
- ':id' => 'layout-editor-block-' .$block_uuid,
- ':class' => 'layout-editor-block-title',
- ':title' => $block_new_label,
- ));
- $this->assertEqual(count($elements), 1, 'The sample block label was found.');
- $elements = $this->xpath('//*[contains(@id,:id)]//*[contains(@class,:class) and contains(text(), :description)]', array(
- ':id' => 'layout-editor-block-' .$block_uuid,
- ':class' => 'layout-editor-block-content',
- ':description' => $block_new_description,
- ));
- $this->assertEqual(count($elements), 1, 'The sample block description was changed.');
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('admin/structure/layouts');
- $this->assertText(check_plain($layout_title));
-
-
-
- $this->backdropGet($layout_url);
- $this->assertText('Foo subject');
- $this->assertText(format_string('The setting of count is @setting.', array('@setting' => 5)));
- $elements = $this->xpath('//*[contains(@class,:region)]//*[contains(@class,:block)]', array(
- ':region' => 'l-sidebar',
- ':block' => 'block-layout-test-foo',
- ));
- $this->assertEqual(count($elements), 1, 'The sample block was found in the sidebar.');
-
-
- $block_new_title = $this->randomName();
- $edit = array(
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'title' => $block_new_title,
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
- $this->backdropGet($layout_url);
- $this->assertText(check_plain($block_new_title));
-
-
- $edit = array(
- 'title_display' => LAYOUT_TITLE_NONE,
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
- $this->backdropGet($layout_url);
- $this->assertNoText('Foo subject');
- $this->assertNoText($block_new_title);
-
-
- $custom_class = $this->randomName();
- $edit = array(
- 'title_display' => LAYOUT_TITLE_DEFAULT,
- 'style_settings[classes]' => $custom_class,
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($layout_url);
- $this->assertText('Foo subject');
- $this->assertNoText($block_new_title);
- $block_element = $this->xpath('(//*[contains(@class,:region)]//*[contains(@class,:block)])[contains(@class,:custom-class)]', array(
- ':region' => 'l-sidebar',
- ':block' => 'block-layout-test-foo',
- ':custom-class' => $custom_class,
- ));
- $this->assertEqual(count($block_element), 1, 'The sample block was found in the sidebar.');
-
-
-
- $title_class = $this->randomName();
- $content_class = $this->randomName();
- $edit = array(
- 'style' => 'dynamic',
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
- $edit = array(
- 'style_settings[wrapper_tag]' => 'aside',
- 'style_settings[title_tag]' => 'h3',
- 'style_settings[title_classes]' => $title_class,
- 'style_settings[content_tag]' => 'p',
- 'style_settings[content_classes]' => $content_class,
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($layout_url);
- $block_element = $this->xpath('(//*[contains(@class,:region)]//aside[contains(@class,:block)])[contains(@class,:custom-class)]', array(
- ':region' => 'l-sidebar',
- ':block' => 'block-layout-test-foo',
- ':custom-class' => $custom_class,
- ));
- $this->assertEqual(count($block_element), 1, 'The sample block was found in the sidebar as an aside tag.');
- if ($block_element) {
- $title_element = $block_element[0]->xpath('h3');
- $content_element = $block_element[0]->xpath('p');
- $this->assertEqual(count($title_element), 1, 'The sample block has the correct H3 heading tag.');
- $this->assertEqual(count($content_element), 1, 'The sample block has the correct P content tag.');
- $this->assertEqual($title_element[0]['class'], $title_class, 'The sample block title has the correct class.');
- $this->assertEqual($content_element[0]['class'], $content_class, 'The sample block content has the correct class.');
- }
-
-
- $xss = '"><svg onload="alert(\'XSS hole\')">';
-
-
- $filtered_xss = 'svg onloadalertXSS hole';
- $edit = array(
- 'style_settings[classes]' => $xss,
- 'style_settings[title_classes]' => $xss,
- 'style_settings[content_classes]' => $xss,
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($layout_url);
- $this->assertNoRaw($xss);
- $this->assertRaw($filtered_xss);
-
-
- $edit = array(
- 'content[positions][content]' => $block_uuid,
- 'content[positions][sidebar]' => '',
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name, $edit, t('Save layout'));
- $this->backdropGet($layout_url);
- $block_element = $this->xpath('//*[contains(@class,:region)]//*[contains(@class,:block)]', array(
- ':region' => 'l-content',
- ':block' => 'block-layout-test-foo',
- ));
- $this->assertEqual(count($block_element), 1, 'The sample block was found in the content area after moving it from the sidebar.');
-
-
- $edit = array(
- 'region' => 'footer',
- );
- $this->backdropPost($block_edit_url, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($layout_url);
- $block_element = $this->xpath('(//*[contains(@class,:region)]//*[contains(@class,:block)])', array(
- ':region' => 'l-footer',
- ':block' => 'block-layout-test-foo',
- ));
- $this->assertEqual(count($block_element), 1, 'The sample block was found in the footer after moving via block form.');
-
-
- backdrop_static_reset();
- $layout = layout_load($layout_name);
- $layout->setBlockPosition($block_uuid, 'sidebar');
- $layout->save();
-
- $this->backdropGet($layout_url);
- $block_element = $this->xpath('(//*[contains(@class,:region)]//*[contains(@class,:block)])', array(
- ':region' => 'l-sidebar',
- ':block' => 'block-layout-test-foo',
- ));
- $this->assertEqual(count($block_element), 1, 'The sample block was found in the sidebar after moving via the API.');
-
-
-
-
- $block_element = $this->xpath('//*[contains(@class,:block)]', array(
- ':block' => 'block-layout-test-foo',
- ));
- $this->assertEqual(count($block_element), 1, 'The sample block is only displayed once after moving it.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $disable_link = $this->xpath('//*[@data-block-id=:uuid]//a[contains(@class,"disable-block")]', array(
- ':uuid' => $block_uuid,
- ));
- $disable_url_parts = backdrop_parse_url($disable_link[0]['href']);
- $this->backdropGet($disable_url_parts['path'], $disable_url_parts);
-
- $this->assertText(t('Block "@title" disabled.', array('@title' => $block_new_label)));
-
-
- $elements = $this->xpath('//*[contains(@id,:id)]//*[contains(@class,:class)]//span[normalize-space()=:title]', array(
- ':id' => 'layout-editor-block-' .$block_uuid,
- ':class' => 'layout-editor-block-title',
- ':title' => $block_new_label . ' (Disabled)',
- ));
- $this->assertEqual(count($elements), 1, 'The sample block label was found.');
- $elements = $this->xpath('//*[contains(@id,:id)]//*[contains(@class,:class) and contains(text(), :description)]', array(
- ':id' => 'layout-editor-block-' .$block_uuid,
- ':class' => 'layout-editor-block-content',
- ':description' => $block_new_description,
- ));
- $this->assertEqual(count($elements), 1, 'The sample block description was changed.');
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet($layout_url);
- $this->assertNoText('Foo subject');
- $block_element = $this->xpath('//*[contains(@class,:block)]', array(
- ':block' => 'block-layout-test-foo',
- ));
- $this->assertEqual(count($block_element), 0, 'The sample block is not visible on the page.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $this->backdropGet($disable_url_parts['path'], $disable_url_parts);
-
- $this->assertText(t('Block "@title" disabled.', array('@title' => $block_new_label)));
-
-
- $elements = $this->xpath('//*[contains(@id,:id)]//*[contains(@class,:class)]//span[normalize-space()=:title]', array(
- ':id' => 'layout-editor-block-' .$block_uuid,
- ':class' => 'layout-editor-block-title',
- ':title' => $block_new_label,
- ));
- $this->assertEqual(count($elements), 1, 'The sample block label was found.');
- $elements = $this->xpath('//*[contains(@id,:id)]//*[contains(@class,:class) and contains(text(), :description)]', array(
- ':id' => 'layout-editor-block-' .$block_uuid,
- ':class' => 'layout-editor-block-content',
- ':description' => $block_new_description,
- ));
- $this->assertEqual(count($elements), 1, 'The sample block description was changed.');
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet($layout_url);
- $this->assertText('Foo subject');
- $block_element = $this->xpath('//*[contains(@class,:block)]', array(
- ':block' => 'block-layout-test-foo',
- ));
- $this->assertEqual(count($block_element), 1, 'The sample block is again visible on the page.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $remove_link = $this->xpath('//*[@data-block-id=:uuid]//a[contains(@class,"remove-block")]', array(
- ':uuid' => $block_uuid,
- ));
- $remove_url_parts = backdrop_parse_url($remove_link[0]['href']);
- $this->backdropGet($remove_url_parts['path'], $remove_url_parts);
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($layout_url);
- $this->assertNoText('Foo subject');
- $block_element = $this->xpath('//*[contains(@class,:block)]', array(
- ':block' => 'block-layout-test-foo',
- ));
- $this->assertEqual(count($block_element), 0, 'The sample block has been removed.');
-
-
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/delete', array(), t('Delete layout'));
- }
-
-
- * Test block path and type conditions.
- */
- function testBlockPathTypeConditions() {
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'node/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Layout foo block'));
- $block_title = $this->randomString();
- $edit = array(
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'title' => $block_title,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $edit = array(
- 'condition' => 'node_type',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'bundles[page]' => TRUE,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertNoText(check_plain($block_title), 'Block not shown on post content.');
-
- $this->backdropGet('node/' . $this->test_node2->nid);
- $this->assertText(check_plain($block_title), 'Block shown on page content.');
-
-
- layout_reset_caches();
- $layout = layout_load($layout_name);
- $block_uuid = end($layout->positions['sidebar']);
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid);
- $this->backdropPost(NULL, array(), t('Configure'));
- $this->assertRaw('<label for="edit-bundles">Node Type </label>');
-
- $edit = array(
- 'condition' => 'node_type',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'bundles[post]' => TRUE,
- 'bundles[page]' => FALSE,
- );
- $this->backdropPost(NULL, $edit, t('Save visibility condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertText(check_plain($block_title), 'Block shown on post content.');
-
- $this->backdropGet('node/' . $this->test_node2->nid);
- $this->assertNoText(check_plain($block_title), 'Block not shown on page content.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid);
- $this->backdropPost(NULL, array(), t('Add condition'));
- $edit = array(
- 'condition' => 'path',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'paths' => 'node/' . $this->test_node1->nid,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $second_post = $this->backdropCreateNode(array(
- 'type' => 'post',
- 'title' => $this->randomString(),
- ));
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertText(check_plain($block_title), 'Block shown on post content and path matches.');
-
- $this->backdropGet('node/' . $second_post->nid);
- $this->assertNoText(check_plain($block_title), 'Block not shown on post content when path does not match.');
- }
-
-
- * Test block entity ID conditions.
- */
- function testBlockEntityIDConditions() {
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'node/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $second_post = $this->backdropCreateNode(array(
- 'type' => 'post',
- 'title' => $this->randomString(),
- ));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Layout foo block'));
- $block_title = $this->randomString();
- $edit = array(
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'title' => $block_title,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $edit = array(
- 'condition' => 'node_nid',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'entity_id' => $this->test_node1->nid,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertText(check_plain($block_title), 'Block shown and node ID matches.');
-
- $this->backdropGet('node/' . $second_post->nid);
- $this->assertNoText(check_plain($block_title), 'Block not shown when node ID does not match.');
-
-
- layout_reset_caches();
- $layout = layout_load($layout_name);
- $block_uuid = end($layout->positions['sidebar']);
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid);
- $this->backdropPost(NULL, array(), t('Add condition'));
- $edit = array(
- 'condition' => 'user_uid',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'entity_id' => $this->web_user->uid,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertNoText(check_plain($block_title), 'Block not shown when user ID does not match.');
-
- $this->backdropGet('node/' . $second_post->nid);
- $this->assertNoText(check_plain($block_title), 'Block not shown when user ID does not match.');
-
-
- $this->backdropLogin($this->web_user);
-
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertText(check_plain($block_title), 'Block shown when user ID and node ID matches.');
-
- $this->backdropGet('node/' . $second_post->nid);
- $this->assertNoText(check_plain($block_title), 'Block not shown when user ID and node ID does not match.');
- }
-
-
- * Tests user account comparison condition.
- */
- function testBlockUserCompareConditions() {
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'user/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Layout foo block'));
- $block_title = $this->randomString();
- $edit = array(
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'title' => $block_title,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $edit = array(
- 'condition' => 'user_compare',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
-
-
-
- $this->assertOption('edit-contexts-user2', '1', 'User account from path in position 2 selected as second comparison user account.');
- $this->assertNoOption('edit-contexts-user2', 'current_user');
-
- $edit = array(
- 'contexts[user2]' => '1',
- 'equality' => '1',
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('user/' . $this->admin_user->uid);
- $this->assertText(check_plain($block_title), 'Block shown when user views own profile page.');
-
- $this->backdropGet('user/' . $this->web_user->uid);
- $this->assertNoText(check_plain($block_title), 'Block not shown when user views profile page of another user.');
-
-
- layout_reset_caches();
- $layout = layout_load($layout_name);
- $block_uuid = end($layout->positions['sidebar']);
-
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid);
- $this->backdropPost(NULL, array(), t('Configure'));
- $edit = array(
- 'equality' => '0',
- );
- $this->backdropPost(NULL, $edit, t('Save visibility condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('user/' . $this->admin_user->uid);
- $this->assertNoText(check_plain($block_title), 'Block not shown when user views own profile page');
-
- $this->backdropGet('user/' . $this->web_user->uid);
- $this->assertText(check_plain($block_title), 'Block shown when user views profile page of another user.');
- }
-
-
- * Tests 403 and 404 visibility conditions.
- */
- function testBlockHttpResponseCodeConditions() {
-
- $layout_title = 'Response Codes Test';
- $layout_name = 'response_codes_test';
- $layout_url = 'response-codes-test';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Layout foo block'));
- $block_title_404 = $this->randomString();
- $edit = array(
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'title' => $block_title_404,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $edit = array(
- 'condition' => 'http_response_code',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'http_response_codes[404]' => TRUE,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Layout foo block'));
- $block_title_403 = $this->randomString();
- $edit = array(
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'title' => $block_title_403,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $edit = array(
- 'condition' => 'http_response_code',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'http_response_codes[403]' => TRUE,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Layout foo block'));
- $block_title_non_200 = $this->randomString();
- $edit = array(
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'title' => $block_title_non_200,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $edit = array(
- 'condition' => 'http_response_code',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'http_response_codes[200]' => TRUE,
- 'negate' => TRUE,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Update block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $edit = array(
- 'site_404' => 'response-codes-test',
- 'site_403' => 'response-codes-test',
- );
- $this->backdropPost('admin/config/system/site-information', $edit, t('Save configuration'));
-
-
- $this->backdropGet('response-codes-test');
- $this->assertNoText(check_plain($block_title_403), 'Block not shown when not on a 403 page.');
- $this->assertNoText(check_plain($block_title_404), 'Block not shown when not on a 404 page.');
- $this->assertNoText(check_plain($block_title_non_200), 'Block not shown when not on a non-200 page.');
-
-
- $this->backdropGet('non-existent-page-test-url');
- $this->assertText(check_plain($block_title_404), 'Block shown when on a 404 page.');
- $this->assertText(check_plain($block_title_non_200), 'Block shown when on a non-200 page.');
-
-
- $this->backdropLogout();
- $this->backdropGet('admin');
- $this->assertText(check_plain($block_title_403), 'Block shown when on a 403 page.');
- $this->assertText(check_plain($block_title_non_200), 'Block shown when on a non-200 page.');
- }
-
-
- * Test the support for contexts within conditions and blocks.
- */
- function testContexts() {
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_path = 'node/%/foo/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_path,
- );
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Check path'));
-
-
- $edit = array(
- 'context[required][3][plugin]' => 'user',
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 2);
- $this->assertText(t('A testing block for layouts with contexts.'));
- $this->clickLink(t('Layout bar block'));
-
- $this->assertNoField('contexts[my_node]', 'Node context selector not shown, only a single option.');
- $this->assertField('contexts[my_user]', 'User context selector is shown.');
- $this->backdropPost(NULL, array(), t('Add block'));
-
-
- $last_block = $this->xpath('(//*[@id="layout-content-form"]//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
- ':region' => 'l-content',
- ));
- $block_uuid = (string) $last_block[0]['data-block-id'];
- $block_edit_url = 'admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid;
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('node/' . $this->test_node1->nid . '/foo/' . $this->web_user->uid);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->web_user->mail, '@title' => $this->test_node1->title)));
-
-
- $edit = array(
- 'path' => 'foo/%/bar/%',
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Check path'));
- $edit = array(
- 'context[required][1][plugin]' => 'node',
- );
- $this->backdropPost(NULL, $edit, t('Save layout'));
-
-
- $this->backdropGet('foo/' . $this->test_node1->nid . '/bar/' . $this->web_user->uid);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->web_user->mail, '@title' => $this->test_node1->title)));
-
-
-
- $edit = array(
- 'context[required][3][plugin]' => 'node',
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Save layout'));
-
-
- $this->backdropGet('foo/' . $this->test_node1->nid . '/bar/' . $this->test_node2->nid);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->admin_user->mail, '@title' => $this->test_node1->title)));
-
-
-
- $this->backdropGet($block_edit_url);
- $this->assertField('contexts[my_node]', 'Node context selector is shown.');
- $this->assertNoField('contexts[my_user]', 'User context selector is not shown, only the current user available.');
-
- $edit = array(
- 'contexts[my_node]' => '3',
- );
- $this->backdropPost(NULL, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('foo/' . $this->test_node1->nid . '/bar/' . $this->test_node2->nid);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->admin_user->mail, '@title' => $this->test_node2->title)));
-
-
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/delete', array(), t('Delete layout'));
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_path = 'passthrough/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'boxton',
- 'path' => $layout_path,
- );
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 2);
- $this->clickLink(t('String pass-through test'));
- $this->backdropPost(NULL, array(), t('Add block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $argument_string = 'argument-value-from-url';
- $this->backdropGet('passthrough/' . $argument_string);
- $this->assertText(format_string('The page argument is @string', array('@string' => $argument_string)));
-
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_path = $layout_name;
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_path,
- );
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Check path'));
-
- $this->assertNoText(t('Node ID: 1'));
- $this->assertNoText(t('Node ID: 2'));
- $this->assertNoText(t('User account ID: 3'));
-
- $this->backdropPost('admin/structure/layouts/add', array(), t('Create layout'));
-
-
-
- $this->clickLink(t('Add block'), 2);
- $this->assertNoText(t('A testing block for layouts with contexts.'));
-
-
- $edit = array();
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Add context'));
-
-
- $edit = array(
- 'context' => 'node',
- );
- $this->backdropPost(NULL, $edit, t('Load context'));
- $edit = array(
- 'id' => '2',
- );
- $this->backdropPost(NULL, $edit, t('Add context'));
-
- $this->assertNoText(t('Node ID: 1'));
- $this->assertText(t('Node ID: 2'));
- $this->assertNoText(t('User account ID: 3'));
-
-
-
- $this->backdropPost(NULL, array(), t('Configure'));
- $edit = array(
- 'context' => 'file',
- );
- $this->backdropPost(NULL, $edit, t('Load context'));
- $edit = array(
- 'id' => '1',
- );
- $this->backdropPost(NULL, $edit, t('Save context'));
- $error_message = t('The selected File does not exist.');
- $this->assertRaw($error_message);
- $edit = array(
- 'id' => '',
- );
- $this->backdropPost(NULL, $edit, t('Save context'));
- $error_message = t('An ID is required.');
- $this->assertRaw($error_message);
- $this->backdropPost(NULL, $edit, t('Cancel'));
-
- $this->backdropPost(NULL, array(), t('Remove'));
-
- $this->assertNoText(t('Node ID: 1'));
- $this->assertNoText(t('Node ID: 2'));
- $this->assertNoText(t('User account ID: 3'));
-
-
- $this->backdropPost(NULL, array(), t('Add context'));
- $edit = array(
- 'context' => 'node',
- );
- $this->backdropPost(NULL, $edit, t('Load context'));
- $edit = array(
- 'id' => '1',
- );
- $this->backdropPost(NULL, $edit, t('Add context'));
-
- $this->assertText(t('Node ID: 1'));
- $this->assertNoText(t('Node ID: 2'));
- $this->assertNoText(t('User account ID: 3'));
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
-
- $this->clickLink(t('Add block'), 2);
- $this->assertText(t('A testing block for layouts with contexts.'));
- $this->clickLink(t('Layout bar block'));
-
- $this->assertNoField('contexts[my_node]', 'Node context selector not shown, only a single option.');
- $this->assertNoField('contexts[my_user]', 'User context selector is not shown.');
- $this->backdropPost(NULL, array(), t('Add block'));
-
-
- $last_block = $this->xpath('(//*[@id="layout-content-form"]//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
- ':region' => 'l-content',
- ));
- $block_uuid = (string) $last_block[0]['data-block-id'];
- $block_edit_url = 'admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid;
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($layout_path);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->admin_user->mail, '@title' => $this->test_node1->title)));
-
-
- $edit = array();
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Add context'));
- $edit = array(
- 'context' => 'node',
- );
- $this->backdropPost(NULL, $edit, t('Load context'));
- $edit = array(
- 'id' => '2',
- );
- $this->backdropPost(NULL, $edit, t('Add context'));
-
- $this->assertText(t('Node ID: 1'));
- $this->assertText(t('Node ID: 2'));
- $this->assertNoText(t('User account ID: 3'));
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($block_edit_url);
- $this->assertField('contexts[my_node]', 'Node context selector is shown.');
- $this->assertNoField('contexts[my_user]', 'User context selector is not shown, only the current user available.');
-
- $edit = array(
- 'contexts[my_node]' => 'node2',
- );
- $this->backdropPost(NULL, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet($layout_path);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->admin_user->mail, '@title' => $this->test_node2->title)));
-
-
- $edit = array();
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Add context'));
- $edit = array(
- 'context' => 'user',
- );
- $this->backdropPost(NULL, $edit, t('Load context'));
- $edit = array(
- 'id' => $this->web_user->uid,
- );
- $this->backdropPost(NULL, $edit, t('Add context'));
-
- $this->assertText(t('Node ID: 1'));
- $this->assertText(t('Node ID: 2'));
- $this->assertText(t('User account ID: 3'));
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($block_edit_url);
- $this->assertField('contexts[my_node]', 'Node context selector is shown.');
- $this->assertField('contexts[my_user]', 'User context selector is shown.');
-
- $edit = array(
- 'contexts[my_user]' => 'user3',
- );
- $this->backdropPost(NULL, $edit, t('Update block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet($layout_path);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->web_user->mail, '@title' => $this->test_node2->title)));
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_path = 'node/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_path,
- );
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Check path'));
-
- $this->assertNoText(t('Node ID: 1'));
- $this->backdropPost('admin/structure/layouts/add', array(), t('Create layout'));
-
-
- $edit = array();
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Add context'));
- $edit = array(
- 'context' => 'node',
- );
- $this->backdropPost(NULL, $edit, t('Load context'));
- $edit = array(
- 'id' => '2',
- );
- $this->backdropPost(NULL, $edit, t('Add context'));
-
- $this->assertText(t('Position 2: node/%'));
- $this->assertText(t('Node ID: 2'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
-
- $this->clickLink(t('Add block'), 2);
- $this->assertText(t('A testing block for layouts with contexts.'));
- $this->clickLink(t('Layout bar block'));
-
- $this->assertField('contexts[my_node]', 'Node context selector shown.');
-
- $edit = array(
- 'contexts[my_node]' => 'node2',
- );
- $this->backdropPost(NULL, array(), t('Add block'));
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
-
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertText(format_string('The user email is @mail and the node title is @title', array('@mail' => $this->admin_user->mail, '@title' => $this->test_node2->title)));
-
- }
-
-
- * Test the overriding of paths.
- */
- function testOverriddenPaths() {
-
- $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,
- );
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Node title test'));
- $this->backdropPost(NULL, array(), t('Add block'));
-
-
- $last_block = $this->xpath('(//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
- ':region' => 'l-sidebar',
- ));
-
-
-
- $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'));
-
-
- $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_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 condition'));
- $edit = array(
- 'condition' => 'node_type',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
- $edit = array(
- 'bundles[post]' => TRUE,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Save 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.');
-
-
-
- $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'));
-
-
- $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.');
-
-
- $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.');
- }
-
-
- * Check special conditions around the main content block.
- */
- function testMainContentBlock() {
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_path = 'layout-test-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_path,
- );
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Main page content'));
- $this->backdropPost(NULL, array(), t('Add block'));
-
-
- $last_block = $this->xpath('(//*[@id="layout-edit-main"]//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
- ':region' => 'l-sidebar',
- ));
- $new_content_block_uuid = (string) $last_block[0]['data-block-id'];
-
-
- $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'));
-
-
- $this->assertText(t('The "@block" block may only be added once to this layout.', array('@block' => t('Main page content'))));
-
-
- $old_content_block = $this->xpath('//*[@id="layout-edit-main"]//*[contains(@class,:region)]//*[@data-block-id]', array(
- ':region' => 'l-content',
- ));
- $old_content_block_uuid = (string) $old_content_block[0]['data-block-id'];
- $remove_link = $this->xpath('//*[@id="layout-edit-main"]//*[@data-block-id=:uuid]//a[contains(@class,"remove-block")]', array(
- ':uuid' => $old_content_block_uuid,
- ));
- $remove_url_parts = backdrop_parse_url($remove_link[0]['href']);
- $this->backdropGet($remove_url_parts['path'], $remove_url_parts);
-
- $this->backdropPost(NULL, array(), t('Save layout'));
- $this->assertText(t('Layout content saved.'), 'Layout saved successfully after removing old content block.');
-
-
-
-
- $this->backdropGet($layout_path);
- $front_end_content = $this->xpath('//*[contains(@class,:region)]/div[@id=:page-content]', array(
- ':region' => 'l-sidebar',
- ':page-content' => 'layout-test-page-content',
- ));
- $this->assertEqual(count($front_end_content), 1, 'Main content shown in sidebar after moving main content block.');
-
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $remove_link = $this->xpath('//*[@data-block-id=:uuid]//a[contains(@class,"remove-block")]', array(
- ':uuid' => $new_content_block_uuid,
- ));
- $remove_url_parts = backdrop_parse_url($remove_link[0]['href']);
- $this->backdropGet($remove_url_parts['path'], $remove_url_parts);
-
- $this->backdropPost(NULL, array(), t('Save layout'));
- $this->assertText(t('Layout content saved.'));
-
-
- $this->backdropGet($layout_path);
- $front_end_content = $this->xpath('//*[@id=:id]', array(
- ':id' => 'layout-test-page-content',
- ));
- $this->assertEqual(count($front_end_content), 0, 'Main content is no longer shown at all.');
-
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
- $default_content_block = $this->xpath('//*[@id="layout-edit-main"]//*[contains(@class,:region)]//*[@data-block-id]', array(
- ':region' => 'l-content',
- ));
- $default_content_block_uuid = (string) $default_content_block[0]['data-block-id'];
- $remove_link = $this->xpath('//*[@data-block-id=:uuid]//a[contains(@class,"remove-block")]', array(
- ':uuid' => $default_content_block_uuid,
- ));
- $remove_url_parts = backdrop_parse_url($remove_link[0]['href']);
- $this->backdropGet($remove_url_parts['path'], $remove_url_parts);
-
- $this->backdropPost(NULL, array(), t('Save layout'));
- $this->assertText(t('The "@block" block must be added to this layout.', array('@block' => t('Main page content'))));
-
-
- $this->backdropPost(NULL, array(), t('Cancel'));
-
-
- $layout = layout_load($layout_name);
- $layout->delete();
-
- }
-
-
- * Tests conditions and menu item navigation.
- */
- function testLayoutMenuItems() {
- $layout_name = strtolower($this->randomName());
- $layout_path = $layout_name . '/' . strtolower($this->randomName());
- $edit = array(
- 'name' => $layout_name,
- 'title' => $layout_name,
- 'path' => $layout_path,
- 'layout_template' => 'moscone_flipped',
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
- $edit = array(
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'title' => 'Menu item test',
- );
- $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'));
- $this->backdropGet($layout_path);
- $this->assertResponse(200, 'Layout displayed at the given path.');
-
-
-
-
-
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Menu settings'));
- $this->assertUrl('admin/structure/layouts/menu/' . $layout_name, array(), 'Menu settings link goes to the correct layout menu item settings.');
-
-
- $menu_title = $this->randomName();
- $edit = array(
- 'menu[type]' => 'normal',
- 'menu[title]' => $menu_title,
- 'menu[weight]' => 1,
- );
- $this->backdropPost(NULL, $edit, t('Save menu settings'));
-
-
- $this->backdropGet('<front>');
- $this->assertLink($menu_title, 0, 'Menu link shown on the homepage.');
-
- $this->backdropPost('admin/structure/layouts/menu/' . $layout_name, array(), t('Add condition'));
- $edit = array(
- 'condition' => 'path',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
-
-
-
-
- $edit = array(
- 'paths' => "<front>\n$layout_name*\n",
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
- $this->backdropPost(NULL, array(), t('Save menu settings'));
- $vc_text = 'Current path is one of "' . str_replace("\n", ', ', $edit['paths']);
- $vc = $this->xpath('//tr[contains(@class,"layout-group")]//ul//li[contains(., :vc_text)]', array(
- ':vc_text' => $vc_text,
- ));
- $this->assertEqual(count($vc), 1, 'The visibility condition shows up properly.');
-
- $this->backdropGet('<front>');
- $this->assertLink($menu_title, 0, 'Menu link found on the homepage.');
- $this->backdropGet('node/' . $this->test_node1->nid);
- $this->assertNoLink($menu_title, 'Menu link not shown when conditions prevent it.');
- $this->backdropGet($layout_path);
- $this->assertLink($menu_title, 0, 'Menu link shown on the layout page itself.');
-
-
- $menu_tab_title = $this->randomName();
- $edit = array(
- 'menu[type]' => 'default tab',
- 'menu[title]' => $menu_tab_title,
- 'menu[weight]' => 1,
- 'menu[parent][type]' => 'normal',
- 'menu[parent][title]' => $menu_title,
- );
- $this->backdropPost('admin/structure/layouts/menu/' . $layout_name, $edit, t('Save menu settings'));
-
-
- $this->backdropGet('<front>');
- $this->assertLink($menu_title, 0, 'Menu link found on the homepage when registered as a parent menu item link.');
- $this->clickLink($menu_title);
- $this->assertUrl($layout_name, array(), 'Menu link uses the parent path, without the default tab portion of the path.');
-
-
- $tab_layout_name = strtolower($this->randomName());
- $tab_layout_path = $layout_name . '/' . strtolower($this->randomName());
- $edit = array(
- 'name' => $tab_layout_name,
- 'title' => $tab_layout_name,
- 'path' => $tab_layout_path,
- 'layout_template' => 'moscone_flipped',
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
- $tab_layout_title = $this->randomName();
- $edit = array(
- 'menu[type]' => 'tab',
- 'menu[title]' => $tab_layout_title,
- 'menu[weight]' => 1,
- );
- $this->backdropPost('admin/structure/layouts/menu/' . $tab_layout_name, $edit, t('Save menu settings'));
-
-
- $this->backdropGet($layout_name);
- $active_tab = $this->xpath('//ul[contains(@class,"tabs")]/li[contains(@class,"active")]/a[@href=:path]', array(
- ':path' => url($layout_name),
- ));
- $this->assertEqual(count($active_tab), 1, 'The menu default tab for a layout shows up properly.');
- $second_tab = $this->xpath('//ul[contains(@class,"tabs")]/li/a[@href=:path]', array(
- ':path' => url($tab_layout_path),
- ));
- $this->assertEqual(count($second_tab), 1, 'The normal menu tab for a layout shows up properly.');
-
-
- $subtab_layout_name = strtolower($this->randomName());
- $subtab_layout_path = $tab_layout_path . '/' . strtolower($this->randomName());
- $subtab_layout_path_last = $subtab_layout_path . '/' . strtolower($this->randomName());
- $edit = array(
- 'name' => $subtab_layout_name,
- 'title' => $subtab_layout_name,
- 'path' => $subtab_layout_path_last,
- 'layout_template' => 'moscone_flipped',
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
- $subtab_layout_title = $this->randomName();
- $sub_subtab_layout_title = $this->randomName();
- $edit = array(
- 'menu[type]' => 'default tab',
- 'menu[title]' => $sub_subtab_layout_title,
- 'menu[weight]' => 0,
- 'menu[parent][type]' => 'tab',
- 'menu[parent][title]' => $subtab_layout_title,
- );
- $this->backdropPost('admin/structure/layouts/menu/' . $subtab_layout_name, $edit, t('Save menu settings'));
-
-
- $subtab_layout_path_last = $subtab_layout_path . '/' . strtolower($this->randomName());
- $edit = array(
- 'path' => $subtab_layout_path_last,
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $tab_layout_name . '/configure', $edit, t('Save layout'));
-
-
- $this->backdropGet($subtab_layout_path);
- $active_tab = $this->xpath('//ul[contains(@class,"tabs")][contains(@class,"secondary")]/li[contains(@class,"active")]/a[@href=:path]', array(
- ':path' => url($subtab_layout_path),
- ));
- $this->assertEqual(count($active_tab), 1, 'The sub-tab default menu item for a layout shows up properly.');
- $second_tab = $this->xpath('//ul[contains(@class,"tabs")][contains(@class,"secondary")]/li/a[@href=:path]', array(
- ':path' => url($subtab_layout_path_last),
- ));
- $this->assertEqual(count($second_tab), 1, 'The sub-tab menu item for a layout shows up properly.');
-
-
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/delete', array(), t('Delete layout'));
- $this->backdropPost('admin/structure/layouts/manage/' . $tab_layout_name . '/delete', array(), t('Delete layout'));
- $this->backdropPost('admin/structure/layouts/manage/' . $subtab_layout_name . '/delete', array(), t('Delete layout'));
-
-
- layout_reset_caches();
- $this->assertFalse(layout_load($layout_name), 'Base layout deleted.');
- $this->assertFalse(layout_load($tab_layout_name), 'Tab layout deleted.');
- $this->assertFalse(layout_load($subtab_layout_name), 'Sub-tab layout deleted.');
- $this->assertFalse(layout_menu_item_load($layout_name), 'Base menu item deleted.');
- $this->assertFalse(layout_menu_item_load($tab_layout_name), 'Tab menu item deleted.');
- $this->assertFalse(layout_menu_item_load($subtab_layout_name), 'Sub-tab menu item deleted.');
- }
-
-
- * Test region styles.
- */
- function testRegionStyles() {
- $this->backdropGet('admin/structure/layouts/manage/default/configure-region/editor/header');
- $edit = array(
- 'element' => 'aside',
- 'classes' => 'new-test-class',
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
- $this->backdropGet('admin/structure/layouts/manage/default');
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet('node');
- $style_exists = $this->xpath('//header[contains(@class,"l-header")]//aside[contains(@class,"new-test-class")]');
- $this->assertTrue($style_exists, 'Style exists on header div.');
- }
-
-
- * Ensure that reassignment of menu items works when deleting layouts.
- */
- function testMenuItemReassignment() {
-
- $layout_name = strtolower($this->randomName());
- $layout_path = $layout_name;
- $edit = array(
- 'name' => $layout_name,
- 'title' => $layout_name,
- 'path' => $layout_path,
- 'layout_template' => 'moscone_flipped',
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $result = config_get('layout.layout.' . $layout_name, 'name');
- $this->assertEqual($result, $layout_name, 'Config created for new layout.');
- $result = config_get('layout.menu_item.' . $layout_name, 'name');
- $this->assertEqual($result, $layout_name, 'Config created for new layout menu item.');
-
- $layout_title = $this->randomName();
- $edit = array(
- 'menu[type]' => 'normal',
- 'menu[title]' => $layout_title,
- 'menu[weight]' => 1,
- );
- $this->backdropPost('admin/structure/layouts/menu/' . $layout_name, $edit, t('Save menu settings'));
-
- $this->backdropGet('<front>');
- $this->assertLink(check_plain($layout_title), 0, 'Menu link displayed on homepage.');
-
-
- $second_layout_name = strtolower($this->randomName());
- $edit = array(
- 'name' => $second_layout_name,
- 'title' => $second_layout_name,
- 'path' => $layout_path,
- 'layout_template' => 'moscone_flipped',
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
-
- $result = config_get('layout.layout.' . $second_layout_name, 'name');
- $this->assertEqual($result, $second_layout_name, 'Config created for second layout.');
- $result = config_get('layout.menu_item.' . $second_layout_name, 'name');
- $this->assertNull($result, 'No config created for second layout menu item (reuses the existing one).');
-
-
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/delete', array(), t('Delete layout'));
-
- layout_reset_caches();
- $this->assertFalse(layout_load($layout_name), 'Base layout deleted.');
- $this->assertFalse(layout_menu_item_load($layout_name), 'Base layout menu item deleted.');
-
- $menu_item = layout_menu_item_load($second_layout_name);
- $this->assertTrue($menu_item, 'Menu item transferred to second layout.');
- $this->assertEqual($menu_item->name, $second_layout_name, 'Menu name updated.');
- $this->assertEqual($menu_item->path, $layout_path, 'Menu path copied correctly.');
-
- $this->backdropGet('<front>');
- $this->assertLink(check_plain($layout_title), 0, 'Previous menu item link still displayed after deleting first layout.');
-
-
- $this->backdropPost('admin/structure/layouts/manage/' . $second_layout_name . '/delete', array(), t('Delete layout'));
- $this->backdropGet('<front>');
- $this->assertNoLink(check_plain($layout_title), 'Menu item no longer present after deleting last layout.');
-
- $result = config_get('layout.menu_item.' . $second_layout_name, 'name');
- $this->assertNull($result, 'Config for second menu item has been deleted.');
- }
-
-
- * Tests switching between different layouts, ensuring block copying.
- */
- function testLayoutChange() {
-
- $default_layout = layout_load('default');
- $default_layout->addBlock('layout_test', 'foo', 'content');
- $default_layout->addBlock('layout_test', 'foo', 'sidebar');
- $default_layout->save();
-
-
-
- $layout_name = strtolower($this->randomName());
- $layout_path = $layout_name;
- $edit = array(
- 'name' => $layout_name,
- 'title' => $layout_name,
- 'path' => $layout_path,
- 'layout_template' => 'moscone_flipped',
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
- layout_reset_caches();
- $layout = layout_load($layout_name);
- $this->assertBlocksMatch($layout, $default_layout);
-
-
- $edit = array(
- 'layout_template' => 'layout_test_layout_template',
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Save layout'));
-
- layout_reset_caches();
- $layout = layout_load($layout_name);
- $this->assertBlocksMatch($layout, $default_layout);
-
-
- $edit = array(
- 'layout_template' => 'boxton',
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/configure', $edit, t('Save layout'));
-
- $orphaned_uuids = $default_layout->positions['sidebar'];
- $this->orphaned_blocks = !empty($orphaned_uuids);
- layout_reset_caches();
- $layout = layout_load($layout_name);
- $this->assertBlocksMatch($layout, $default_layout);
- $this->assertFalse(isset($layout->positions['sidebar']), 'Sidebar region blocks moved out when changing layout to single column.');
-
- $intersection = array_intersect(array_keys($layout->content), $orphaned_uuids);
- $this->assertEqual($intersection, array(), 'The sidebar blocks have been removed from the layout content array.');
-
-
- $default_layout_sidebar_content_regions_count = count($default_layout->positions['sidebar']) + count($default_layout->positions['content']);
- $new_content_region_count = count($layout->positions['content']);
-
-
- if ($default_layout->positions['content'][0] == 'default') {
- $new_content_region_count++;
- }
- $this->assertTrue($default_layout_sidebar_content_regions_count == $new_content_region_count, 'The blocks from the Sidebar and Default regions in the old layout all exist in the Default region of the new layout.');
-
- $moved_block_uuid = $layout->positions['content'][1];
- $moved_block = $layout->content[$moved_block_uuid];
- $this->assertTrue($moved_block->module == 'layout_test', 'The moved block is from the layout_test module.');
- }
-
-
- * Tests current user custom field block
- */
- function testCurrentUser() {
- $field_name = 'field_field1';
-
- $field_info = array('field_name' => $field_name, 'type' => 'text');
- $field = field_create_field($field_info);
- $instance = array(
- 'field_name' => $field_name,
- 'entity_type' => 'user',
- 'bundle' => 'user',
- 'label' => 'Field1',
- );
- field_create_instance($instance);
-
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'layout-test-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
-
-
- $this->assertText(t('Layout created. Blocks may now be added to this layout.'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Field: Field1 (field_field1)'));
- $edit = array();
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $field_value = 'the expected value';
-
- $this->backdropGet('user/' . $this->admin_user->uid . '/edit');
- $this->assertText($instance['label'], 'The field appears on user edit form');
- $edit = array();
- $edit[$field_name . '[' . LANGUAGE_NONE . '][0][value]'] = $field_value;
- $this->backdropPost(NULL, $edit, t('Save'));
-
-
- $this->backdropGet($layout_url);
- $this->assertText($field_value, 'The field appears on the new layout page.');
- }
-
-
- * Tests Taxonomy contexts within layouts.
- */
- function testTaxonomyContext() {
- module_enable(array('taxonomy'));
-
-
- $vocabulary = new TaxonomyVocabulary(array(
- 'name' => 'Tags',
- 'description' => 'Use tags to group posts on similar topics into categories.',
- 'machine_name' => 'tags',
- ));
- taxonomy_vocabulary_save($vocabulary);
-
- $field = array(
- 'field_name' => 'field_' . $vocabulary->machine_name,
- 'type' => 'taxonomy_term_reference',
-
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $vocabulary->machine_name,
- 'parent' => 0,
- ),
- ),
- ),
- );
- field_create_field($field);
-
- $instance = array(
- 'field_name' => 'field_' . $vocabulary->machine_name,
- 'entity_type' => 'node',
- 'label' => 'Tags',
- 'bundle' => 'post',
- 'widget' => array(
- 'type' => 'taxonomy_autocomplete',
- ),
- );
- field_create_instance($instance);
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_path = 'taxonomy/term/%';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_path,
- );
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Check path'));
-
-
-
- $this->backdropPost(NULL, array(), t('Add condition'));
-
- $this->backdropPost(NULL, array('condition' => 'taxonomy_term_vocabulary'), t('Load condition'));
- $this->backdropPost(NULL, array('bundles[tags]' => TRUE), t('Add condition'));
- $this->backdropPost(NULL, array(), t('Create layout'));
-
- $this->assertText(t('Layout created. Blocks may now be added to this layout.'));
- }
-
-
- * Check that all the blocks in $layout match those in $copied_from_layout.
- */
- protected function assertBlocksMatch($layout, $copied_from_layout, $orphaned_uuids = array()) {
- $layout_template_info = layout_get_layout_template_info($layout->layout_template);
- $default_region = $layout_template_info['default region'];
- foreach ($layout->positions as $region_name => $blocks) {
-
-
- if ($this->orphaned_blocks && $region_name == $default_region) {
- $this->orphaned_blocks = FALSE;
- continue;
- }
- if (isset($copied_from_layout->positions[$region_name])) {
- $blocks_match = TRUE;
- $content_block_offset = 0;
- foreach ($blocks as $position => $block_uuid) {
- $copied_block_uuid = $copied_from_layout->positions[$region_name][$position + $content_block_offset];
- $copied_block = $copied_from_layout->content[$copied_block_uuid];
-
-
-
-
-
- if ($copied_block->module === 'system' && $copied_block->delta === 'main' && isset($layout->menu_item)) {
- $content_block_offset = 1;
- $copied_block_uuid = $copied_from_layout->positions[$region_name][$position + $content_block_offset];
- $copied_block = $copied_from_layout->content[$copied_block_uuid];
- }
-
- $block = $layout->content[$block_uuid];
- if ($block->module !== $copied_block->module || $block->delta !== $copied_block->delta) {
- $blocks_match = FALSE;
- }
- }
- $this->assertTrue($blocks_match, format_string('Blocks copied from @layout1 into @layout2 match in the @region region.', array('@layout1' => $copied_from_layout->layout_template, '@layout2' => $layout->layout_template, '@region' => $region_name)));
- }
- else {
- debug(format_string('The new layout @layout does not have the region @region, so no blocks are being copied.', array('@layout' => $layout->layout_template, '@region' => $region_name)));
- }
- }
- }
-
-
- * Tests layout_modules_uninstalled().
- */
- function testBlockUninstall() {
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'layout-test-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 5,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $this->assertText(t('A testing block for layouts.'));
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
-
-
- $this->clickLink(t('Add block'), 3);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 5,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
- $this->assertText(t('A testing block for layouts.'));
-
-
- module_disable(array('layout_test'));
- backdrop_uninstall_modules(array('layout_test'));
- $this->assertFalse(module_exists('layout_test'), 'The module has been uninstalled.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
- $this->assertNoText(t('A testing block for layouts.'));
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $this->assertNoText(t('A testing block for layouts.'));
- }
- }
-
- * Tests the blocks title, content, and display settings.
- */
- class LayoutBlockTest extends BackdropWebTestCase {
- protected $profile = 'minimal';
- protected $admin_user;
-
- function setUp() {
- parent::setUp(array('file', 'block'));
-
- $this->backdropCreateContentType(array('type' => 'page', 'name' => 'Page'));
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access administration pages',
- 'administer layouts',
- 'access user profiles',
- 'edit any page content',
- 'administer nodes',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Test Custom Text blocks.
- */
- function testCustomTextBlocks() {
- $this->backdropGet('admin/structure/layouts/manage/default');
- $block_title_1 = 'Title of block one';
- $block_content_1 = 'Content of block one';
- $block_content_2 = 'Content of block two';
- $block_title_3 = 'Title of block three';
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Custom block'));
- $edit = array(
- 'title' => $block_title_1,
- 'content[value]' => $block_content_1,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
- $first_block = $this->xpath('(//*[@id="layout-content-form"]//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
- ':region' => 'l-sidebar',
- ));
- $first_block_uuid = (string) $first_block[0]['data-block-id'];
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Custom block'));
- $edit = array(
- 'content[value]' => $block_content_2,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Custom block'));
- $edit = array(
- 'title' => $block_title_3,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('<front>');
-
- $elements = $this->xpath('//*[contains(@class,:region)]//*[contains(@class,:block)]', array(
- ':region' => 'l-sidebar',
- ':block' => 'block-layout-custom-block',
- ));
- $this->assertEqual(count($elements), 2, 'Two custom text blocks were found in the sidebar.');
-
-
- $this->assertText($block_title_1);
- $this->assertText($block_content_1);
-
-
- $this->assertText($block_content_2);
-
- $title_2 = $this->xpath('(//div[contains(@class, "block-layout-text-block")])[2]//h2');
- $this->assertFalse($title_2);
-
-
- $this->assertNoText($block_title_3);
- $block_3 = $this->xpath('(//div[contains(@class, "block-layout-text-block")])[3]');
- $this->assertFalse($block_3);
-
-
- module_enable(array('block'));
- $edit = array(
- 'reusable' => TRUE,
- );
- $this->backdropPost('admin/structure/layouts/manage/default/configure-block/editor/' . $first_block_uuid, $edit, t('Update block'));
- $this->assertText(t('Admin label is required when making a block reusable.'));
- $edit['admin_label'] = 'My custom block label';
- $this->backdropPost(NULL, $edit, t('Update block'));
- $this->assertText(t('An internal name is required when making a block reusable.'));
- $edit['delta'] = 'my_custom_block';
- $this->backdropPost(NULL, $edit, t('Update block'));
-
-
- $this->assertText('My custom block label');
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('admin/structure/layouts/manage/default/configure-block/editor/' . $first_block_uuid);
-
- $this->assertFieldByXPath('//input[@name="block_settings[reusable]"][@disabled="disabled"]');
-
-
- $this->backdropGet('<front>');
- $custom_block = $this->xpath('//*[contains(@class,:region)]//*[contains(@class,:block)]', array(
- ':region' => 'l-sidebar',
- ':block' => 'block-block-my-custom-block',
- ));
- $this->assertEqual(count($custom_block), 1, 'Converted custom block found.');
- if (count($custom_block)) {
- $custom_block_title = $custom_block[0]->xpath('.//*[contains(@class, "block-title")]');
- $custom_block_content = $custom_block[0]->xpath('.//*[contains(@class, "block-content")]/p');
- $this->assertEqual((string) $custom_block_title[0], $block_title_1, 'Converted custom block title found.');
- $this->assertEqual((string) $custom_block_content[0], $block_content_1, 'Converted custom block content.');
- }
- }
-
-
- * Test Hero blocks.
- */
- function testHeroBlocks() {
- $hero_title_1 = 'Wonder Woman';
- $hero_content_1 = 'Youth is your greatest weapon, your greatest tool.';
- $hero_title_2 = 'Black Widow';
- $hero_content_2 = "Whatever it takes.";
-
-
- $good_image = imagecreate(2400, 400);
- $good_filename = 'good.jpg';
- $good_realpath_filename = backdrop_realpath('temporary://' . $good_filename);
- imagejpeg($good_image, $good_realpath_filename);
-
- $bad_image = imagecreate(1024, 260);
- imagecolorallocate($bad_image, 255, 0, 0);
- $bad_filename = 'bad.jpg';
- $bad_realpath_filename = backdrop_realpath('temporary://' . $bad_filename);
- imagejpeg($bad_image, $bad_realpath_filename);
-
- $good_image2 = imagecreate(2400, 400);
- $good_filename2 = 'good2.jpg';
- $good_realpath_filename2 = backdrop_realpath('temporary://' . $good_filename2);
- imagejpeg($good_image2, $good_realpath_filename2);
-
- $this->backdropGet('admin/structure/layouts/manage/default');
-
-
- $this->clickLink(t('Add block'), 2);
- $this->clickLink(t('Hero block'));
- $edit = array(
- 'title' => $hero_title_1,
- 'content[value]' => $hero_content_1,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->clickLink(t('Add block'), 2);
- $this->clickLink(t('Hero block'));
- $edit = array(
- 'content[value]' => $hero_content_2,
- 'files[image]' => $good_realpath_filename,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->clickLink(t('Add block'), 2);
- $this->clickLink(t('Hero block'));
-
-
- $edit = array(
- 'files[image]' => $bad_realpath_filename,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
- $error_message = t('The specified file %name could not be uploaded.', array('%name' => $bad_filename));
- $error_message .= ' ' . t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => '1200x300'));
- $this->assertRaw($error_message);
-
-
- $edit['files[image]'] = $good_realpath_filename2;
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('user');
-
-
- $elements = $this->xpath('//*[contains(@class,:region)]//*[contains(@class,:block)]', array(
- ':region' => 'l-content',
- ':block' => 'block-layout-hero',
- ));
- $this->assertEqual(count($elements), 3, 'Three hero blocks were found in the content area.');
-
-
- $elements = $this->xpath('(//div[contains(@class, "block-layout-hero")])');
-
-
- $this->assertText($hero_title_1);
- $this->assertText($hero_content_1);
-
- $classes_1 = (string)$elements[0]['class'];
- $this->assertTrue(strstr($classes_1, 'block-hero-no-image'));
-
- $this->assertNull($elements[0]['style'], 'No image present for 1st hero block.');
-
-
- $title_2 = $elements[1]->xpath('.//h2');
- $this->assertIdentical($title_2, array(), 'No title present for 2nd hero block.');
-
- $this->assertText($hero_content_2);
-
- $classes_2 = (string)$elements[1]['class'];
- $this->assertTrue(strstr($classes_2, 'block-hero-image'));
-
- $style_2 = (string)$elements[1]['style'];
- $this->assertTrue(strstr($style_2, $good_filename), 'Image present for 2nd hero block.');
-
-
- $title_3 = $elements[2]->xpath('.//h2');
- $this->assertIdentical($title_3, array(), 'No title present for 3rd hero block.');
-
- $content_3_element = $elements[2]->xpath('.//div[contains(@class, "block-content")]');
- $this->assertEqual(count($content_3_element), 1, '3rd hero block content found.');
-
- $content_3 = (string)$content_3_element[0];
-
-
-
-
-
- $unicode_nbsp = trim(json_encode(trim($content_3)), '"');
- $this->assertEqual($unicode_nbsp, '\u00a0', '3rd hero block contains only a non-breaking space.');
-
-
- $style_3 = (string)$elements[2]['style'];
- $this->assertTrue(strstr($style_3, $good_filename2), 'Image present for 3rd hero block.');
- }
-
-
- * Test Page component blocks.
- */
- function testPageComponentBlocks() {
-
- $page_node = $this->backdropCreateNode(array(
- 'type' => 'page',
- 'title' => "Test node title",
- ));
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
- $this->clickLink(t('Remove'), 3);
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('node/1');
-
- $page_title = $this->xpath('(//div[contains(@class, "l-page-title")])//h1');
- $this->assertEqual(count($page_title), 1, 'The page title was found.');
- $this->assertEqual((string) $page_title[0], 'Test node title');
-
- $this->backdropGet('admin/structure/layouts/manage/default');
-
-
- $this->clickLink(t('Add block'), 0);
- $this->clickLink(t('Page title'));
- $this->backdropPost(NULL, array(), t('Add block'));
- $title_block = $this->xpath('(//*[@id="layout-content-form"]//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
- ':region' => 'header',
- ));
- $title_block_uuid = (string) $title_block[0]['data-block-id'];
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('node/1');
- $page_title = $this->xpath('(//div[contains(@class, "l-page-title")])//h1');
- $this->assertEqual(count($page_title), 0, 'The page title was not found.');
-
-
- $page_title = $this->xpath('(//div[contains(@class, "block-system-title")])//h1');
- $this->assertEqual((string) $page_title[0], 'Test node title');
-
-
-
- $data = array(
- 'title_display' => 'custom',
- 'title' => 'A & "custom" title',
- );
- $this->backdropPost('admin/structure/layouts/manage/default/edit-title/editor/title', $data, t('Save configuration'));
- $this->backdropPost('admin/structure/layouts/manage/default/blocks', array(), t('Save layout'));
- $this->backdropGet('node/1');
- $title = $this->xpath('(//div[contains(@class, "block-system-title")])//h1');
- $this->assertEqual((string) $title[0], 'A & "custom" title');
-
-
-
- $this->backdropGet('admin/structure/layouts/manage/default/edit-title/editor/title');
- $block_value = $this->xpath('//select[@name="title_block"]/option[@selected]');
- $first_block_uuid = $block_value[0]['value'];
- $data = array(
- 'title_display' => 'block',
- );
- $this->backdropPost(NULL, $data, t('Save configuration'));
-
-
-
- $data = array(
- 'title_display' => 'custom',
- 'title' => 'A title from a different block',
- );
- $this->backdropPost('admin/structure/layouts/manage/default/configure-block/editor/' . $first_block_uuid, $data, t('Update block'));
- $this->backdropPost('admin/structure/layouts/manage/default/blocks', array(), t('Save layout'));
- $this->backdropGet('node/1');
- $title = $this->xpath('(//div[contains(@class, "block-system-title")])//h1');
- $this->assertEqual((string)$title[0], 'A title from a different block');
-
-
-
- $data = array(
- 'title_display' => 'none',
- );
- $this->backdropPost('admin/structure/layouts/manage/default/edit-title/editor/title', $data, t('Save configuration'));
- $this->backdropPost('admin/structure/layouts/manage/default/blocks', array(), t('Save layout'));
- $this->backdropGet('node/1');
- $title = $this->xpath('(//div[contains(@class, "block-system-title")])');
- $this->assertEqual(count($title), 0, 'The entire title block is hidden when title is not displayed.');
- $head_title = $this->xpath('//head//title');
- $this->assertIdentical(strpos((string) $head_title[0], 'Test node title'), 0, 'Default title found in HEAD when title is hidden on page.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
- $remove_link = $this->xpath('//*[@data-block-id=:uuid]//a[contains(@class,"remove-block")]', array(
- ':uuid' => $title_block_uuid,
- ));
- $remove_url_parts = backdrop_parse_url($remove_link[0]['href']);
- $this->backdropGet($remove_url_parts['path'], $remove_url_parts);
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('admin/structure/layouts/manage/default/edit-title/editor/title');
- $data = array(
- 'title_display' => 'default',
- );
- $this->backdropPost(NULL, $data, t('Save configuration'));
- $this->backdropPost('admin/structure/layouts/manage/default', array(), t('Save layout'));
-
-
- $this->backdropGet('node/1');
- $page_title = $this->xpath('(//div[contains(@class, "l-page-title")])//h1');
- $this->assertEqual(count($page_title), 1, 'The page title was found.');
- $this->assertEqual((string) $page_title[0], 'Test node title');
-
-
- $this->backdropPost("node/1/edit", array(), t('Save'));
-
-
- $messages = $this->xpath('(//div[contains(@class, "l-messages")])//div[contains(@class, "messages")]');
- $this->assertEqual(count($messages), 1, 'The Page messages DIV was found.');
-
-
- $tabs = $this->xpath('(//nav[contains(@class, "tabs")])//ul[contains(@class, "tabs")]');
- $this->assertEqual(count($tabs), 1, 'The tabs nav element was found.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
-
-
- $this->clickLink(t('Add block'), 0);
- $this->clickLink(t('Page title combo'));
- $this->backdropPost(NULL, array(), t('Add block'));
- $title_combo_block = $this->xpath('(//*[@id="layout-content-form"]//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
- ':region' => 'header',
- ));
- $title_combo_block_uuid = (string) $title_combo_block[0]['data-block-id'];
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('node/1');
- $page_title = $this->xpath('(//div[contains(@class, "l-page-title")])//h1["Your first post!"]');
- $this->assertEqual(count($page_title), 0, 'The page title was not found.');
- $tabs = $this->xpath('(//nav[contains(@class, "tabs")])//div[contains(@class, "tabs")]');
- $this->assertEqual(count($tabs), 0, 'The tabs DIV was not found.');
-
-
- $this->backdropPost("node/1/edit", array(), t('Save'));
- $messages = $this->xpath('(//div[contains(@class, "l-wrapper")])//div[contains(@class, "l-messages")]');
- $this->assertEqual(count($messages), 0, 'The messages DIV was not found.');
-
-
- $combo_page_title = $this->xpath('(//div[contains(@class, "block-system-title-combo")])//h1[contains(@class, "title")]');
- $this->assertEqual(count($combo_page_title), 1, 'The Title combo title DIV was found.');
- $combo_tabs = $this->xpath('(//div[contains(@class, "block-system-title-combo")])//nav[contains(@class, "tabs")]');
- $this->assertEqual(count($combo_tabs), 1, 'The Title combo tabs DIV was found.');
- $combo_messages = $this->xpath('(//div[contains(@class, "block-system-title-combo")])//div[contains(@class, "l-messages")]');
- $this->assertEqual(count($combo_messages), 1, 'The Title combo messages DIV was found.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
- $remove_link = $this->xpath('//*[@data-block-id=:uuid]//a[contains(@class,"remove-block")]', array(
- ':uuid' => $title_combo_block_uuid,
- ));
- $remove_url_parts = backdrop_parse_url($remove_link[0]['href']);
- $this->backdropGet($remove_url_parts['path'], $remove_url_parts);
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->clickLink(t('Add block'), 0);
- $this->clickLink(t('Page local actions'));
- $this->backdropPost(NULL, array(), t('Add block'));
-
-
- $this->clickLink(t('Add block'), 0);
- $this->clickLink(t('Page messages'));
- $this->backdropPost(NULL, array(), t('Add block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
-
- $messages = $this->xpath('(//div[contains(@class, "l-wrapper")])//div[contains(@class, "l-messages")]');
- $this->assertEqual(count($messages), 0, 'The messages DIV was not found.');
- $block_messages = $this->xpath('(//div[contains(@class, "block-system-messages")])//div[contains(@class, "l-messages")]');
- $this->assertEqual(count($block_messages), 1, 'The Page messages block was found.');
-
-
-
- $this->backdropGet('admin/structure/layouts');
- $actions = $this->xpath('(//div[contains(@class, "l-wrapper")])//div[contains(@class, "l-action-links")]');
- $this->assertEqual(count($actions), 0, 'The messages DIV was not found.');
- $block_actions = $this->xpath('(//div[contains(@class, "block-system-action-links")])//ul[contains(@class, "action-links")]');
- $this->assertEqual(count($block_actions), 1, 'The Page messages block was found.');
- }
- }
-
- * Tests that the correct layout is used in various situations.
- */
- class LayoutSelectionTest extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $content_type;
- protected $web_user;
- protected $admin_user;
-
- function setUp() {
- parent::setUp(array('layout'));
- config_set('system.core', 'node_admin_theme', TRUE);
-
-
- $this->content_type = $this->backdropCreateContentType();
-
-
- $this->web_user = $this->backdropCreateUser(array(
- 'access content',
- 'create ' . $this->content_type->type . ' content',
- ));
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access content',
- 'create ' . $this->content_type->type . ' content',
- 'access administration pages',
- 'administer content types',
- 'view the administration theme',
- 'administer filters',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Tests the correct layout is used on 404 and 403 pages.
- */
- function testPages() {
-
- $this->backdropGet('admin/config/content/formats/plain_text');
- $this->assertIsAdminLayout();
-
-
- $this->backdropGet('node/add/' . $this->content_type->type);
- $this->assertIsAdminLayout();
-
-
- $this->backdropGet('admin/appearance');
- $this->assertIsAdminLayout();
-
-
- $this->backdropGet('admin/config/content/formats/fake-format');
- $this->assertIsAdminLayout();
-
-
- $this->backdropGet('node');
- $this->assertIsDefaultLayout();
-
-
- $this->backdropLogout();
-
-
- $this->backdropGet('admin/config/content/formats/plain_text');
- $this->assertIsDefaultLayout();
-
-
- $this->backdropGet('admin/config/content/formats/fake-format');
- $this->assertIsDefaultLayout();
-
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('node/add/' . $this->content_type->type);
- $this->assertIsDefaultLayout();
- }
-
-
- * Test role-based selection of layouts.
- */
- function testRoleSelection() {
-
- $admin_user = $this->backdropCreateUser(array(
- 'access administration pages',
- 'administer site configuration',
- 'administer modules',
- 'administer layouts',
- 'administer nodes',
- ));
- $this->backdropLogin($admin_user);
-
-
- $web_user = $this->backdropCreateUser(array('access user profiles', 'access content'));
-
-
-
- $layout_name = strtolower($this->randomName());
- $layout_path = $layout_name;
- $edit = array(
- 'name' => $layout_name,
- 'title' => $layout_name,
- 'path' => $layout_path,
- 'layout_template' => 'moscone_flipped',
- );
-
-
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Add condition'));
-
-
- $edit = array(
- 'condition' => 'user_role',
- );
- $this->backdropPost(NULL, $edit, t('Load condition'));
-
-
- $edit = array(
- 'roles[authenticated]' => TRUE,
- );
- $this->backdropPost(NULL, $edit, t('Add condition'));
-
-
- $this->backdropPost(NULL, array(), t('Create layout'));
-
-
- $this->backdropGet($layout_path);
- $this->assertResponse(200);
- $this->backdropLogout();
-
-
- $this->backdropLogin($web_user);
- $this->backdropGet($layout_path);
- $this->assertResponse(200);
- $this->backdropLogout();
-
-
- $this->backdropGet($layout_path);
- $this->assertResponse(404);
-
-
- $this->backdropLogin($admin_user);
-
- $edit = array(
- 'roles[authenticated]' => FALSE,
- 'roles[anonymous]' => TRUE,
- 'negate' => TRUE,
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/condition/edit/layout/0', $edit, t('Save visibility condition'));
-
-
- $this->backdropGet($layout_path);
- $this->assertResponse(200);
- $this->backdropLogout();
-
-
- $this->backdropLogin($web_user);
- $this->backdropGet($layout_path);
- $this->assertResponse(200);
- $this->backdropLogout();
-
-
- $this->backdropGet($layout_path);
- $this->assertResponse(404);
- }
-
- private function assertIsDefaultLayout($message = '') {
- $result = $this->xpath('//div[contains(@class, "layout--moscone-flipped")]');
- $this->assertEqual(count($result), 1, $message ? $message : format_string('Admin layout used at @path', array('@path' => $this->getUrl())));
- }
-
- private function assertIsAdminLayout($message = '') {
- $result = $this->xpath('//div[contains(@class, "layout--boxton")]');
- $this->assertEqual(count($result), 1, $message ? $message : format_string('Admin layout used at @path', array('@path' => $this->getUrl())));
- }
- }
-
- * Tests the BlockTest (custom text) block functionality.
- */
- class LayoutBlockTextTest extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $admin_user;
-
- function setUp() {
- parent::setUp(array('layout', 'block'));
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access content',
- 'access administration pages',
- 'administer layouts',
- 'view the administration theme',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Tests the BlockText class functionality.
- */
- function testBlockText() {
-
- $files = $this->backdropGetTestFiles('image');
- $file_info = (array) array_pop($files);
- $file_info['status'] = 0;
- $file = new File($file_info);
- $file->save();
- $fid = $file->fid;
- $file_info['attributes']['data-file-id'] = $fid;
- $image_string = theme('image', $file_info);
-
- $this->backdropGet('admin/structure/layouts/manage/default/add-block/editor/sidebar');
- $this->clickLink(t('Custom block'));
- $this->backdropPost(NULL, array(
- 'title' => 'Custom block test',
- 'content[value]' => '<p>Some content with an image in the middle.</p><p>' . $image_string . '</p><p>End of content.</p>',
- ), t('Add 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'];
-
-
-
- $usage = file_usage_list($file);
- $this->assertEqual($usage, array(), 'No file usages recorded (as correct) when adding block to layout.');
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- entity_get_controller('file')->resetCache();
- $file = file_load($fid);
- $references = file_usage_list($file);
- $this->assertEqual($references['file']['file'][$fid], 1, 'File usage recorded for the file within the block.');
- $this->assertEqual($file->status, 1, 'File has been marked permanent by its file usage.');
-
-
- $this->backdropGet('user');
- $this->assertRaw('Custom block test', 'Custom block found on front-end.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/default');
- $remove_link = $this->xpath('//*[@data-block-id=:uuid]//a[contains(@class,"remove-block")]', array(
- ':uuid' => $block_uuid,
- ));
- $remove_url_parts = backdrop_parse_url($remove_link[0]['href']);
- $this->backdropGet($remove_url_parts['path'], $remove_url_parts);
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- entity_get_controller('file')->resetCache();
- $file = file_load($fid);
- $references = file_usage_list($file);
- $this->assertEqual($references['file']['file'][$fid], 1, 'File usage is unaffected by removing the block from the layout.');
- $this->assertEqual($file->status, 1, 'File still exists and is marked as permanent after removing the block from the layout.');
- }
- }
-
- * Tests the interface for adding, removing, and moving blocks.
- */
- class LayoutCloneTest extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $admin_user;
-
- function setUp() {
- parent::setUp(array('layout', 'layout_test'));
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access content',
- 'access administration pages',
- 'administer layouts',
- 'view the administration theme',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
- function testLayoutClone() {
-
- $edit = array(
- 'title' => 'Test layout 1',
- 'name' => 'test_layout_1',
- 'layout_template' => 'boxton',
- 'path' => 'test-layout-1',
- );
- $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));
-
-
- $test_layout_1 = layout_load('test_layout_1');
- $test_layout_1->addBlock('layout_test', 'foo', 'content');
- $test_layout_1->addBlock('layout_test', 'foo', 'sidebar');
- $test_layout_1->save();
-
-
- $edit = array(
- 'title' => 'Test layout 2',
- 'name' => 'test_layout_2',
- );
- $this->backdropPost('admin/structure/layouts/manage/test_layout_1/clone', $edit, t('Clone layout'));
-
- $success_message = t('Cloned layout @title created. You may now configure the cloned layout.', array('@title' => 'Test layout 2'));
- $this->assertRaw($success_message);
-
- $edit = array(
- 'path' => 'test-layout-2',
- );
- $this->backdropPost(NULL, $edit, t('Save layout'));
- $this->backdropGet('admin/structure/layouts');
- $this->assertRaw('test_layout_1');
- $this->assertRaw('test_layout_2');
-
- $this->backdropGet('test-layout-1');
- $this->assertResponse(200);
- $this->assertRaw('Foo subject', 'Testing block is present on original layout');
-
- $this->backdropGet('test-layout-2');
- $this->assertRaw('Foo subject', 'Testing block is present on cloned layout.');
- $this->assertResponse(200);
- }
- }
-
- * Tests the upgrade path from block-based regions to layouts.
- */
- class LayoutUpgradePathTest extends UpgradePathTestCase {
-
-
- * Set up environment.
- */
- public function setUp() {
-
- $this->databaseDumpFiles = array(
- backdrop_get_path('module', 'simpletest') . '/tests/upgrade/drupal-7.filled.database.php.gz',
- backdrop_get_path('module', 'layout') . '/tests/layout_upgrade_database.php',
- );
- parent::setUp();
- }
-
-
- * Tests a successful upgrade, where block positions copied to layouts.
- */
- public function testLayoutUpgrade() {
- $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
-
- $this->backdropGet('user');
- $blocks = array(
- 'l-header' => array(
- 'block-system-header',
- 'block-system-main-menu',
- ),
- 'l-sidebar-first' => array(
- 'block-search-form',
- ),
- 'l-triptych-middle' => array(
- 'block-node-syndicate',
- ),
- 'l-footer-first-column' => array(
- 'block-system-main-menu',
- ),
- 'l-footer-second-column' => array(
- 'block-system-management',
- ),
- 'l-footer-third-column' => array(
- 'block-system-user-menu',
- ),
- 'l-footer-fourth-column' => array(
-
-
- ),
- 'l-footer' => array(
- 'block-system-powered-by'
- ),
- );
-
- $this->assertBlocks($blocks);
- $this->assertNoBlocks(array(
- 'l-footer-fourth-column' => array(
- 'block',
- ),
- ));
-
-
- $article_node = $this->backdropCreateNode(array(
- 'type' => 'article',
- 'title' => $this->randomString(),
- ));
- $this->backdropGet('node/' . $article_node->nid);
- $article_blocks = $blocks;
- $article_blocks['sidebar-second'][] = 'block-node-recent';
- $this->assertBlocks($article_blocks);
-
-
-
- $page_node = $this->backdropCreateNode(array(
- 'type' => 'page',
- 'title' => $this->randomString(),
- ));
- $this->backdropGet('node/' . $page_node->nid);
- $this->assertBlocks($blocks);
- $this->assertNoBlocks(array(
- 'l-sidebar-section' => array(
- 'block-node-recent'
- ),
- ));
-
-
- $profile_blocks = $blocks;
- $this->backdropGet('user/1');
- $this->assertBlocks($profile_blocks);
-
-
-
- $path_blocks = array(
- 'l-triptych-last' => array(
- 'block-comment-recent',
- ),
- );
- $this->backdropGet('<front>');
- $this->assertBlocks($path_blocks);
- $this->backdropGet('node/' . $article_node->nid);
- $this->assertBlocks($path_blocks);
- $this->backdropGet('user/1');
- $this->assertNoBlocks($path_blocks);
-
-
-
- $this->backdropLogout();
- $this->backdropGet('<front>');
- $this->assertNoBlocks(array(
- '.region-footer-thirdcolumn' => array(
- 'block-system-user-menu',
- ),
- ));
- }
-
- protected function assertBlocks($blocks, $negate = FALSE) {
- foreach ($blocks as $region => $block_classes) {
- $selector = '//*[contains(@class,:region)]//*[contains(@class,:block)]';
- foreach ($block_classes as $block_class) {
- $elements = $this->xpath($selector, array(
- ':region' => $region,
- ':block' => $block_class,
- ));
- if ($negate) {
- $this->assertEqual(count($elements), 0, format_string('The block "@class" was correctly NOT shown in the "@region" region on the path "@path".', array('@class' => $block_class, '@region' => $region, '@path' => $this->getUrl())));
- }
- else {
- $this->assertEqual(count($elements), 1, format_string('The block "@class" was found in the "@region" region on the path "@path".', array('@class' => $block_class, '@region' => $region, '@path' => $this->getUrl())));
- }
- }
- }
- }
-
- protected function assertNoBlocks($blocks) {
- $this->assertBlocks($blocks, TRUE);
- }
- }
-
- * Tests invocation of hooks when performing an action.
- *
- * Tested hooks are:
- * - hook_layout_presave
- * - hook_layout_insert
- * - hook_layout_update
- * - hook_layout_disable
- * - hook_layout_enable
- * - hook_layout_delete
- * - hook_layout_template_change
- * - hook_layout_revert
- */
- class LayoutHookTestCase extends BackdropWebTestCase {
- protected $admin_user;
- protected $profile = 'testing';
-
- function setUp() {
- parent::setUp('layout', 'layout_test');
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'administer layouts',
- ));
- $this->backdropLogin($this->admin_user);
-
- }
-
-
- * Checks the order of CRUD hook execution messages.
- *
- * layout_test.module implements all core layout CRUD hooks and
- * stores a message for each in state_get('layout_test').
- *
- * @param $messages
- * An array of plain-text messages in the order they should appear.
- */
- protected function assertHookMessageOrder($messages) {
- $positions = array();
- $state_get = state_get('layout_test');
- foreach ($messages as $message) {
-
- $position = array_search($message, $state_get);
- if ($this->assertTrue($position !== FALSE, $message)) {
- $positions[] = $position;
- }
- }
-
- $sorted = $positions;
- sort($sorted);
- $this->assertTrue($sorted == $positions, 'The hook messages appear in the correct order.');
- }
-
-
- * Tests hook invocations for operations on layouts.
- */
- public function testLayoutHooks() {
- state_set('layout_test', array());
-
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'layout-test-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
-
-
- $this->assertText(t('Layout created. Blocks may now be added to this layout.'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->assertHookMessageOrder(array(
- 'layout_test_layout_presave called',
- 'layout_test_layout_insert called',
- ));
-
- state_set('layout_test', array());
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->assertHookMessageOrder(array(
- 'layout_test_layout_presave called',
- 'layout_test_layout_update called',
- ));
-
-
- state_set('layout_test', array());
- $this->backdropGet('admin/structure/layouts');
- $disable_link = $this->xpath('//*[contains(@class, "disable")]//a');
- $disable_url_parts = backdrop_parse_url($disable_link[0]['href']);
- $this->backdropGet($disable_url_parts['path'], $disable_url_parts);
- $this->assertHookMessageOrder(array(
- 'layout_test_layout_disable called',
- ));
-
- state_set('layout_test', array());
-
-
- $this->backdropGet('admin/structure/layouts/manage');
- $enable_link = $this->xpath('//li[contains(@class, "enable")]//a');
- $enable_url_parts = backdrop_parse_url($enable_link[0]['href']);
- $this->backdropGet($enable_url_parts['path'], $enable_url_parts);
- $this->assertHookMessageOrder(array(
- 'layout_test_layout_enable called',
- ));
-
-
- state_set('layout_test', array());
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/delete', array(), t('Delete layout'));
- $this->assertHookMessageOrder(array(
- 'layout_test_layout_delete called',
- ));
-
-
-
- state_set('layout_test', array());
- $edit = array(
- 'layout_template' => 'boxton',
- );
- $this->backdropPost('admin/structure/layouts/manage/default/configure', $edit, t('Save layout'));
- $this->assertHookMessageOrder(array(
- 'layout_test_layout_template_change called',
- ));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- state_set('layout_test', array());
- $this->backdropPost('admin/structure/layouts/manage/default/delete', array(), t('Revert layout'));
- $this->assertHookMessageOrder(array(
- 'layout_test_layout_revert called',
- ));
- }
- }
-
-
- * Tests layout_get_block_usage().
- */
- class LayoutBlockUsageTestCase extends BackdropWebTestCase {
- protected $admin_user;
- protected $profile = 'testing';
-
- function setUp() {
- parent::setUp('layout', 'menu');
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'administer layouts',
- ));
- $this->backdropLogin($this->admin_user);
-
- }
-
-
- * Tests layout_get_block_usage().
- */
- public function testBlockUsage() {
-
-
-
- $this->checkBlockUsage('header', 'default', 'header');
-
-
- $this->checkBlockNoUsage('header', 'default', 'sidebar');
-
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
-
-
- $layout_name = 'block_usage_test_layout';
- $layout_title = 'Block usage test layout';
- $layout_url = 'layout-usage-test-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->checkBlockUsage('header', $layout_name, 'header');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $this->clickLink(t('Add block'), 0);
- $this->clickLink(t('Header block'));
- $this->backdropPost(NULL, array(), t('Add block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $count = $this->checkBlockUsage('header', $layout_name, 'header');
- $this->assertTrue($count == 2, 'Function returns two header blocks in this position.');
-
-
- $this->checkBlockNoUsage('header', $layout_name, 'sidebar');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $this->clickLink(t('Add block'), 3);
- $this->clickLink(t('Header block'));
- $this->backdropPost(NULL, array(), t('Add block'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->checkBlockUsage('header', $layout_name, 'sidebar');
- }
-
-
- * Checks block usage.
- */
- protected function checkBlockUsage($delta, $layout, $position) {
- backdrop_static_reset('layout_get_block_usage');
- layout_reset_caches();
- module_load_include('inc', 'layout', 'layout.admin');
- $usage = layout_get_block_usage();
- $this->assertTrue(isset($usage['system'][$delta][$layout][$position]), 'Block usage returned correctly. Block found in array.');
- if (isset($usage['system'][$delta][$layout][$position])) {
- return count($usage['system'][$delta][$layout][$position]);
- }
- return FALSE;
- }
-
-
- * Checks block not in usage.
- */
- protected function checkBlockNoUsage($delta, $layout, $position) {
- backdrop_static_reset('layout_get_block_usage');
- layout_reset_caches();
- module_load_include('inc', 'layout', 'layout.admin');
- $usage = layout_get_block_usage();
- $this->assertFalse(isset($usage[$delta][$layout][$position]), 'Block usage returned correctly. Block not found in array.');
- return TRUE;
- }
- }
-
- * Tests that the correct renderer is used.
- */
- class LayoutRendererTest extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $admin_user;
-
- function setUp() {
- parent::setUp(array('layout', 'layout_test'));
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access content',
- 'administer layouts',
- 'access user profiles',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Test that the correct renderer is used
- */
- function testRendererSelection() {
-
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
- $layout_name = strtolower($this->randomName());
- $layout_title = $this->randomString();
- $layout_url = 'layout-test-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($layout_url);
- $this->assertNoText('This layout uses the Test renderer');
-
- $test_layout = layout_get_layout_by_path($layout_url);
- $test_layout->renderer_name = 'test_renderer';
- $test_layout->save();
-
- $this->backdropGet($layout_url);
- $this->assertText('This layout uses the Test renderer');
-
-
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
- $layout_name = strtolower($this->randomName());
- $layout_title = $this->randomString();
- $layout_url = 'user/1';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => 'user/%',
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
- $this->backdropPost(NULL, array(), t('Save layout'));
-
- $this->backdropGet($layout_url);
- $this->assertNoText('This layout uses the Test renderer');
-
- $test_layout = layout_get_layout_by_path($layout_url);
- $test_layout->renderer_name = 'test_renderer';
- $test_layout->save();
-
- $this->backdropGet($layout_url);
- $this->assertText('This layout uses the Test renderer');
- }
- }
-
- * Tests the interface for flexible layouts.
- */
- class LayoutFlexibleTemplateTest extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $admin_user;
-
-
- * @var User
- */
- protected $no_flex_user;
-
- function setUp() {
- parent::setUp('layout', 'layout_test');
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access administration pages',
- 'administer site configuration',
- 'administer layouts',
- 'administer flexible templates',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Test that layout templates may be enabled and disabled.
- */
- function testLayoutFlexibleTemplates() {
- $this->backdropGet('admin/structure/layouts/settings');
- $this->clickLink(t('Add flexible layout template'));
-
-
- $template_name1 = $this->randomName();
- $template_machine_name1 = strtolower($template_name1);
- $template_description1 = $this->randomName();
-
- $edit = array(
- 'name' => $template_name1,
- 'machine_name' => $template_machine_name1,
- 'description' => $template_description1,
- );
- $this->backdropPost(NULL, $edit, t('Save and configure'));
- $this->assertText(t('Layout template "@title" saved.', array('@title' => $template_name1)));
-
-
- $all_templates = layout_get_layout_template_info();
- $this->assertTrue(isset($all_templates[$template_machine_name1]), 'The flexible template is found in the cache of templates.');
-
-
- $this->backdropGet('admin/structure/layouts/settings');
- $title = $this->xpath("//td//div[text()=:name]", array(':name' => $template_name1));
- $this->assertTrue($title, 'The flexible template is found in the UI list of templates.');
-
-
- $this->clickLink(t('Add flexible layout template'));
- $template_name2 = $this->randomName();
- $template_machine_name2 = strtolower($template_name2);
- $template_description2 = $this->randomName();
-
- $edit = array(
- 'name' => $template_name2,
- 'machine_name' => $template_machine_name2,
- 'description' => $template_description2,
- );
- $this->backdropPost(NULL, $edit, t('Save and configure'));
- $this->assertText(t('Layout template "@title" saved.', array('@title' => $template_name2)));
- $this->backdropGet('admin/structure/layouts/settings');
- $flexible_layout_edit_link = 'admin/structure/layouts/settings/flexible-template/' . $template_machine_name2 . '/edit';
- $edit = array(
- 'name' => 'To be deleted',
- 'description' => $template_description2,
- );
- $this->backdropPost($flexible_layout_edit_link, $edit, t('Save and configure'));
- $this->backdropGet('admin/structure/layouts/settings');
- $title = $this->xpath("//td//div[text()=:name]", array(':name' => 'To be deleted'));
- $this->assertTrue($title, 'The flexible template is found in the UI list of templates with the new name.');
- $flexible_layout_delete_link = 'admin/structure/layouts/settings/flexible-template/' . $template_machine_name2 . '/delete';
- $edit = array();
- $this->backdropPost($flexible_layout_delete_link, $edit, t('Delete template'));
- $this->backdropGet('admin/structure/layouts/settings');
- $title = $this->xpath("//td//div[text()=:name]", array(':name' => 'To be deleted'));
- $this->assertFalse($title, 'The flexible template is not found in the UI list of templates with the new name.');
-
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'layout-test-path';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => $template_machine_name1,
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
-
-
- $this->assertText(t('Layout created. Blocks may now be added to this layout.'));
-
-
- $this->clickLink(t('Add block'), 0);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 30,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->clickLink(t('Add block'), 1);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 15,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->clickLink(t('Add block'), 2);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 5,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
- $this->backdropGet('admin/structure/layouts');
- $this->assertText(check_plain($layout_title));
-
-
-
- $this->backdropGet($layout_url);
- $layout_template = layout_flexible_template_load($template_machine_name1);
- $layout_region_names = array_keys($layout_template->rows);
- $region_block_settings = array(
- $layout_region_names[0] => 30,
- $layout_region_names[1] => 15,
- $layout_region_names[2] => 5,
- );
- foreach ($region_block_settings as $region_name => $setting) {
- $string = format_string('The setting of count is @setting.', array('@setting' => $setting));
- $elements = $this->xpath('//*[contains(@class,:region)]//*[contains(text(),:string)]', array(
- ':region' => 'l-' . $region_name,
- ':string' => $string,
- ));
- $this->assertEqual(count($elements), 1, "The sample block was found in the $region_name region.");
- }
-
-
- $flexible_layout_configure_link = 'admin/structure/layouts/settings/flexible-template/' . $template_machine_name1 . '/configure';
- $this->backdropGet($flexible_layout_configure_link);
-
- $rows = $this->xpath("//*[@id=:id]//*[contains(@id, :row_id)]", array(':id' => 'layout-flexible-content', ':row_id' => 'flexible-row'));
- $this->assertEqual(count($rows), 3, 'Three rows are found in the template');
-
-
-
- $this->clickLink(t('Configure'), 0);
- $edit = array(
- 'region_names[region_0][label]' => 'New header',
- 'region_names[region_0][name]' => 'new-header-new',
- 'region_names[region_0][classes]' => 'blue-blue',
- 'region_names[region_0][region_class_enable]' => TRUE,
- 'row_classes' => 'new-class another-class',
- 'element' => 'main',
- 'container' => 'no_container',
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
-
- $header_row = $this->xpath("//main[contains(@id, :row_id)]//h2[text()=:row_title]", array(':row_id' => 'flexible-row--' . $layout_region_names[0], ':row_title' => 'New header'));
- $this->assertEqual(count($header_row), 1, 'The header row has been renamed in the template editor.');
-
- $this->backdropPost(NULL, array(), t('Save layout template'));
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $header_row = $this->xpath("//main[contains(@class, :row_class)]//h2[text()=:row_title]", array(':row_class' => 'l-' . $layout_region_names[0], ':row_title' => 'New header'));
- $this->assertEqual(count($header_row), 1, 'The header row has been renamed in the block add page.');
-
-
- $rows = $this->xpath("//div[contains(@class, :region_class)]", array(':region_class' => 'l-region--new-header-new blue-blue'));
- $this->assertEqual(count($rows), 1, 'The header region class has been renamed in the block add page.');
-
-
- $this->backdropGet($flexible_layout_configure_link);
- $this->clickLink(t('Configure'), 0);
- $edit = array(
- 'region_names[region_0][region_class_enable]' => FALSE,
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
- $this->backdropPost(NULL, array(), t('Save layout template'));
-
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $rows = $this->xpath("//div[contains(@class, :region_class)]", array(':region_class' => 'l-region--1 blue-blue'));
- $this->assertNotEqual(count($rows), 1, 'The header region class has no additional classes.');
-
-
-
- $this->backdropGet($layout_url);
-
- $string = format_string('The setting of count is @setting.', array('@setting' => 30));
- $elements = $this->xpath('//main[contains(@class,:region)]/div[contains(@class, :container_class)]//*[contains(text(),:string)]', array(
- ':region' => 'l-' . $layout_region_names[0],
- ':container_class' => 'no-container',
- ':string' => $string,
- ));
- $this->assertEqual(count($elements), 1, "The header element has been changed to 'main'");
-
-
- $flexible_layout_configure_link = 'admin/structure/layouts/settings/flexible-template/' . $template_machine_name1 . '/configure';
- $this->backdropGet($flexible_layout_configure_link);
- $this->backdropPost(NULL, array(), t('Add row'));
- $edit = array(
- 'region_count' => 3,
- );
- $this->backdropPost(NULL, $edit, t('Choose region widths'));
- $edit = array(
- 'region_style' => 'region_4_4_4',
- );
- $this->backdropPost(NULL, $edit, t('Continue'));
-
- $edit = array(
- 'region_names[region_0][label]' => 'First region',
-
- 'region_names[region_0][name]' => 'first-region',
- 'region_names[region_1][name]' => 'region-2',
- 'region_names[region_2][name]' => 'region-3',
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
- $this->backdropPost(NULL, array(), t('Save layout template'));
-
- $row_count = $this->xpath("//*[@id=:id]//*[contains(@id, :row_id)]", array(':id' => 'layout-flexible-content', ':row_id' => 'flexible-row'));
- $this->assertEqual(count($row_count), 4, 'Four rows are found in the template');
-
-
- $last_row_attr = $this->xpath('//div[contains(@class, :class)]/*[4]/@data-row-id', array(
- ':class' => 'layout-flexible-content',
- ));
- $data_row_id = (string) $last_row_attr[0][0];
- $last_row_id = 'flexible-row--' . $last_row_attr[0][0];
-
-
- $row_count = $this->xpath('//div[contains(@id, :id)]//div[contains(@class, :class)]/div', array(
- ':id' => $last_row_id,
- ':class' => 'l-flexible-row row',
- ));
- $this->assertEqual(count($row_count), 3, 'The last row has 3 regions.');
-
-
- $fourth_row_first_region_title = $this->xpath('//div[contains(@id, :id)]//div[contains(@class, :class)]/div[1]//h2[text()=:region_title]', array(
- ':id' => $last_row_id,
- ':class' => 'l-flexible-row row',
- ':region_title' => 'First region',
- ));
- $this->assertTrue($fourth_row_first_region_title, 'The region has the correct title.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
-
-
- $row_count = $this->xpath('//div[contains(@data-row-id, :id)]//div[contains(@class, :class)]/div', array(
- ':id' => $data_row_id,
- ':class' => 'l-flexible-row row',
- ));
- $this->assertEqual(count($row_count), 3, 'The last row has 3 regions.');
-
-
- $fourth_row_first_region_title = $this->xpath('//div[contains(@data-row-id, :id)]//div[contains(@class, :class)]/div[1]//h2[text()=:region_title]', array(
- ':id' => $data_row_id,
- ':class' => 'l-flexible-row row',
- ':region_title' => 'First region',
- ));
- $this->assertTrue($fourth_row_first_region_title, 'The region has the correct title.');
-
-
- $this->clickLink(t('Add block'), 3);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 19,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->clickLink(t('Add block'), 4);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 18,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->clickLink(t('Add block'), 5);
- $this->assertText(t('A testing block for layouts.'));
- $this->clickLink(t('Layout foo block'));
- $edit = array(
- 'block_settings[count]' => 17,
- );
- $this->backdropPost(NULL, $edit, t('Add block'));
-
-
- $this->backdropPost(NULL, array(), t('Save layout'));
-
-
-
- $this->backdropGet($layout_url);
- $region_block_settings = array('19', '18', '17');
- foreach ($region_block_settings as $index => $setting) {
- $string = format_string('The setting of count is @setting.', array('@setting' => $setting));
- $elements = $this->xpath('//*[contains(@data-row-id,:id)]//div[contains(@class,:row)]/div[:index]//div[normalize-space(text())=:string]', array(
- ':id' => $data_row_id,
- ':row' => 'l-flexible-row row',
- ':index' => $index + 1,
- ':string' => $string,
- ));
- $this->assertEqual(count($elements), 1, "The sample block was found in the correct region.");
- }
-
-
- $this->backdropGet($flexible_layout_configure_link);
- $edit = array(
- 'row_positions' => "{$layout_region_names[0]},{$layout_region_names[1]},$data_row_id,{$layout_region_names[2]}",
- );
- $this->backdropPost(NULL, $edit, t('Save layout template'));
- $last_row_attr = $this->xpath('//div[contains(@class, :class)]/*[4]/@data-row-id', array(
- ':class' => 'layout-flexible-content',
- ));
- $last_row_attr = (string) $last_row_attr[0][0];
- $this->assertEqual($last_row_attr, $layout_region_names[2], 'The last row is footer.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $last_row_attr = $this->xpath('//div[contains(@class, :class)]/*[4]/@data-row-id', array(
- ':class' => 'layout-flexible-content',
- ));
- $last_row_attr = (string) $last_row_attr[0][0];
- $this->assertEqual($last_row_attr, $layout_region_names[2], 'The last row is footer.');
-
-
- $this->backdropGet($layout_url);
- $last_row_attr = $this->xpath('//div[contains(@class, :class)]/*[4]/@data-row-id', array(
- ':class' => 'layout-flexible-content',
- ));
- $last_row_attr = (string) $last_row_attr[0][0];
- $this->assertEqual($last_row_attr, $layout_region_names[2], 'The last row is footer.');
-
-
- $this->backdropGet($flexible_layout_configure_link);
- $this->clickLink(t('Delete row'), 3);
- $this->backdropPost(NULL, array(), t('Save layout template'));
-
-
- $rows = $this->xpath("//*[@id=:id]//*[contains(@id, :row_id)]", array(':id' => 'layout-flexible-content', ':row_id' => 'flexible-row'));
- $this->assertEqual(count($rows), 3, 'Three rows are found in the template');
-
- $last_row_attr = $this->xpath('//div[contains(@class, :class)]/*[last()]/@data-row-id', array(
- ':class' => 'layout-flexible-content',
- ));
- $last_row_attr = (string) $last_row_attr[0][0];
- $this->assertEqual($last_row_attr, $data_row_id, 'The last row is the new row.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $last_row_attr = $this->xpath('//div[contains(@class, :class)]/*[last()]/@data-row-id', array(
- ':class' => 'layout-flexible-content',
- ));
- $last_row_attr = (string) $last_row_attr[0][0];
- $this->assertEqual($last_row_attr, $data_row_id, 'The last row is the new row.');
-
-
- $this->backdropGet($layout_url);
- $last_row_attr = $this->xpath('//div[contains(@class, :class)]/*[last()]/@data-row-id', array(
- ':class' => 'layout-flexible-content',
- ));
- $last_row_attr = (string) $last_row_attr[0][0];
- $this->assertEqual($last_row_attr, $data_row_id, 'The last row is the new row.');
-
-
-
- $this->no_flex_user = $this->backdropCreateUser(array(
- 'access administration pages',
- 'administer site configuration',
- 'administer layouts',
- ));
- $this->backdropLogin($this->no_flex_user);
-
- $this->backdropGet('admin/structure/layouts/settings');
- $this->assertNoLink(t('Add flexible layout template'));
- $this->assertNoLink(t('Configure regions'));
-
-
-
- $flexible_layout_configure_link = 'admin/structure/layouts/settings/flexible-template/' . $template_machine_name1 . '/configure';
- $this->backdropGet($flexible_layout_configure_link);
- $this->assertResponse(403, 'Access not allowed to flexible layout configuration pages without permission.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
- $this->backdropPost(NULL, array(), t('Save layout'));
- }
-
- }
-
- * Tests that default layout paths are handled properly.
- */
- class LayoutPathTest extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $admin_user;
-
-
- * Set up environment.
- */
- public function setUp() {
- parent::setUp(array('layout_test'));
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access content',
- 'administer layouts',
- 'access user profiles',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Tests that null paths (in default layouts) don't cause problems.
- */
- public function testLayoutPath() {
- $layouts = layout_load_multiple_by_path('');
- $default_layout = $layouts['default'];
- $path = $default_layout->getPath();
- $this->assertNull($path, 'Default layout path is NULL.');
-
-
- backdrop_static_reset('path_is_admin');
- $result = path_is_admin($path);
- $this->assertFalse($result, 'Default layout is not an admin path.');
-
-
- backdrop_match_path($path, "foo\nbar");
- }
- }
-
- * Tests that ensures deletion messages are appropriate if layout page has
- * any special role.
- */
- class LayoutDeletionTest extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $admin_user;
-
-
- * Set up environment.
- */
- public function setUp() {
- parent::setUp(array('layout_test'));
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access content',
- 'administer layouts',
- 'access user profiles',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Tests that layouts that have special roles issue warning messages upon
- * attempted deletion.
- */
- public function testLayoutDeletion() {
-
-
- $this->backdropGet('admin/structure/layouts');
- $this->clickLink(t('Add layout'));
-
-
- $layout_title = $this->randomName();
- $layout_name = strtolower($layout_title);
- $layout_url = 'a-special-layout';
- $edit = array(
- 'title' => $layout_title,
- 'name' => $layout_name,
- 'layout_template' => 'moscone_flipped',
- 'path' => $layout_url,
- );
- $this->backdropPost(NULL, $edit, t('Create layout'));
- layout_reset_caches();
-
- $deletion_path = 'admin/structure/layouts/manage/' . $layout_name . '/delete';
-
-
-
- $this->backdropGet($deletion_path);
- $this->assertNoText(format_string('This layout creates a page at @path', array('@path' => $layout_url)));
-
-
-
- config_set('system.core', 'site_frontpage', $layout_url);
- $this->backdropGet($deletion_path);
- $this->assertText(format_string('This layout creates a page at @path that is used as the home page of the site.', array('@path' => $layout_url)));
- config_set('system.core', 'site_frontpage', '');
-
-
-
- config_set('system.core', 'site_403', $layout_url);
- $this->backdropGet($deletion_path);
- $this->assertText(format_string('This layout creates a page at @path that is used as the default 403 (access denied) page of the site.', array('@path' => $layout_url)));
- config_set('system.core', 'site_403', '');
-
-
-
- config_set('system.core', 'site_404', $layout_url);
- $this->backdropGet($deletion_path);
- $this->assertText(format_string('This layout creates a page at @path that is used as the default 404 (not found) page of the site.', array('@path' => $layout_url)));
- config_set('system.core', 'site_404', '');
- }
- }
-