Skip to content
Browse files

New Phing-based build system.

Massive updates to the build system. QueryPath now uses Phing
to build packages. Test and various scripts have been updated
accordingly.
  • Loading branch information...
1 parent b0bb428 commit e51bacc31f964d3a0d25841a059be872da5a3173 M Butcher committed Jul 2, 2009
View
1 COPYING-LGPL.txt
@@ -1,4 +1,5 @@
QueryPath: Find Your Way
+Matt Butcher <mbutcher@aleph-null.tv>
Copyright (C) 2009 Matt Butcher
This library is free software; you can redistribute it and/or
View
3 COPYING-MIT.txt
@@ -16,6 +16,3 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-You are expressly forbidden from removing this copyright message from
-this or any Caryatid file without explicit written permission from the
-copyright holder.
View
43 INSTALL
@@ -1,8 +1,47 @@
+INSTALLING QUERYPATH
+==============================
+
+There are two distributions of QueryPath:
+
+1. The full version, which includes source, documentation, unit tests,
+and examples.
+
+2. The minimal version, which includes only the source code in
+compacted form.
+
+INSTALLING THE MINIMAL VERSION
+==============================
+To install QueryPath-minimal:
+- Extract the contents of the archive:
+
+ tar -zxvf QueryPath-2.0-minimal.tgz
+
+- Move the extracted directory to the desired location. Generally,
+ it is best to rename this folder 'QueryPath'.
+
+ mv QueryPath-2.0-minimal myproject/QueryPath
+
+- Include QueryPath in your scripts:
+
+ require 'QueryPath/QueryPath.php';
+
+- The minimal package does not contain any documentation. To view
+ the documentation online, go to http://api.querypath.org.
+
+INSTALLING THE FULL VERSION
+==============================
To install QueryPath:
- Extract the contents of the archive.
+
+ tar -zxvf QueryPath-2.0.tgz
+
- Copy the src/QueryPath directory to the desired location.
+
+ cp QueryPath-2.0/src/QueryPath myproject
+
- Include QueryPath/QueryPath.php in your PHP scripts
-For more information, visit https://fedorahosted.org/querypath and
-http://querypath.org.
+ require 'QueryPath/QueryPath.php';
+
+For more information, visit http://querypath.org.
View
161 build.xml
@@ -0,0 +1,161 @@
+<?xml version="1.0"?>
+<project
+ name="QueryPath"
+ description="A simple, powerful, robust tool for working with XML, HTML, and HTTP"
+ default="ftest">
+<!--
+This is the Phing build file for QueryPath.
+
+Phing is a build tool. Learn more about it at http://phing.info.
+
+Copyright (c) 2009, Matt Butcher, some rights reserved.
+
+License:
+This file is released under the GNU LGPL 2.1 or, at your preference,
+an MIT license. See COPYING-LGPL.txt and COPYING-MIT.txt for details.
+-->
+
+ <!-- Global properties -->
+ <property name="srcdir" value="./src"/>
+ <property name="testdir" value="./test"/>
+ <property name="builddir" value="./bin"/>
+
+ <!-- Default version -->
+ <property name="version" value="dev"/>
+
+ <!-- Files that must be included in the release -->
+ <fileset id="licensefiles" dir=".">
+ <include name="README"/>
+ <include name="INSTALL"/>
+ <include name="LGPL-2.1.txt"/>
+ <include name="COPYING-LGPL.txt"/>
+ <include name="COPYING-MIT.txt"/>
+ </fileset>
+
+ <!-- Files to be treated as source code -->
+ <fileset id="sourcecode" dir="${srcdir}">
+ <include name="**/*.php" />
+ </fileset>
+
+ <!-- Unit tests and auxilliary files -->
+ <fileset id="unittests" dir="${testdir}/Tests">
+ <include name="**/*Test.php" />
+ </fileset>
+
+ <!-- Examples -->
+ <fileset id="examplecode" dir="./examples">
+ <include name="**/*" />
+ </fileset>
+
+ <!-- DocBook Tutorials -->
+ <fileset id="tutorials" dir="./tutorials">
+ <include name="**/*" />
+ </fileset>
+
+ <target name="build"></target>
+
+ <target name="minimalBuild" description="Minimal QueryPath build.">
+ <property name="releasedir" value="${builddir}/QueryPath-${version}-minimal"/>
+ <delete dir="${releasedir}" />
+ <mkdir dir="${releasedir}"/>
+ <copy todir="${releasedir}">
+ <filterchain>
+ <stripphpcomments/>
+ <stripwhitespace/>
+ </filterchain>
+ <fileset dir="${srcdir}/QueryPath">
+ <include name="**/*"/>
+ </fileset>
+ </copy>
+ <copy todir="${releasedir}">
+ <fileset refid="licensefiles"/>
+ </copy>
+ <tar destfile="QueryPath-${version}-minimal.tgz" compression="gzip" basedir="${releasedir}"/>
+ </target>
+
+ <!-- Check syntax -->
+ <target name="lint" description="Check syntax of source.">
+ <phplint>
+ <fileset refid="sourcecode" />
+ </phplint>
+ </target>
+
+ <!-- Build documentation -->
+ <target name="doc" depends="lint" description="Generate API docs.">
+ <phpdoc title="QueryPath 2 (Quark)"
+ sourcecode="yes"
+ destdir="docs"
+ output="HTML:Smarty:QueryPath"
+ defaultcategoryname="QueryPath"
+ defaultpackagename="QueryPath"
+ examplesdir="examples"
+ quiet="true"
+ >
+ <fileset refid="sourcecode"/>
+ <fileset refid="tutorials"/>
+ <fileset dir="examplecode"/>
+ <projdocfileset dir=".">
+ <include name="README"/>
+ <include name="INSTALL"/>
+ <include name="COPYING-LGPL.txt"/>
+ <include name="COPYING-MIT.txt"/>
+ <include name="LGPL-2.1.txt"/>
+ </projdocfileset>
+ </phpdoc>
+ </target>
+
+ <!-- Run a fast test and print the results to the console -->
+ <target name="ftest" depends="lint" description="Run a quick unit test.">
+ <!-- Fast test. -->
+ <phpunit>
+ <formatter type="plain" usefile="false"/>
+ <batchtest>
+ <fileset refid="unittests"/>
+ </batchtest>
+ </phpunit>
+ <delete file="./test/db/qpTest.db" />
+ <delete file="./test/db/qpTest2.db" />
+ </target>
+
+ <!-- Run a coverage report -->
+ <target name="coverage" depends="lint" description="Run a coverage analysis.">
+ <coverage-setup database="./test/db/coverage.db">
+ <fileset dir="src">
+ <include name="QueryPath/*.php"/>
+ </fileset>
+ </coverage-setup>
+ <phpunit codecoverage="true" haltonfailure="true">
+ <formatter type="plain" todir="test/reports" outfile="coverage.xml"/>
+ <batchtest>
+ <fileset dir="test/Tests">
+ <include name="**/*Test.php"/>
+ </fileset>
+ </batchtest>
+ </phpunit>
+ <coverage-report outfile="test/reports/coverage.xml">
+ <report todir="test/coverage"/>
+ </coverage-report>
+ </target>
+
+ <!-- Run a full test and format an HTML report -->
+ <target name="test" depends="lint" description="Run full tests">
+ <phpunit>
+ <formatter todir="test/reports" type="xml"/>
+ <batchtest>
+ <fileset dir="test/Tests">
+ <include name="**/*Test.php"/>
+ </fileset>
+ </batchtest>
+ </phpunit>
+ <phpunitreport
+ infile="test/reports/testsuites.xml"
+ format="noframes"
+ todir="test/reports/html"
+ />
+ <delete file="./test/db/qpTest.db" />
+ <delete file="./test/db/qpTest2.db" />
+ </target>
+
+</project>
+
+
View
30 src/QueryPath/QueryPath.php
@@ -2034,7 +2034,15 @@ public function writeXML($path = NULL) {
print $this->document->saveXML();
}
else {
- $this->document->save($path);
+ try {
+ set_error_handler(array('QueryPathIOException', 'initializeFromError'));
+ $this->document->save($path);
+ }
+ catch (Exception $e) {
+ restore_error_handler();
+ throw $e;
+ }
+ restore_error_handler();
}
return $this;
}
@@ -2061,7 +2069,15 @@ public function writeHTML($path = NULL) {
print $this->document->saveHTML();
}
else {
- $this->document->saveHTMLFile($path);
+ try {
+ set_error_handler(array('QueryPathIOException', 'initializeFromError'));
+ $this->document->saveHTMLFile($path);
+ }
+ catch (Exception $e) {
+ restore_error_handler();
+ throw $e;
+ }
+ restore_error_handler();
}
return $this;
}
@@ -3007,6 +3023,14 @@ public function __construct($msg = '', $code = 0, $file = NULL, $line = NULL) {
}
public static function initializeFromError($code, $str, $file, $line, $cxt) {
- throw new QueryPathParseException($str, $code, $file, $line);
+ $class = __CLASS__;
+ throw new $class($str, $code, $file, $line);
+ }
+}
+
+class QueryPathIOException extends QueryPathParseException {
+ public static function initializeFromError($code, $str, $file, $line, $cxt) {
+ $class = __CLASS__;
+ throw new $class($str, $code, $file, $line);
}
}
View
3 test/Tests/QueryPath/CssEventTest.php
@@ -4,7 +4,8 @@
*/
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/CssEventHandler.php';
+//require_once 'src/QueryPath/CssEventHandler.php';
+require_once 'src/QueryPath/QueryPath.php';
class CssTokenTest extends PHPUnit_Framework_TestCase {
public function testName() {
View
16 test/Tests/QueryPath/Extensions/QPDBTest.php
@@ -1,21 +1,23 @@
<?php
/**
* Tests for the QueryPath library.
- * @package Tests
* @author M Butcher <matt@aleph-null.tv>
* @license The GNU Lesser GPL (LGPL) or an MIT-like license.
+ * @package Tests
*/
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/QueryPath.php';
-require_once '../src/QueryPath/Extension/QPDB.php';
-require_once '../src/QueryPath/Extension/QPTPL.php';
-
-QPDB::baseDB('sqlite:./db/qpTest.db');
+require_once 'src/QueryPath/QueryPath.php';
+require_once 'src/QueryPath/Extension/QPDB.php';
+require_once 'src/QueryPath/Extension/QPTPL.php';
+QPDB::baseDB('sqlite:./test/db/qpTest.db');
+/**
+ * @package Tests
+ */
class QPDBTest extends PHPUnit_Framework_TestCase {
- private $dsn = 'sqlite:./db/qpTest.db';
+ private $dsn = 'sqlite:./test/db/qpTest.db';
public function setUp() {
$this->db = QPDB::getBaseDB();
View
4 test/Tests/QueryPath/Extensions/QPListTest.php
@@ -7,8 +7,8 @@
*/
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/QueryPath.php';
-require_once '../src/QueryPath/Extension/QPList.php';
+require_once 'src/QueryPath/QueryPath.php';
+require_once 'src/QueryPath/Extension/QPList.php';
class QPListTests extends PHPUnit_Framework_TestCase {
public function testAppendList() {
View
6 test/Tests/QueryPath/Extensions/QPTPLTest.php
@@ -7,8 +7,8 @@
*/
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/QueryPath.php';
-require_once '../src/QueryPath/Extension/QPTPL.php';
+require_once 'src/QueryPath/QueryPath.php';
+require_once 'src/QueryPath/Extension/QPTPL.php';
class QPTPLTest extends PHPUnit_Framework_TestCase {
@@ -151,7 +151,7 @@ class FixtureTwo {
private $db;
public function __construct() {
- $this->db = new PDO('sqlite:./db/qpTest2.db');
+ $this->db = new PDO('sqlite:./test/db/qpTest2.db');
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->db->exec('CREATE TABLE IF NOT EXISTS test (message TEXT)');
$this->db->exec('INSERT INTO test (message) VALUES ("This is a message")');
View
6 test/Tests/QueryPath/Extensions/QPXMLTest.php
@@ -7,12 +7,12 @@
*/
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/QueryPath.php';
-require_once '../src/QueryPath/Extension/QPXML.php';
+require_once 'src/QueryPath/QueryPath.php';
+require_once 'src/QueryPath/Extension/QPXML.php';
class QPXMLTests extends PHPUnit_Framework_TestCase {
- protected $file = './advanced.xml';
+ protected $file = './test/advanced.xml';
public function testCDATA() {
$this->assertEquals('This is a CDATA section.', qp($this->file, 'first')->cdata());
View
2 test/Tests/QueryPath/QueryPathEntitiesTest.php
@@ -7,7 +7,7 @@
*/
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/QueryPath.php';
+require_once 'src/QueryPath/QueryPath.php';
class QueryPathEntitiesTest extends PHPUnit_Framework_TestCase {
public function testReplaceEntity() {
View
13 test/Tests/QueryPath/QueryPathExtensionTest.php
@@ -7,10 +7,15 @@
*/
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/QueryPath.php';
+require_once 'src/QueryPath/QueryPath.php';
require_once 'QueryPathTest.php';
/**
+ *
+ */
+define('DATA_FILE', 'test/data.xml');
+
+/**
* Run all of the usual tests, plus some extras, with some extensions loaded.
*/
class QueryPathExtensionTest extends QueryPathTest {
@@ -24,11 +29,11 @@ public function testHasExtension() {
}
public function testStubToe() {
- $this->assertEquals(1, qp('./data.xml', 'unary')->stubToe()->find(':root > toe')->size());
+ $this->assertEquals(1, qp(DATA_FILE, 'unary')->stubToe()->find(':root > toe')->size());
}
public function testStuble() {
- $this->assertEquals('arg1arg2', qp('./data.xml')->stuble('arg1', 'arg2'));
+ $this->assertEquals('arg1arg2', qp(DATA_FILE)->stuble('arg1', 'arg2'));
}
/**
@@ -37,7 +42,7 @@ public function testStuble() {
public function testNoRegistry() {
QueryPathExtensionRegistry::$useRegistry = FALSE;
try {
- qp('./data.xml')->stuble('arg1', 'arg2');
+ qp(DATA_FILE)->stuble('arg1', 'arg2');
}
catch (QueryPathException $e) {
QueryPathExtensionRegistry::$useRegistry = TRUE;
View
2 test/Tests/QueryPath/QueryPathOptionsTest.php
@@ -7,7 +7,7 @@
*/
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/QueryPath.php';
+require_once 'src/QueryPath/QueryPath.php';
class QueryPathOptionsTest extends PHPUnit_Framework_TestCase {
View
144 test/Tests/QueryPath/QueryPathTest.php
@@ -1,13 +1,19 @@
<?php
/**
* Tests for the QueryPath library.
+ *
* @package Tests
* @author M Butcher <matt@aleph-null.tv>
* @license The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
+/** */
require_once 'PHPUnit/Framework.php';
-require_once '../src/QueryPath/QueryPath.php';
+require_once 'src/QueryPath/QueryPath.php';
+
+define('DATA_FILE', 'test/data.xml');
+define('DATA_HTML_FILE', 'test/data.html');
+define('NO_WRITE_FILE', 'test/no-write.xml');
/**
* Tests for DOM Query. Primarily, this is focused on the DomQueryImpl
@@ -19,7 +25,7 @@ class QueryPathTest extends PHPUnit_Framework_TestCase {
public function testQueryPathConstructors() {
// From XML file
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file);
$this->assertEquals(1, count($qp->get()));
$this->assertTrue($qp->get(0) instanceof DOMNode);
@@ -53,7 +59,7 @@ public function testQueryPathConstructors() {
$this->assertEquals($qp->get(0)->tagName, 'head');
// Test HTML:
- $htmlFile = './data.html';
+ $htmlFile = DATA_HTML_FILE;
$qp = qp($htmlFile);
$this->assertEquals(1, count($qp->get()));
$this->assertTrue($qp->get(0) instanceof DOMNode);
@@ -163,7 +169,7 @@ public function testFailedParseEntity() {
}
public function testFind() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file)->find('#head');
$this->assertEquals(1, count($qp->get()));
$this->assertEquals($qp->get(0)->tagName, 'head');
@@ -172,14 +178,14 @@ public function testFind() {
}
public function testTop() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file)->find('li');
$this->assertGreaterThan(2, $qp->size());
$this->assertEquals(1, $qp->top()->size());
}
public function testAttr() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file)->find('#head');
$this->assertEquals(1, $qp->size());
@@ -205,14 +211,14 @@ public function testVal() {
}
public function testCss() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals('foo: bar', qp($file, 'unary')->css('foo', 'bar')->attr('style'));
$this->assertEquals('foo: bar', qp($file, 'unary')->css('foo', 'bar')->css());
$this->assertEquals('foo: bar', qp($file, 'unary')->css(array('foo' =>'bar'))->css());
}
public function testRemoveAttr() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file, 'inner')->removeAttr('class');
$this->assertEquals(2, $qp->size());
@@ -221,14 +227,14 @@ public function testRemoveAttr() {
}
public function testEq() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file)->find('li')->eq(0);
$this->assertEquals(1, $qp->size());
$this->assertEquals($qp->attr('id'), 'one');
}
public function testIs() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertTrue(qp($file)->find('#one')->is('#one'));
$this->assertTrue(qp($file)->find('li')->is('#one'));
}
@@ -242,14 +248,14 @@ public function testIndex() {
}
public function testFilter() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(1, qp($file)->filter('li')->size());
$this->assertEquals(2, qp($file, 'inner')->filter('li')->size());
$this->assertEquals('inner-two', qp($file, 'inner')->filter('li')->eq(1)->attr('id'));
}
public function testFilterLambda() {
- $file = './data.xml';
+ $file = DATA_FILE;
// Get all evens:
$l = 'return (($index + 1) % 2 == 0);';
$this->assertEquals(2, qp($file, 'li')->filterLambda($l)->size());
@@ -260,7 +266,7 @@ public function filterCallbackFunction($index, $item) {
}
public function testFilterCallback() {
- $file = './data.xml';
+ $file = DATA_FILE;
$cb = array($this, 'filterCallbackFunction');
$this->assertEquals(2, qp($file, 'li')->filterCallback($cb)->size());
}
@@ -269,7 +275,7 @@ public function testFilterCallback() {
* @expectedException QueryPathException
*/
public function testFailedFilterCallback() {
- $file = './data.xml';
+ $file = DATA_FILE;
$cb = array($this, 'noSuchFunction');
qp($file, 'li')->filterCallback($cb)->size();
}
@@ -278,14 +284,14 @@ public function testFailedFilterCallback() {
* @expectedException QueryPathException
*/
public function testFailedMapCallback() {
- $file = './data.xml';
+ $file = DATA_FILE;
$cb = array($this, 'noSuchFunction');
qp($file, 'li')->map($cb)->size();
}
public function testNot() {
- $file = './data.xml';
+ $file = DATA_FILE;
// Test with selector
$qp = qp($file, 'li:odd')->not('#one');
@@ -305,7 +311,7 @@ public function testNot() {
}
public function testSlice() {
- $file = './data.xml';
+ $file = DATA_FILE;
// There are five <li> elements
$qp = qp($file, 'li')->slice(1);
$this->assertEquals(4, $qp->size());
@@ -339,7 +345,7 @@ public function mapCallbackFunction($index, $item) {
}
public function testMap() {
- $file = './data.xml';
+ $file = DATA_FILE;
$fn = 'mapCallbackFunction';
$this->assertEquals(7, qp($file, 'li')->map(array($this, $fn))->size());
}
@@ -354,7 +360,7 @@ public function eachCallbackFunction($index, $item) {
}
public function testEach() {
- $file = './data.xml';
+ $file = DATA_FILE;
$fn = 'eachCallbackFunction';
$res = qp($file, 'li')->each(array($this, $fn));
$this->assertEquals(5, $res->size());
@@ -370,13 +376,13 @@ public function testEach() {
* @expectedException QueryPathException
*/
public function testEachOnInvalidCallback() {
- $file = './data.xml';
+ $file = DATA_FILE;
$fn = 'eachCallbackFunctionFake';
$res = qp($file, 'li')->each(array($this, $fn));
}
public function testEachLambda() {
- $file = './data.xml';
+ $file = DATA_FILE;
$fn = 'qp($item)->attr("class", "foo");';
$res = qp($file, 'li')->eachLambda($fn);
$this->assertEquals('foo', $res->eq(1)->attr('class'));
@@ -410,12 +416,12 @@ public function testDeepest() {
}
public function testTag() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals('li', qp($file, 'li')->tag());
}
public function testAppend() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(1, qp($file,'unary')->append('<test/>')->find(':root > unary > test')->size());
$qp = qp($file,'#inner-one')->append('<li id="appended"/>');
$this->assertEquals(1, $qp->find('#appended')->size());
@@ -449,7 +455,7 @@ public function testAppend() {
* @expectedException QueryPathParseException
*/
public function testAppendBadMarkup() {
- $file = './data.xml';
+ $file = DATA_FILE;
try{
qp($file, 'root')->append('<foo><bar></foo>');
}
@@ -463,7 +469,7 @@ public function testAppendBadMarkup() {
* @expectedException QueryPathException
*/
public function testAppendBadObject() {
- $file = './data.xml';
+ $file = DATA_FILE;
try{
qp($file, 'root')->append(new stdClass);
}
@@ -474,14 +480,14 @@ public function testAppendBadObject() {
}
public function testAppendTo() {
- $file = './data.xml';
+ $file = DATA_FILE;
$dest = qp('<?xml version="1.0"?><root><dest/></root>', 'dest');
$qp = qp($file,'li')->appendTo($dest);
$this->assertEquals(5, $dest->find(':root li')->size());
}
public function testPrepend() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(1, qp($file,'unary')->prepend('<test/>')->find(':root > unary > test')->size());
$qp = qp($file,'#inner-one')->prepend('<li id="appended"/>')->find('#appended');
$this->assertEquals(1, $qp->size());
@@ -492,14 +498,14 @@ public function testPrepend() {
}
public function testPrependTo() {
- $file = './data.xml';
+ $file = DATA_FILE;
$dest = qp('<?xml version="1.0"?><root><dest/></root>', 'dest');
$qp = qp($file,'li')->prependTo($dest);
$this->assertEquals(5, $dest->find(':root li')->size());
}
public function testBefore() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(1, qp($file,'unary')->before('<test/>')->find(':root > unary ~ test')->size());
$this->assertEquals('unary', qp($file,'unary')->before('<test/>')->find(':root > test')->get(0)->nextSibling->tagName);
@@ -508,7 +514,7 @@ public function testBefore() {
}
public function testAfter() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(1, qp($file,'unary')->after('<test/>')->find(':root > unary ~ test')->size());
$this->assertEquals('unary', qp($file,'unary')->after('<test/>')->find(':root > test')->get(0)->previousSibling->tagName);
@@ -517,21 +523,21 @@ public function testAfter() {
}
public function testInsertBefore() {
- $file = './data.xml';
+ $file = DATA_FILE;
$dest = qp('<?xml version="1.0"?><root><dest/></root>', 'dest');
$qp = qp($file,'li')->insertBefore($dest);
$this->assertEquals(5, $dest->find(':root > li')->size());
$this->assertEquals('li', $dest->end()->find('dest')->get(0)->previousSibling->tagName);
}
public function testInsertAfter() {
- $file = './data.xml';
+ $file = DATA_FILE;
$dest = qp('<?xml version="1.0"?><root><dest/></root>', 'dest');
$qp = qp($file,'li')->insertAfter($dest);
//print $dest->get(0)->ownerDocument->saveXML();
$this->assertEquals(5, $dest->find(':root > li')->size());
}
public function testReplaceWith() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file,'unary')->replaceWith('<test><foo/></test>')->find(':root test');
//print $qp->get(0)->ownerDocument->saveXML();
$this->assertEquals(1, $qp->size());
@@ -547,7 +553,7 @@ public function testReplaceAll() {
}
public function testWrap() {
- $file = './data.xml';
+ $file = DATA_FILE;
$xml = qp($file,'unary')->wrap('');
$this->assertTrue($xml instanceof QueryPath);
@@ -562,7 +568,7 @@ public function testWrap() {
}
public function testWrapAll() {
- $file = './data.xml';
+ $file = DATA_FILE;
$xml = qp($file,'unary')->wrapAll('');
$this->assertTrue($xml instanceof QueryPath);
@@ -576,7 +582,7 @@ public function testWrapAll() {
}
public function testWrapInner() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertTrue(qp($file,'#inner-one')->wrapInner('') instanceof QueryPath);
@@ -586,7 +592,7 @@ public function testWrapInner() {
}
public function testRemove() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file, 'li');
$start = $qp->size();
$finish = $qp->remove()->size();
@@ -595,65 +601,65 @@ public function testRemove() {
}
public function testHasClass() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertTrue(qp($file, '#inner-one')->hasClass('innerClass'));
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertFalse(qp($file, '#inner-one')->hasClass('noSuchClass'));
}
public function testAddClass() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertTrue(qp($file, '#inner-one')->addClass('testClass')->hasClass('testClass'));
}
public function testRemoveClass() {
- $file = './data.xml';
+ $file = DATA_FILE;
// The add class tests to make sure that this works with multiple values.
$this->assertFalse(qp($file, '#inner-one')->removeClass('innerClass')->hasClass('innerClass'));
$this->assertTrue(qp($file, '#inner-one')->addClass('testClass')->removeClass('innerClass')->hasClass('testClass'));
}
public function testAdd() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(7, qp($file, 'li')->add('inner')->size());
}
public function testEnd() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(2, qp($file, 'inner')->find('li')->end()->size());
}
public function testAndSelf() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(7, qp($file, 'inner')->find('li')->andSelf()->size());
}
public function testChildren() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(5, qp($file, 'inner')->children()->size());
$this->assertEquals(5, qp($file, 'inner')->children('li')->size());
$this->assertEquals(1, qp($file, ':root')->children('unary')->size());
}
public function testRemoveChildren() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(0, qp($file, '#inner-one')->removeChildren()->find('li')->size());
}
public function testContents() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertGreaterThan(5, qp($file, 'inner')->contents()->size());
// Two cdata nodes and one element node.
$this->assertEquals(3, qp($file, '#inner-two')->contents()->size());
}
public function testSiblings() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(3, qp($file, '#one')->siblings()->size());
$this->assertEquals(2, qp($file, 'unary')->siblings('inner')->size());
}
public function testHTML() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file, 'unary');
$html = '<b>test</b>';
$this->assertEquals($html, $qp->html($html)->find('b')->html());
@@ -676,7 +682,7 @@ public function testHTML() {
}
public function testXML() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file, 'unary');
$xml = '<b>test</b>';
$this->assertEquals($xml, $qp->xml($xml)->find('b')->xml());
@@ -698,7 +704,7 @@ public function testXML() {
}
public function testXHTML() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file, 'unary');
$xml = '<b>test</b>';
$this->assertEquals($xml, $qp->xml($xml)->find('b')->xhtml());
@@ -790,11 +796,11 @@ public function testWriteXHTML() {
}
/**
- * @expectedException Exception
+ * @expectedException QueryPathIOException
*/
public function testFailWriteXML() {
try {
- qp()->writeXML('./no-writing.xml');
+ qp()->writeXML('./test/no-writing.xml');
}
catch (Exception $e) {
//print $e->getMessage();
@@ -804,27 +810,27 @@ public function testFailWriteXML() {
}
/**
- * @expectedException Exception
+ * @expectedException QueryPathIOException
*/
public function testFailWriteXHTML() {
try {
- qp()->writeXHTML('./no-writing.xml');
+ qp()->writeXHTML('./test/no-writing.xml');
}
- catch (Exception $e) {
+ catch (QueryPathIOException $e) {
//print $e->getMessage();
throw $e;
}
}
/**
- * @expectedException Exception
+ * @expectedException QueryPathIOException
*/
public function testFailWriteHTML() {
try {
- qp()->writeXML('./no-writing.xml');
+ qp()->writeXML('./test/no-writing.xml');
}
- catch (Exception $e) {
+ catch (QueryPathIOException $e) {
//print $e->getMessage();
throw $e;
}
@@ -903,50 +909,50 @@ public function testTextImplode() {
}
public function testNext() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals('inner', qp($file, 'unary')->next()->tag());
$this->assertEquals('foot', qp($file, 'inner')->next()->eq(1)->tag());
$this->assertEquals('foot', qp($file, 'unary')->next('foot')->tag());
}
public function testPrev() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals('head', qp($file, 'unary')->prev()->tag());
$this->assertEquals('inner', qp($file, 'inner')->prev()->eq(1)->tag());
$this->assertEquals('head', qp($file, 'foot')->prev('head')->tag());
}
public function testNextAll() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(3, qp($file, '#one')->nextAll()->size());
$this->assertEquals(2, qp($file, 'unary')->nextAll('inner')->size());
}
public function testPrevAll() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(3, qp($file, '#four')->prevAll()->size());
$this->assertEquals(2, qp($file, 'foot')->prevAll('inner')->size());
}
public function testPeers() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals(3, qp($file, '#two')->peers()->size());
$this->assertEquals(2, qp($file, 'foot')->peers('inner')->size());
}
public function testParent() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals('root', qp($file, 'unary')->parent()->tag());
$this->assertEquals('root', qp($file, 'li')->parent('root')->tag());
$this->assertEquals(2, qp($file, 'li')->parent()->size());
}
public function testParents() {
- $file = './data.xml';
+ $file = DATA_FILE;
// Three: two inners and a root.
$this->assertEquals(3, qp($file, 'li')->parents()->size());
$this->assertEquals('root', qp($file, 'li')->parents('root')->tag());
}
public function testCloneAll() {
- $file = './data.xml';
+ $file = DATA_FILE;
// Shallow test
$qp = qp($file, 'unary');
@@ -979,13 +985,13 @@ public function testBranch() {
}
public function testXpath() {
- $file = './data.xml';
+ $file = DATA_FILE;
$this->assertEquals('head', qp($file)->xpath("//*[@id='head']")->tag());
}
public function test__clone() {
- $file = './data.xml';
+ $file = DATA_FILE;
$qp = qp($file, 'inner:first');
$qp2 = clone $qp;
View
4 test/runTests.sh
@@ -1,6 +1,8 @@
#!/bin/bash
phpunit=/Applications/MAMP/bin/php5/bin/phpunit
-$phpunit Tests/
+cd ..
+$phpunit test/Tests/
+cd -
rm "db/qpTest.db"
rm "db/qpTest2.db"

0 comments on commit e51bacc

Please sign in to comment.
Something went wrong with that request. Please try again.