class MigrationPluginsAltererTest in Paragraphs 8
Tests the MigrationPluginsAlterer service.
@todo Cover every method.
@coversDefaultClass \Drupal\paragraphs\MigrationPluginsAlterer
@group paragraphs
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\paragraphs\Unit\migrate\MigrationPluginsAltererTest
Expanded class hierarchy of MigrationPluginsAltererTest
File
- tests/
src/ Unit/ migrate/ MigrationPluginsAltererTest.php, line 17
Namespace
Drupal\Tests\paragraphs\Unit\migrateView source
class MigrationPluginsAltererTest extends UnitTestCase {
/**
* The migration plugin alterer.
*
* @var \Drupal\paragraphs\MigrationPluginsAlterer
*/
protected $paragraphsMigrationPluginsAlterer;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$logger_channel = $this
->createMock('Drupal\\Core\\Logger\\LoggerChannelInterface');
$logger_factory = $this
->getMockBuilder('Drupal\\Core\\Logger\\LoggerChannelFactory')
->getMock();
$logger_factory
->expects($this
->atLeastOnce())
->method('get')
->with('paragraphs')
->will($this
->returnValue($logger_channel));
$this->paragraphsMigrationPluginsAlterer = new MigrationPluginsAlterer($logger_factory);
}
/**
* Tests that migration processes are transformed to an array of processors.
*
* @dataProvider providerParagraphsMigrationPrepareProcess
* @covers ::paragraphsMigrationPrepareProcess
*/
public function testParagraphsMigrationPrepareProcess(array $input, array $expected) {
[
'process' => $process,
'property' => $property,
] = $input;
$success = $this->paragraphsMigrationPluginsAlterer
->paragraphsMigrationPrepareProcess($process, $property);
$this
->assertSame($expected['return'], $success);
$this
->assertEquals($expected['process'], $process);
}
/**
* Provides data and expected results for testing the prepare process method.
*
* @return array[]
* Data and expected results.
*/
public function providerParagraphsMigrationPrepareProcess() {
return [
// Missing property (no change).
[
'input' => [
'process' => [
'catname' => 'Picurka',
'wont/touch' => 'this',
],
'property' => 'missing',
],
'expected' => [
'return' => FALSE,
'process' => [
'catname' => 'Picurka',
'wont/touch' => 'this',
],
],
],
// Existing string property.
[
'input' => [
'process' => [
'catname' => 'Picurka',
'wont/touch' => 'this',
],
'property' => 'catname',
],
'expected' => [
'return' => TRUE,
'process' => [
'catname' => [
[
'plugin' => 'get',
'source' => 'Picurka',
],
],
'wont/touch' => 'this',
],
],
],
// Single process plugin.
[
'input' => [
'process' => [
'cat' => [
'plugin' => 'migration_lookup',
'migration' => 'cats',
'source' => 'cat_id',
],
],
'property' => 'cat',
],
'expected' => [
'return' => TRUE,
'process' => [
'cat' => [
[
'plugin' => 'migration_lookup',
'migration' => 'cats',
'source' => 'cat_id',
],
],
],
],
],
// Array of process plugins (no change).
[
'input' => [
'process' => [
'catname' => [
[
'plugin' => 'migration_lookup',
'migration' => 'cats',
'source' => 'cat_id',
],
[
'plugin' => 'extract',
'index' => [
'name',
],
],
[
'plugin' => 'callback',
'callable' => 'ucfirst',
],
],
],
'property' => 'catname',
],
'expected' => [
'return' => TRUE,
'process' => [
'catname' => [
[
'plugin' => 'migration_lookup',
'migration' => 'cats',
'source' => 'cat_id',
],
[
'plugin' => 'extract',
'index' => [
'name',
],
],
[
'plugin' => 'callback',
'callable' => 'ucfirst',
],
],
],
],
],
// Invalid type.
[
'input' => [
'process' => [
'invalid' => (object) [
[
'not a' => 'kitten',
],
],
],
'property' => 'invalid',
],
'expected' => [
'return' => FALSE,
'process' => [
'invalid' => (object) [
[
'not a' => 'kitten',
],
],
],
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrationPluginsAltererTest:: |
protected | property | The migration plugin alterer. | |
MigrationPluginsAltererTest:: |
public | function | Provides data and expected results for testing the prepare process method. | |
MigrationPluginsAltererTest:: |
protected | function |
Overrides UnitTestCase:: |
|
MigrationPluginsAltererTest:: |
public | function | Tests that migration processes are transformed to an array of processors. | |
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. | |
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. |