You are here

public function PrintableLinkBlockTest::testBuild in Printer and PDF versions for Drupal 8+ 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/Plugin/Block/PrintableLinkBlockTest.php \Drupal\Tests\printable\Unit\Plugin\Block\PrintableLinkBlockTest::testBuild()

Tests the block build method.

@covers PrintableLinksBlock::build

File

tests/src/Unit/Plugin/Block/PrintableLinkBlockTest.php, line 47

Class

PrintableLinkBlockTest
Tests the printable links block plugin.

Namespace

Drupal\Tests\printable\Unit\Plugin\Block

Code

public function testBuild() {
  $routematch = $this
    ->getMockBuilder('Drupal\\Core\\Routing\\CurrentRouteMatch')
    ->disableOriginalConstructor()
    ->setMethods([
    'getMasterRouteMatch',
    'getParameter',
  ])
    ->getMock();
  $routematch
    ->expects($this
    ->exactly(2))
    ->method('getMasterRouteMatch')
    ->will($this
    ->returnSelf());
  $routematch
    ->expects($this
    ->exactly(2))
    ->method('getParameter')
    ->will($this
    ->returnValue($this
    ->getMock('Drupal\\Core\\Entity\\EntityInterface')));
  $links = [
    'title' => 'Print',
    'url' => '/foo/1/printable/print',
    'attributes' => [
      'target' => '_blank',
    ],
  ];
  $links_builder = $this
    ->getMockBuilder('Drupal\\printable\\PrintableLinkBuilderInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $links_builder
    ->expects($this
    ->once())
    ->method('buildLinks')
    ->will($this
    ->returnValue($links));
  $block = new PrintableLinksBlock($this->configuration, $this->pluginId, $this->pluginDefinition, $routematch, $links_builder);
  $expected_build = [
    '#theme' => 'links__entity__printable',
    '#links' => $links,
  ];
  $this
    ->assertEquals($expected_build, $block
    ->build());
}