protected function UserAccountFormFieldsTest::assertFieldOrder in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/src/Tests/UserAccountFormFieldsTest.php \Drupal\user\Tests\UserAccountFormFieldsTest::assertFieldOrder()
Asserts that the 'name' form element is directly before the 'pass' element.
Parameters
array $elements: A form array section that contains the user account form elements.
3 calls to UserAccountFormFieldsTest::assertFieldOrder()
- UserAccountFormFieldsTest::testInstallConfigureForm in core/
modules/ user/ src/ Tests/ UserAccountFormFieldsTest.php - Tests the root user account form section in the "Configure site" form.
- UserAccountFormFieldsTest::testUserEditForm in core/
modules/ user/ src/ Tests/ UserAccountFormFieldsTest.php - Tests the user edit form.
- UserAccountFormFieldsTest::testUserRegistrationForm in core/
modules/ user/ src/ Tests/ UserAccountFormFieldsTest.php - Tests the user registration form.
File
- core/
modules/ user/ src/ Tests/ UserAccountFormFieldsTest.php, line 102 - Contains \Drupal\user\Tests\UserAccountFormFieldsTest.
Class
- UserAccountFormFieldsTest
- Verifies that the field order in user account forms is compatible with password managers of web browsers.
Namespace
Drupal\user\TestsCode
protected function assertFieldOrder(array $elements) {
$name_index = 0;
$name_weight = 0;
$pass_index = 0;
$pass_weight = 0;
$index = 0;
foreach ($elements as $key => $element) {
if ($key === 'name') {
$name_index = $index;
$name_weight = $element['#weight'];
$this
->assertTrue($element['#sorted'], "'name' field is #sorted.");
}
elseif ($key === 'pass') {
$pass_index = $index;
$pass_weight = $element['#weight'];
$this
->assertTrue($element['#sorted'], "'pass' field is #sorted.");
}
$index++;
}
$this
->assertEqual($name_index, $pass_index - 1, "'name' field ({$name_index}) appears before 'pass' field ({$pass_index}).");
$this
->assertTrue($name_weight < $pass_weight, "'name' field weight ({$name_weight}) is smaller than 'pass' field weight ({$pass_weight}).");
}