Completed
Pull Request — 8.x-3.x (#686)
by Sebastian
01:50
created

LanguageTest::testLanguageSwitchLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 50
rs 9.0909
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\Tests\graphql_core\Kernel\Languages;
4
5
use Drupal\language\Entity\ConfigurableLanguage;
6
use Drupal\Tests\graphql_core\Kernel\GraphQLCoreTestBase;
7
8
/**
9
 * Test multilingual behavior.
10
 *
11
 * @group graphql_core
12
 */
13
class LanguageTest extends GraphQLCoreTestBase {
14
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public static $modules = [
19
    'language',
20
  ];
21
22
  /**
23
   * {@inheritdoc}
24
   */
25
  protected function setUp() {
26
    parent::setUp();
27
28
    $this->installConfig(['language']);
29
    $this->installEntitySchema('configurable_language');
30
    $this->container->get('router.builder')->rebuild();
31
32
    ConfigurableLanguage::create([
33
      'id' => 'es',
34
      'weight' => 2,
35
    ])->save();
36
37
    ConfigurableLanguage::create([
38
      'id' => 'pt-br',
39
      'weight' => 3,
40
    ])->save();
41
42
    $config = $this->config('language.negotiation');
43
    $config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])
44
      ->save();
45
46
    $this->container->get('kernel')->rebuildContainer();
47
  }
48
49
  /**
50
   * Test listing of available languages.
51
   */
52
  public function testLanguageId() {
53
    // TODO: Check cache metadata.
54
    $metadata = $this->defaultCacheMetaData();
55
56
    $this->assertResults($this->getQueryFromFile('languages.gql'), [], [
57
      'languages' => [
58
        0 => [
59
          'id' => 'en',
60
          'name' => 'English',
61
          'isDefault' => TRUE,
62
          'isLocked' => FALSE,
63
          'direction' => 'ltr',
64
          'weight' => 0,
65
          'argument' => 'en',
66
        ],
67
        1 => [
68
          'id' => 'fr',
69
          'name' => 'French',
70
          'isDefault' => FALSE,
71
          'isLocked' => FALSE,
72
          'direction' => 'ltr',
73
          'weight' => 1,
74
          'argument' => 'fr',
75
        ],
76
        2 => [
77
          'id' => 'es',
78
          'name' => 'Spanish',
79
          'isDefault' => FALSE,
80
          'isLocked' => FALSE,
81
          'direction' => 'ltr',
82
          'weight' => 2,
83
          'argument' => 'es',
84
        ],
85
        3 => [
86
          'id' => 'pt-br',
87
          'name' => 'Portuguese, Brazil',
88
          'isDefault' => FALSE,
89
          'isLocked' => FALSE,
90
          'direction' => 'ltr',
91
          'weight' => 3,
92
          'argument' => 'pt_br',
93
        ],
94
      ],
95
    ], $metadata);
96
  }
97
98
  /**
99
   * Test language switch links.
100
   */
101
  public function testLanguageSwitchLinks() {
102
    $metadata = $this->defaultCacheMetaData();
103
104
    $this->assertResults($this->getQueryFromFile('language_switch_links.gql'), [], [
105
      'route' => [
106
        'links' => [
107
          0 => [
108
            'language' => [
109
              'id' => 'en',
110
            ],
111
            'url' => [
112
              'path' => '/en',
113
            ],
114
            'title' => 'English',
115
            'active' => TRUE,
116
          ],
117
          1 => [
118
            'language' => [
119
              'id' => 'fr',
120
            ],
121
            'url' => [
122
              'path' => '/fr',
123
            ],
124
            'title' => NULL,
125
            'active' => FALSE,
126
          ],
127
          2 => [
128
            'language' => [
129
              'id' => 'es',
130
            ],
131
            'url' => [
132
              'path' => '/es',
133
            ],
134
            'title' => NULL,
135
            'active' => FALSE,
136
          ],
137
          3 => [
138
            'language' => [
139
              'id' => 'pt-br',
140
            ],
141
            'url' => [
142
              'path' => '/',
143
            ],
144
            'title' => NULL,
145
            'active' => FALSE,
146
          ],
147
        ],
148
      ],
149
    ], $metadata);
150
  }
151
}
152