class PrintFormatTest in Printer and PDF versions for Drupal 8+ 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Plugin/PrintableFormat/PrintFormatTest.php \Drupal\Tests\printable\Unit\Plugin\PrintableFormat\PrintFormatTest
Tests the print format plugin.
@group Printable
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\printable\Unit\Plugin\PrintableFormat\PrintFormatTest
Expanded class hierarchy of PrintFormatTest
File
- tests/
src/ Unit/ Plugin/ PrintableFormat/ PrintFormatTest.php, line 13
Namespace
Drupal\Tests\printable\Unit\Plugin\PrintableFormatView source
class PrintFormatTest extends UnitTestCase {
/**
* The plugin definition of this plugin.
*
* @var array
*/
protected $pluginDefinition;
/**
* The ID of the plugin.
*
* @var string
*/
protected $pluginId;
/**
* The configuration to be passed into the format plugin constructor.
*
* @var array
*/
protected $configuration;
/**
* {@inheritdoc}
*/
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 = [];
}
/**
* {@inheritdoc}
*/
public static function getInfo() {
return [
'name' => 'Printable Format Base',
'descriptions' => 'Tests the printable format base class.',
'group' => 'Printable',
];
}
/**
* Tests getting the plugin label from the plugin.
*
* @covers PrintFormat::GetLabel
*/
public function testGetLabel() {
$format = new PrintFormat($this->configuration, $this->pluginId, $this->pluginDefinition, $this
->getConfigFactoryStub(), $this
->getCssIncludeStub(), $this
->getLinkExtractorIncludeStub());
$this
->assertEquals('Print', $format
->getLabel());
}
/**
* Tests getting the plugin description from the plugin.
*
* @covers PrintFormat::GetDescription
*/
public function testGetDescription() {
$format = new PrintFormat($this->configuration, $this->pluginId, $this->pluginDefinition, $this
->getConfigFactoryStub(), $this
->getCssIncludeStub(), $this
->getLinkExtractorIncludeStub());
$this
->assertEquals('Print description.', $format
->getDescription());
}
/**
* Tests getting the default configuration for this plugin.
*
* @covers PrintFormat::DefaultConfiguration
*/
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());
}
/**
* Tests getting the current configuration for this plugin.
*
* @covers PrintFormat::GetConfiguration
*/
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());
}
/**
* Tests that additional configuration is internally stored and accessible.
*
* @covers PrintFormat::GetPassedInConfiguration
*/
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());
}
/**
* Test that default configuration can be modified and changes accessed.
*
* @covers PrintFormat::SetConfiguration
*/
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());
}
/**
* Get the CSS include stub.
*/
protected function getCssIncludeStub() {
return $this
->getMockBuilder('Drupal\\printable\\PrintableCssIncludeInterface')
->disableOriginalConstructor()
->getMock();
}
/**
* Get the Link extractor stub.
*/
protected function getLinkExtractorIncludeStub() {
return $this
->getMockBuilder('Drupal\\printable\\LinkExtractor\\LinkExtractorInterface')
->disableOriginalConstructor()
->getMock();
}
}
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. | |
PrintFormatTest:: |
protected | property | The configuration to be passed into the format plugin constructor. | |
PrintFormatTest:: |
protected | property | The plugin definition of this plugin. | |
PrintFormatTest:: |
protected | property | The ID of the plugin. | |
PrintFormatTest:: |
protected | function | Get the CSS include stub. | |
PrintFormatTest:: |
public static | function | ||
PrintFormatTest:: |
protected | function | Get the Link extractor stub. | |
PrintFormatTest:: |
public | function | Tests getting the default configuration for this plugin. | |
PrintFormatTest:: |
public | function | Tests getting the current configuration for this plugin. | |
PrintFormatTest:: |
public | function | Tests getting the plugin description from the plugin. | |
PrintFormatTest:: |
public | function | Tests getting the plugin label from the plugin. | |
PrintFormatTest:: |
public | function | Tests that additional configuration is internally stored and accessible. | |
PrintFormatTest:: |
public | function | Test that default configuration can be modified and changes accessed. | |
PrintFormatTest:: |
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 |