2008-05-15 09:15:33 +02:00
|
|
|
<?php
|
2008-06-15 15:33:53 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-06-15 15:33:53 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2008-05-15 09:15:33 +02:00
|
|
|
class CSSContentParserTest extends SapphireTest {
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testSelector2xpath() {
|
2008-05-15 09:15:33 +02:00
|
|
|
$parser = new CSSContentParser("<html><head><title>test</title></head><body><p>test</p></body></html>");
|
|
|
|
|
|
|
|
$this->assertEquals("//div[@id='UserProfile']//label", $parser->selector2xpath("div#UserProfile label"));
|
|
|
|
$this->assertEquals("//div", $parser->selector2xpath("div"));
|
|
|
|
$this->assertEquals("//div[contains(@class,'test')]", $parser->selector2xpath("div.test"));
|
|
|
|
$this->assertEquals("//*[@id='UserProfile']//div[contains(@class,'test')]//*[contains(@class,'other')]//div[@id='Item']",
|
|
|
|
$parser->selector2xpath("#UserProfile div.test .other div#Item"));
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetBySelector() {
|
2008-05-15 09:15:33 +02:00
|
|
|
$parser = new CSSContentParser(<<<HTML
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>test</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="A" class="one two three">
|
|
|
|
<p class="other">result</p>
|
|
|
|
</div>
|
|
|
|
<p>test</p>
|
|
|
|
</body>
|
2008-10-17 01:39:02 +02:00
|
|
|
</html>
|
2008-05-15 09:15:33 +02:00
|
|
|
HTML
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $parser->getBySelector('div.one');
|
|
|
|
$this->assertEquals("A", $result[0]['id'].'');
|
|
|
|
$result = $parser->getBySelector('div.two');
|
|
|
|
$this->assertEquals("A", $result[0]['id'].'');
|
|
|
|
$result = $parser->getBySelector('div.three');
|
|
|
|
$this->assertEquals("A", $result[0]['id'].'');
|
|
|
|
|
|
|
|
$result = $parser->getBySelector('div#A p.other');
|
|
|
|
$this->assertEquals("result", $result[0] . '');
|
|
|
|
$result = $parser->getBySelector('#A .other');
|
|
|
|
$this->assertEquals("result", $result[0] . '');
|
|
|
|
}
|
2008-10-17 01:39:02 +02:00
|
|
|
}
|