Version 1
[yaffs-website] / web / core / modules / language / tests / src / Unit / process / LanguageNegotiationTest.php
1 <?php
2
3 namespace Drupal\Tests\language\Unit\process;
4
5 use Drupal\language\Plugin\migrate\process\LanguageNegotiation;
6 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
7 use Drupal\migrate\MigrateException;
8
9 /**
10  * @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageNegotiation
11  * @group language
12  */
13 class LanguageNegotiationTest extends MigrateProcessTestCase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function setUp() {
19     $this->plugin = new LanguageNegotiation([], 'map', []);
20     parent::setUp();
21   }
22
23   /**
24    * Tests successful transformation without weights.
25    */
26   public function testTransformWithWeights() {
27     $source = [
28       [
29         'locale-url' => [],
30         'language-default' => [],
31       ],
32       [
33         'locale-url' => -10,
34         'locale-session' => -9,
35         'locale-user' => -8,
36         'locale-browser' => -7,
37         'language-default' => -6,
38       ],
39     ];
40     $expected = [
41       'enabled' => [
42         'language-url' => -10,
43         'language-selected' => -6,
44       ],
45       'method_weights' => [
46         'language-url' => -10,
47         'language-session' => -9,
48         'language-user' => -8,
49         'language-browser' => -7,
50         'language-selected' => -6,
51       ],
52     ];
53     $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
54     $this->assertSame($value, $expected);
55   }
56
57   /**
58    * Tests successful transformation without weights.
59    */
60   public function testTransformWithoutWeights() {
61     $source = [
62       [
63         'locale-url' => [],
64         'locale-url-fallback' => [],
65       ],
66     ];
67     $expected = [
68       'enabled' => [
69         'language-url' => 0,
70         'language-url-fallback' => 1,
71       ],
72     ];
73     $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
74     $this->assertSame($value, $expected);
75   }
76
77   /**
78    * Tests string input.
79    */
80   public function testStringInput() {
81     $this->plugin = new LanguageNegotiation([], 'map', []);
82     $this->setExpectedException(MigrateException::class, 'The input should be an array');
83     $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
84   }
85
86 }