3 namespace Drupal\Tests\ctools\Unit;
5 use Drupal\Component\Uuid\UuidInterface;
6 use Drupal\ctools\Plugin\BlockPluginCollection;
7 use Drupal\ctools\Plugin\BlockVariantTrait;
8 use Drupal\Tests\UnitTestCase;
11 * Tests the methods of a block-based variant.
13 * @coversDefaultClass \Drupal\ctools\Plugin\BlockVariantTrait
17 class BlockVariantTraitTest extends UnitTestCase {
20 * Tests the getRegionAssignments() method.
22 * @covers ::getRegionAssignments
24 * @dataProvider providerTestGetRegionAssignments
26 public function testGetRegionAssignments($expected, $blocks = []) {
27 $block_collection = $this->prophesize(BlockPluginCollection::class);
28 $block_collection->getAllByRegion()
32 $display_variant = new TestBlockVariantTrait();
33 $display_variant->setBlockPluginCollection($block_collection->reveal());
35 $this->assertSame($expected, $display_variant->getRegionAssignments());
38 public function providerTestGetRegionAssignments() {
79 class TestBlockVariantTrait {
80 use BlockVariantTrait;
85 protected $blockConfig = [];
88 * @var \Drupal\Component\Uuid\UuidInterface
90 protected $uuidGenerator;
93 * @param BlockPluginCollection $block_plugin_collection
97 public function setBlockPluginCollection(BlockPluginCollection $block_plugin_collection) {
98 $this->blockPluginCollection = $block_plugin_collection;
103 * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator
107 public function setUuidGenerator(UuidInterface $uuid_generator) {
108 $this->uuidGenerator = $uuid_generator;
115 protected function uuidGenerator() {
116 return $this->uuidGenerator;
120 * Sets the block configuration.
122 * @param array $config
123 * The block configuration.
127 public function setBlockConfig(array $config) {
128 $this->blockConfig = $config;
135 protected function getBlockConfig() {
136 return $this->blockConfig;
142 public function getRegionNames() {
145 'bottom' => 'Bottom',