function TableDragTest::testKeyboardAccessibility
Same name in other branches
- 9 core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testKeyboardAccessibility()
- 10 core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testKeyboardAccessibility()
- 11.x core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testKeyboardAccessibility()
Tests accessibility through keyboard of the tabledrag functionality.
File
-
core/
tests/ Drupal/ FunctionalJavascriptTests/ TableDrag/ TableDragTest.php, line 132
Class
- TableDragTest
- Tests draggable table.
Namespace
Drupal\FunctionalJavascriptTests\TableDragCode
public function testKeyboardAccessibility() {
$this->state
->set('tabledrag_test_table', array_flip(range(1, 5)));
$expected_table = [
[
'id' => 1,
'weight' => 0,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
[
'id' => 2,
'weight' => 0,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
[
'id' => 3,
'weight' => 0,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
[
'id' => 4,
'weight' => 0,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
[
'id' => 5,
'weight' => 0,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
],
];
$this->drupalGet('tabledrag_test');
$this->assertDraggableTable($expected_table);
// Nest the row with id 2 as child of row 1.
$this->moveRowWithKeyboard($this->findRowById(2), 'right');
$expected_table[1] = [
'id' => 2,
'weight' => -10,
'parent' => 1,
'indentation' => 1,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
// Nest the row with id 3 as child of row 1.
$this->moveRowWithKeyboard($this->findRowById(3), 'right');
$expected_table[2] = [
'id' => 3,
'weight' => -9,
'parent' => 1,
'indentation' => 1,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
// Nest the row with id 3 as child of row 2.
$this->moveRowWithKeyboard($this->findRowById(3), 'right');
$expected_table[2] = [
'id' => 3,
'weight' => -10,
'parent' => 2,
'indentation' => 2,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
// Nesting should be allowed to maximum level 2.
$this->moveRowWithKeyboard($this->findRowById(4), 'right', 4);
$expected_table[3] = [
'id' => 4,
'weight' => -9,
'parent' => 2,
'indentation' => 2,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
// Re-order children of row 1.
$this->moveRowWithKeyboard($this->findRowById(4), 'up');
$expected_table[2] = [
'id' => 4,
'weight' => -10,
'parent' => 2,
'indentation' => 2,
'changed' => TRUE,
];
$expected_table[3] = [
'id' => 3,
'weight' => -9,
'parent' => 2,
'indentation' => 2,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
// Move back the row 3 to the 1st level.
$this->moveRowWithKeyboard($this->findRowById(3), 'left');
$expected_table[3] = [
'id' => 3,
'weight' => -9,
'parent' => 1,
'indentation' => 1,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
$this->moveRowWithKeyboard($this->findRowById(3), 'left');
$expected_table[0] = [
'id' => 1,
'weight' => -10,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
];
$expected_table[3] = [
'id' => 3,
'weight' => -9,
'parent' => '',
'indentation' => 0,
'changed' => TRUE,
];
$expected_table[4] = [
'id' => 5,
'weight' => -8,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
];
$this->assertDraggableTable($expected_table);
// Move row 3 to the last position.
$this->moveRowWithKeyboard($this->findRowById(3), 'down');
$expected_table[3] = [
'id' => 5,
'weight' => -9,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
];
$expected_table[4] = [
'id' => 3,
'weight' => -8,
'parent' => '',
'indentation' => 0,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
// Nothing happens when trying to move the last row further down.
$this->moveRowWithKeyboard($this->findRowById(3), 'down');
$this->assertDraggableTable($expected_table);
// Nest row 3 under 5. The max depth allowed should be 1.
$this->moveRowWithKeyboard($this->findRowById(3), 'right', 3);
$expected_table[4] = [
'id' => 3,
'weight' => -10,
'parent' => 5,
'indentation' => 1,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
// The first row of the table cannot be nested.
$this->moveRowWithKeyboard($this->findRowById(1), 'right');
$this->assertDraggableTable($expected_table);
// Move a row which has nested children. The children should move with it,
// with nesting preserved. Swap the order of the top-level rows by moving
// row 1 to after row 3.
$this->moveRowWithKeyboard($this->findRowById(1), 'down', 2);
$expected_table[0] = [
'id' => 5,
'weight' => -10,
'parent' => '',
'indentation' => 0,
'changed' => FALSE,
];
$expected_table[3] = $expected_table[1];
$expected_table[1] = $expected_table[4];
$expected_table[4] = $expected_table[2];
$expected_table[2] = [
'id' => 1,
'weight' => -9,
'parent' => '',
'indentation' => 0,
'changed' => TRUE,
];
$this->assertDraggableTable($expected_table);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.