Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / field_layout / tests / src / FunctionalJavascript / FieldLayoutTest.php
index 162d22329c422c904f9fbefd31bfdc131157aca7..8a36c8489f51954974848b6afa58c139ffa9dca0 100644 (file)
@@ -3,14 +3,14 @@
 namespace Drupal\Tests\field_layout\FunctionalJavascript;
 
 use Drupal\entity_test\Entity\EntityTest;
-use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
 
 /**
  * Tests using field layout for entity displays.
  *
  * @group field_layout
  */
-class FieldLayoutTest extends JavascriptTestBase {
+class FieldLayoutTest extends WebDriverTestBase {
 
   /**
    * {@inheritdoc}
@@ -100,12 +100,15 @@ class FieldLayoutTest extends JavascriptTestBase {
     // After a refresh the new regions are still there.
     $this->drupalGet('entity_test/structure/entity_test/form-display');
     $this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles());
+    $this->assertSession()->waitForElement('css', '.tabledrag-handle');
+    $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();
 
     // Drag the field to the second region.
     $field_test_text_row = $this->getSession()->getPage()->find('css', '#field-test-text');
     $second_region_row = $this->getSession()->getPage()->find('css', '.region-second-message');
     $field_test_text_row->find('css', '.handle')->dragTo($second_region_row);
     $this->assertSession()->assertWaitOnAjaxRequest();
+    $this->assertSession()->waitForElement('css', "[name='form_build_id']:not([value='$id'])");
     $this->submitForm([], 'Save');
     $this->assertSession()->pageTextContains('Your settings have been saved.');
 
@@ -158,6 +161,8 @@ class FieldLayoutTest extends JavascriptTestBase {
     // After a refresh the new regions are still there.
     $this->drupalGet('entity_test/structure/entity_test/display');
     $this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles());
+    $this->assertSession()->waitForElement('css', '.tabledrag-handle');
+    $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();
 
     // Drag the field to the first region.
     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
@@ -166,6 +171,7 @@ class FieldLayoutTest extends JavascriptTestBase {
     $field_test_text_row->find('css', '.handle')->dragTo($first_region_row);
     $this->assertSession()->assertWaitOnAjaxRequest();
     $this->assertFalse($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
+    $this->assertSession()->waitForElement('css', "[name='form_build_id']:not([value='$id'])");
     $this->submitForm([], 'Save');
     $this->assertSession()->pageTextContains('Your settings have been saved.');
 
@@ -233,6 +239,40 @@ class FieldLayoutTest extends JavascriptTestBase {
     $this->assertSession()->pageTextContains('Blah: Test text');
   }
 
+  /**
+   * Tests changing the formatter and region at the same time.
+   */
+  public function testChangingFormatterAndRegion() {
+    $assert_session = $this->assertSession();
+    $page = $this->getSession()->getPage();
+
+    // Add the test field to the content region.
+    $this->drupalGet('entity_test/structure/entity_test/display');
+    $page->find('css', '#field-test-text .handle')->dragTo($page->find('css', '.region-content-message'));
+    $assert_session->assertWaitOnAjaxRequest();
+    $page->pressButton('Save');
+    $assert_session->fieldValueEquals('fields[field_test_text][region]', 'content');
+    $assert_session->fieldValueEquals('fields[field_test_text][type]', 'text_default');
+
+    // Switch the layout to two columns.
+    $this->click('#edit-field-layouts');
+    $page->selectFieldOption('field_layout', 'layout_twocol');
+    $assert_session->assertWaitOnAjaxRequest();
+    $page->pressButton('Save');
+    $assert_session->fieldValueEquals('fields[field_test_text][region]', 'first');
+
+    // Change the formatter and move to another region.
+    $page->selectFieldOption('fields[field_test_text][type]', 'text_trimmed');
+    $assert_session->assertWaitOnAjaxRequest();
+    $page->find('css', '#field-test-text .handle')->dragTo($page->find('css', '.region-second-message'));
+    $assert_session->assertWaitOnAjaxRequest();
+    $page->pressButton('Save');
+
+    // Assert that both the formatter and region change are persisted.
+    $assert_session->fieldValueEquals('fields[field_test_text][region]', 'second');
+    $assert_session->fieldValueEquals('fields[field_test_text][type]', 'text_trimmed');
+  }
+
   /**
    * Gets the region titles on the page.
    *