You are here

class PrintableLinkBlockTest 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

Tests the printable links block plugin.

@group Printable

Hierarchy

Expanded class hierarchy of PrintableLinkBlockTest

File

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

Namespace

Drupal\Tests\printable\Unit\Plugin\Block
View source
class PrintableLinkBlockTest extends UnitTestCase {
  protected $configuration = [];
  protected $pluginId;
  protected $pluginDefinition = [];

  /**
   * {@inheritdoc}
   */
  public function __construct() {
    parent::__construct();
    $this->pluginId = 'printable_links_block:node';
    $this->pluginDefinition['module'] = 'printable';
    $this->pluginDefinition['provider'] = '';
  }

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return [
      'name' => 'Printable Block',
      'descriptions' => 'Tests the printable block plugin class.',
      'group' => 'Printable',
    ];
  }

  /**
   * Tests the block build method.
   *
   * @covers PrintableLinksBlock::build
   */
  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());
  }

}

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.
PrintableLinkBlockTest::$configuration protected property
PrintableLinkBlockTest::$pluginDefinition protected property
PrintableLinkBlockTest::$pluginId protected property
PrintableLinkBlockTest::getInfo public static function
PrintableLinkBlockTest::testBuild public function Tests the block build method.
PrintableLinkBlockTest::__construct public function
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.
UnitTestCase::setUp protected function 340