Loading src/Plugin/migrate/process/Dom.php +7 −2 Changes for src/Plugin/migrate/process/Dom.php: 7 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ use Masterminds\HTML5; * - import_method: (optional) What parser to use. Possible values: * - 'html': (default) use dom extension parsing. * - 'html5': use html5 parsing. * - 'xml': use XML parsing. * * @codingStandardsIgnoreStart * Loading Loading @@ -102,8 +103,8 @@ class Dom extends ProcessPluginBase { throw new \InvalidArgumentException('The "method" must be "import" or "export".'); } $configuration['import_method'] = $configuration['import_method'] ?? 'html'; if (!in_array($configuration['import_method'], ['html', 'html5'])) { throw new \InvalidArgumentException('The "import_method" must be "html" or "html5".'); if (!in_array($configuration['import_method'], ['html', 'html5', 'xml'])) { throw new \InvalidArgumentException('The "import_method" must be "html", "html5", or "xml".'); } parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configuration += $this->defaultValues(); Loading Loading @@ -180,6 +181,10 @@ class Dom extends ProcessPluginBase { $html5->loadHTML($html); break; case 'xml': $document->loadXML($html); break; case 'html': default: $document->loadHTML($html); Loading tests/src/Unit/process/DomTest.php +14 −2 Changes for tests/src/Unit/process/DomTest.php: 14 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -42,11 +42,11 @@ class DomTest extends MigrateProcessTestCase { /** * @covers ::__construct */ public function testInvalidImportMethod() { public function testInvalidImportMethod(): void { $configuration['method'] = 'import'; $configuration['import_method'] = 'invalid'; $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "import_method" must be "html" or "html5".'); $this->expectExceptionMessage('The "import_method" must be "html", "html5", or "xml".'); (new Dom($configuration, 'dom', [])); } Loading @@ -73,6 +73,18 @@ class DomTest extends MigrateProcessTestCase { $this->assertTrue($document instanceof \DOMDocument); } /** * @covers ::import */ public function testImportMethodXml(): void { $configuration['method'] = 'import'; $configuration['import_method'] = 'xml'; $value = '<item><value>A simple paragraph.</value></item>'; $document = (new Dom($configuration, 'dom', [])) ->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty'); $this->assertTrue($document instanceof \DOMDocument); } /** * @covers ::import */ Loading Loading
src/Plugin/migrate/process/Dom.php +7 −2 Changes for src/Plugin/migrate/process/Dom.php: 7 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ use Masterminds\HTML5; * - import_method: (optional) What parser to use. Possible values: * - 'html': (default) use dom extension parsing. * - 'html5': use html5 parsing. * - 'xml': use XML parsing. * * @codingStandardsIgnoreStart * Loading Loading @@ -102,8 +103,8 @@ class Dom extends ProcessPluginBase { throw new \InvalidArgumentException('The "method" must be "import" or "export".'); } $configuration['import_method'] = $configuration['import_method'] ?? 'html'; if (!in_array($configuration['import_method'], ['html', 'html5'])) { throw new \InvalidArgumentException('The "import_method" must be "html" or "html5".'); if (!in_array($configuration['import_method'], ['html', 'html5', 'xml'])) { throw new \InvalidArgumentException('The "import_method" must be "html", "html5", or "xml".'); } parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configuration += $this->defaultValues(); Loading Loading @@ -180,6 +181,10 @@ class Dom extends ProcessPluginBase { $html5->loadHTML($html); break; case 'xml': $document->loadXML($html); break; case 'html': default: $document->loadHTML($html); Loading
tests/src/Unit/process/DomTest.php +14 −2 Changes for tests/src/Unit/process/DomTest.php: 14 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -42,11 +42,11 @@ class DomTest extends MigrateProcessTestCase { /** * @covers ::__construct */ public function testInvalidImportMethod() { public function testInvalidImportMethod(): void { $configuration['method'] = 'import'; $configuration['import_method'] = 'invalid'; $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "import_method" must be "html" or "html5".'); $this->expectExceptionMessage('The "import_method" must be "html", "html5", or "xml".'); (new Dom($configuration, 'dom', [])); } Loading @@ -73,6 +73,18 @@ class DomTest extends MigrateProcessTestCase { $this->assertTrue($document instanceof \DOMDocument); } /** * @covers ::import */ public function testImportMethodXml(): void { $configuration['method'] = 'import'; $configuration['import_method'] = 'xml'; $value = '<item><value>A simple paragraph.</value></item>'; $document = (new Dom($configuration, 'dom', [])) ->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty'); $this->assertTrue($document instanceof \DOMDocument); } /** * @covers ::import */ Loading