f473dc4c83c27ac56609c9ad17eb59f1b64e93f4
[yaffs-website] / web / core / modules / block / tests / src / Unit / Plugin / migrate / process / BlockRegionTest.php
1 <?php
2
3 namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
4
5 use Drupal\block\Plugin\migrate\process\BlockRegion;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\Row;
8 use Drupal\Tests\UnitTestCase;
9
10 /**
11  * @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockRegion
12  * @group block
13  */
14 class BlockRegionTest extends UnitTestCase {
15
16   /**
17    * Transforms a value through the block_region plugin.
18    *
19    * @param array $value
20    *   The value to transform.
21    * @param \Drupal\migrate\Row|null $row
22    *   (optional) The mocked row.
23    *
24    * @return array|string
25    *   The transformed value.
26    */
27   protected function transform(array $value, Row $row = NULL) {
28     $executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
29     if (empty($row)) {
30       $row = $this->prophesize(Row::class)->reveal();
31     }
32
33     $configuration = [
34       'map' => [
35         'bartik' => [
36           'bartik' => [
37             'triptych_first' => 'triptych_first',
38             'triptych_middle' => 'triptych_second',
39             'triptych_last' => 'triptych_third',
40           ],
41         ],
42       ],
43       'default_value' => 'content',
44     ];
45
46     $plugin = new BlockRegion($configuration, 'block_region', [], $configuration['map']['bartik']['bartik']);
47     return $plugin->transform($value, $executable, $row, 'foo');
48   }
49
50   /**
51    * If the source and destination themes are identical, the region should only
52    * be passed through if it actually exists in the destination theme.
53    *
54    * @covers ::transform
55    */
56   public function testTransformSameThemeRegionExists() {
57     $this->assertSame('triptych_second', $this->transform(['bartik', 'bartik', 'triptych_middle']));
58   }
59
60   /**
61    * If the source and destination themes are identical, the region should be
62    * changed to 'content' if it doesn't exist in the destination theme.
63    *
64    * @covers ::transform
65    */
66   public function testTransformSameThemeRegionNotExists() {
67     $this->assertSame('content', $this->transform(['bartik', 'bartik', 'footer']));
68   }
69
70 }