You are here

class FeedsXPathParserQueryParserTestCase in Feeds XPath Parser 6

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

@file Test cases for the xpath query parser.

Hierarchy

Expanded class hierarchy of FeedsXPathParserQueryParserTestCase

File

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

View source
class FeedsXPathParserQueryParserTestCase extends DrupalUnitTestCase {

  /**
   * Describe this test.
   */
  public static function getInfo() {
    return array(
      'name' => t('Query Parser'),
      'description' => t('Unit tests for the query parser inside Feeds XPath Parser.'),
      'group' => t('Feeds XPath Parser'),
    );
  }
  public function setUp() {
    parent::setUp();
    require_once dirname(__FILE__) . '/../FeedsXPathParserQueryParser.inc';
  }
  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');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$originalPrefix protected property The original database prefix, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion.
DrupalTestCase::errorHandler public function Handle errors during test runs.
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs verbose message in a text file.
DrupalUnitTestCase::tearDown protected function
DrupalUnitTestCase::__construct function Constructor for DrupalUnitTestCase. Overrides DrupalTestCase::__construct
FeedsXPathParserQueryParserTestCase::getInfo public static function Describe this test.
FeedsXPathParserQueryParserTestCase::setUp public function Sets up unit test environment. Overrides DrupalUnitTestCase::setUp
FeedsXPathParserQueryParserTestCase::testSimple public function