function HtmlTagTest::providerPreRenderConditionalComments

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php \Drupal\Tests\Core\Render\Element\HtmlTagTest::providerPreRenderConditionalComments()

Data provider for conditional comments test.

File

core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php, line 230

Class

HtmlTagTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21HtmlTag.php/class/HtmlTag/9" title="Provides a render element for any HTML tag, with properties and value." class="local">\Drupal\Core\Render\Element\HtmlTag</a> @group Render

Namespace

Drupal\Tests\Core\Render\Element

Code

public function providerPreRenderConditionalComments() {
    // No browser specification.
    $element = [
        '#tag' => 'link',
    ];
    $tags['no-browser'] = [
        $element,
        $element,
    ];
    // Specify all browsers.
    $element['#browsers'] = [
        'IE' => TRUE,
        '!IE' => TRUE,
    ];
    $tags['all-browsers'] = [
        $element,
        $element,
    ];
    // All IE.
    $element = [
        '#tag' => 'link',
        '#browsers' => [
            'IE' => TRUE,
            '!IE' => FALSE,
        ],
    ];
    $expected = $element;
    $expected['#prefix'] = "\n<!--[if IE]>\n";
    $expected['#suffix'] = "<![endif]-->\n";
    $tags['all-ie'] = [
        $element,
        $expected,
    ];
    // Exclude IE.
    $element = [
        '#tag' => 'link',
        '#browsers' => [
            'IE' => FALSE,
        ],
    ];
    $expected = $element;
    $expected['#prefix'] = "\n<!--[if !IE]><!-->\n";
    $expected['#suffix'] = "<!--<![endif]-->\n";
    $tags['no-ie'] = [
        $element,
        $expected,
    ];
    // IE gt 8
    $element = [
        '#tag' => 'link',
        '#browsers' => [
            'IE' => 'gt IE 8',
        ],
    ];
    $expected = $element;
    $expected['#prefix'] = "\n<!--[if gt IE 8]><!-->\n";
    $expected['#suffix'] = "<!--<![endif]-->\n";
    $tags['ie9plus'] = [
        $element,
        $expected,
    ];
    // Prefix and suffix filtering if not safe.
    $element = [
        '#tag' => 'link',
        '#browsers' => [
            'IE' => FALSE,
        ],
        '#prefix' => '<blink>prefix</blink>',
        '#suffix' => '<blink>suffix</blink>',
    ];
    $expected = $element;
    $expected['#prefix'] = "\n<!--[if !IE]><!-->\nprefix";
    $expected['#suffix'] = "suffix<!--<![endif]-->\n";
    $tags['non-ie-unsafe'] = [
        $element,
        $expected,
    ];
    // Prefix and suffix filtering if marked as safe. This has to come after the
    // previous test case.
    $expected['#prefix'] = "\n<!--[if !IE]><!-->\n<blink>prefix</blink>";
    $expected['#suffix'] = "<blink>suffix</blink><!--<![endif]-->\n";
    $tags['non-ie-safe'] = [
        $element,
        $expected,
        TRUE,
    ];
    return $tags;
}

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