Commit dd7d7e59 authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2826505 by quietone, pen, Yogesh Pawar, mikeryan, drzraf, mglaman:...

Issue #2826505 by quietone, pen, Yogesh Pawar, mikeryan, drzraf, mglaman: Undefined index: allowed_html FilterSettings.php:45
parent 95059ed3
......@@ -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;
}
......
<?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>',
],
],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment