parseFragment('foobar'); $this->assertInstanceOf(TextInterface::class, $fragment->children()[0]); $fragment = $parser->parseFragment('foobar
fizzbuzz
'); $this->assertInstanceOf(TextInterface::class, $fragment->children()[0]); $this->assertInstanceOf(DivTag::class, $fragment->children()[1]); } public function testAttributes() { $parser = new Parser(); $fragment = $parser->parseFragment('
'); $this->assertEquals('foo', $fragment->children()[0]->id()); $this->assertEquals('b', $fragment->children()[0]->attributes()['a']); $this->assertEquals('d', $fragment->children()[0]->attributes()['c']); } public function testStylesAndClasses() { $parser = new Parser(); $fragment = $parser->parseFragment('
'); $this->assertEquals(['bar', 'foo'], $fragment->children()[0]->classes()->getArray()); $this->assertEquals(['background-color' => 'blue', 'color' => 'red'], $fragment->children()[0]->styles()->getArray()); } public function testNesting() { $parser = new Parser(); $fragment = $parser->parseFragment('

foobar

foo

'); $this->assertInstanceOf(DivTag::class, $fragment->children()[0]); $this->assertCount(2, $fragment->children()[0]->children()); $this->assertCount(3, $fragment->children()[0]->children()[0]->children()); } public function testUnknownTags() { $parser = new Parser(); $fragment = $parser->parseFragment('
'); $this->assertCount(1, $fragment->children()); } public function testParseDocument() { $parser = new Parser(); $document = $parser->parseDocument('Title
foo
'); $this->assertEquals('Title', $document->html()->head()->title()->content()); $this->assertEquals('
' . PHP_EOL . 'foo' . PHP_EOL . '
', $document->body()->children()[0]->__toString()); } }