Esempio n. 1
0
 /**
  * Tests the retrieval of block entities that are context-aware.
  *
  * @covers ::getVisibleBlocksPerRegion
  */
 public function testGetVisibleBlocksPerRegionWithContext()
 {
     $block = $this->getMock('Drupal\\block\\BlockInterface');
     $block->expects($this->once())->method('setContexts')->willReturnSelf();
     $block->expects($this->once())->method('access')->willReturn(TRUE);
     $block->expects($this->once())->method('getRegion')->willReturn('top');
     $blocks['block_id'] = $block;
     $contexts = [];
     $this->blockStorage->expects($this->once())->method('loadByProperties')->with(['theme' => $this->theme])->willReturn($blocks);
     $result = [];
     foreach ($this->blockRepository->getVisibleBlocksPerRegion($contexts) as $region => $resulting_blocks) {
         $result[$region] = [];
         foreach ($resulting_blocks as $plugin_id => $block) {
             $result[$region][] = $plugin_id;
         }
     }
     $expected = ['top' => ['block_id'], 'center' => [], 'bottom' => []];
     $this->assertSame($expected, $result);
 }
 /**
  * Tests the retrieval of block entities that are context-aware.
  *
  * @covers ::getVisibleBlocksPerRegion
  */
 public function testGetVisibleBlocksPerRegionWithContext()
 {
     $block = $this->getMock('Drupal\\block\\BlockInterface');
     $block->expects($this->once())->method('access')->willReturn(AccessResult::allowed()->addCacheTags(['config:block.block.block_id']));
     $block->expects($this->once())->method('getRegion')->willReturn('top');
     $blocks['block_id'] = $block;
     $this->blockStorage->expects($this->once())->method('loadByProperties')->with(['theme' => $this->theme])->willReturn($blocks);
     $result = [];
     $cacheable_metadata = [];
     foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheable_metadata) as $region => $resulting_blocks) {
         $result[$region] = [];
         foreach ($resulting_blocks as $plugin_id => $block) {
             $result[$region][] = $plugin_id;
         }
     }
     $expected = ['top' => ['block_id'], 'center' => [], 'bottom' => []];
     $this->assertSame($expected, $result);
     // Assert that the cacheable metadata from the block access results was
     // collected.
     $this->assertEquals(['config:block.block.block_id'], $cacheable_metadata['top']->getCacheTags());
 }