function OptionsFieldUITest::testRequiredPropertyForAllowedValuesList

Same name in other branches
  1. 10 core/modules/options/tests/src/Functional/OptionsFieldUITest.php \Drupal\Tests\options\Functional\OptionsFieldUITest::testRequiredPropertyForAllowedValuesList()

Confirms the allowed value list is a required field.

File

core/modules/options/tests/src/Functional/OptionsFieldUITest.php, line 446

Class

OptionsFieldUITest
Tests the Options field UI functionality.

Namespace

Drupal\Tests\options\Functional

Code

public function testRequiredPropertyForAllowedValuesList() : void {
    $field_types = [
        'list_float',
        'list_string',
        'list_integer',
    ];
    foreach ($field_types as $field_type) {
        $this->fieldName = "field_options_{$field_type}";
        $this->createOptionsField($field_type);
        $page = $this->getSession()
            ->getPage();
        $this->drupalGet($this->adminPath);
        // Assert that the delete button for a single row is disabled.
        $this->assertCount(1, $page->findAll('css', '#allowed-values-order tr.draggable'));
        $delete_button_0 = $page->findById('remove_row_button__0');
        $this->assertTrue($delete_button_0->hasAttribute('disabled'), 'Button is disabled');
        $page->findButton('Add another item')
            ->click();
        // Assert that the delete button for the first row is enabled if there are
        // more that one rows.
        $this->assertCount(2, $page->findAll('css', '#allowed-values-order tr.draggable'));
        $this->assertFalse($delete_button_0->hasAttribute('disabled'), 'Button is enabled');
        // Delete a row.
        $delete_button_0->click();
        // Assert that the button is disabled again.
        $this->assertTrue($delete_button_0->hasAttribute('disabled'), 'Button is disabled');
        // Try to proceed without entering any value.
        $page->findButton('Save')
            ->click();
        if ($field_type == 'list_string') {
            // Asserting only name field as there is no value field for list_string.
            $this->assertSession()
                ->pageTextContains('Name field is required.');
        }
        else {
            // Confirmation message that name and value are required fields for
            // list_float and list_integer.
            $this->assertSession()
                ->pageTextContains('Name field is required.');
            $this->assertSession()
                ->pageTextContains('Value field is required.');
        }
    }
}

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