Commit dd953d48 authored by alexpott's avatar alexpott

Issue #2807891 by svendecabooter: Convert Filter's Migrate source tests to new base class

parent d2ec8a49
<?php
namespace Drupal\Tests\filter\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D6 filter format source plugin.
*
* @covers \Drupal\filter\Plugin\migrate\source\d6\FilterFormat
*
* @group filter
*/
class FilterFormatTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['filter', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['filter_formats'] = [
[
'format' => 1,
'name' => 'Filtered HTML',
'roles' => ',1,2,',
'cache' => 1,
],
[
'format' => 2,
'name' => 'Full HTML',
'roles' => '',
'cache' => 1,
],
[
'format' => 4,
'name' => 'Example Custom Format',
'roles' => '4',
'cache' => 1,
],
];
$tests[0]['source_data']['filters'] = [
[
'fid' => 1,
'format' => 1,
'module' => 'filter',
'delta' => 2,
'weight' => 0,
],
[
'fid' => 2,
'format' => 1,
'module' => 'filter',
'delta' => 0,
'weight' => 1,
],
[
'fid' => 3,
'format' => 1,
'module' => 'filter',
'delta' => 1,
'weight' => 2,
],
[
'fid' => 4,
'format' => 2,
'module' => 'filter',
'delta' => 2,
'weight' => 0,
],
[
'fid' => 5,
'format' => 2,
'module' => 'filter',
'delta' => 1,
'weight' => 1,
],
[
'fid' => 6,
'format' => 2,
'module' => 'filter',
'delta' => 3,
'weight' => 10,
],
[
'fid' => 7,
'format' => 4,
'module' => 'markdown',
'delta' => 1,
'weight' => 10,
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'format' => 1,
'name' => 'Filtered HTML',
'roles' => [1, 2],
'cache' => 1,
'filters' => [
[
'module' => 'filter',
'delta' => 2,
'weight' => 0,
'settings' => [],
],
[
'module' => 'filter',
'delta' => 0,
'weight' => 1,
'settings' => [],
],
[
'module' => 'filter',
'delta' => 1,
'weight' => 2,
'settings' => [],
],
],
],
[
'format' => 2,
'name' => 'Full HTML',
'roles' => [],
'cache' => 1,
'filters' => [
[
'module' => 'filter',
'delta' => 2,
'weight' => 0,
'settings' => [],
],
[
'module' => 'filter',
'delta' => 1,
'weight' => 1,
'settings' => [],
],
[
'module' => 'filter',
'delta' => 3,
'weight' => 10,
'settings' => [],
],
],
],
[
'format' => 4,
'name' => 'Example Custom Format',
'roles' => [4],
'cache' => 1,
'filters' => [
// This custom format uses a filter defined by a contrib module.
[
'module' => 'markdown',
'delta' => 1,
'weight' => 10,
'settings' => [],
],
],
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\filter\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D7 filter format source plugin.
*
* @covers \Drupal\filter\Plugin\migrate\source\d7\FilterFormat
*
* @group filter
*/
class FilterFormatTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['filter', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['filter_format'] = [
[
'format' => 'custom_text_format',
'name' => 'Custom Text format',
'cache' => 1,
'status' => 1,
'weight' => 0,
],
[
'format' => 'full_html',
'name' => 'Full HTML',
'cache' => 1,
'status' => 1,
'weight' => 1,
],
];
$tests[0]['source_data']['filter'] = [
[
'format' => 'custom_text_format',
'module' => 'filter',
'name' => 'filter_autop',
'weight' => 0,
'status' => 1,
'settings' => serialize(array()),
],
[
'format' => 'custom_text_format',
'module' => 'filter',
'name' => 'filter_html',
'weight' => 1,
'status' => 1,
'settings' => serialize(array()),
],
[
'format' => 'full_html',
'module' => 'filter',
'name' => 'filter_url',
'weight' => 0,
'status' => 1,
'settings' => serialize(array()),
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'format' => 'custom_text_format',
'name' => 'Custom Text format',
'cache' => 1,
'status' => 1,
'weight' => 0,
'filters' => [
'filter_autop' => [
'format' => 'custom_text_format',
'module' => 'filter',
'name' => 'filter_autop',
'weight' => 0,
'status' => 1,
'settings' => [],
],
'filter_html' => [
'format' => 'custom_text_format',
'module' => 'filter',
'name' => 'filter_html',
'weight' => 1,
'status' => 1,
'settings' => [],
],
],
],
[
'format' => 'full_html',
'name' => 'Full HTML',
'cache' => 1,
'status' => 1,
'weight' => 1,
'filters' => [
'filter_url' => [
'format' => 'full_html',
'module' => 'filter',
'name' => 'filter_url',
'weight' => 0,
'status' => 1,
'settings' => [],
],
],
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\filter\Unit\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests d6_filter_format source plugin.
*
* @group filter
*/
class FilterFormatTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\filter\Plugin\migrate\source\d6\FilterFormat';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_filter_formats',
),
);
protected $expectedResults = array(
array(
'format' => 1,
'name' => 'Filtered HTML',
'roles' => array(1, 2),
'cache' => 1,
'filters' => array(
array(
'module' => 'filter',
'delta' => 2,
'weight' => 0,
'settings' => array(),
),
array(
'module' => 'filter',
'delta' => 0,
'weight' => 1,
'settings' => array(),
),
array(
'module' => 'filter',
'delta' => 1,
'weight' => 2,
'settings' => array(),
),
),
),
array(
'format' => 2,
'name' => 'Full HTML',
'roles' => array(),
'cache' => 1,
'filters' => array(
array(
'module' => 'filter',
'delta' => 2,
'weight' => 0,
'settings' => array(),
),
array(
'module' => 'filter',
'delta' => 1,
'weight' => 1,
'settings' => array(),
),
array(
'module' => 'filter',
'delta' => 3,
'weight' => 10,
'settings' => array(),
),
),
),
array(
'format' => 4,
'name' => 'Example Custom Format',
'roles' => array(4),
'cache' => 1,
'filters' => array(
// This custom format uses a filter defined by a contrib module.
array(
'module' => 'markdown',
'delta' => 1,
'weight' => 10,
'settings' => array(),
),
),
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$fid = 1;
$empty_array = serialize(array());
foreach ($this->expectedResults as $k => $row) {
$row['roles'] = ',' . implode(',', $row['roles']) . ',';
foreach ($row['filters'] as $filter) {
$filter['settings'] = $empty_array;
$this->databaseContents['filters'][$fid] = $filter;
$this->databaseContents['filters'][$fid]['format'] = $row['format'];
$this->databaseContents['filters'][$fid]['fid'] = $fid;
$fid++;
}
unset($row['filters']);
$this->databaseContents['filter_formats'][$k] = $row;
}
parent::setUp();
}
}
<?php
namespace Drupal\Tests\filter\Unit\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests d7_filter_format source plugin.
*
* @group filter
*/
class FilterFormatTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\filter\Plugin\migrate\source\d7\FilterFormat';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_filter_formats',
),
);
protected $expectedResults = array(
array(
'format' => 'custom_text_format',
'name' => 'Custom Text format',
'cache' => 1,
'status' => 1,
'weight' => 0,
'filters' => array(
'filter_autop' => array(
'format' => 'custom_text_format',
'module' => 'filter',
'name' => 'filter_autop',
'weight' => 0,
'status' => 1,
'settings' => array(),
),
'filter_html' => array(
'format' => 'custom_text_format',
'module' => 'filter',
'name' => 'filter_html',
'weight' => 1,
'status' => 1,
'settings' => array(),
),
),
),
array(
'format' => 'full_html',
'name' => 'Full HTML',
'cache' => 1,
'status' => 1,
'weight' => 1,
'filters' => array(
'filter_url' => array(
'format' => 'full_html',
'module' => 'filter',
'name' => 'filter_url',
'weight' => 0,
'status' => 1,
'settings' => array(),
),
),
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as $row) {
foreach ($row['filters'] as $filter) {
$filter['format'] = $row['format'];
$filter['settings'] = serialize($filter['settings']);
$this->databaseContents['filter'][] = $filter;
}
unset($row['filters']);
$this->databaseContents['filter_format'][] = $row;
}
parent::setUp();
}
}
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