LanguageTest::testLanguageSwitchLinks()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 55
rs 9.312
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Drupal\Tests\graphql_core\Kernel\Languages;
4
5
use Drupal\language\Entity\ConfigurableLanguage;
0 ignored issues
show
Bug introduced by
The type Drupal\language\Entity\ConfigurableLanguage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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(): void {
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
    // @todo Should this also contain the language config cache metadata?
55
    $this->assertResults($this->getQueryFromFile('languages.gql'), [], [
56
      'languages' => [
57
        0 => [
58
          'id' => 'en',
59
          'name' => 'English',
60
          'isDefault' => TRUE,
61
          'isLocked' => FALSE,
62
          'direction' => 'ltr',
63
          'weight' => 0,
64
          'argument' => 'en',
65
        ],
66
        1 => [
67
          'id' => 'fr',
68
          'name' => 'French',
69
          'isDefault' => FALSE,
70
          'isLocked' => FALSE,
71
          'direction' => 'ltr',
72
          'weight' => 1,
73
          'argument' => 'fr',
74
        ],
75
        2 => [
76
          'id' => 'es',
77
          'name' => 'Spanish',
78
          'isDefault' => FALSE,
79
          'isLocked' => FALSE,
80
          'direction' => 'ltr',
81
          'weight' => 2,
82
          'argument' => 'es',
83
        ],
84
        3 => [
85
          'id' => 'pt-br',
86
          'name' => 'Portuguese, Brazil',
87
          'isDefault' => FALSE,
88
          'isLocked' => FALSE,
89
          'direction' => 'ltr',
90
          'weight' => 3,
91
          'argument' => 'pt_br',
92
        ],
93
      ],
94
    ], $metadata);
95
  }
96
97
  /**
98
   * Test language switch links.
99
   */
100
  public function testLanguageSwitchLinks() {
101
    $metadata = $this->defaultCacheMetaData();
102
    $metadata->addCacheTags([
103
      'config:language.entity.en',
104
      'config:language.entity.es',
105
      'config:language.entity.fr',
106
      'config:language.entity.pt-br',
107
    ]);
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
}
158