class StandardDisplayBuilderTest in Panels 8.4
Same name and namespace in other branches
- 8.3 tests/src/Unit/StandardDisplayBuilderTest.php \Drupal\Tests\panels\Unit\StandardDisplayBuilderTest
@coversDefaultClass \Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder @group Panels
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\panels\Unit\StandardDisplayBuilderTest
Expanded class hierarchy of StandardDisplayBuilderTest
File
- tests/
src/ Unit/ StandardDisplayBuilderTest.php, line 18
Namespace
Drupal\Tests\panels\UnitView source
class StandardDisplayBuilderTest extends UnitTestCase {
/**
* @var \Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder
*/
protected $builder;
/**
* {@inheritdoc}
*/
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);
}
/**
* @covers ::build
*/
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());
// Ensure that regions get the proper prefix and suffix.
$this
->assertEquals('<div class="block-region-content">', $build['content']['#prefix']);
$this
->assertEquals('</div>', $build['content']['#suffix']);
// Ensure that blocks which allowed access showed up...
$this
->assertEquals('Foo!', $build['content']['foo']['content']['#markup']);
$this
->assertEquals('Bar...', $build['sidebar']['bar']['content']['#markup']);
// ...and that blocks which disallowed access did not.
$this
->assertArrayNotHasKey('baz', $build['sidebar']);
// Ensure that empty regions don't show up in $build.
$this
->assertArrayNotHasKey('footer', $build);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
StandardDisplayBuilderTest:: |
protected | property | ||
StandardDisplayBuilderTest:: |
public | function |
Overrides UnitTestCase:: |
|
StandardDisplayBuilderTest:: |
public | function | @covers ::build | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |