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}
// 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.');
// 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());
$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.');
$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.
*