class MediaWysiwygFilterTest in Media Migration 8
Tests the MediaWysiwygFilter migration process plugin.
@coversDefaultClass \Drupal\media_migration\Plugin\migrate\process\MediaWysiwygFilter @group media_migration
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\media_migration\Unit\Plugin\migrate\process\ProcessTestBase
- class \Drupal\Tests\media_migration\Unit\Plugin\migrate\process\MediaWysiwygFilterTest
- class \Drupal\Tests\media_migration\Unit\Plugin\migrate\process\ProcessTestBase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of MediaWysiwygFilterTest
File
- tests/
src/ Unit/ Plugin/ migrate/ process/ MediaWysiwygFilterTest.php, line 16
Namespace
Drupal\Tests\media_migration\Unit\Plugin\migrate\processView source
class MediaWysiwygFilterTest extends ProcessTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
new Settings([]);
$this
->setSetting(MediaMigration::MEDIA_TOKEN_DESTINATION_FILTER_SETTINGS, MediaMigration::MEDIA_TOKEN_DESTINATION_FILTER_ENTITY_EMBED);
}
/**
* Test the MediaWysiwygFilter plugin's transform.
*
* @param string|string[] $input_value
* The transformed value.
* @param string|string[] $expected_value
* The expected value.
*
* @dataProvider providerTransformTest
*/
public function testMediaWysiwygFilterTransform($input_value, $expected_value) {
$migration_plugin_manager = $this
->prophesize(MigrationPluginManagerInterface::class);
$this->plugin = new MediaWysiwygFilter([], 'media_wysiwyg_filter', [], $this->migration, NULL, $migration_plugin_manager
->reveal(), $this->uuidOracle
->reveal());
$this
->assertEquals($expected_value, $this->plugin
->transform($input_value, $this->migrateExecutable, $this->row, 'destination_property'));
}
/**
* Data provider for ::testMediaWysiwygFilterTransform.
*
* @return array[]
* The test cases.
*/
public function providerTransformTest() {
return [
'Plain text' => [
'input' => [
'value' => 'Lorem ipsum dolor sit amet.',
],
'expected' => [
'value' => 'Lorem ipsum dolor sit amet.',
],
],
'Plain text with non-media token' => [
'input' => 'Blah
[[nid:1]]
Blah',
'expected' => 'Blah
[[nid:1]]
Blah',
],
'Plain text with non-media JSON' => [
'input' => 'Blah
[[{"nid":"1"}]]
Blah',
'expected' => 'Blah
[[{"nid":"1"}]]
Blah',
],
'HTML text with non-media JSON' => [
'input' => '<p>Blah</p>
[[{"nid":"1"}]]
<p><strong>Blah</strong></p>',
'expected' => '<p>Blah</p>
[[{"nid":"1"}]]
<p><strong>Blah</strong></p>',
],
'Plain text with non-media and media JSON tokens' => [
'input' => '[[{"nid":"1"}]]
Lorem ipsum dolor sit amet.
[[{"fid":"3","view_mode":"default","type":"media"}]]
Nam finibus elit nec ipsum feugiat convallis.
[[{"fid":"1","view_mode":"wysiwyg","type":"media"}]]
Aliquam tellus nisi.
[[nid:1]]',
'expected' => '[[{"nid":"1"}]]
Lorem ipsum dolor sit amet.
<drupal-entity data-embed-button="media" data-entity-type="media" data-entity-id="3" data-entity-embed-display="view_mode:media.default"></drupal-entity>
Nam finibus elit nec ipsum feugiat convallis.
<drupal-entity data-embed-button="media" data-entity-type="media" data-entity-id="1" data-entity-embed-display="view_mode:media.wysiwyg"></drupal-entity>
Aliquam tellus nisi.
[[nid:1]]',
],
'HTML text with non-media and media JSON tokens' => [
'input' => '<p class="lead">[[{"foo":"bar"}]]</p>
<p>Lorem ipsum dolor sit amet.</p>
[[{"fid":"453","view_mode":"default","type":"media"}]]
<p>Nam finibus elit nec ipsum feugiat convallis.</p>
<p>[[{"fid":"154","view_mode":"wysiwyg","type":"media"}]]</p>
<ul>
<li>Aliquam tellus nisi.</li>
</ul>
[[tid:15]]
<p></p>',
'expected' => '<p class="lead">[[{"foo":"bar"}]]</p>
<p>Lorem ipsum dolor sit amet.</p>
<drupal-entity data-embed-button="media" data-entity-type="media" data-entity-id="453" data-entity-embed-display="view_mode:media.default"></drupal-entity>
<p>Nam finibus elit nec ipsum feugiat convallis.</p>
<p><drupal-entity data-embed-button="media" data-entity-type="media" data-entity-id="154" data-entity-embed-display="view_mode:media.wysiwyg"></drupal-entity></p>
<ul>
<li>Aliquam tellus nisi.</li>
</ul>
[[tid:15]]
<p></p>',
],
'Text with invalid (?) JSON' => [
'input' => '<p>Foo?</p>
[[{ "fid":"123456","view_mode":"default","type":"media","attributes":{ "class":"css-class1
css-class2 css-class3" ,"alt":"Overridden alt attribute for embed" ,"title":"Overridden title attribute for embed" },
"fields":{ "format":"default" ,"alt":"Overridden alt attribute for embed","field_file_image_alt_text[und][0][value]":"Media alt attribute" ,"title":"Overridden title attribute for embed","field_file_image_title_text[und][0][value]":"Media title attribute"} }]]
<p>Bar baz!</p>',
'expected' => '<p>Foo?</p>
<drupal-entity data-embed-button="media" data-entity-type="media" data-entity-id="123456" data-entity-embed-display="view_mode:media.default" alt="Overridden alt attribute for embed" title="Overridden title attribute for embed"></drupal-entity>
<p>Bar baz!</p>',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MediaWysiwygFilterTest:: |
public | function | Data provider for ::testMediaWysiwygFilterTransform. | |
MediaWysiwygFilterTest:: |
protected | function |
Overrides ProcessTestBase:: |
|
MediaWysiwygFilterTest:: |
public | function | Test the MediaWysiwygFilter plugin's transform. | |
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateTestCase:: |
protected | property | The migration ID map. | |
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Gets an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieves a mocked migration. | 1 |
MigrateTestCase:: |
protected | function | Gets the value on a row for a given key. | 1 |
MigrateTestCase:: |
public | function | Tests a query. | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
ProcessTestBase:: |
protected | property | A logger channel object prophecy. | |
ProcessTestBase:: |
protected | property | The migration the process plugin is tested with. | |
ProcessTestBase:: |
protected | property |
An array of migration configuration values. Overrides MigrateTestCase:: |
|
ProcessTestBase:: |
protected | property |
The process plugin we test. Overrides MigrateProcessTestCase:: |
|
ProcessTestBase:: |
protected | property | A SqlBase migration source plugin object prophecy. | |
ProcessTestBase:: |
protected | property | A source database to test with. | 1 |
ProcessTestBase:: |
protected | property | A media migration UUID oracle object prophecy. | |
ProcessTestBase:: |
protected | function | Sets an in-memory Settings variable. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |