public function TableDragTest::testDragAndDrop in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testDragAndDrop()
Tests draggable table drag'n'drop.
File
- core/
tests/ Drupal/ FunctionalJavascriptTests/ TableDrag/ TableDragTest.php, line 87
Class
- TableDragTest
- Tests draggable table.
Namespace
Drupal\FunctionalJavascriptTests\TableDragCode
public function testDragAndDrop() {
$this->state
->set('tabledrag_test_table', array_flip(range(1, 3)));
$this
->drupalGet('tabledrag_test');
$session = $this
->getSession();
$page = $session
->getPage();
$weight_select1 = $page
->findField("table[1][weight]");
$weight_select2 = $page
->findField("table[2][weight]");
$weight_select3 = $page
->findField("table[3][weight]");
// 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());
// Now move the last row (row3) in the second position. row1 should go last.
$row3
->dragTo($row1);
// Check that the order is: row2, row3 and row1.
$this
->assertOrder([
'Row with id 2',
'Row with id 3',
'Row with id 1',
]);
}