summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Hojtsy2017-05-26 12:25:06 +0200
committerGabor Hojtsy2017-05-26 12:26:27 +0200
commitdd7d7e5973bfdec4f728450046bc7f6db544d56e (patch)
tree66b7d10a968978e560112575674f1cbaa87c1300
parent95059ed38265133e781997e2065c45e02a110790 (diff)
Issue #2826505 by quietone, pen, Yogesh Pawar, mikeryan, drzraf, mglaman: Undefined index: allowed_html FilterSettings.php:45
-rw-r--r--core/modules/filter/src/Plugin/migrate/process/FilterSettings.php4
-rw-r--r--core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php102
2 files changed, 105 insertions, 1 deletions
diff --git a/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php b/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php
index 2350426..eb0da32 100644
--- a/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php
+++ b/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php
@@ -42,7 +42,9 @@ class FilterSettings extends ProcessPluginBase {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Only the filter_html filter's settings have a changed format.
if ($row->getDestinationProperty('id') === 'filter_html') {
- $value['allowed_html'] = str_replace(array_keys($this->allowedHtmlDefaultAttributes), array_values($this->allowedHtmlDefaultAttributes), $value['allowed_html']);
+ if (!empty($value['allowed_html'])) {
+ $value['allowed_html'] = str_replace(array_keys($this->allowedHtmlDefaultAttributes), array_values($this->allowedHtmlDefaultAttributes), $value['allowed_html']);
+ }
}
return $value;
}
diff --git a/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php b/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php
new file mode 100644
index 0000000..4250211
--- /dev/null
+++ b/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php
@@ -0,0 +1,102 @@
+<?php
+
+namespace Drupal\Tests\filter\Kernel\Plugin\migrate\process;
+
+use Drupal\filter\Plugin\migrate\process\FilterSettings;
+use Drupal\migrate\MigrateExecutableInterface;
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\migrate\Row;
+use Drupal\Tests\migrate\Unit\MigrateTestCase;
+
+/**
+ * Unit tests of the filter_settings plugin.
+ *
+ * @coversDefaultClass \Drupal\filter\Plugin\migrate\process\FilterSettings
+ * @group filter
+ */
+class FilterSettingsTest extends MigrateTestCase {
+
+ /**
+ * Tests transformation of filter settings.
+ *
+ * @dataProvider dataProvider
+ * @covers ::transform
+ */
+ public function testTransform($value, $destination_id, $expected_value) {
+ $migration = $this->getMock(MigrationInterface::class);
+ $plugin = new FilterSettings([], 'filter_settings', [], $migration);
+
+ $executable = $this->getMock(MigrateExecutableInterface::class);
+ $row = $this->getMockBuilder(Row::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $row->expects($this->atLeastOnce())
+ ->method('getDestinationProperty')
+ ->willReturn($destination_id);
+
+ $output_value = $plugin->transform($value, $executable, $row, 'foo');
+ $this->assertSame($expected_value, $output_value);
+ }
+
+ /**
+ * The test data provider.
+ *
+ * @return array
+ */
+ public function dataProvider() {
+ return [
+ // Tests that the transformed value is identical to the input value when
+ // destination is not the filter_html.
+
+ // Test with an empty source array.
+ [
+ [],
+ 'any_filter',
+ [],
+ ],
+ // Test with a source string.
+ [
+ 'a string',
+ 'any_filter',
+ 'a string',
+ ],
+ // Test with a source filter array.
+ [
+ [
+ 'allowed_html' => '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>',
+ ],
+ 'any_filter',
+ [
+ 'allowed_html' => '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>',
+ ],
+ ],
+
+ // Tests that the transformed value for 'allowed_html' is altered when the
+ // destination is filter_html.
+
+ // Test with an empty source array.
+ [
+ [],
+ 'filter_html',
+ [],
+ ],
+ // Test with a source string.
+ [
+ 'a string',
+ 'filter_html',
+ 'a string',
+ ],
+ [
+ [
+ 'allowed_html' => '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>',
+ ],
+ 'filter_html',
+ [
+ 'allowed_html' => '<a href hreflang> <em> <strong> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>',
+ ],
+ ],
+ ];
+ }
+
+}