Skip to content
Snippets Groups Projects
Commit 75da9df2 authored by Kurucz István's avatar Kurucz István
Browse files

Test refactor and "Filtered HTML" test.

parent 68bfb574
No related branches found
No related tags found
No related merge requests found
......@@ -12,22 +12,66 @@ use Drupal\filter\FilterFormatInterface;
*/
class MigrateFilterFormatTest extends MigrateDrupal5TestBase {
/**
* @var \Drupal\filter\FilterPluginManager
*/
protected $filterPluginManager;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->filterPluginManager = \Drupal::service('plugin.manager.filter');
$this->executeMigration('d5_filter_format');
}
/**
* Test "Empty input format" filter format.
* Asserts various aspects of a filter format entity.
*
* @see \Drupal\Tests\filter\Kernel\Migrate\d7\MigrateFilterFormatTest::assertEntity
*
* @param string $id
* The format ID.
* @param string $label
* The expected label of the format.
* @param array $enabled_filters
* The expected filters in the format, keyed by ID with weight as values.
*
* @internal
*/
protected function assertEntity(string $id, string $label, array $enabled_filters): void {
/** @var \Drupal\filter\FilterFormatInterface $entity */
$entity = FilterFormat::load($id);
$this->assertInstanceOf(FilterFormatInterface::class, $entity);
$this->assertSame($label, $entity->label());
// get('filters') will return enabled filters only, not all of them.
$this->assertSame(array_keys($enabled_filters), array_keys($entity->get('filters')));
foreach ($entity->get('filters') as $filter_id => $filter) {
$this->assertSame($filter['weight'], $enabled_filters[$filter_id]);
}
}
/**
* Test 'Empty input format' filter format.
*/
public function testEmptyFilterFormat() {
$filter_format = FilterFormat::load('empty_input_format');
$this->assertInstanceOf(FilterFormatInterface::class, $filter_format);
// Check filter status.
$filters = $filter_format->get('filters');
$this->assertEmpty($filters);
$this->assertEntity('empty_input_format', 'Empty input format', []);
}
/**
* Test 'Filtered HTML' filter format.
*/
public function testFilteredHtmlFilterFormat() {
$this->assertEntity('filtered_html', 'Filtered HTML', ['filter_url' => 0, 'filter_html' => 1, 'filter_autop' => 2]);
// filter_html
$filter_plugin = $this->filterPluginManager->createInstance('filter_html');
$filter_config = FilterFormat::load('filtered_html')->filters('filter_html')->getConfiguration();
$this->assertSame($filter_plugin->getPluginDefinition()['settings']['allowed_html'], $filter_config['settings']['allowed_html']);
$this->assertEquals(TRUE, $filter_config['settings']['filter_html_help']);
// filter_url
$filter_plugin = $this->filterPluginManager->createInstance('filter_url');
$filter_config = FilterFormat::load('filtered_html')->filters('filter_url')->getConfiguration();
$this->assertSame($filter_plugin->getPluginDefinition()['settings']['filter_url_length'], $filter_config['settings']['filter_url_length']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment