Version 1
[yaffs-website] / web / core / modules / block / tests / src / Unit / Plugin / migrate / process / BlockVisibilityTest.php
1 <?php
2
3 namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
4
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;
9
10 /**
11  * Tests the block_visibility process plugin.
12  *
13  * @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockVisibility
14  * @group block
15  */
16 class BlockVisibilityTest extends MigrateProcessTestCase {
17
18   /**
19    * The module handler.
20    *
21    * @var \Drupal\Core\Extension\ModuleHandlerInterface
22    */
23   protected $moduleHandler;
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setUp() {
29     parent::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());
33   }
34
35   /**
36    * @covers ::transform
37    */
38   public function testTransformNoData() {
39     $transformed_value = $this->plugin->transform([0, '', []], $this->migrateExecutable, $this->row, 'destinationproperty');
40     $this->assertEmpty($transformed_value);
41   }
42
43   /**
44    * @covers ::transform
45    */
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']);
51   }
52
53   /**
54    * @covers ::transform
55    */
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']);
61   }
62
63   /**
64    * @covers ::transform
65    */
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']);
72   }
73
74   /**
75    * @covers ::transform
76    */
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);
81   }
82
83 }