PrintLinkTest.php in Entity Print 8.2
File
tests/src/Kernel/PrintLinkTest.php
View source
<?php
namespace Drupal\Tests\entity_print\Kernel;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\block\Traits\BlockCreationTrait;
class PrintLinkTest extends KernelTestBase {
use BlockCreationTrait;
public static $modules = [
'system',
'block',
'entity_print',
];
public function testPlaceBlock() {
$this
->placeBlock('print_links');
$this
->assertTrue(TRUE);
}
public function testBuildLinks() {
$build = $this
->getBlock()
->build();
$this
->assertSame('pdf', $build['pdf']['#export_type']);
$this
->assertFalse(isset($build['epub']));
$this
->assertFalse(isset($build['word_docx']));
$build = $this
->getBlock([
'epub_enabled' => TRUE,
])
->build();
$this
->assertSame('pdf', $build['pdf']['#export_type']);
$this
->assertSame('epub', $build['epub']['#export_type']);
$this
->assertFalse(isset($build['word_docx']));
}
protected function getBlock(array $config = []) {
$manager = $this->container
->get('plugin.manager.block');
$entity = $this
->createMock('Drupal\\Core\\Entity\\EntityInterface');
$context = new Context(ContextDefinition::create(), $entity);
$block = $manager
->createInstance('print_links', $config);
$block
->setContext('entity', $context);
return $block;
}
}