class DomStrReplaceTest in Migrate Plus 8.4
Same name and namespace in other branches
- 8.5 tests/src/Unit/process/DomStrReplaceTest.php \Drupal\Tests\migrate_plus\Unit\process\DomStrReplaceTest
Tests the dom_str_replace process plugin.
@group migrate @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\DomStrReplace
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\DomStrReplaceTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of DomStrReplaceTest
File
- tests/
src/ Unit/ process/ DomStrReplaceTest.php, line 17
Namespace
Drupal\Tests\migrate_plus\Unit\processView source
class DomStrReplaceTest extends MigrateProcessTestCase {
/**
* Example configuration for the dom_str_replace process plugin.
*
* @var array
*/
protected $exampleConfiguration = [
'mode' => 'attribute',
'expression' => '//a',
'attribute_options' => [
'name' => 'href',
],
'search' => 'foo',
'replace' => 'bar',
];
/**
* @covers ::__construct
*
* @dataProvider providerTestConfigEmpty
*/
public function testConfigValidation(array $config_overrides, $message) {
$configuration = $config_overrides + $this->exampleConfiguration;
$value = '<p>A simple paragraph.</p>';
$this
->setExpectedException(InvalidPluginDefinitionException::class, $message);
(new DomStrReplace($configuration, 'dom_str_replace', []))
->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
}
/**
* Dataprovider for testConfigValidation().
*/
public function providerTestConfigEmpty() {
$cases = [
'expression-null' => [
[
'expression' => NULL,
],
"Configuration option 'expression' is required.",
],
'mode-null' => [
[
'mode' => NULL,
],
"Configuration option 'mode' is required.",
],
'mode-invalid' => [
[
'mode' => 'invalid',
],
'Configuration option "mode" only accepts the following values: attribute.',
],
'attribute_options-null' => [
[
'attribute_options' => NULL,
],
"Configuration option 'attribute_options' is required.",
],
'search-null' => [
[
'search' => NULL,
],
"Configuration option 'search' is required.",
],
'replace-null' => [
[
'replace' => NULL,
],
"Configuration option 'replace' is required.",
],
];
return $cases;
}
/**
* @covers ::transform
*/
public function testTransformInvalidInput() {
$configuration = [
'expression' => '//a',
'mode' => 'attribute',
'attribute_options' => [
'name' => 'href',
],
'search' => 'foo',
'replace' => 'bar',
];
$value = 'string';
$this
->setExpectedException(MigrateSkipRowException::class, 'The dom_str_replace plugin in the destinationproperty process pipeline requires a \\DOMDocument object. You can use the dom plugin to convert a string to \\DOMDocument.');
(new DomStrReplace($configuration, 'dom_str_replace', []))
->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
}
/**
* @covers ::transform
*
* @dataProvider providerTestTransform
*/
public function testTransform($input_string, $configuration, $output_string) {
$value = Html::load($input_string);
$document = (new DomStrReplace($configuration, 'dom_str_replace', []))
->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertTrue($document instanceof \DOMDocument);
$this
->assertEquals($output_string, Html::serialize($document));
}
/**
* Dataprovider for testTransform().
*/
public function providerTestTransform() {
$cases = [
'string:case_sensitive' => [
'<a href="/foo/Foo/foo">text</a>',
$this->exampleConfiguration,
'<a href="/bar/Foo/bar">text</a>',
],
'string:case_insensitive' => [
'<a href="/foo/Foo/foo">text</a>',
[
'case_insensitive' => TRUE,
] + $this->exampleConfiguration,
'<a href="/bar/bar/bar">text</a>',
],
'regex' => [
'<a href="/foo/Foo/foo">text</a>',
[
'search' => '/(.)\\1/',
'regex' => TRUE,
] + $this->exampleConfiguration,
'<a href="/fbar/Fbar/fbar">text</a>',
],
];
return $cases;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DomStrReplaceTest:: |
protected | property | Example configuration for the dom_str_replace process plugin. | |
DomStrReplaceTest:: |
public | function | Dataprovider for testConfigValidation(). | |
DomStrReplaceTest:: |
public | function | Dataprovider for testTransform(). | |
DomStrReplaceTest:: |
public | function | @covers ::__construct | |
DomStrReplaceTest:: |
public | function | @covers ::transform | |
DomStrReplaceTest:: |
public | function | @covers ::transform | |
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | function |
Overrides UnitTestCase:: |
19 |
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. |