View source
<?php
namespace Drupal\Tests\ctools\Unit;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\ctools\Plugin\BlockPluginCollection;
use Drupal\ctools\Plugin\BlockVariantTrait;
use Drupal\Tests\UnitTestCase;
class BlockVariantTraitTest extends UnitTestCase {
public function testGetRegionAssignments($expected, $blocks = []) {
$block_collection = $this
->prophesize(BlockPluginCollection::class);
$block_collection
->getAllByRegion()
->willReturn($blocks)
->shouldBeCalled();
$display_variant = new TestBlockVariantTrait();
$display_variant
->setBlockPluginCollection($block_collection
->reveal());
$this
->assertSame($expected, $display_variant
->getRegionAssignments());
}
public function providerTestGetRegionAssignments() {
return [
[
[
'top' => [],
'bottom' => [],
],
],
[
[
'top' => [
'foo',
],
'bottom' => [],
],
[
'top' => [
'foo',
],
],
],
[
[
'top' => [],
'bottom' => [],
],
[
'invalid' => [
'foo',
],
],
],
[
[
'top' => [],
'bottom' => [
'foo',
],
],
[
'bottom' => [
'foo',
],
'invalid' => [
'bar',
],
],
],
];
}
}
class TestBlockVariantTrait {
use BlockVariantTrait;
protected $blockConfig = [];
protected $uuidGenerator;
public function setBlockPluginCollection(BlockPluginCollection $block_plugin_collection) {
$this->blockPluginCollection = $block_plugin_collection;
return $this;
}
public function setUuidGenerator(UuidInterface $uuid_generator) {
$this->uuidGenerator = $uuid_generator;
return $this;
}
protected function uuidGenerator() {
return $this->uuidGenerator;
}
public function setBlockConfig(array $config) {
$this->blockConfig = $config;
return $this;
}
protected function getBlockConfig() {
return $this->blockConfig;
}
public function getRegionNames() {
return [
'top' => 'Top',
'bottom' => 'Bottom',
];
}
}