function LinkFieldUITest::providerTestFieldUI

Same name in other branches
  1. 9 core/modules/link/tests/src/Functional/LinkFieldUITest.php \Drupal\Tests\link\Functional\LinkFieldUITest::providerTestFieldUI()
  2. 8.9.x core/modules/link/tests/src/Functional/LinkFieldUITest.php \Drupal\Tests\link\Functional\LinkFieldUITest::providerTestFieldUI()
  3. 11.x core/modules/link/tests/src/Functional/LinkFieldUITest.php \Drupal\Tests\link\Functional\LinkFieldUITest::providerTestFieldUI()

Provides test data for ::testFieldUI().

1 call to LinkFieldUITest::providerTestFieldUI()
LinkFieldUITest::testFieldUI in core/modules/link/tests/src/Functional/LinkFieldUITest.php
Tests the link field UI.

File

core/modules/link/tests/src/Functional/LinkFieldUITest.php, line 85

Class

LinkFieldUITest
Tests link field UI functionality.

Namespace

Drupal\Tests\link\Functional

Code

protected function providerTestFieldUI() {
    // There are many combinations of field settings: where the description
    // should show: variation on internal, external, both; cardinality (where
    // the fieldset is hidden or used); and link text shown (required or
    // optional) or disabled. There are two descriptions: field and URL help
    // text.
    $cardinalities = [
        1,
        2,
    ];
    $title_settings = [
        DRUPAL_DISABLED,
        DRUPAL_OPTIONAL,
    ];
    $link_types = [
        LinkItemInterface::LINK_EXTERNAL => 'https://example.com',
        LinkItemInterface::LINK_GENERIC => '',
        LinkItemInterface::LINK_INTERNAL => '<front>',
    ];
    // Test all variations of link types on all cardinalities.
    foreach ($cardinalities as $cardinality) {
        foreach ($link_types as $link_type => $default_uri) {
            // Now, test this with both the title enabled and disabled.
            foreach ($title_settings as $title_setting) {
                // Test both empty and non-empty labels.
                foreach ([
                    TRUE,
                    FALSE,
                ] as $label_provided) {
                    // Generate a unique machine name for the field so it can be
                    // identified in the test.
                    $id = implode('_', [
                        'link',
                        $cardinality,
                        $link_type,
                        $title_setting,
                        (int) $label_provided,
                    ]);
                    // Use a unique label that contains some HTML.
                    $label = '<img src="https://example.com">' . $id;
                    (yield [
                        $cardinality,
                        $link_type,
                        $title_setting,
                        $label_provided ? $label : '',
                        $id,
                        $default_uri,
                    ]);
                }
            }
        }
    }
}

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