Completed
Pull Request — 8.x-3.x (#509)
by Sebastian
02:18
created

LanguageTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 28 1
B testLanguageId() 0 45 1
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' => 'fr',
34
      'weight' => 1,
35
    ])->save();
36
37
    ConfigurableLanguage::create([
38
      'id' => 'es',
39
      'weight' => 2,
40
    ])->save();
41
42
    ConfigurableLanguage::create([
43
      'id' => 'pt-br',
44
      'weight' => 3,
45
    ])->save();
46
47
    $config = $this->config('language.negotiation');
48
    $config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])
49
      ->save();
50
51
    $this->container->get('kernel')->rebuildContainer();
52
  }
53
54
  /**
55
   * Test listing of available languages.
56
   */
57
  public function testLanguageId() {
58
    // TODO: Check cache metadata.
59
    $metadata = $this->defaultCacheMetaData();
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