/**
  * 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());
 }
示例#2
0
 /**
  * @covers ::render
  * @covers ::defineOptions
  * @covers ::init
  */
 public function testRenderWithUuid()
 {
     $this->setupEntityManager();
     $uuid = '1d52762e-b9d8-4177-908f-572d1a5845a4';
     $options = ['target' => $uuid, 'tokenize' => FALSE];
     $entity = $this->getMock('Drupal\\Core\\Entity\\EntityInterface');
     $entity->expects($this->once())->method('access')->willReturn(TRUE);
     $this->entityStorage->expects($this->never())->method('load');
     $this->entityManager->expects($this->once())->method('loadEntityByConfigTarget')->willReturn($entity);
     $this->entityViewBuilder->expects($this->once())->method('view')->with($entity, 'default')->willReturn(['#markup' => 'hallo']);
     $this->entityHandler->init($this->executable, $this->display, $options);
     $result = $this->entityHandler->render();
     $this->assertEquals(['#markup' => 'hallo'], $result);
 }
示例#3
0
 /**
  * Tests the building of a full page variant.
  *
  * @covers ::build
  *
  * @dataProvider providerBuild
  */
 public function testBuild(array $blocks_config, $visible_block_count, array $expected_render_array)
 {
     $display_variant = $this->setUpDisplayVariant();
     $display_variant->setMainContent(['#markup' => 'Hello kittens!']);
     $blocks = ['top' => [], 'center' => [], 'bottom' => []];
     $block_plugin = $this->getMock('Drupal\\Core\\Block\\BlockPluginInterface');
     $main_content_block_plugin = $this->getMock('Drupal\\Core\\Block\\MainContentBlockPluginInterface');
     $messages_block_plugin = $this->getMock('Drupal\\Core\\Block\\MessagesBlockPluginInterface');
     foreach ($blocks_config as $block_id => $block_config) {
         $block = $this->getMock('Drupal\\block\\BlockInterface');
         $block->expects($this->atLeastOnce())->method('getPlugin')->willReturn($block_config[1] ? $main_content_block_plugin : ($block_config[2] ? $messages_block_plugin : $block_plugin));
         $blocks[$block_config[0]][$block_id] = $block;
     }
     $this->blockViewBuilder->expects($this->exactly($visible_block_count))->method('view')->will($this->returnValue(array()));
     $this->blockRepository->expects($this->once())->method('getVisibleBlocksPerRegion')->will($this->returnValue($blocks));
     $this->assertSame($expected_render_array, $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());
 }