/** * Tests the building of a full page variant. * * @covers ::build * @covers ::getRegionAssignments */ public function testBuild() { $theme = $this->randomMachineName(); $display_variant = $this->setUpDisplayVariant(); $this->themeNegotiator->expects($this->any())->method('determineActiveTheme')->with($this->routeMatch)->will($this->returnValue($theme)); $display_variant->expects($this->once())->method('getRegionNames')->will($this->returnValue(array('top' => 'Top', 'bottom' => 'Bottom'))); $blocks_config = array('block1' => array(TRUE, 'top', 0), 'block2' => array(FALSE, 'bottom', 0), 'block3' => array(TRUE, 'bottom', 5), 'block4' => array(TRUE, 'bottom', -5)); $blocks = array(); foreach ($blocks_config as $block_id => $block_config) { $block = $this->getMock('Drupal\\block\\BlockInterface'); $block->expects($this->once())->method('access')->will($this->returnValue($block_config[0])); $block->expects($this->any())->method('get')->will($this->returnValueMap(array(array('region', $block_config[1]), array('weight', $block_config[2]), array('status', TRUE)))); $blocks[$block_id] = $block; } $this->blockViewBuilder->expects($this->exactly(3))->method('view')->will($this->returnValue(array())); $this->blockStorage->expects($this->once())->method('loadByProperties')->with(array('theme' => $theme))->will($this->returnValue($blocks)); $expected = array('top' => array('block1' => array(), '#sorted' => TRUE), 'bottom' => array('block4' => array(), 'block3' => array(), '#sorted' => TRUE)); $this->assertSame($expected, $display_variant->build()); }
/** * Tests the building of a full page variant. * * @covers ::build * @covers ::getRegionAssignments * * @dataProvider providerBuild */ public function testBuild(array $blocks_config, $visible_block_count, array $expected_render_array) { $theme = $this->randomMachineName(); $display_variant = $this->setUpDisplayVariant(); $this->themeNegotiator->expects($this->any())->method('determineActiveTheme')->with($this->routeMatch)->will($this->returnValue($theme)); $display_variant->expects($this->once())->method('getRegionNames')->will($this->returnValue(array('top' => 'Top', 'center' => 'Center', 'bottom' => 'Bottom'))); $display_variant->setMainContent(['#markup' => 'Hello kittens!']); $blocks = array(); $block_plugin = $this->getMock('Drupal\\Core\\Block\\BlockPluginInterface'); $main_content_block_plugin = $this->getMock('Drupal\\Core\\Block\\MainContentBlockPluginInterface'); foreach ($blocks_config as $block_id => $block_config) { $block = $this->getMock('Drupal\\block\\BlockInterface'); $block->expects($this->once())->method('access')->will($this->returnValue($block_config[0])); $block->expects($this->any())->method('get')->will($this->returnValueMap(array(array('region', $block_config[1]), array('weight', $block_config[2]), array('status', TRUE)))); $block->expects($this->any())->method('getPlugin')->willReturn($block_config[3] ? $main_content_block_plugin : $block_plugin); $blocks[$block_id] = $block; } $this->blockViewBuilder->expects($this->exactly($visible_block_count))->method('view')->will($this->returnValue(array())); $this->blockStorage->expects($this->once())->method('loadByProperties')->with(array('theme' => $theme))->will($this->returnValue($blocks)); $this->assertSame($expected_render_array, $display_variant->build()); }