Test the various block remapping scenarios allowed for by the assorted Display types.
This includes remapping a Display's blocks to a new layout, binding an UnboundDisplay with a layout to generate a new Display, and releasing a Display from its layout binding to generate an UnboundDisplay.
public function testBlockMapping() {
// Remap from twocol to onecol. All blocks are expected to move to the one
// and only region and be sorted by their original weights.
$expected = array(
'middle' => array(
'block.test_block_3',
'block.test_block_2',
'block.test_block_1',
),
);
$two_to_one = clone $this->twocol;
$two_to_one
->remapToLayout($this->onecol
->getLayoutInstance());
$this
->assertIdentical($two_to_one
->getAllSortedBlocks(), $expected);
// Remap from onecol to twocol. Since the blocks are assigned the 'content'
// region type, and twocol's 'left' region has that type, the blocks are
// expected to move to there and be sorted by their original weights.
$expected = array(
'left' => array(
'block.test_block_2',
'block.test_block_1',
),
'right' => array(),
);
$one_to_two = clone $this->onecol;
$one_to_two
->remapToLayout($this->twocol
->getLayoutInstance());
$this
->assertIdentical($one_to_two
->getAllSortedBlocks(), $expected);
// Bind the unbound display to the twocol layout:
// - Block 1 is assigned the 'content' region type, so is expected to be
// mapped to the 'left' region, which has that type.
// - Block 2 is assigned the 'aside' region type, so is expected to be
// mapped to the 'right' region, which has that type.
// - Block 3 is assigned the 'nav' region type, and there is no twocol
// region with that type, so it is expected to be mapped to twocol's
// first region, which is 'left'.
$expected = array(
'left' => array(
'block.test_block_1',
'block.test_block_3',
),
'right' => array(
'block.test_block_2',
),
);
$unbound_to_twocol = $this->unbound
->generateDisplay($this->twocol
->getLayoutInstance(), 'unbound_to_twocol');
$this
->assertTrue($unbound_to_twocol instanceof Display, 'Binding the unbound display successfully created a Display object');
$this
->assertIdentical($unbound_to_twocol
->getAllSortedBlocks(), $expected);
// Generate an unbound display from the twocol display.
$expected = array(
'block.test_block_1' => array(
'region-type' => 'content',
'weight' => 100,
),
'block.test_block_2' => array(
'region-type' => 'aside',
'weight' => 0,
),
'block.test_block_3' => array(
'region-type' => 'content',
'weight' => -100,
),
);
$twocol_to_unbound = $this->twocol
->generateUnboundDisplay('twocol_to_unbound');
$this
->assertTrue($twocol_to_unbound instanceof UnboundDisplay, 'Unbinding the twocol display successfully created an UnboundDisplay object');
// We can use Equal instead of Identical, because for this, array order and
// integer vs. string data types do not matter.
$this
->assertEqual($twocol_to_unbound
->getAllBlockInfo(), $expected);
}