diff core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
line wrap: on
line diff
--- a/core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php	Tue Jul 10 15:07:59 2018 +0100
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php	Thu Feb 28 13:21:36 2019 +0000
@@ -2,14 +2,14 @@
 
 namespace Drupal\FunctionalJavascriptTests\Core;
 
-use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
 
 /**
  * Tests for the machine name field.
  *
  * @group field
  */
-class MachineNameTest extends JavascriptTestBase {
+class MachineNameTest extends WebDriverTestBase {
 
   /**
    * Required modules.
@@ -59,7 +59,6 @@
 
     // Get page and session.
     $page = $this->getSession()->getPage();
-    $assert_session = $this->assertSession();
 
     // Get elements from the page.
     $title_1 = $page->findField('machine_name_1_label');
@@ -111,6 +110,36 @@
 
     // Validate if the element contains the correct value.
     $this->assertEquals($test_values[1]['expected'], $machine_name_1_field->getValue(), 'The ID field value must be equal to the php generated machine name');
+
+    $assert = $this->assertSession();
+    $this->drupalGet('/form-test/form-test-machine-name-validation');
+
+    // Test errors after with no AJAX.
+    $assert->buttonExists('Save')->press();
+    $assert->pageTextContains('Machine-readable name field is required.');
+    // Ensure only the first machine name field has an error.
+    $this->assertTrue($assert->fieldExists('id')->hasClass('error'));
+    $this->assertFalse($assert->fieldExists('id2')->hasClass('error'));
+
+    // Test a successful submit after using AJAX.
+    $assert->fieldExists('Name')->setValue('test 1');
+    $assert->fieldExists('id')->setValue('test_1');
+    $assert->selectExists('snack')->selectOption('apple');
+    $assert->assertWaitOnAjaxRequest();
+    $assert->buttonExists('Save')->press();
+    $assert->pageTextContains('The form_test_machine_name_validation_form form has been submitted successfully.');
+
+    // Test errors after using AJAX.
+    $assert->fieldExists('Name')->setValue('duplicate');
+    $this->assertJsCondition('document.forms[0].id.value === "duplicate"');
+    $assert->fieldExists('id2')->setValue('duplicate2');
+    $assert->selectExists('snack')->selectOption('potato');
+    $assert->assertWaitOnAjaxRequest();
+    $assert->buttonExists('Save')->press();
+    $assert->pageTextContains('The machine-readable name is already in use. It must be unique.');
+    // Ensure both machine name fields both have errors.
+    $this->assertTrue($assert->fieldExists('id')->hasClass('error'));
+    $this->assertTrue($assert->fieldExists('id2')->hasClass('error'));
   }
 
 }