function TableDragTest::assertKeyboardAccessibility

Same name and namespace in other branches
  1. 10 core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::assertKeyboardAccessibility()
  2. 11.x core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::assertKeyboardAccessibility()

Asserts accessibility through keyboard of a test draggable table.

@internal

Parameters

string $drupal_path: The drupal path where the '#tabledrag-test-table' test table is present. Defaults to 'tabledrag_test'.

array|null $structure: The expected table structure. If this isn't specified or equals NULL, then the expected structure will be set by this method. Defaults to NULL.

2 calls to TableDragTest::assertKeyboardAccessibility()
TableDragTest::testKeyboardAccessibility in core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php
Tests accessibility through keyboard of the tabledrag functionality.
TableDragTest::testNestedDraggableTables in core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php
Tests nested draggable tables through keyboard.

File

core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php, line 162

Class

TableDragTest
Tests draggable table.

Namespace

Drupal\FunctionalJavascriptTests\TableDrag

Code

protected function assertKeyboardAccessibility(string $drupal_path = 'tabledrag_test', ?array $structure = NULL) : void {
    $expected_table = $structure ?: [
        [
            '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,
        ],
    ];
    if (!empty($drupal_path)) {
        $this->state
            ->set('tabledrag_test_table', array_flip(range(1, 5)));
        $this->drupalGet($drupal_path);
    }
    $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.