public function TableDragTest::testNestedDraggableTables in Drupal 9
Same name and namespace in other branches
- 10 core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testNestedDraggableTables()
Tests nested draggable tables through keyboard.
File
- core/
tests/ Drupal/ FunctionalJavascriptTests/ TableDrag/ TableDragTest.php, line 342
Class
- TableDragTest
- Tests draggable table.
Namespace
Drupal\FunctionalJavascriptTests\TableDragCode
public function testNestedDraggableTables() {
$this->state
->set('tabledrag_test_table', array_flip(range(1, 5)));
$this
->drupalGet('tabledrag_test_nested');
$this
->assertKeyboardAccessibility('');
// Now move the rows of the parent table.
$expected_parent_table = [
[
'id' => 'parent_1',
'weight' => 0,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
[
'id' => 'parent_2',
'weight' => 0,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
[
'id' => 'parent_3',
'weight' => 0,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
];
$this
->assertDraggableTable($expected_parent_table, 'tabledrag-test-parent-table', TRUE);
// Switch parent table rows children.
$this
->moveRowWithKeyboard($this
->findRowById('parent_2', 'tabledrag-test-parent-table'), 'up');
$expected_parent_table = [
[
'id' => 'parent_2',
'weight' => -10,
'parent' => '',
'indentation' => 0,
'changed' => TRUE,
],
[
'id' => 'parent_1',
'weight' => -9,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
[
'id' => 'parent_3',
'weight' => -8,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
];
$this
->assertDraggableTable($expected_parent_table, 'tabledrag-test-parent-table', TRUE);
// Try to move the row that contains the nested table to the last position.
// Order should be changed, but changed marker isn't added.
// This seems to be buggy, but this is the original behavior.
$this
->moveRowWithKeyboard($this
->findRowById('parent_1', 'tabledrag-test-parent-table'), 'down');
$expected_parent_table = [
[
'id' => 'parent_2',
'weight' => -10,
'parent' => '',
'indentation' => 0,
'changed' => TRUE,
],
[
'id' => 'parent_3',
'weight' => -9,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
// Since 'parent_1' row was moved, it should be marked as changed, but
// this would fail with core tabledrag.js.
[
'id' => 'parent_1',
'weight' => -8,
'parent' => '',
'indentation' => 0,
'changed' => NULL,
],
];
$this
->assertDraggableTable($expected_parent_table, 'tabledrag-test-parent-table', TRUE);
// Re-test the nested draggable table.
$expected_child_table_structure = [
[
'id' => 5,
'weight' => -10,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
[
'id' => 3,
'weight' => -10,
'parent' => 5,
'indentation' => 1,
'changed' => TRUE,
],
[
'id' => 1,
'weight' => -9,
'parent' => '',
'indentation' => 0,
'changed' => TRUE,
],
[
'id' => 2,
'weight' => -10,
'parent' => 1,
'indentation' => 1,
'changed' => TRUE,
],
[
'id' => 4,
'weight' => -10,
'parent' => 2,
'indentation' => 2,
'changed' => TRUE,
],
];
$this
->assertDraggableTable($expected_child_table_structure);
}