3 namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
5 use Drupal\block\Plugin\migrate\process\BlockVisibility;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\migrate\Plugin\MigrateProcessInterface;
8 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
11 * Tests the block_visibility process plugin.
13 * @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockVisibility
16 class BlockVisibilityTest extends MigrateProcessTestCase {
21 * @var \Drupal\Core\Extension\ModuleHandlerInterface
23 protected $moduleHandler;
28 protected function setUp() {
30 $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
31 $migration_plugin = $this->prophesize(MigrateProcessInterface::class);
32 $this->plugin = new BlockVisibility([], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal());
38 public function testTransformNoData() {
39 $transformed_value = $this->plugin->transform([0, '', []], $this->migrateExecutable, $this->row, 'destinationproperty');
40 $this->assertEmpty($transformed_value);
46 public function testTransformSinglePageWithFront() {
47 $visibility = $this->plugin->transform([0, '<front>', []], $this->migrateExecutable, $this->row, 'destinationproperty');
48 $this->assertSame('request_path', $visibility['request_path']['id']);
49 $this->assertTrue($visibility['request_path']['negate']);
50 $this->assertSame('<front>', $visibility['request_path']['pages']);
56 public function testTransformMultiplePagesWithFront() {
57 $visibility = $this->plugin->transform([1, "foo\n/bar\rbaz\r\n<front>", []], $this->migrateExecutable, $this->row, 'destinationproperty');
58 $this->assertSame('request_path', $visibility['request_path']['id']);
59 $this->assertFalse($visibility['request_path']['negate']);
60 $this->assertSame("/foo\n/bar\n/baz\n<front>", $visibility['request_path']['pages']);
66 public function testTransformPhpEnabled() {
67 $this->moduleHandler->moduleExists('php')->willReturn(TRUE);
68 $visibility = $this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
69 $this->assertSame('php', $visibility['php']['id']);
70 $this->assertFalse($visibility['php']['negate']);
71 $this->assertSame('<?php', $visibility['php']['php']);
77 public function testTransformPhpDisabled() {
78 $this->moduleHandler->moduleExists('php')->willReturn(FALSE);
79 $transformed_value = $this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
80 $this->assertEmpty($transformed_value);