Completed
Pull Request — 8.x-3.x (#686)
by Sebastian
02:04
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
    $metadata = $this->defaultCacheMetaData();
54
    $metadata->addCacheTags([
55
      'config:language.entity.en',
56
      'config:language.entity.es',
57
      'config:language.entity.fr',
58
      'config:language.entity.pt-br'
59
    ]);
60
61
    $this->assertResults($this->getQueryFromFile('languages.gql'), [], [
62
      'languages' => [
63
        0 => [
64
          'id' => 'en',
65
          'name' => 'English',
66
          'isDefault' => TRUE,
67
          'isLocked' => FALSE,
68
          'direction' => 'ltr',
69
          'weight' => 0,
70
          'argument' => 'en',
71
        ],
72
        1 => [
73
          'id' => 'fr',
74
          'name' => 'French',
75
          'isDefault' => FALSE,
76
          'isLocked' => FALSE,
77
          'direction' => 'ltr',
78
          'weight' => 1,
79
          'argument' => 'fr',
80
        ],
81
        2 => [
82
          'id' => 'es',
83
          'name' => 'Spanish',
84
          'isDefault' => FALSE,
85
          'isLocked' => FALSE,
86
          'direction' => 'ltr',
87
          'weight' => 2,
88
          'argument' => 'es',
89
        ],
90
        3 => [
91
          'id' => 'pt-br',
92
          'name' => 'Portuguese, Brazil',
93
          'isDefault' => FALSE,
94
          'isLocked' => FALSE,
95
          'direction' => 'ltr',
96
          'weight' => 3,
97
          'argument' => 'pt_br',
98
        ],
99
      ],
100
    ], $metadata);
101
  }
102
103
  /**
104
   * Test language switch links.
105
   */
106
  public function testLanguageSwitchLinks() {
107
    $metadata = $this->defaultCacheMetaData();
108
109
    $this->assertResults($this->getQueryFromFile('language_switch_links.gql'), [], [
110
      'route' => [
111
        'links' => [
112
          0 => [
113
            'language' => [
114
              'id' => 'en',
115
            ],
116
            'url' => [
117
              'path' => '/en',
118
            ],
119
            'title' => 'English',
120
            'active' => TRUE,
121
          ],
122
          1 => [
123
            'language' => [
124
              'id' => 'fr',
125
            ],
126
            'url' => [
127
              'path' => '/fr',
128
            ],
129
            'title' => NULL,
130
            'active' => FALSE,
131
          ],
132
          2 => [
133
            'language' => [
134
              'id' => 'es',
135
            ],
136
            'url' => [
137
              'path' => '/es',
138
            ],
139
            'title' => NULL,
140
            'active' => FALSE,
141
          ],
142
          3 => [
143
            'language' => [
144
              'id' => 'pt-br',
145
            ],
146
            'url' => [
147
              'path' => '/',
148
            ],
149
            'title' => NULL,
150
            'active' => FALSE,
151
          ],
152
        ],
153
      ],
154
    ], $metadata);
155
  }
156
}
157