c9281070b26487612ff00a9c7c4c0520aa7a0aca
[yaffs-website] / web / modules / contrib / ctools / tests / src / Unit / BlockPluginCollectionTest.php
1 <?php
2
3 namespace Drupal\Tests\ctools\Unit;
4
5 use Drupal\Core\Block\BlockManagerInterface;
6 use Drupal\Core\Block\BlockPluginInterface;
7 use Drupal\ctools\Plugin\BlockPluginCollection;
8 use Drupal\Tests\UnitTestCase;
9 use Prophecy\Argument;
10
11 /**
12  * Tests the block plugin collection.
13  *
14  * @coversDefaultClass \Drupal\ctools\Plugin\BlockPluginCollection
15  *
16  * @group CTools
17  */
18 class BlockPluginCollectionTest extends UnitTestCase {
19
20   /**
21    * Tests the getAllByRegion() method.
22    *
23    * @covers ::getAllByRegion
24    */
25   public function testGetAllByRegion() {
26     $blocks = [
27       'foo' => [
28         'id' => 'foo',
29         'label' => 'Foo',
30         'plugin' => 'system_powered_by_block',
31         'region' => 'bottom',
32       ],
33       'bar' => [
34         'id' => 'bar',
35         'label' => 'Bar',
36         'plugin' => 'system_powered_by_block',
37         'region' => 'top',
38       ],
39       'bing' => [
40         'id' => 'bing',
41         'label' => 'Bing',
42         'plugin' => 'system_powered_by_block',
43         'region' => 'bottom',
44         'weight' => -10,
45       ],
46       'baz' => [
47         'id' => 'baz',
48         'label' => 'Baz',
49         'plugin' => 'system_powered_by_block',
50         'region' => 'bottom',
51       ],
52     ];
53     $block_manager = $this->prophesize(BlockManagerInterface::class);
54     $plugins = [];
55     foreach ($blocks as $block_id => $block) {
56       $plugin = $this->prophesize(BlockPluginInterface::class);
57       $plugin->label()->willReturn($block['label']);
58       $plugin->getConfiguration()->willReturn($block);
59       $plugins[$block_id] = $plugin->reveal();
60
61       $block_manager->createInstance($block_id, $block)
62         ->willReturn($plugin->reveal())
63         ->shouldBeCalled();
64     }
65
66
67     $block_plugin_collection = new BlockPluginCollection($block_manager->reveal(), $blocks);
68     $expected = [
69       'bottom' => [
70         'bing' => $plugins['bing'],
71         'baz' => $plugins['baz'],
72         'foo' => $plugins['foo'],
73       ],
74       'top' => [
75         'bar' => $plugins['bar'],
76       ],
77     ];
78     $this->assertSame($expected, $block_plugin_collection->getAllByRegion());
79   }
80
81 }