StandardDisplayBuilderTest.php in Panels 8.4
File
tests/src/Unit/StandardDisplayBuilderTest.php
View source
<?php
namespace Drupal\Tests\panels\Unit;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\Context\ContextHandlerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder;
use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
class StandardDisplayBuilderTest extends UnitTestCase {
protected $builder;
public function setUp() {
$context_handler = $this
->prophesize(ContextHandlerInterface::class)
->reveal();
$account = $this
->prophesize(AccountInterface::class)
->reveal();
$module_handler = $this
->prophesize(ModuleHandlerInterface::class)
->reveal();
$this->builder = new StandardDisplayBuilder(array(), 'standard', array(), $context_handler, $account, $module_handler);
}
public function testBuild() {
$regions = array();
$block = $this
->prophesize(BlockPluginInterface::class);
$block
->access(Argument::type(AccountInterface::class))
->willReturn(TRUE);
$block
->getConfiguration()
->willReturn([]);
$block
->getPluginId()
->willReturn('foo');
$block
->getBaseId()
->willReturn('foo');
$block
->getDerivativeId()
->willReturn('foo');
$block
->build()
->willReturn([
'#markup' => 'Foo!',
]);
$regions['content']['foo'] = $block
->reveal();
$block = $this
->prophesize(BlockPluginInterface::class);
$block
->access(Argument::type(AccountInterface::class))
->willReturn(TRUE);
$block
->getConfiguration()
->willReturn([]);
$block
->getPluginId()
->willReturn('bar');
$block
->getBaseId()
->willReturn('bar');
$block
->getDerivativeId()
->willReturn('bar');
$block
->build()
->willReturn([
'#markup' => 'Bar...',
]);
$regions['sidebar']['bar'] = $block
->reveal();
$block = $this
->prophesize(BlockPluginInterface::class);
$block
->access(Argument::type(AccountInterface::class))
->willReturn(FALSE);
$regions['sidebar']['baz'] = $block
->reveal();
$regions['footer'] = array();
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$panels_display
->getRegionAssignments()
->willReturn($regions);
$panels_display
->getContexts()
->willReturn([]);
$panels_display
->getLayout()
->willReturn(NULL);
$build = $this->builder
->build($panels_display
->reveal());
$this
->assertEquals('<div class="block-region-content">', $build['content']['#prefix']);
$this
->assertEquals('</div>', $build['content']['#suffix']);
$this
->assertEquals('Foo!', $build['content']['foo']['content']['#markup']);
$this
->assertEquals('Bar...', $build['sidebar']['bar']['content']['#markup']);
$this
->assertArrayNotHasKey('baz', $build['sidebar']);
$this
->assertArrayNotHasKey('footer', $build);
}
}