You are here

public function FeedsXPathParserQueryParserTestCase::testSimple in Feeds XPath Parser 6

Same name and namespace in other branches
  1. 7 tests/feeds_xpathparser_query_parser.test \FeedsXPathParserQueryParserTestCase::testSimple()

File

tests/feeds_xpathparser_query_parser.test, line 24
Test cases for the xpath query parser.

Class

FeedsXPathParserQueryParserTestCase
@file Test cases for the xpath query parser.

Code

public function testSimple() {
  $parser = new FeedsXPathParserQueryParser('cow');
  $this
    ->assertEqual($parser
    ->getQuery(), '__default__:cow');
  $parser = new FeedsXPathParserQueryParser('/cow');
  $this
    ->assertEqual($parser
    ->getQuery(), '/__default__:cow');
  $parser = new FeedsXPathParserQueryParser('/cow/barn');
  $this
    ->assertEqual($parser
    ->getQuery(), '/__default__:cow/__default__:barn');
  $parser = new FeedsXPathParserQueryParser('/cow/barn[@id = "asdfsaf"]');
  $this
    ->assertEqual($parser
    ->getQuery(), '/__default__:cow/__default__:barn[@id = "asdfsaf"]');
  $parser = new FeedsXPathParserQueryParser('/cow/barn[@id=chair]');
  $this
    ->assertEqual($parser
    ->getQuery(), '/__default__:cow/__default__:barn[@id=__default__:chair]');
  $parser = new FeedsXPathParserQueryParser('/cow:asdf');
  $this
    ->assertEqual($parser
    ->getQuery(), '/cow:asdf');
  $parser = new FeedsXPathParserQueryParser('@cow');
  $this
    ->assertEqual($parser
    ->getQuery(), '@cow');
  $parser = new FeedsXPathParserQueryParser('starts-with(@id, "cat")');
  $this
    ->assertEqual($parser
    ->getQuery(), 'starts-with(@id, "cat")');
  $parser = new FeedsXPathParserQueryParser('starts-with(cat/dog/fire:breather, "cat")');
  $this
    ->assertEqual($parser
    ->getQuery(), 'starts-with(__default__:cat/__default__:dog/fire:breather, "cat")');
  $parser = new FeedsXPathParserQueryParser('//state[@id = ../city[name="CityName"]/state_id]/name');
  $this
    ->assertEqual($parser
    ->getQuery(), '//__default__:state[@id = ../__default__:city[__default__:name="CityName"]/__default__:state_id]/__default__:name');
  $parser = new FeedsXPathParserQueryParser('attribute::lang');
  $this
    ->assertEqual($parser
    ->getQuery(), 'attribute::lang');
  $parser = new FeedsXPathParserQueryParser('child::book');
  $this
    ->assertEqual($parser
    ->getQuery(), 'child::__default__:book');
  $parser = new FeedsXPathParserQueryParser('child::*');
  $this
    ->assertEqual($parser
    ->getQuery(), 'child::*');
  $parser = new FeedsXPathParserQueryParser('child::text()');
  $this
    ->assertEqual($parser
    ->getQuery(), 'child::text()');
  $parser = new FeedsXPathParserQueryParser('ancestor-or-self::book');
  $this
    ->assertEqual($parser
    ->getQuery(), 'ancestor-or-self::__default__:book');
  $parser = new FeedsXPathParserQueryParser('child::*/child::price');
  $this
    ->assertEqual($parser
    ->getQuery(), 'child::*/child::__default__:price');
  $parser = new FeedsXPathParserQueryParser("/asdfasfd[@id = 'a' or @id='b']");
  $this
    ->assertEqual($parser
    ->getQuery(), "/__default__:asdfasfd[@id = 'a' or @id='b']");

  // Go! difficult xpath queries from stack overflow.
  $parser = new FeedsXPathParserQueryParser("id('yui-gen2')/x:div[3]/x:div/x:a[1]");
  $this
    ->assertEqual($parser
    ->getQuery(), "id('yui-gen2')/x:div[3]/x:div/x:a[1]");
  $parser = new FeedsXPathParserQueryParser("/descendant::a[@class='buttonCheckout']");
  $this
    ->assertEqual($parser
    ->getQuery(), "/descendant::__default__:a[@class='buttonCheckout']");
  $parser = new FeedsXPathParserQueryParser("//a[@href='javascript:void(0)']");
  $this
    ->assertEqual($parser
    ->getQuery(), "//__default__:a[@href='javascript:void(0)']");
  $parser = new FeedsXPathParserQueryParser('//*/@attribute');
  $this
    ->assertEqual($parser
    ->getQuery(), '//*/@attribute');
  $parser = new FeedsXPathParserQueryParser('/descendant::*[attribute::attribute]');
  $this
    ->assertEqual($parser
    ->getQuery(), '/descendant::*[attribute::attribute]');
  $parser = new FeedsXPathParserQueryParser('//Event[not(System/Level = preceding::Level) or not(System/Task = preceding::Task)]');
  $this
    ->assertEqual($parser
    ->getQuery(), '//__default__:Event[not(__default__:System/__default__:Level = preceding::__default__:Level) or not(__default__:System/__default__:Task = preceding::__default__:Task)]');
  $parser = new FeedsXPathParserQueryParser("section[@type='cover']/line/@page");
  $this
    ->assertEqual($parser
    ->getQuery(), "__default__:section[@type='cover']/__default__:line/@page");
  $parser = new FeedsXPathParserQueryParser('/articles/article/*[name()="title" or name()="short"]');
  $this
    ->assertEqual($parser
    ->getQuery(), '/__default__:articles/__default__:article/*[name()="title" or name()="short"]');
  $parser = new FeedsXPathParserQueryParser("/*/article[@id='2']/*[self::title or self::short]");
  $this
    ->assertEqual($parser
    ->getQuery(), "/*/__default__:article[@id='2']/*[self::__default__:title or self::__default__:short]");
  $parser = new FeedsXPathParserQueryParser('not(/asdfasfd/asdfasf//asdfasdf) | /asdfasf/sadfasf/@asdf');
  $this
    ->assertEqual($parser
    ->getQuery(), 'not(/__default__:asdfasfd/__default__:asdfasf//__default__:asdfasdf) | /__default__:asdfasf/__default__:sadfasf/@asdf');
  $parser = new FeedsXPathParserQueryParser('Ülküdak');
  $this
    ->assertEqual($parser
    ->getQuery(), '__default__:Ülküdak');
}