diff --git a/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php index 00dd1cc..6e8fa3a 100644 --- a/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php +++ b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php @@ -25,7 +25,14 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPluginInterface { /** - * The migration plugin. + * The migration. + * + * @var \Drupal\migrate\Entity\MigrationInterface + */ + protected $migration; + + /** + * The d6 user role migration plugin. * * @var \Drupal\migrate\Plugin\MigrateProcessInterface */ diff --git a/core/modules/block/tests/src/Unit/Plugin/migrate/process/d6/BlockVisibilityTest.php b/core/modules/block/tests/src/Unit/Plugin/migrate/process/d6/BlockVisibilityTest.php new file mode 100644 index 0000000..88e0adb --- /dev/null +++ b/core/modules/block/tests/src/Unit/Plugin/migrate/process/d6/BlockVisibilityTest.php @@ -0,0 +1,129 @@ +migration = $this->prophesize(MigrationInterface::class); + $this->migrationPlugin = $this->prophesize(MigrateProcessInterface::class); + $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class); + $this->plugin = new BlockVisibility([], 'map', array(), $this->migration->reveal(), $this->migrationPlugin->reveal(), $this->moduleHandler->reveal()); + } + + /** + * @covers ::transform + * + * @dataProvider providerTestTransform + */ + public function testTransform($pages, $roles, $visibility, $expected) { + $value = [$pages, $roles, $visibility]; + $transformed_value = $this->plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame($expected, $transformed_value); + } + + public function providerTestTransform() { + $data = []; + $data[] = [ + '', + [], + 0, + [], + ]; + $data[] = [ + '', + [], + 0, + ['request_path' => [ + 'id' => 'request_path', + 'negate' => TRUE, + 'pages' => '', + ]], + ]; + $data[] = [ + "foo\n/bar\rbaz\r\n", + [], + 1, + ['request_path' => [ + 'id' => 'request_path', + 'negate' => FALSE, + 'pages' => "/foo\n/bar\n/baz\n", + ]], + ]; + return $data; + } + + /** + * @covers ::transform + */ + public function testTransformPhpEnabled() { + $this->moduleHandler->moduleExists('php')->willReturn(TRUE); + + $pages = 'plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty'); + + $expected = ['request_path' => [ + 'id' => 'request_path', + 'negate' => FALSE, + 'pages' => $pages, + ]]; + $this->assertSame($expected, $transformed_value); + } + + /** + * @covers ::transform + * + * @expectedException \Drupal\migrate\MigrateSkipRowException + */ + public function testTransformPhpDisabled() { + $value = ['plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty'); + + $expected = []; + $this->assertSame($expected, $transformed_value); + } + +}