You are here

public function HtmlTagTest::providerPreRenderConditionalComments in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 118
Contains \Drupal\Tests\Core\Render\Element\HtmlTagTest.

Class

HtmlTagTest
@coversDefaultClass \Drupal\Core\Render\Element\HtmlTag @group Render

Namespace

Drupal\Tests\Core\Render\Element

Code

public function providerPreRenderConditionalComments() {

  // No browser specification.
  $element = array(
    '#tag' => 'link',
  );
  $tags[] = array(
    $element,
    $element,
  );

  // Specify all browsers.
  $element['#browsers'] = array(
    'IE' => TRUE,
    '!IE' => TRUE,
  );
  $tags[] = array(
    $element,
    $element,
  );

  // All IE.
  $element = array(
    '#tag' => 'link',
    '#browsers' => array(
      'IE' => TRUE,
      '!IE' => FALSE,
    ),
  );
  $expected = $element;
  $expected['#prefix'] = "\n<!--[if IE]>\n";
  $expected['#suffix'] = "<![endif]-->\n";
  $tags[] = array(
    $element,
    $expected,
  );

  // Exclude IE.
  $element = array(
    '#tag' => 'link',
    '#browsers' => array(
      'IE' => FALSE,
    ),
  );
  $expected = $element;
  $expected['#prefix'] = "\n<!--[if !IE]><!-->\n";
  $expected['#suffix'] = "<!--<![endif]-->\n";
  $tags[] = array(
    $element,
    $expected,
  );

  // IE gt 8
  $element = array(
    '#tag' => 'link',
    '#browsers' => array(
      'IE' => 'gt IE 8',
    ),
  );
  $expected = $element;
  $expected['#prefix'] = "\n<!--[if gt IE 8]><!-->\n";
  $expected['#suffix'] = "<!--<![endif]-->\n";
  $tags[] = array(
    $element,
    $expected,
  );

  // Prefix and suffix filtering if not safe.
  $element = array(
    '#tag' => 'link',
    '#browsers' => array(
      'IE' => FALSE,
    ),
    '#prefix' => '<blink>prefix</blink>',
    '#suffix' => '<blink>suffix</blink>',
  );
  $expected = $element;
  $expected['#prefix'] = "\n<!--[if !IE]><!-->\nprefix";
  $expected['#suffix'] = "suffix<!--<![endif]-->\n";
  $tags[] = array(
    $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[] = array(
    $element,
    $expected,
    TRUE,
  );
  return $tags;
}