public function test_post() { include 'CssParser.php'; $parser = new CssParser(); $parser->load_file('/home/travis/build/phpBB3/phpBB/ext/anavaro/postlove/styles/all/theme/default.css'); $parser->parse(); $this->login(); // Test creating topic and post to test $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test [b]post[/b] posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); //Do we see the static? $class = $crawler->filter('#p' . $post2['post_id'])->filter('.postlove')->filter('span')->attr('class'); $this->assertContains('heart-red-16.png', $parser->parsed['main']['.' . $class]['background']); $this->assertContains('0 x', $crawler->filter('#p' . $post2['post_id'])->filter('.postlove')->text()); //toggle like $url = $crawler->filter('#p' . $post2['post_id'])->filter('.postlove')->filter('a')->attr('href'); $crw1 = self::request('GET', substr($url, 1), array(), array(), array('CONTENT_TYPE' => 'application/json')); //reload page and test ... $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $class = $crawler->filter('#p' . $post2['post_id'])->filter('.postlove')->filter('span')->attr('class'); $this->assertContains('heart-white-16.png', $parser->parsed['main']['.' . $class]['background']); $this->assertContains('1 x', $crawler->filter('#p' . $post2['post_id'])->filter('.postlove')->text()); $this->logout(); }
public function testWhitewashingHeaders() { $parser = new PHPricot_Parser(); $doc = $parser->parse(file_get_contents(dirname(__FILE__) . "/_files/whitewashing.html")); $cssHandler = new PHPricot_CssParser_EventHandler($doc); $cssParser = new CssParser('div.box h2', $cssHandler); $cssParser->parse(); $headers = $cssHandler->getMatches(); $this->assertEquals(10, count($headers), "Whitewashing Main Page example should have 10 h2 tags"); }
public function testAllCombo() { $selector = '*|ele1 > ele2.class1 + ns1|ele3.class2[attr=simple] ~ .class2[attr2~="longer string of text."]:pseudoClass(value) .class3::pseudoElement'; $expect = array(new TestEvent(TestEvent::elementNS, 'ele1', '*'), new TestEvent(TestEvent::directDescendant), new TestEvent(TestEvent::element, 'ele2'), new TestEvent(TestEvent::elementClass, 'class1'), new TestEvent(TestEvent::adjacent), new TestEvent(TestEvent::elementNS, 'ele3', 'ns1'), new TestEvent(TestEvent::elementClass, 'class2'), new TestEvent(TestEvent::attribute, 'attr', 'simple', CssEventHandler::isExactly), new TestEvent(TestEvent::sibling), new TestEvent(TestEvent::elementClass, 'class2'), new TestEvent(TestEvent::attribute, 'attr2', 'longer string of text.', CssEventHandler::containsWithSpace), new TestEvent(TestEvent::pseudoClass, 'pseudoClass', 'value'), new TestEvent(TestEvent::anyDescendant), new TestEvent(TestEvent::elementClass, 'class3'), new TestEvent(TestEvent::pseudoElement, 'pseudoElement')); $handler = new TestCssEventHandler(); $handler->expects($expect); $parser = new CssParser($selector, $handler); $parser->parse(); //$handler->dumpStack(); $this->assertTrue($handler->success()); /* // Again, with spaces this time: $selector = ' *|ele1 > ele2. class1 + ns1|ele3. class2[ attr=simple] ~ .class2[attr2 ~= "longer string of text."]:pseudoClass(value) .class3::pseudoElement'; $handler = new TestCssEventHandler(); $handler->expects($expect); $parser = new CssParser($selector, $handler); $parser->parse(); $handler->dumpStack(); $this->assertTrue($handler->success()); */ }
/** * Generic finding method. * * This is the primary searching method used throughout QueryPath. * * @param string $filter * A valid CSS 3 filter. * @return QueryPathCssEventHandler * Returns itself. */ public function find($filter) { $parser = new CssParser($filter, $this); $parser->parse(); return $this; }
static function select($node, $query) { $p = new CssParser($node, $query); return $p->parse(); }
public function search($cssSelector) { $cssHandler = new PHPricot_CssParser_EventHandler($this->doc); $cssParser = new CssParser($cssSelector, $cssHandler); $cssParser->parse(); return new PHPricot_Query($cssHandler->getMatches()); }
const sibling = 12; const anyElementInNS = 13; const anyDescendant = 14; var $type = NULL; var $params = NULL; public function __construct($event_type) { $this->type = $event_type; $args = func_get_args(); array_shift($args); $this->params = $args; print "Event " . $event_type; print_r($args); } public function eventType() { return $this->type; } public function params() { return $this->params; } } print ord('"'); #$str = 'tag.class #id :test (test) + anotherElement > yetAnother[test] more[test="ing"]'; $str = 'tag.class #id :test (test)'; print "Now testing: {$str}\n"; $c = new SimpleTestCssEventHandler(); $p = new CssParser($str, $c); $p->parse();