Completed
Pull Request — 8.x-3.x (#509)
by Sebastian
08:13 queued 05:46
created

LanguageTest::testLanguageId()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 37
nc 1
nop 0
dl 0
loc 45
rs 8.8571
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
    'graphql_context_test',
21
  ];
22
23
  /**
24
   * {@inheritdoc}
25
   */
26
  protected function setUp() {
27
    parent::setUp();
28
29
    $this->installconfig(['language']);
30
    $this->installEntitySchema('configurable_language');
31
    $this->container->get('router.builder')->rebuild();
32
33
    ConfigurableLanguage::create([
34
      'id' => 'fr',
35
      'weight' => 1,
36
    ])->save();
37
38
    ConfigurableLanguage::create([
39
      'id' => 'es',
40
      'weight' => 2,
41
    ])->save();
42
43
    ConfigurableLanguage::create([
44
      'id' => 'pt-br',
45
      'weight' => 3,
46
    ])->save();
47
48
    $config = $this->config('language.negotiation');
49
    $config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])
50
      ->save();
51
52
    $this->container->get('kernel')->rebuildContainer();
53
  }
54
55
  /**
56
   * Test listing of available languages.
57
   */
58
  public function testLanguageId() {
59
    // TODO: Check cache metadata.
60
    $metadata = $this->defaultCacheMetaData();
61
62
    $this->assertResults($this->getQueryFromFile('languages.gql'), [], [
63
      'languages' => [
64
        0 => [
65
          'id' => 'en',
66
          'name' => 'English',
67
          'isDefault' => TRUE,
68
          'isLocked' => FALSE,
69
          'direction' => 'ltr',
70
          'weight' => 0,
71
          'argument' => 'en',
72
        ],
73
        1 => [
74
          'id' => 'fr',
75
          'name' => 'French',
76
          'isDefault' => FALSE,
77
          'isLocked' => FALSE,
78
          'direction' => 'ltr',
79
          'weight' => 1,
80
          'argument' => 'fr',
81
        ],
82
        2 => [
83
          'id' => 'es',
84
          'name' => 'Spanish',
85
          'isDefault' => FALSE,
86
          'isLocked' => FALSE,
87
          'direction' => 'ltr',
88
          'weight' => 2,
89
          'argument' => 'es',
90
        ],
91
        3 => [
92
          'id' => 'pt-br',
93
          'name' => 'Portuguese, Brazil',
94
          'isDefault' => FALSE,
95
          'isLocked' => FALSE,
96
          'direction' => 'ltr',
97
          'weight' => 3,
98
          'argument' => 'pt_br',
99
        ],
100
      ],
101
    ], $metadata);
102
  }
103
104
  /**
105
   * Test language switch links.
106
   */
107
  public function testLanguageSwitchLinks() {
108
    $result = $this->executeQueryFile('languages.gql');
109
110
    $english = [
111
      'language' => [
112
        'id' => 'en',
113
      ],
114
      'url' => [
115
        'path' => '/en',
116
      ],
117
      'title' => 'English',
118
      'active' => true,
119
    ];
120
121
    $french = [
122
      'language' => [
123
        'id' => 'fr',
124
      ],
125
      'url' => [
126
        'path' => '/fr',
127
      ],
128
      'title' => NULL,
129
      'active' => false,
130
    ];
131
132
    $spanish = [
133
      'language' => [
134
        'id' => 'es',
135
      ],
136
      'url' => [
137
        'path' => '/es',
138
      ],
139
      'title' => NULL,
140
      'active' => false,
141
    ];
142
143
    $brazil = [
144
      'language' => [
145
        'id' => 'pt-br',
146
      ],
147
      'url' => [
148
        'path' => '/',
149
      ],
150
      'title' => NULL,
151
      'active' => false,
152
    ];
153
154
    $this->assertEquals([$english, $french, $spanish, $brazil], $result['data']['frontpage']['languageSwitchLinks']);
155
  }
156
157
}
158