Version 1
[yaffs-website] / web / core / modules / language / tests / src / Unit / process / LanguageDomainsTest.php
1 <?php
2
3 namespace Drupal\Tests\language\Unit\process;
4
5 use Drupal\language\Plugin\migrate\process\LanguageDomains;
6 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
7
8 /**
9  * @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageDomains
10  * @group language
11  */
12 class LanguageDomainsTest extends MigrateProcessTestCase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected $backupGlobalsBlacklist = ['base_url'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp() {
23     $configuration = [
24       'key' => 'language',
25       'value' => 'domain',
26     ];
27     $this->plugin = new LanguageDomains($configuration, 'map', []);
28     parent::setUp();
29
30     // The language_domains plugin calls getSourceProperty() to check if domain
31     // negotiation is used. If it is the values will be processed so we need it
32     // to return TRUE to be able to test the process.
33     $this->row->expects($this->once())
34       ->method('getSourceProperty')
35       ->will($this->returnValue(TRUE));
36
37     // The language_domains plugin use $base_url to fill empty domains.
38     global $base_url;
39     $base_url = 'http://example.com';
40   }
41
42   /**
43    * @covers ::transform
44    */
45   public function testTransform() {
46     $source = [
47       ['language' => 'en', 'domain' => ''],
48       ['language' => 'fr', 'domain' => 'fr.example.com'],
49       ['language' => 'es', 'domain' => 'http://es.example.com'],
50       ['language' => 'hu', 'domain' => 'https://hu.example.com'],
51     ];
52     $expected = [
53       'en' => 'example.com',
54       'fr' => 'fr.example.com',
55       'es' => 'es.example.com',
56       'hu' => 'hu.example.com',
57     ];
58     $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
59     $this->assertSame($value, $expected);
60   }
61
62 }