You are here

public function TokenizerTest::testRawText in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/masterminds/html5/test/HTML5/Parser/TokenizerTest.php \Masterminds\HTML5\Tests\Parser\TokenizerTest::testRawText()

File

vendor/masterminds/html5/test/HTML5/Parser/TokenizerTest.php, line 851

Class

TokenizerTest

Namespace

Masterminds\HTML5\Tests\Parser

Code

public function testRawText() {
  $good = array(
    '<script>abcd efg hijk lmnop</script>     ' => 'abcd efg hijk lmnop',
    '<script><not/><the/><tag></script>' => '<not/><the/><tag>',
    '<script><<<<<<<<</script>' => '<<<<<<<<',
    '<script>hello</script</script>' => 'hello</script',
    "<script>\nhello</script\n</script>" => "\nhello</script\n",
    '<script>&amp;</script>' => '&amp;',
    '<script><!--not a comment--></script>' => '<!--not a comment-->',
    '<script><![CDATA[not a comment]]></script>' => '<![CDATA[not a comment]]>',
  );
  foreach ($good as $test => $expects) {
    $events = $this
      ->parse($test);
    $this
      ->assertEventEquals('startTag', 'script', $events
      ->get(0));
    $this
      ->assertEventEquals('text', $expects, $events
      ->get(1));
    $this
      ->assertEventEquals('endTag', 'script', $events
      ->get(2));
  }
  $bad = array(
    '<script>&amp;</script' => '&amp;</script',
    '<script>Hello world' => 'Hello world',
  );
  foreach ($bad as $test => $expects) {
    $events = $this
      ->parse($test);
    $this
      ->assertEquals(4, $events
      ->depth(), "Counting events for '{$test}': " . print_r($events, true));
    $this
      ->assertEventEquals('startTag', 'script', $events
      ->get(0));
    $this
      ->assertEventError($events
      ->get(1));
    $this
      ->assertEventEquals('text', $expects, $events
      ->get(2));
  }

  // Testing case sensitivity
  $events = $this
    ->parse('<TITLE>a test</TITLE>');
  $this
    ->assertEventEquals('startTag', 'title', $events
    ->get(0));
  $this
    ->assertEventEquals('text', 'a test', $events
    ->get(1));
  $this
    ->assertEventEquals('endTag', 'title', $events
    ->get(2));

  // Testing end tags with whitespaces
  $events = $this
    ->parse('<title>Whitespaces are tasty</title >');
  $this
    ->assertEventEquals('startTag', 'title', $events
    ->get(0));
  $this
    ->assertEventEquals('text', 'Whitespaces are tasty', $events
    ->get(1));
  $this
    ->assertEventEquals('endTag', 'title', $events
    ->get(2));
}