summaryrefslogtreecommitdiffstatshomepage
path: root/core/tests/Drupal/FunctionalJavascriptTests/MachineName/MachineNameTransliterationTest.php
blob: ad9ba4f89d8e8fa205f140c0a77fad4f947ba5b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php

declare(strict_types=1);

namespace Drupal\FunctionalJavascriptTests\MachineName;

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

use Drupal\language\Entity\ConfigurableLanguage;

/**
 * Tests the machine name transliteration functionality.
 *
 * @group javascript
 * @group #slow
 */
class MachineNameTransliterationTest extends WebDriverTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'language',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    $admin_user = $this->drupalCreateUser([
      'administer site configuration',
      'administer languages',
      'access administration pages',
      'administer permissions',
    ]);
    $this->drupalLogin($admin_user);

  }

  /**
   * Test for machine name transliteration functionality.
   *
   * @dataProvider machineNameInputOutput
   */
  public function testMachineNameTransliterations($langcode, $input, $output): void {
    $page = $this->getSession()->getPage();
    if ($langcode !== 'en') {
      ConfigurableLanguage::createFromLangcode($langcode)->save();
    }
    $this->config('system.site')->set('default_langcode', $langcode)->save();
    $this->rebuildContainer();

    $this->drupalGet("/admin/people/roles/add");
    $page->find('css', '[data-drupal-selector="edit-label"]')->setValue($input);
    $this->assertSession()->elementTextEquals('css', 'span.machine-name-value', $output);
  }

  /**
   * Data for the testMachineNameTransliterations.
   *
   * @return array
   *   An array of arrays, where each sub-array contains a language code,
   *   input string, and the expected transliterated output string.
   */
  public static function machineNameInputOutput(): array {
    return [
      // cSpell:disable
      ['en', 'Bob', 'bob'],
      ['en', 'Äwesome', 'awesome'],
      ['de', 'Äwesome', 'aewesome'],
      ['da', 'äöüåøhello', 'aouaaoehello'],
      ['fr', 'ц', 'c'],
      ['fr', 'ᐑ', 'wii'],
      // This test is not working with chromedriver as '𐌰𐌸' chars are not
      // accepted.
      // ['en', '𐌰𐌸', '__'],
      ['en', 'Ä Ö Ü Å Ø äöüåøhello', 'a_o_u_a_o_aouaohello'],
      ['de', 'Ä Ö Ü Å Ø äöüåøhello', 'ae_oe_ue_a_o_aeoeueaohello'],
      ['de', ']URY&m_G^;', 'ury_m_g'],
      ['da', 'Ä Ö Ü Å Ø äöüåøhello', 'a_o_u_aa_oe_aouaaoehello'],
      ['kg', 'ц', 'ts'],
      ['en', ' Hello Abventor! ', 'hello_abventor'],
      // cSpell:enable
    ];
  }

}