1 layout.test | protected LayoutInterfaceTest::assertBlocksMatch($layout, $copied_from_layout, $orphaned_uuids = array()) |
Check that all the blocks in $layout match those in $copied_from_layout.
File
- core/
modules/ layout/ tests/ layout.test, line 1931 - Tests for the Layout module.
Class
- LayoutInterfaceTest
- Tests the interface for adding, removing, and moving blocks.
Code
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) {
// Don't compare if it's the default region since orphaned blocks might
// get reassigned here, which throws off the numbers.
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 this is the system main block, it may not exist in the new
// layout if the new layout creates a new path instead of overriding
// an existing one. If we encounter the default block, allow it to be
// skipped.
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)));
}
}
}