class DomApplyStylesTest in Migrate Plus 8.5
Tests the dom_apply_styles process plugin.
@group migrate @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\DomApplyStyles
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate_plus\Unit\process\DomApplyStylesTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of DomApplyStylesTest
File
- tests/
src/ Unit/ process/ DomApplyStylesTest.php, line 19
Namespace
Drupal\Tests\migrate_plus\Unit\processView source
class DomApplyStylesTest extends MigrateProcessTestCase {
/**
* Example configuration for the dom_apply_styles process plugin.
*
* @var array
*/
protected $exampleConfiguration = [
'format' => 'test_format',
'rules' => [
[
'xpath' => '//b',
'style' => 'Bold',
],
[
'xpath' => '//span/i',
'style' => 'Italic',
'depth' => 1,
],
],
];
/**
* Mock a config factory object.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory = NULL;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
// Mock a config object.
$prophecy = $this
->prophesize(ImmutableConfig::class);
$prophecy
->get('settings.plugins.stylescombo.styles')
->willReturn("strong.foo|Bold\r\nem.foo.bar|Italic\r\n");
$style_config = $prophecy
->reveal();
// Mock the config factory.
$prophecy = $this
->prophesize(ConfigFactory::class);
$prophecy
->get('editor.editor.test_format')
->willReturn($style_config);
$this->configFactory = $prophecy
->reveal();
parent::setUp();
}
/**
* @covers ::__construct
*
* @dataProvider providerTestConfig
*/
public function testValidateRules(array $config_overrides, $message) : void {
$configuration = $config_overrides + $this->exampleConfiguration;
$value = '<p>A simple paragraph.</p>';
$this
->expectException(InvalidPluginDefinitionException::class);
$this
->expectExceptionMessage($message);
(new DomApplyStyles($configuration, 'dom_apply_styles', [], $this->configFactory))
->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
}
/**
* Dataprovider for testValidateRules().
*/
public function providerTestConfig() : array {
$cases = [
'format-empty' => [
[
'format' => '',
],
'The "format" option must be a non-empty string.',
],
'format-not-string' => [
[
'format' => [
1,
2,
3,
],
],
'The "format" option must be a non-empty string.',
],
'rules-not-array' => [
[
'rules' => 'invalid',
],
'The "rules" option must be an array.',
],
'xpath-null' => [
[
'rules' => [
[
'xpath' => NULL,
'style' => 'Bold',
],
],
],
'The "xpath" and "style" options are required for each rule.',
],
'style-invalid' => [
[
'rules' => [
[
'xpath' => '//b',
'style' => 'invalid-style',
],
],
],
'The style "invalid-style" is not defined.',
],
];
return $cases;
}
/**
* @covers ::transform
*/
public function testTransformInvalidInput() : void {
$value = 'string';
$this
->expectException(MigrateSkipRowException::class);
$this
->expectExceptionMessage('The dom_apply_styles plugin in the destinationproperty process pipeline requires a \\DOMDocument object. You can use the dom plugin to convert a string to \\DOMDocument.');
(new DomApplyStyles($this->exampleConfiguration, 'dom_apply_styles', [], $this->configFactory))
->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
}
/**
* @covers ::transform
*/
public function testTransform() : void {
$input_string = '<div><span><b>Bold text</b></span><span><i>Italic text</i></span></div>';
$output_string = '<div><span><strong class="foo">Bold text</strong></span><em class="foo bar">Italic text</em></div>';
$value = Html::load($input_string);
$document = (new DomApplyStyles($this->exampleConfiguration, 'dom_apply_styles', [], $this->configFactory))
->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertTrue($document instanceof \DOMDocument);
$this
->assertEquals($output_string, Html::serialize($document));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DomApplyStylesTest:: |
protected | property | Mock a config factory object. | |
DomApplyStylesTest:: |
protected | property | Example configuration for the dom_apply_styles process plugin. | |
DomApplyStylesTest:: |
public | function | Dataprovider for testValidateRules(). | |
DomApplyStylesTest:: |
protected | function |
Overrides MigrateProcessTestCase:: |
|
DomApplyStylesTest:: |
public | function | @covers ::transform | |
DomApplyStylesTest:: |
public | function | @covers ::transform | |
DomApplyStylesTest:: |
public | function | @covers ::__construct | |
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateTestCase:: |
protected | property | The migration ID map. | |
MigrateTestCase:: |
protected | property | An array of migration configuration values. | 16 |
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Gets an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieves a mocked migration. | 1 |
MigrateTestCase:: |
protected | function | Gets the value on a row for a given key. | 1 |
MigrateTestCase:: |
public | function | Tests a query. | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
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. | |
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. |