View source
<?php
namespace Drupal\Tests\printable\Unit\Plugin\PrintableFormat;
use Drupal\Tests\UnitTestCase;
use Drupal\printable\Plugin\PrintableFormat\PrintFormat;
class PrintFormatTest extends UnitTestCase {
protected $pluginDefinition;
protected $pluginId;
protected $configuration;
public function __construct() {
$this->pluginDefinition = [
'description' => 'Print description.',
'id' => 'print',
'module' => 'printable',
'title' => 'Print',
'class' => 'Drupal\\printable\\Plugin\\PrintableFormat\\PrintFormat',
'provider' => 'printable',
];
$this->pluginId = 'print';
$this->configuration = [];
}
public static function getInfo() {
return [
'name' => 'Printable Format Base',
'descriptions' => 'Tests the printable format base class.',
'group' => 'Printable',
];
}
public function testGetLabel() {
$format = new PrintFormat($this->configuration, $this->pluginId, $this->pluginDefinition, $this
->getConfigFactoryStub(), $this
->getCssIncludeStub(), $this
->getLinkExtractorIncludeStub());
$this
->assertEquals('Print', $format
->getLabel());
}
public function testGetDescription() {
$format = new PrintFormat($this->configuration, $this->pluginId, $this->pluginDefinition, $this
->getConfigFactoryStub(), $this
->getCssIncludeStub(), $this
->getLinkExtractorIncludeStub());
$this
->assertEquals('Print description.', $format
->getDescription());
}
public function testDefaultConfiguration() {
$format = new PrintFormat($this->configuration, $this->pluginId, $this->pluginDefinition, $this
->getConfigFactoryStub(), $this
->getCssIncludeStub(), $this
->getLinkExtractorIncludeStub());
$this
->assertEquals([
'show_print_dialogue' => TRUE,
], $format
->defaultConfiguration());
}
public function testGetConfiguration() {
$format = new PrintFormat($this->configuration, $this->pluginId, $this->pluginDefinition, $this
->getConfigFactoryStub(), $this
->getCssIncludeStub(), $this
->getLinkExtractorIncludeStub(), $this
->getLinkExtractorIncludeStub());
$this
->assertEquals([
'show_print_dialogue' => TRUE,
], $format
->getConfiguration());
}
public function testGetPassedInConfiguration() {
$format = new PrintFormat([
'test_configuration_value' => TRUE,
], $this->pluginId, $this->pluginDefinition, $this
->getConfigFactoryStub(), $this
->getCssIncludeStub(), $this
->getLinkExtractorIncludeStub());
$this
->assertEquals([
'show_print_dialogue' => TRUE,
'test_configuration_value' => TRUE,
], $format
->getConfiguration());
}
public function testSetConfiguration() {
$new_configuration = [
'show_print_dialogue' => FALSE,
];
$config_mock = $this
->getMockBuilder('\\Drupal\\Core\\Config\\Config')
->disableOriginalConstructor()
->getMock();
$config_mock
->expects($this
->once())
->method('set')
->with('print', $new_configuration)
->will($this
->returnSelf());
$config_mock
->expects($this
->once())
->method('save');
$config_factory_mock = $this
->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')
->disableOriginalConstructor()
->getMock();
$config_factory_mock
->expects($this
->once())
->method('get')
->with('printable.format')
->will($this
->returnValue($config_mock));
$format = new PrintFormat($this->configuration, $this->pluginId, $this->pluginDefinition, $config_factory_mock, $this
->getCssIncludeStub(), $this
->getLinkExtractorIncludeStub());
$format
->setConfiguration($new_configuration);
$this
->assertEquals($new_configuration, $format
->getConfiguration());
}
protected function getCssIncludeStub() {
return $this
->getMockBuilder('Drupal\\printable\\PrintableCssIncludeInterface')
->disableOriginalConstructor()
->getMock();
}
protected function getLinkExtractorIncludeStub() {
return $this
->getMockBuilder('Drupal\\printable\\LinkExtractor\\LinkExtractorInterface')
->disableOriginalConstructor()
->getMock();
}
}