b57cffea49d4b4420c342d7c95f86f3eadad6371
[yaffs-website] / ConfigTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit\destination;
4
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\migrate\Plugin\migrate\destination\Config;
7 use Drupal\Tests\UnitTestCase;
8
9 /**
10  * @coversDefaultClass \Drupal\migrate\Plugin\migrate\destination\Config
11  * @group migrate
12  */
13 class ConfigTest extends UnitTestCase {
14
15   /**
16    * Test the import method.
17    */
18   public function testImport() {
19     $source = [
20       'test' => 'x',
21     ];
22     $migration = $this->getMockBuilder('Drupal\migrate\Plugin\Migration')
23       ->disableOriginalConstructor()
24       ->getMock();
25     $config = $this->getMockBuilder('Drupal\Core\Config\Config')
26       ->disableOriginalConstructor()
27       ->getMock();
28     foreach ($source as $key => $val) {
29       $config->expects($this->once())
30         ->method('set')
31         ->with($this->equalTo($key), $this->equalTo($val))
32         ->will($this->returnValue($config));
33     }
34     $config->expects($this->once())
35       ->method('save');
36     $config->expects($this->once())
37       ->method('getName')
38       ->willReturn('d8_config');
39     $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
40     $config_factory->expects($this->once())
41       ->method('getEditable')
42       ->with('d8_config')
43       ->will($this->returnValue($config));
44     $row = $this->getMockBuilder('Drupal\migrate\Row')
45       ->disableOriginalConstructor()
46       ->getMock();
47     $row->expects($this->any())
48       ->method('getRawDestination')
49       ->will($this->returnValue($source));
50     $language_manager = $this->getMockBuilder('Drupal\language\ConfigurableLanguageManagerInterface')
51       ->disableOriginalConstructor()
52       ->getMock();
53     $language_manager->expects($this->never())
54       ->method('getLanguageConfigOverride')
55       ->with('fr', 'd8_config')
56       ->will($this->returnValue($config));
57     $destination = new Config(['config_name' => 'd8_config'], 'd8_config', ['pluginId' => 'd8_config'], $migration, $config_factory, $language_manager);
58     $destination_id = $destination->import($row);
59     $this->assertEquals($destination_id, ['d8_config']);
60   }
61
62   /**
63    * Test the import method.
64    */
65   public function testLanguageImport() {
66     $source = [
67       'langcode' => 'mi',
68     ];
69     $migration = $this->getMockBuilder(MigrationInterface::class)
70       ->disableOriginalConstructor()
71       ->getMock();
72     $config = $this->getMockBuilder('Drupal\Core\Config\Config')
73       ->disableOriginalConstructor()
74       ->getMock();
75     foreach ($source as $key => $val) {
76       $config->expects($this->once())
77         ->method('set')
78         ->with($this->equalTo($key), $this->equalTo($val))
79         ->will($this->returnValue($config));
80     }
81     $config->expects($this->once())
82       ->method('save');
83     $config->expects($this->any())
84       ->method('getName')
85       ->willReturn('d8_config');
86     $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
87     $config_factory->expects($this->once())
88       ->method('getEditable')
89       ->with('d8_config')
90       ->will($this->returnValue($config));
91     $row = $this->getMockBuilder('Drupal\migrate\Row')
92       ->disableOriginalConstructor()
93       ->getMock();
94     $row->expects($this->any())
95       ->method('getRawDestination')
96       ->will($this->returnValue($source));
97     $row->expects($this->any())
98       ->method('getDestinationProperty')
99       ->will($this->returnValue($source['langcode']));
100     $language_manager = $this->getMockBuilder('Drupal\language\ConfigurableLanguageManagerInterface')
101       ->disableOriginalConstructor()
102       ->getMock();
103     $language_manager->expects($this->any())
104       ->method('getLanguageConfigOverride')
105       ->with('mi', 'd8_config')
106       ->will($this->returnValue($config));
107     $destination = new Config(['config_name' => 'd8_config', 'translations' => 'true'], 'd8_config', ['pluginId' => 'd8_config'], $migration, $config_factory, $language_manager);
108     $destination_id = $destination->import($row);
109     $this->assertEquals($destination_id, ['d8_config', 'mi']);
110   }
111
112 }