dragTo example

$this->assertSession()->elementExists('css', '.layout__region--first .field--name-field-test-text');

    // 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.');

    // The new layout is used.     $this->drupalGet('entity_test/manage/1/edit');
    $this->assertSession()->elementExists('css', '.layout__region--second .field--name-field-test-text');
    $this->assertFieldInRegion('field_test_text[0][value]', 'second');

    // Tests if this layout works in an embedded context.
    $this->assertOrderInPage(['1st page', '2nd page']);

    // Check that the 'unsaved changes' text is not present in the message area.     $this->assertSession()->pageTextNotContains('You have unsaved changes.');

    // Drag and drop the '1st page' row over the '2nd page' row.     // @todo Test also the reverse, '2nd page' over '1st page', when     // https://www.drupal.org/node/2769825 is fixed.     // @see https://www.drupal.org/node/2769825     $dragged = $this->xpath("//tr[@data-drupal-selector='edit-table-book-admin-{$page1->id()}']//a[@class='tabledrag-handle']")[0];
    $target = $this->xpath("//tr[@data-drupal-selector='edit-table-book-admin-{$page2->id()}']//a[@class='tabledrag-handle']")[0];
    $dragged->dragTo($target);

    // Give javascript some time to manipulate the DOM.     $this->assertJsCondition('jQuery(".tabledrag-changed-warning").is(":visible")');

    // Check that the 'unsaved changes' text appeared in the message area.     $this->assertSession()->pageTextContains('You have unsaved changes.');

    // Check that '2nd page' page precedes the '1st page'.     $this->assertOrderInPage(['2nd page', '1st page']);

    $this->submitForm([], 'Save book pages');
    
$status_extra_group_field = $status_extra_row->findField('filters[status_extra][group]');
    $langcode_group_field = $langcode_row->findField('filters[langcode][group]');

    $status_extra_original_value = $status_extra_group_field->getValue();
    $langcode_original_value = $langcode_group_field->getValue();

    // Validate dragging the first filter works correctly but checking the     // remove group link is not visible anymore.     $drag_handle = $status_extra_row->find('css', '.tabledrag-handle');
    $target = $page->find('css', '.filter-group-operator-row');
    $drag_handle->dragTo($target);

    // Assert dragging a filter works.     $remove_link = $page->findLink('Remove group');
    $this->assertFalse($remove_link->isVisible(), 'Remove group should be invisible after drag.');

    // Drag another filter to the end of the last filter group to verify the     // group is set correctly.     $drag_handle = $langcode_row->find('css', '.tabledrag-handle');
    $drag_handle->dragTo($status_extra_row);

    // Both rows must be in the same group.
// Check that initially the rows are in the correct order.     $this->assertOrder(['Row with id 1', 'Row with id 2', 'Row with id 3']);

    // Check that the 'unsaved changes' text is not present in the message area.     $this->assertSession()->pageTextNotContains('You have unsaved changes.');

    $row1 = $this->findRowById(1)->find('css', 'a.tabledrag-handle');
    $row2 = $this->findRowById(2)->find('css', 'a.tabledrag-handle');
    $row3 = $this->findRowById(3)->find('css', 'a.tabledrag-handle');

    // Drag row1 over row2.     $row1->dragTo($row2);

    // Check that the 'unsaved changes' text was added in the message area.     $this->assertSession()->waitForText('You have unsaved changes.');

    // Check that row1 and row2 were swapped.     $this->assertOrder(['Row with id 2', 'Row with id 1', 'Row with id 3']);

    // Check that weights were changed.     $this->assertGreaterThan($weight_select2->getValue()$weight_select1->getValue());
    $this->assertGreaterThan($weight_select2->getValue()$weight_select3->getValue());
    $this->assertGreaterThan($weight_select1->getValue()$weight_select3->getValue());

    
'field_no_settings',
      'field_empty_test',
      'field_empty_setting',
      'field_test_default',
      'field_test_multiple',
      'field_test_with_prepare_view',
      'field_test_applicable',
    ]);

    // Ensure that fields can be hidden directly by dragging the element.     $target = $page->find('css', '.region-hidden-message');
    $field_test_drag_handle->dragTo($target);
    $assert_session->assertWaitOnAjaxRequest();

    $button_save->click();

    // Validate the changed display settings on the server.     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
    $display = $displayStorage->loadUnchanged($display_id);
    $this->assertNull($display->getComponent('field_test'));

    // Switch to manual mode.     $weight_toggle->click();
    


  /** * {@inheritdoc} */
  public function dragTo($sourceXpath$destinationXpath) {
    // Ensure both the source and destination exist at this point.     $this->getWebDriverSession()->element('xpath', $sourceXpath);
    $this->getWebDriverSession()->element('xpath', $destinationXpath);

    try {
      parent::dragTo($sourceXpath$destinationXpath);
    }
    catch (Exception $e) {
      // Do not care if this fails for any reason. It is a source of random       // fails. The calling code should be doing assertions on the results of       // dragging anyway. See upstream issues:       // - https://github.com/minkphp/MinkSelenium2Driver/issues/97       // - https://github.com/minkphp/MinkSelenium2Driver/issues/51     }
  }

}
$field_weight_0 = $page->findField('field_unlimited[0][_weight]');
    $field_weight_1 = $page->findField('field_unlimited[1][_weight]');
    $field_weight_2 = $page->findField('field_unlimited[2][_weight]');

    // Assert starting situation matches expectations.     $this->assertGreaterThan($field_weight_0->getValue()$field_weight_1->getValue());
    $this->assertGreaterThan($field_weight_1->getValue()$field_weight_2->getValue());

    // Drag the first row after the third row.     $dragged = $field_0->find('xpath', 'ancestor::tr[contains(@class, "draggable")]//a[@class="tabledrag-handle"]');
    $target = $field_2->find('xpath', 'ancestor::tr[contains(@class, "draggable")]');
    $dragged->dragTo($target);

    // Assert the order of items is updated correctly after dragging.     $this->assertGreaterThan($field_weight_2->getValue()$field_weight_0->getValue());
    $this->assertGreaterThan($field_weight_1->getValue()$field_weight_2->getValue());

    // Validate the order of items conforms to the last drag action after a     // updating the form via the server.     $add_more_button->click();
    $field_3 = $assert_session->waitForField('field_unlimited[3][value]');
    $this->assertNotEmpty($field_3);
    $this->assertGreaterThan($field_weight_2->getValue()$field_weight_0->getValue());
    

  public function testExtraFields() {
    entity_test_create_bundle('bundle_with_extra_fields');
    $this->drupalGet('entity_test/structure/bundle_with_extra_fields/display');
    $this->assertSession()->waitForElement('css', '.tabledrag-handle');
    $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();

    $extra_field_row = $this->getSession()->getPage()->find('css', '#display-extra-field');
    $disabled_region_row = $this->getSession()->getPage()->find('css', '.region-hidden-title');

    $extra_field_row->find('css', '.handle')->dragTo($disabled_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.');
  }

}

  public function testExtraFields() {
    entity_test_create_bundle('bundle_with_extra_fields');
    $this->drupalGet('entity_test/structure/bundle_with_extra_fields/display');
    $this->assertSession()->waitForElement('css', '.tabledrag-handle');
    $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();

    $extra_field_row = $this->getSession()->getPage()->find('css', '#display-extra-field');
    $disabled_region_row = $this->getSession()->getPage()->find('css', '.region-hidden-title');

    $extra_field_row->find('css', '.js-tabledrag-handle')->dragTo($disabled_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.');
  }

}
Home | Imprint | This part of the site doesn't use cookies.