function FormTest::testSelectSorting

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::testSelectSorting()
  2. 10 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::testSelectSorting()
  3. 11.x core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::testSelectSorting()

Tests sorting and not sorting of options in a select element.

File

core/modules/system/tests/src/Functional/Form/FormTest.php, line 484

Class

FormTest
Tests various form element validation mechanisms.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testSelectSorting() {
    $this->drupalGet('form-test/select');
    // Verify the order of the select options.
    $this->validateSelectSorting('unsorted', [
        'uso_first_element',
        'uso_second',
        'uso_zzgroup',
        'uso_gc',
        'uso_ga',
        'uso_gb',
        'uso_yygroup',
        'uso_ge',
        'uso_gd',
        'uso_gf',
        'uso_xxgroup',
        'uso_gz',
        'uso_gi',
        'uso_gh',
        'uso_d',
        'uso_c',
        'uso_b',
        'uso_a',
    ]);
    $this->validateSelectSorting('sorted', [
        'sso_a',
        'sso_d',
        'sso_first_element',
        'sso_b',
        'sso_c',
        'sso_second',
        'sso_xxgroup',
        'sso_gz',
        'sso_gh',
        'sso_gi',
        'sso_yygroup',
        'sso_ge',
        'sso_gd',
        'sso_gf',
        'sso_zzgroup',
        'sso_ga',
        'sso_gb',
        'sso_gc',
    ]);
    $this->validateSelectSorting('sorted_none', [
        'sno_empty',
        'sno_first_element',
        'sno_second',
        'sno_zzgroup',
        'sno_ga',
        'sno_gb',
        'sno_gc',
        'sno_a',
        'sno_d',
        'sno_b',
        'sno_c',
        'sno_xxgroup',
        'sno_gz',
        'sno_gi',
        'sno_gh',
        'sno_yygroup',
        'sno_ge',
        'sno_gd',
        'sno_gf',
    ]);
    $this->validateSelectSorting('sorted_none_nostart', [
        'snn_empty',
        'snn_a',
        'snn_d',
        'snn_first_element',
        'snn_b',
        'snn_c',
        'snn_second',
        'snn_xxgroup',
        'snn_gz',
        'snn_gi',
        'snn_gh',
        'snn_yygroup',
        'snn_ge',
        'snn_gd',
        'snn_gf',
        'snn_zzgroup',
        'snn_ga',
        'snn_gb',
        'snn_gc',
    ]);
    // Verify that #sort_order and #sort_start are not in the page.
    $this->assertSession()
        ->responseNotContains('#sort_order');
    $this->assertSession()
        ->responseNotContains('#sort_start');
}

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