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,
));
}
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'));
}
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');
}
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.');
}
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'));
}
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.');
}
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.');
}
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.');
}
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.');
}
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)));
}
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.');
}
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();
}
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.');
}
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.');
}
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.');
}
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',
);
$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.');
}
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.');
}
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.'));
}
protected function assertBlocksMatch($layout, $copied_from_layout, $orphaned_uuids = array()) {
$layout_info = layout_get_layout_template_info($layout->layout_template);
$default_region = $layout_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)));
}
}
}
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.'));
}
}