class PrintableLinkBlockTest in Printer and PDF versions for Drupal 8+ 8
Same name and namespace in other branches
- 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
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\printable\Unit\Plugin\Block\PrintableLinkBlockTest
Expanded class hierarchy of PrintableLinkBlockTest
File
- tests/
src/ Unit/ Plugin/ Block/ PrintableLinkBlockTest.php, line 13
Namespace
Drupal\Tests\printable\Unit\Plugin\BlockView 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
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. | |
PrintableLinkBlockTest:: |
protected | property | ||
PrintableLinkBlockTest:: |
protected | property | ||
PrintableLinkBlockTest:: |
protected | property | ||
PrintableLinkBlockTest:: |
public static | function | ||
PrintableLinkBlockTest:: |
public | function | Tests the block build method. | |
PrintableLinkBlockTest:: |
public | function | ||
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. | |
UnitTestCase:: |
protected | function | 340 |