You are here

class StandardDisplayBuilderTest in Panels 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/StandardDisplayBuilderTest.php \Drupal\Tests\panels\Unit\StandardDisplayBuilderTest

@coversDefaultClass \Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder @group Panels

Hierarchy

Expanded class hierarchy of StandardDisplayBuilderTest

File

tests/src/Unit/StandardDisplayBuilderTest.php, line 18

Namespace

Drupal\Tests\panels\Unit
View 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

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
StandardDisplayBuilderTest::$builder protected property
StandardDisplayBuilderTest::setUp public function Overrides UnitTestCase::setUp
StandardDisplayBuilderTest::testBuild public function @covers ::build
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.