You are here

public function TokenizerTest::testDoctype 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::testDoctype()

File

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

Class

TokenizerTest

Namespace

Masterminds\HTML5\Tests\Parser

Code

public function testDoctype() {
  $good = array(
    '<!DOCTYPE html>' => array(
      'html',
      0,
      null,
      false,
    ),
    '<!doctype html>' => array(
      'html',
      0,
      null,
      false,
    ),
    '<!DocType html>' => array(
      'html',
      0,
      null,
      false,
    ),
    "<!DOCTYPE\nhtml>" => array(
      'html',
      0,
      null,
      false,
    ),
    "<!DOCTYPE\fhtml>" => array(
      'html',
      0,
      null,
      false,
    ),
    '<!DOCTYPE html PUBLIC "foo bar">' => array(
      'html',
      EventStack::DOCTYPE_PUBLIC,
      'foo bar',
      false,
    ),
    "<!DOCTYPE html PUBLIC 'foo bar'>" => array(
      'html',
      EventStack::DOCTYPE_PUBLIC,
      'foo bar',
      false,
    ),
    '<!DOCTYPE      html      PUBLIC     "foo bar"    >' => array(
      'html',
      EventStack::DOCTYPE_PUBLIC,
      'foo bar',
      false,
    ),
    "<!DOCTYPE html \nPUBLIC\n'foo bar'>" => array(
      'html',
      EventStack::DOCTYPE_PUBLIC,
      'foo bar',
      false,
    ),
    '<!DOCTYPE html SYSTEM "foo bar">' => array(
      'html',
      EventStack::DOCTYPE_SYSTEM,
      'foo bar',
      false,
    ),
    "<!DOCTYPE html SYSTEM 'foo bar'>" => array(
      'html',
      EventStack::DOCTYPE_SYSTEM,
      'foo bar',
      false,
    ),
    '<!DOCTYPE      html      SYSTEM "foo/bar"    >' => array(
      'html',
      EventStack::DOCTYPE_SYSTEM,
      'foo/bar',
      false,
    ),
    "<!DOCTYPE html \nSYSTEM\n'foo bar'>" => array(
      'html',
      EventStack::DOCTYPE_SYSTEM,
      'foo bar',
      false,
    ),
  );
  $this
    ->isAllGood('doctype', 2, $good);
  $bad = array(
    '<!DOCTYPE>' => array(
      null,
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE    >' => array(
      null,
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE  foo' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE foo PUB' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE foo PUB>' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE  foo PUB "Looks good">' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE  foo SYSTME "Looks good"' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    // Can't tell whether these are ids or ID types, since the context is chopped.
    '<!DOCTYPE foo PUBLIC' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE  foo PUBLIC>' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE foo SYSTEM' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE  foo SYSTEM>' => array(
      'foo',
      EventStack::DOCTYPE_NONE,
      null,
      true,
    ),
    '<!DOCTYPE html SYSTEM "foo bar"' => array(
      'html',
      EventStack::DOCTYPE_SYSTEM,
      'foo bar',
      true,
    ),
    '<!DOCTYPE html SYSTEM "foo bar" more stuff>' => array(
      'html',
      EventStack::DOCTYPE_SYSTEM,
      'foo bar',
      true,
    ),
  );
  foreach ($bad as $test => $expects) {
    $events = $this
      ->parse($test);

    // fprintf(STDOUT, $test . PHP_EOL);
    $this
      ->assertEquals(3, $events
      ->depth(), "Counting events for '{$test}': " . print_r($events, true));
    $this
      ->assertEventError($events
      ->get(0));
    $this
      ->assertEventEquals('doctype', $expects, $events
      ->get(1));
  }
}