function TableDragTest::testRootLeafDraggableRowsWithKeyboard

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testRootLeafDraggableRowsWithKeyboard()
  2. 10 core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testRootLeafDraggableRowsWithKeyboard()
  3. 11.x core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php \Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testRootLeafDraggableRowsWithKeyboard()

Tests the root and leaf behaviors for rows.

File

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

Class

TableDragTest
Tests draggable table.

Namespace

Drupal\FunctionalJavascriptTests\TableDrag

Code

public function testRootLeafDraggableRowsWithKeyboard() {
    $this->state
        ->set('tabledrag_test_table', [
        1 => [],
        2 => [
            'parent' => 1,
            'depth' => 1,
            'classes' => [
                'tabledrag-leaf',
            ],
        ],
        3 => [
            'parent' => 1,
            'depth' => 1,
        ],
        4 => [],
        5 => [
            'classes' => [
                'tabledrag-root',
            ],
        ],
    ]);
    $this->drupalGet('tabledrag_test');
    $expected_table = [
        [
            'id' => 1,
            'weight' => 0,
            'parent' => '',
            'indentation' => 0,
            'changed' => FALSE,
        ],
        [
            'id' => 2,
            'weight' => 0,
            'parent' => 1,
            'indentation' => 1,
            'changed' => FALSE,
        ],
        [
            'id' => 3,
            'weight' => 0,
            'parent' => 1,
            'indentation' => 1,
            'changed' => FALSE,
        ],
        [
            'id' => 4,
            'weight' => 0,
            'parent' => '',
            'indentation' => 0,
            'changed' => FALSE,
        ],
        [
            'id' => 5,
            'weight' => 0,
            'parent' => '',
            'indentation' => 0,
            'changed' => FALSE,
        ],
    ];
    $this->assertDraggableTable($expected_table);
    // Rows marked as root cannot be moved as children of another row.
    $this->moveRowWithKeyboard($this->findRowById(5), 'right');
    $this->assertDraggableTable($expected_table);
    // Rows marked as leaf cannot have children. Trying to move the row #3
    // as child of #2 should have no results.
    $this->moveRowWithKeyboard($this->findRowById(3), 'right');
    $this->assertDraggableTable($expected_table);
    // Leaf can be still swapped and moved to first level.
    $this->moveRowWithKeyboard($this->findRowById(2), 'down');
    $this->moveRowWithKeyboard($this->findRowById(2), 'left');
    $expected_table[0]['weight'] = -10;
    $expected_table[1]['id'] = 3;
    $expected_table[1]['weight'] = -10;
    $expected_table[2] = [
        'id' => 2,
        'weight' => -9,
        'parent' => '',
        'indentation' => 0,
        'changed' => TRUE,
    ];
    $expected_table[3]['weight'] = -8;
    $expected_table[4]['weight'] = -7;
    $this->assertDraggableTable($expected_table);
    // Root rows can have children.
    $this->moveRowWithKeyboard($this->findRowById(4), 'down');
    $this->moveRowWithKeyboard($this->findRowById(4), 'right');
    $expected_table[3]['id'] = 5;
    $expected_table[4] = [
        'id' => 4,
        'weight' => -10,
        'parent' => 5,
        'indentation' => 1,
        'changed' => TRUE,
    ];
    $this->assertDraggableTable($expected_table);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.