Index: core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php	(revision )
+++ core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php	(revision )
@@ -0,0 +1,103 @@
+<?php
+
+namespace Drupal\FunctionalJavascriptTests\Core;
+
+use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\Component\Transliteration\TransliterationInterface;
+use Drupal\Component\Utility\Unicode;
+
+/**
+ * Tests for the machine name field.
+ *
+ * @group session
+ */
+class MachineNameTest extends JavascriptTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['system', 'node', 'user'];
+
+  /**
+   * The transliteration helper.
+   *
+   * @var \Drupal\Component\Transliteration\TransliterationInterface
+   */
+  protected $transliteration;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $account = $this->drupalCreateUser(array(
+      'access content',
+      'administer permissions',
+    ));
+    $this->drupalLogin($account);
+
+    // Get the transliteration server for validating the generated machine name.
+    $this->transliteration = \Drupal::service('transliteration');
+  }
+
+  /**
+   * Tests that machine name field functions.
+   *
+   * Makes sure that the machine name field automatically provides a valid
+   * machine name and that the manual editing mode functions.
+   */
+  public function testMachineName() {
+    // Visit the add role page which contains a machine name field.
+    $this->drupalGet('admin/people/roles/add');
+
+    // Test values for conversion.
+    $test_values = array(
+      'Test value !0-9@' => 'A title that should be transliterated must be equal to the php generated machine name',
+      'Test value' => 'A title that should not be transliterated must be equal to the php generated machine name',
+    );
+
+    // Find relevant elements on the page for this test.
+    $page = $this->getSession()->getPage();
+    $assert_session = $this->assertSession();
+    $element = $page->findField('label');
+    $machine_name = $page->find('css', '#edit-label-machine-name-suffix .machine-name-value');
+    $button = $page->find('css', '#edit-label-machine-name-suffix button.link');
+    $id = $page->findField('id');
+
+    // Test each value for conversion to a machine name.
+    foreach ($test_values as $test_value => $message) {
+      $transliterated = $this->transliteration->transliterate($test_value);
+      $transliterated = Unicode::strtolower($transliterated);
+      $transliterated = preg_replace('@' . strtr('[^a-z0-9_]+', [
+          '@' => '\@',
+          chr(0) => ''
+        ]) . '@', '_', $transliterated);
+
+      // Set the value for the role, triggering the machine name update.
+      $element->setValue($test_value);
+
+      // Wait the set timeout for fetching the machine name.
+      $this->getSession()->wait(300);
+
+      // And wait for the autocomplete to finish.
+      $assert_session->waitOnAutocomplete();
+
+      // Get the generated machine name.
+      $generated_value = $machine_name->getHTML();
+
+      // Validate the generated machine name.
+      $this->assertEquals($transliterated, $generated_value, $message);
+    }
+
+    // Test switching back to the manual editing mode by clicking the edit link.
+    $button->click();
+
+    // Validate the visibility of the machine name field.
+    $this->assertTrue($id->isVisible(), 'The ID field must now be visible');
+
+    // Validate if the element contains the correct value.
+    $this->assertEquals($transliterated, $id->getValue(), 'The ID field value must be equal to the php generated machine name');
+  }
+
+}
