First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,4 @@
<div>
<span>Hello World!</span>
<span>ąśżźć</span>
</div>

View file

@ -0,0 +1,15 @@
<br />
<p>Test: &nbsp; żźć</p>
<p>This is an example of an
<abbr title="Extensible HyperText Markup Language">XHTML</abbr> 1.0 Strict document.<br />
<img id="validation-icon"
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" /><br />
<object id="pdf-object"
name="pdf-object"
type="application/pdf"
data="http://www.w3.org/TR/xhtml1/xhtml1.pdf"
width="100%"
height="500">
</object>
</p>

View file

@ -0,0 +1,10 @@
<instructions>
<step>Mix all ingredients together.</step>
<step>Knead thoroughly.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Knead again.</step>
<step>Place in a bread baking tin.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Bake in the oven at 180(degrees)C for 30 minutes.</step>
<step>Charset test: ąśżźć</step>
</instructions>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTML document without charset (encoded in ISO-8859-2)</title>
</head>
<body>
<span>Hello World!</span>
<span>±¶¿¼æ</span>
</body>
</html>

View file

@ -0,0 +1,32 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">-->
<head>
<title>XHTML 1.0 Example</title>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
function loadpdf() {
document.getElementById("pdf-object").src="http://www.w3.org/TR/xhtml1/xhtml1.pdf";
}
//--><!]]>
</script>
</head>
<body onload="loadpdf()">
<p>Test: &nbsp; ¿¼æ</p>
<p>This is an example of an
<abbr title="Extensible HyperText Markup Language">XHTML</abbr> 1.0 Strict document.<br />
<img id="validation-icon"
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" /><br />
<object id="pdf-object"
name="pdf-object"
type="application/pdf"
data="http://www.w3.org/TR/xhtml1/xhtml1.pdf"
width="100%"
height="500">
</object>
</p>
</body>
</html>

View file

@ -0,0 +1,17 @@
<recipe name="bread" prep_time="5 mins" cook_time="3 hours">
<title>Basic bread</title>
<ingredient amount="8" unit="dL">Flour</ingredient>
<ingredient amount="10" unit="grams">Yeast</ingredient>
<ingredient amount="4" unit="dL" state="warm">Water</ingredient>
<ingredient amount="1" unit="teaspoon">Salt</ingredient>
<instructions>
<step>Mix all ingredients together.</step>
<step>Knead thoroughly.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Knead again.</step>
<step>Place in a bread baking tin.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Bake in the oven at 180(degrees)C for 30 minutes.</step>
<step>Charset test: ±¶¿¼æ</step>
</instructions>
</recipe>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTML document with ISO-8859-2 charset</title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-2">
</head>
<body>
<span>Hello World!</span>
<span>±¶¿¼æ</span>
</body>
</html>

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="iso-8859-2"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<title>XHTML 1.0 Example</title>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
function loadpdf() {
document.getElementById("pdf-object").src="http://www.w3.org/TR/xhtml1/xhtml1.pdf";
}
//--><!]]>
</script>
</head>
<body onload="loadpdf()">
<p>Test: &nbsp; ¿¼æ</p>
<p>This is an example of an
<abbr title="Extensible HyperText Markup Language">XHTML</abbr> 1.0 Strict document.<br />
<img id="validation-icon"
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" /><br />
<object id="pdf-object"
name="pdf-object"
type="application/pdf"
data="http://www.w3.org/TR/xhtml1/xhtml1.pdf"
width="100%"
height="500">
</object>
</p>
</body>
</html>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-2"?>
<recipe name="bread" prep_time="5 mins" cook_time="3 hours">
<title>Basic bread</title>
<ingredient amount="8" unit="dL">Flour</ingredient>
<ingredient amount="10" unit="grams">Yeast</ingredient>
<ingredient amount="4" unit="dL" state="warm">Water</ingredient>
<ingredient amount="1" unit="teaspoon">Salt</ingredient>
<instructions>
<step>Mix all ingredients together.</step>
<step>Knead thoroughly.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Knead again.</step>
<step>Place in a bread baking tin.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Bake in the oven at 180(degrees)C for 30 minutes.</step>
<step>Charset test: ±¶¿¼æ</step>
</instructions>
</recipe>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTML document without charset (encoded in UTF-8)</title>
</head>
<body>
<span>Hello World!</span>
<span>ąśżźć</span>
</body>
</html>

View file

@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">-->
<head>
<title>XHTML 1.0 Example</title>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
function loadpdf() {
document.getElementById("pdf-object").src="http://www.w3.org/TR/xhtml1/xhtml1.pdf";
}
//--><!]]>
</script>
</head>
<body onload="loadpdf()">
<p>Test: &nbsp; żźć</p>
<p>This is an example of an
<abbr title="Extensible HyperText Markup Language">XHTML</abbr> 1.0 Strict document.<br />
<img id="validation-icon"
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" /><br />
<object id="pdf-object"
name="pdf-object"
type="application/pdf"
data="http://www.w3.org/TR/xhtml1/xhtml1.pdf"
width="100%"
height="500">
</object>
</p>
</body>
</html>

View file

@ -0,0 +1,17 @@
<recipe name="bread" prep_time="5 mins" cook_time="3 hours">
<title>Basic bread</title>
<ingredient amount="8" unit="dL">Flour</ingredient>
<ingredient amount="10" unit="grams">Yeast</ingredient>
<ingredient amount="4" unit="dL" state="warm">Water</ingredient>
<ingredient amount="1" unit="teaspoon">Salt</ingredient>
<instructions>
<step>Mix all ingredients together.</step>
<step>Knead thoroughly.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Knead again.</step>
<step>Place in a bread baking tin.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Bake in the oven at 180(degrees)C for 30 minutes.</step>
<step>Charset test: ąśżźć</step>
</instructions>
</recipe>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTML document with UTF-8 charset ąśżźć</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<span>Hello World!</span>
<span>ąśżźć</span>
</body>
</html>

View file

@ -0,0 +1,13 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTML document with UTF-8 charset</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<?php print '<title>foob\'"bar</title>'; ?>
</head>
<body>
<span>Hello World!</span>
<span>ąśżźć</span>
<a href='<?php foreach($foo as $bar} { print $foo['1'] } ?>'>Attr test</a>
</body>
</html>

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>XHTML 1.0 Example</title>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
function loadpdf() {
document.getElementById("pdf-object").src="http://www.w3.org/TR/xhtml1/xhtml1.pdf";
}
//--><!]]>
</script>
</head>
<body onload="loadpdf()">
<select name='test'></select>
<textarea name='test'></textarea>
<br />
<p>Test: &nbsp; żźć</p>
<p>This is an example of an
<abbr title="Extensible HyperText Markup Language">XHTML</abbr> 1.0 Strict document.<br />
<img id="validation-icon"
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" /><br />
<object id="pdf-object"
name="pdf-object"
type="application/pdf"
data="http://www.w3.org/TR/xhtml1/xhtml1.pdf"
width="100%"
height="500">
</object>
</p>
</body>
</html>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<recipe name="bread" prep_time="5 mins" cook_time="3 hours">
<title>Basic bread</title>
<ingredient amount="8" unit="dL">Flour</ingredient>
<ingredient amount="10" unit="grams">Yeast</ingredient>
<ingredient amount="4" unit="dL" state="warm">Water</ingredient>
<ingredient amount="1" unit="teaspoon">Salt</ingredient>
<instructions>
<step>Mix all ingredients together.</step>
<step>Knead thoroughly.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Knead again.</step>
<step>Place in a bread baking tin.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Bake in the oven at 180(degrees)C for 30 minutes.</step>
<step>Charset test: ąśżźć</step>
</instructions>
</recipe>

View file

@ -0,0 +1,151 @@
<?php
/**
* Charset and document types test.
*
* Remember:
* - never test charset with htmlentities ! Use htmlspecialchars (or define charset as parameter)
*
* TODO:
* - document fragments tests (with all 4 charset scenarios)
*
*/
class phpQuery {
static $defaultDocumentID;
static $debug = 0;
static $documents = array();
static $defaultCharset = 'utf-8';
static function debug($text) {
if (self::$debug)
print var_dump($text);
}
}
require_once('../phpQuery/DOMDocumentWrapper.php');
phpQuery::$debug = 2;
/* ENCODINGS */
//print '<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-2">';
print '<meta http-equiv="Content-Type" content="text/html;charset=utf-8">';
/* HTML */
//$htmlIso = new DOMDocumentWrapper(
// file_get_contents('document-types/document-iso88592.html')
//);
//$htmlIsoNoCharset = new DOMDocumentWrapper(
// file_get_contents('document-types/document-iso88592-nocharset.html'),
// 'text/html;charset=iso-8859-2'
//);
$htmlUtf = new DOMDocumentWrapper(
file_get_contents('document-types/document-utf8.html')
);
var_dump($htmlUtf->markup());
//$htmlUtfNoCharset = new DOMDocumentWrapper(
// file_get_contents('document-types/document-utf8-nocharset.html'),
// 'text/html;charset=utf-8'
//);
//print htmlspecialchars($htmlIso->markup(
// $htmlIso->document->getElementsByTagName('span'))
//);
//print htmlspecialchars($htmlIsoNoCharset->markup(
// $htmlIsoNoCharset->document->getElementsByTagName('p'))
//);
//print htmlspecialchars($htmlUtf->markup());
//print htmlspecialchars($htmlUtfNoCharset->markup());
/* XML */
//$xmlIso = new DOMDocumentWrapper(
// file_get_contents('document-types/document-iso88592.xml')
//);
//$xmlIsoNoCharset = new DOMDocumentWrapper(
// file_get_contents('document-types/document-iso88592-nocharset.xml'),
// 'text/xml;charset=iso-8859-2'
//);
//$xmlUtf = new DOMDocumentWrapper(
// file_get_contents('document-types/document-utf8.xml')
//);
//$xmlUtfNoCharset = new DOMDocumentWrapper(
// file_get_contents('document-types/document-utf8-nocharset.xml'),
// 'text/xml;charset=utf-8'
//);
//print var_dump($xmlIso->markup(
// $xmlIso->document->getElementsByTagName('step')->item(0)
//));
//print htmlspecialchars($xmlIsoNoCharset->markup());
//print htmlspecialchars($xmlUtf->markup());
//print htmlspecialchars($xmlUtfNoCharset->markup());
/* XHTML */
//$xhtmlIso = new DOMDocumentWrapper(
// file_get_contents('document-types/document-iso88592.xhtml')
//);
//$xhtmlIsoNoCharset = new DOMDocumentWrapper(
// file_get_contents('document-types/document-iso88592-nocharset.xhtml'),
// 'application/xhtml+xml;charset=iso-8859-2'
//);
//$xhtmlUtf = new DOMDocumentWrapper(
// file_get_contents('document-types/document-utf8.xhtml')
//);
//$xhtmlUtfNoCharset = new DOMDocumentWrapper(
// file_get_contents('document-types/document-utf8-nocharset.xhtml'),
// 'application/xhtml+xml'
//);
//print htmlspecialchars($xhtmlIso->markup());
//print var_dump($xhtmlIsoNoCharset->markup());
//print var_dump($xhtmlIsoNoCharset->markup(
// $xhtmlIsoNoCharset->document->getElementsByTagName('p')
//));
//print var_dump($xhtmlUtf->markup());
//print var_dump($xhtmlUtf->markup(
// $xhtmlUtf->document->getElementsByTagName('p')
//));
//print htmlspecialchars($xhtmlUtfNoCharset->markup());
/** FRAGMETNS **/
/* HTML fragment */
//$htmlFragmentUtf = new DOMDocumentWrapper(
// file_get_contents('document-types/document-fragment-utf8.html')
//);
//$htmlFragmentUtf->markup();
//$htmlFragmentUtf->markup(
// $htmlFragmentUtf->document->getElementsByTagName('span')
//);
/* XML fragment */
//$xmlFragmentUtf = new DOMDocumentWrapper(
// file_get_contents('document-types/document-fragment-utf8.xml'),
// 'text/xml'nt var_dump($xhtmlFragmentUtf->document->saveXML());
//$xhtmlFragmentUtf->markup();
//$xhtmlFragmentUtf->markup(
// $xhtmlFragmentUtf->document->getElementsByTagName('p')
//);
//);
//$xmlFragmentUtf->markup();
//$xmlFragmentUtf->markup(
// $xmlFragmentUtf->document->getElementsByTagName('step')
//);
/* XHTML fragment */
//$xhtmlFragmentUtf = new DOMDocumentWrapper(
// file_get_contents('document-types/document-fragment-utf8.xhtml'),
// 'application/xhtml+xml'
//);
//print var_dump($xhtmlFragmentUtf->document->saveXML());
//$xhtmlFragmentUtf->markup();
//$xhtmlFragmentUtf->markup(
// $xhtmlFragmentUtf->document->getElementsByTagName('p')
//);
/* Test template */
//$result = pq('p:eq(1)');
//if ( $result->hasClass('newTitle') )
// print "Test '{$testName}' PASSED :)";
//else
// print "Test '{$testName}' <strong>FAILED</strong> !!! ";
//$result->dump();
//print "\n";

View file

@ -0,0 +1,11 @@
<?php
// TODO move them into directory
include 'test_1.php';
include 'test_2.php';
include 'test_3.php';
include 'test_4.php';
include 'test_5.php';
include 'test_wrap.php';
include 'test_replace.php';
include 'test_multidoc.php';
?>

View file

@ -0,0 +1,54 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>
plainTemplate test
</title>
<script src="../jQueryServer/demo/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="<?php print $js_src; ?>" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class='articles'>
div.articles text node
<
<ul>
<li>
<p>This is paragraph of first LI</p>
<p class='title'>
this is example title
</p>
<p class='body'>
this is example body
</p>
</li>
<li id='testID'>
<p rel='test'>This is paragraph of second LI</p>
<p class='title'>
this is example title 2
</p>
<p class='body'>
this is example body 2
</p>
</li>
<li>
<p rel='test'>This is paragraph of third LI</p>
<p class='noTitle'>There isnt any title</p>
<p class='body'>
this is example body 3
</p>
</li>
</ul>
<p class='after'>paragraph after UL</p>
</div>
<ul>
<li id='i_have_nested_list'>
<ul>
<li class='nested'></li>
</ul>
</li>
<li class='second'>
</li>
</ul>
</body>
</html>

View file

@ -0,0 +1,59 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'Filter with pseudoclass';
$testResult = array(
'p.body',
);
$result = phpQuery::newDocumentFile('test.html');
$result = $result->find('p')
->filter('.body:gt(1)');
if ( $result->whois() == $testResult )
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print_r($result->whois());
print "\n";
$testName = 'Filter with multiplie selectors';
$testResult = array(
'p.body',
);
$testDOM = phpQuery::newDocumentFile('test.html');
$single = $testDOM->find('p')->filter('.body')
->add(
$testDOM->find('p')->filter('.title')
)
;
$double = $testDOM->find('p')
->filter('.body, .title');
if ($single->length == count($double))
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print "\n";
print_r($single->whois());
print "\n";
print_r($double->whois());
print "\n";
$testName = 'Attributes in HTML element';
$validResult = 'testValue';
$result = phpQuery::newDocumentFile('test.html')->find('html')
->empty()
->attr('test', $validResult);
$result = phpQuery::newDocument($result->htmlOuter())->find('html')
->attr('test');
//similar_text($result->htmlOuter(), $validResult, $similarity);
if ( $result == $validResult )
print "Test '{$testName}' PASSED :)";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print "<pre>";
print $result;
print "</pre>\n";
}

View file

@ -0,0 +1,109 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
// SLICE1
$testResult = array(
'li#testID',
);
$result = phpQuery::newDocumentFile('test.html')
->find('li')
->slice(1, 2);
if ( $result->whois() == $testResult )
print "Test 'Slice1' PASSED :)";
else {
print "Test 'Slice1' <strong>FAILED</strong> !!! ";
print "<pre>";
print_r($result->whois());
print "</pre>\n";
}
print "\n";
// SLICE2
$testResult = array(
'li#testID',
'li',
'li#i_have_nested_list',
'li.nested',
);
$result = phpQuery::newDocumentFile('test.html')
->find('li')
->slice(1, -1);
if ( $result->whois() == $testResult )
print "Test 'Slice2' PASSED :)";
else {
print "Test 'Slice2' <strong>FAILED</strong> !!! ";
print "<pre>";
print_r($result->whois());
print "</pre>\n";
}
print "\n";
// Multi-insert
$result = phpQuery::newDocument('<li><span class="field1"></span><span class="field1"></span></li>')
->find('.field1')
->php('longlongtest');
$validResult = '<li><span class="field1"><php>longlongtest</php></span><span class="field1"><php>longlongtest</php></span></li>';
similar_text($result->htmlOuter(), $validResult, $similarity);
if ( $similarity > 80 )
print "Test 'Multi-insert' PASSED :)";
else {
print "Test 'Multi-insert' <strong>FAILED</strong> !!! ";
print "<pre>";
var_dump($result->htmlOuter());
print "</pre>\n";
}
print "\n";
// INDEX
$testResult = 1;
$result = phpQuery::newDocumentFile('test.html')
->find('p')
->index(pq('p.title:first'));
if ( $result == $testResult )
print "Test 'Index' PASSED :)";
else {
print "Test 'Index' <strong>FAILED</strong> !!! ";
}
print "\n";
// CLONE
$testName = 'Clone';
$testResult = 3;
$document;
$p = phpQuery::newDocumentFile('test.html')
->toReference($document)
->find('p:first');
foreach(array(0,1,2) as $i) {
$p->clone()
->addClass("clone-test")
->addClass("class-$i")
->insertBefore($p);
}
if (pq('.clone-test')->size() == $testResult)
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
}
print "\n";
// SIBLINGS
$testName = 'Next';
$testResult = 3;
$document;
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->next()
->next()
->prev()
->is('#testID');
if ($result)
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
}
print "\n";
?>
<?php die();

View file

@ -0,0 +1,47 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
// CALLBACKS
class callbackClass {
static function staticMethodCallback($node) {
pq($node)->addClass('newClass');
}
function methodCallback($node) {
pq($node)->addClass('newClass');
}
}
function functionCallback($node) {
pq($node)->addClass('newClass');
}
$testResult = array(
'li.newClass',
'li#testID.newClass',
'li.newClass',
'li#i_have_nested_list.newClass',
'li.nested.newClass',
'li.second.newClass',
);
$tests = array(
'functionCallback',
array('callbackClass', 'staticMethodCallback'),
array(new callbackClass, 'methodCallback')
);
foreach($tests as $test) {
$result = phpQuery::newDocumentFile('test.html')
->find('li')
->each($test);
$testName = is_array($test)
? $test[1]
: $test;
if ( $result->whois() == $testResult )
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
print "<pre>";
print_r($result->whois());
print "</pre>\n";
}
print "\n";
}
?>

View file

@ -0,0 +1,86 @@
<?php
//error_reporting(E_ALL);
set_include_path(
get_include_path().PATH_SEPARATOR
.'zend-framework/'
);
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
phpQuery::$ajaxAllowedHosts[] = 'wikipedia.org';
phpQuery::$ajaxAllowedHosts[] = 'google.com';
phpQuery::$ajaxAllowedHosts[] = 'code.google.com';
phpQuery::$ajaxAllowedHosts[] = 'www.google.com';
//$pq = phpQuery::ajax(array(
// 'url' => 'http://wikipedia.org/',
// 'success' => 'v87shs79d8fhs9d'
//));
//function v87shs79d8fhs9d($html) {
// $title = phpQuery::newDocument($html)->find('title');
// $testName = 'Simple AJAX';
// if ( strpos(strtolower($title->html()), 'wikipedia') !== false )
// print "Test '$testName' PASSED :)";
// else {
// print "Test '$testName' <strong>FAILED</strong> !!! ";
// print "<pre>";
// print_r($title->whois());
// print "</pre>\n";
// }
// print "\n";
//}
$testName = 'Load';
$test = phpQuery::newDocumentFile('test.html')
->find('div:first')
->load('http://wikipedia.org/ div[lang]');
if (pq('div[lang]')->size())
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
print "<pre>";
print "</pre>\n";
}
print "\n";
// http://code.google.com/p/phpquery/issues/detail?id=130
$pq = phpQuery::ajax(array(
'url' => 'http://'.$_SERVER['SERVER_NAME'].preg_replace('@/[^/]+$@', '/test_ajax_data_1', $_SERVER['REQUEST_URI']),
'success' => 'a789fhasdui3124',
'error' => 'jhdbg786213u8dsfg7y'
));
function a789fhasdui3124($html) {
$testName = 'AJAX request text node';
if ( $html == 'hello world' )
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
}
print "\n";
}
function jhdbg786213u8dsfg7y() {
$testName = 'AJAX request text node';
print "Test '$testName' <strong>FAILED</strong> !!! ";
}
//$testName = 'gdata plugin';
//phpQuery::extend('gdata');
//$xhr = phpQuery::$plugins->gdata('tobiasz.cudnik@gmail.com', 'XXX');
//$url = 'http://code.google.com/p/phpquery/w/edit/Callbacks';
//phpQuery::ajax(array('url' => $url, 'success' => 'ksjsdgh892jh23'), $xhr);
//function ksjsdgh892jh23($html) {
// print $html;
// print pq($html)->find('script')->remove()->end();
// if (pq('div[lang]')->size())
// print "Test '$testName' PASSED :)";
// else {
// print "Test '$testName' <strong>FAILED</strong> !!! ";
// print "<pre>";
// print "</pre>\n";
// }
// print "\n";
//}

View file

@ -0,0 +1 @@
hello world

View file

@ -0,0 +1,36 @@
<?php
//error_reporting(E_ALL);
set_include_path(
get_include_path()
.':/home/bob/Sources/PHP/zend-framework/'
);
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testHtml = phpQuery::newDocumentFile('test.html');
$testHtml['li:first']->append('<span class="just-added">test</span>');
$testName = 'Array Access get';
if (trim($testHtml['.just-added']->html()) == 'test')
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
print "<pre>";
print_r($testHtml['.just-added']->whois());
print "</pre>\n";
}
print "\n";
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testHtml = phpQuery::newDocumentFile('test.html');
$testHtml['li:first'] = 'new inner html';
$testName = 'Array Access set';
if (trim($testHtml['li:first']->html()) == 'new inner html')
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
print "<pre>";
print_r($testHtml['.just-added']->whois());
print "</pre>\n";
}
print "\n";

View file

@ -0,0 +1,26 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'Attribute change';
$expected = 'new attr value';
$result = phpQuery::newDocumentFile('test.html')
->find('p[rel]:first')
->attr('rel', $expected);
if ($result->attr('rel') == $expected)
print "Test '{$testName}' passed :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!!";
print "\n";
$testName = 'Attribute change in iteration';
$expected = 'new attr value';
$doc = phpQuery::newDocumentFile('test.html');
foreach($doc['p[rel]:first'] as $p)
pq($p)->attr('rel', $expected);
if ($doc['p[rel]:first']->attr('rel') == $expected)
print "Test '{$testName}' passed :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!!";
print "\n";

View file

@ -0,0 +1,27 @@
<?php
//if (PHP_VERSION < 5.3)
// throw new Exception("This test case is only for PHP 5.3 and above.");
require('/home/bob/Sources/php/simpletest/simpletest/trunk/autorun.php');
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
class CallbackTest extends UnitTestCase {
public function callback2() {
return 'callback2';
}
public function callback1($self) {
return $self;
}
public function testExtend() {
$newMethods = array(
'newMethod1' => array($this, 'callback1'),
'newMethod2' => array($this, 'callback2'),
);
phpQuery::extend('phpQueryObject', $newMethods);
$doc = phpQuery::newDocumentXML("<div/>");
$this->assertTrue($doc->newMethod1() == $doc,
'$doc->newMethod1 == $doc');
$this->assertTrue($doc->newMethod2() == "callback2",
'$doc->newMethod1 == "callback2"');
}
}

View file

@ -0,0 +1,94 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<?php
require_once('../phpQuery/phpQuery.php');
// phpQuery::$debug = true;
$testName = 'Text node append';
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->find('p:first')
->html('żźć');
if (trim($result->html()) == 'żźć')
print "Test '{$testName}' passed :)<br />\n";
else
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print "\n";
$testName = 'Text node HTML entite append';
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->find('p:first')
->_empty()
->append('&eacute;');
if (trim($result->html()) == 'é')
print "Test '{$testName}' passed :)<br />\n";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print $result->html();
}
print "\n";
$testName = 'DOMElement node HTML entite append';
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->find('p:first')
->empty()
->append('<span>&eacute;</span>');
if (trim($result->html()) == '<span>é</span>')
print "Test '{$testName}' passed :)<br />\n";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print $result->html();
}
print "\n";
$testName = 'Append and move';
$result = phpQuery::newDocumentFile('test.html');
$li = $result->find('li:first');
$result->find('div')->_empty();
$li->html('test1-&eacute;-test1')
->append('test2-é-test2')
->appendTo(
$result->find('div:first')
);
$result = $result->find('div:first li:first');
$expected = 'test1-é-test1test2-é-test2';
if (trim(str_replace("\n", '', $result->html())) == $expected)
print "Test '{$testName}' passed :)<br />\n";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print "'".trim($result->html())."'";
}
print "\n";
$testName = 'Attr charset';
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->attr('test', 'foo &eacute; żźć bar');
if (trim($result->attr('test')) == 'foo &eacute; żźć bar')
print "Test '{$testName}' passed :)<br />\n";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print $result->attr('test');
}
print "\n";
//$testName = 'Loading document without meta charset';
//$result = phpQuery::newDocumentFile('test.html')
// ->_empty();
////var_dump((string)$result->htmlOuter());
//$result = phpQuery::newDocument($result->htmlOuter());
//$validResult = <<<EOF
//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
//<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /></head></html>
//EOF;
//$similarity = 0;
//similar_text($result->htmlOuter(), $validResult, $similarity);
//if ( $similarity > 90 )
// print "Test '{$testName}' passed :)<br />\n";
//else
// print "Test '{$testName}' <strong>FAILED</strong> !!! ";
//print "<pre>";
//print $result;
//print "</pre>\n";

View file

@ -0,0 +1,20 @@
<?php
//error_reporting(E_ALL);
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'HTML document load';
$doc = phpQuery::newDocumentFile('test.html');
print $doc->find('li:first')->html('foo <p>bar</p> foo <b><i>foo</i</b>')->html();
die();
$testResult = 10;
if ($doc->script('example', 'p')->length == $testResult)
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
print "<pre>";
var_dump($doc->whois());
print "</pre>\n";
}
print "\n";

View file

@ -0,0 +1,49 @@
<?php
require_once('../phpQuery/phpQuery.php');
// phpQuery::$debug = true;
$form = <<<EOF
<form>
<input name='input-example'>
<input name='array[array-example]'>
<textarea name='textarea-example'></textarea>
<select name='select-example'>
<option value='first'></option>
</select>
<input type='radio' name='radio-example' value='foo'>
<input type='checkbox' name='checkbox-example' value='foo'>
</form>
EOF;
$doc = phpQuery::newDocumentHTML($form);
$inputs = $doc['form > *'];
// creates array from input names
// $results = $inputs->get(null,
// create_function('$node', 'return $node->getAttribute("name");')
// );
$results = array();
foreach($inputs as $node) {
$node = pq($node);
$name = $node->attr('name');
$results[$name] = false;
$node->change(
new CallbackReference($results[$name])
);
}
$inputs
->not('select,:checkbox,:radio')
->val('new value')
->end()
->filter('select')
->val('first')
->end()
->filter(':checkbox')
->val(array('foo'))
->end()
->filter(':radio')
->val(array('foo'))
->end()
;
foreach($results as $name => $result) {
print $result
? "Test for '$name' PASSED :)<br />\n"
: "Test for '$name' <strong>FAILED</strong> !!!<br />\n";
}

View file

@ -0,0 +1,20 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = 2;
$testName = 'HTML insertion';
$doc = phpQuery::newDocumentFile('document-types/document-utf8.xhtml');
//$doc = phpQuery::newDocumentFile('document-types/document-utf8.html');
//$doc = phpQuery::newDocumentFile('document-types/document-utf8.xml');
//print $doc->find('step');
print $doc->find('p');
$markup = "test<br />test<p>test p</p>";
$doc['body > p:last']->append($markup);
if ($doc['body > p:last p']->length == 1)
print "Test '{$testName}' PASSED :)";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print $doc->htmlOuter('htmlspecialchars');
}
print "\n";

View file

@ -0,0 +1,143 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'Simple data insertion';
$testResult = <<<EOF
<div class="articles">
div.articles text node
<ul>
<li>
<p>This is paragraph of first LI</p>
<p class="title">News 1 title</p>
<p class="body">News 1 body</p>
</li>
<li>
<p>This is paragraph of first LI</p>
<p class="title">News 2 title</p>
<p class="body">News 2 body</p>
</li>
<li>
<p>This is paragraph of first LI</p>
<p class="title">News 3</p>
<p class="body">News 3 body</p>
</li>
</ul>
<p>paragraph after UL</p>
</div>
EOF;
$rows = array(
array(
'title' => 'News 1 title',
'body' => 'News 1 body',
),
array(
'title' => 'News 2 title',
'body' => 'News 2 body',
),
array(
'title' => 'News 3',
'body' => 'News 3 body',
),
);
phpQuery::newDocumentFile('test.html');
$articles = pq('.articles ul');
$rowSrc = $articles->find('li')
->remove()
->eq(0);
foreach( $rows as $r ) {
$row = $rowSrc->_clone();
foreach( $r as $field => $value ) {
$row->find(".{$field}")
->html($value);
// die($row->htmlOuter());
}
$row->appendTo($articles);
}
$result = pq('.articles')->htmlOuter();
//print htmlspecialchars("<pre>{$result}</pre>").'<br />';
$similarity = 0.0;
similar_text($testResult, $result, $similarity);
if ($similarity > 90)
print "Test '{$testName}' passed :)";
else
print "Test '{$testName}' <strong>FAILED</strong> ($similarity) !!!";
print "\n";
$testName = 'Parent && children';
$result = phpQuery::newDocumentFile('test.html');
$parent = $result->find('ul:first');
$children = $parent->find('li:first');
$e = null;
try {
$children->before('<li>test</li>');
} catch(Exception $e) {
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
}
if (! $e) {
print "Test '{$testName}' PASSED :)";
}
print "\n";
$testName = 'HTML insertion';
$doc = phpQuery::newDocument('<div><p/></div>');
$string = "La Thermo-sonde de cuisson vous permet de cuire à la perfection au four comme au bain-marie. Température: entre <b>0°C et 210°C</b>.";
$doc->find('p')->html($string);
if (pq('p')->length == 1)
print "Test '{$testName}' PASSED :)";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print $doc->htmlOuter('htmlentities');
}
print "\n";
$testName = 'HTML insertion 2';
$doc = phpQuery::newDocument('<div><p/></div>');
$string = "<div>La Thermo-sonde de cuisson vous permet de cuire à la perfection au four comme au bain-marie. Température: entre <b>0°C et 210°C</b>.</div>";
$doc->find('p')->html($string);
if (pq('div')->length == 2) {
print "Test '{$testName}' PASSED :)";
} else {
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print $doc->htmlOuter('htmlentities');
}
print "\n";
$testName = 'HTML insertion 3';
$doc = phpQuery::newDocument('<div><p/></div>');
$string = 'Hors paragraphe.
<img align="right" src="http://www.stlouisstpierre.com/institution/images/plan.jpg">
<p>Éditorial de l\'institution Saint-Pierre.</p>
Hors paragraphe.';
$doc->find('p')->html($string);
if (pq('img')->length == 1) {
print "Test '{$testName}' PASSED :)";
print $doc->htmlOuter();
} else {
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print $doc->htmlOuter('htmlentities');
}
print "\n";
$testName = 'Text insertion';
$doc = phpQuery::newDocument('<div><p/></div>');
$string = "La Thermo-sonde de cuisson vous permet de cuire à la perfection au four comme au bain-marie";
$doc->find('p')->html($string);
if (trim(pq('p:first')->html()) == $string)
print "Test '{$testName}' PASSED :)";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print $doc->htmlOuter('htmlentities');
}
print "\n";
?>

View file

@ -0,0 +1,301 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<?php
require_once('../phpQuery/phpQuery.php');
//phpQuery::$debug = 2;
phpQuery::plugin('Scripts');
//$doc = phpQuery::newDocumentXML('<article><someMarkupStuff/><p>p</p></article>');
//print $doc['article']->children(':empty')->get(0)->tagName;
//$doc = phpQuery::newDocumentFile('test.html');
//setlocale(LC_ALL, 'pl_PL.UTF-8');
//$string = strftime('%B %Y', time());
//$doc['p:first']->append($string)->dump();
/*
*
$doc1 = phpQuery::newDocumentFileXHTML('doc1.html');
$doc2 = phpQuery::newDocumentFileXHTML('doc2.html');
$doc3 = phpQuery::newDocumentFileXHTML('doc3.html');
$doc4 = phpQuery::newDocumentFileXHTML('doc4.html');
$doc2['body']
->append($doc3['body >*'])
->append($doc4['body >*']);
$doc1['body']
->append($doc2['body >*']);
print $doc1->plugin('Scripts')->script('safe_print');
*/
//$doc = phpQuery::newDocument('<p> p1 <b> b1 </b> <b> b2 </b> </p><p> p2 </p>');
//print $doc['p']->contents()->not('[nodeType=1]');
//print phpQuery::newDocumentFileXML('tmp.xml');
//$doc = phpQuery::newDocumentXML('text<node>node</node>test');
//pq('<p/>', $doc)->insertBefore(pq('node'))->append(pq('node'));
//$doc->contents()->wrap('<p/>');
//$doc['node']->wrapAll('<p/>');
// ->contents()
// ->wrap('<p></p>');
//print $doc;
// http://code.google.com/p/phpquery/issues/detail?id=66
//$doc = phpQuery::newDocumentXML('<p>123<span/>123</p>');
//$doc->dump();
//$doc->children()->wrapAll('<div/>')->dump();
// http://code.google.com/p/phpquery/issues/detail?id=69
//$doc = phpQuery::newDocumentXML('<p class="test">123<span/>123</p>');
//$doc['[class^="test"]']->dump();
// http://code.google.com/p/phpquery/issues/detail?id=71
// $doc = phpQuery::newDocument('<input value=""/>');
// print $doc['input']->val('new')->val();
// http://code.google.com/p/phpquery/issues/detail?id=71
// $doc = phpQuery::newDocument('<select><option value="10">10</option><option value="10">20</option></select>');
// $doc['select']->val('20')->dump();
// http://code.google.com/p/phpquery/issues/detail?id=73
// $doc = phpQuery::newDocument('<input value=""/>');
// var_dump($doc['input']->val(0)->val());
// $a = null;
// new CallbackReference($a);
// phpQuery::callbackRun(new CallbackReference($a), array('new $a value'));
// var_dump($a);
// check next() inside (also, but separatly)
// $inputs->dump();
// foreach($inputs as $node) {
// }
// $inputs->dump();
// http://code.google.com/p/phpquery/issues/detail?id=74
// http://code.google.com/p/phpquery/issues/detail?id=31
//$doc = phpQuery::newDocument('<div class="class1 class2"/><div class="class1"/><div class="class2"/>');
//$doc['div']->filter('.class1, .class2')->dump()->dumpWhois();
// http://code.google.com/p/phpquery/issues/detail?id=76
// mb_internal_encoding("UTF-8");
// mb_regex_encoding("UTF-8");
// $xml = phpQuery::newDocumentXML('<документа/>');
//
// $xml['документа']->append('<список></список>');
// $xml['документа список'] = '<эл>1</эл><эл>2</эл><эл>3</эл>';
// print "<xmp>$xml</xmp>";
// zeromski 0.9.5 vs 0.9.1
// phpQuery::newDocumentXML('<xml><b></xml>')->dump();
// http://code.google.com/p/phpquery/issues/detail?id=77
// phpQuery::newDocumentFile('http://google.com/')
// ->find('body > *')->dumpWhois();
/*$XHTML = <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="fr" />
</head>
<body>
<div id="contenu_volets">
<div id="contenu_voletGauche">
<div id="contenu_navigation" class="bloc_arrondi blanc_10_10 administrable">
<div class="bloc_arrondi_haut">
<div class="bloc_arrondi_haut_gauche"></div>
<div class="bloc_arrondi_haut_droit"></div>
</div>
<div class="bloc_arrondi_centre">
<div class="bloc_arrondi_centre1">
<div class="bloc_arrondi_centre2 bloc_contenu administrable_contenu"></div>
</div>
</div>
<div class="bloc_arrondi_bas">
<div class="bloc_arrondi_bas_gauche"></div>
<div class="bloc_arrondi_bas_droit"></div>
</div>
</div>
</div>
<div id="contenu_voletDroit">
<div id="contenu_article" class="bloc_arrondi grisDegrade_10_10_341 administrable
redimensionnable">
<div class="bloc_arrondi_haut">
<div class="bloc_arrondi_haut_gauche"></div>
<div class="bloc_arrondi_haut_droit"></div>
</div>
<div class="bloc_arrondi_centre">
<div class="bloc_arrondi_centre1">
<div class="bloc_arrondi_centre2 bloc_contenu administrable_contenu
WAI_element-40-WAI_principal-30 WAI_contenu">
<p class="contenu_filAriane justifier_non">
Vous êtes ici : <span class="filAriane_contenu"></span>
</p>
<h1 id="IDcmsRef-page-titre">Editorial</h1>
<div id="IDcmsTag_article"></div>
<div class="nettoyeur"></div>
</div>
</div>
</div>
<div class="bloc_arrondi_bas">
<div class="bloc_arrondi_bas_gauche"></div>
<div class="bloc_arrondi_bas_droit"></div>
</div>
</div>
</div>
<div id="contenu_voletPied"></div>
</div>
</body>
</html>
EOF;
phpQuery::newDocumentXHTML($XHTML)
->find('body:first > *')->dumpWhois();*/
// http://code.google.com/p/phpquery/issues/detail?id=83
//$doc = phpQuery::newDocument('<select
//name="toto"><option></option><option value="1">1</option></select><div><input
//type="hidden" name="toto"/></div>');
//print $doc['[name=toto]']->val('1');
//$doc = phpQuery::newDocumentFile('http://www.google.pl/search?hl=en&q=test&btnG=Google+Search');
//print $doc;
// http://code.google.com/p/phpquery/issues/detail?id=88
//$doc = phpQuery::newDocumentXML('<foo><bar/></foo>');
//$doc['foo']->find('bar')->andSelf()->addClass('test');
//$doc->dump();
// http://code.google.com/p/phpquery/issues/detail?id=90
//print phpQuery::newDocument('<html><body></body></html>')
// ->find('body')
// ->load('http://localhost/phpinfo.php');
// http://code.google.com/p/phpquery/issues/detail?id=91
// phpQuery::newDocumentXML('<foo bar="abc"/><foo bar="bca"/>');
// print pq('foo')->filter('[bar$=c]');
// FIXME http://code.google.com/p/phpquery/issues/detail?id=93
//$doc = '<head><title>SomeTitle</title>
//</head>
//<body bgcolor="#ffffff" text="#000000" topmargin="1" leftmargin="0">blah
//</body>';
//$pq = phpQuery::newDocument($doc);
//echo $pq;
# http://code.google.com/p/phpquery/issues/detail?id=94#makechanges
//$doc = phpQuery::newDocument();
//$test = pq(
//'
//<li>
// <label>Fichier : </label>
// <input type="file" name="pjModification_fichier[0]"/>
// <br/>
// <label>Titre : </label>
// <input type="text" name="pjModification_titre[0]" class="pieceJointe_titre"/>
//</li>
//'
//);
// http://code.google.com/p/phpquery/issues/detail?id=96
//$doc = phpQuery::newDocument('<select name="section"><option
//value="-1">Niveau</option><option value="1">6°</option><option
//value="2">5°</option><option
//value="3">4°</option><option value="4">3°</option></select>');
//$doc = phpQuery::newDocument('<select name="section"><option
//value="-1">Niveau</option><option value="1">6°</option><option
//value="2">5°</option><option
//value="3">4°</option><option value="4">3&deg;</option></select>');
//print $doc['select']->val(3)->end()->script('print_source');
//(16:27:56) jomofcw: $option_element =
//(16:27:56) jomofcw: pq('<option/>')
//(16:27:56) jomofcw: ->attr('value',$section['id'])
//(16:27:56) jomofcw: ->html($section['libelle'])
//(16:27:56) jomofcw: ;
//(16:29:27) jomofcw: where $section['libelle'] is from a database UTF-8
//16:30
//(16:30:20) jomofcw: the value of $section['libelle'] is exactly "3&deg;" in database...
# http://code.google.com/p/phpquery/issues/detail?id=98
//$doc = phpQuery::newDocument('<select id="test"><option value="0">a</option><option
//value="10">b</option><option value="20">c</option></select>');
//print $doc['select']->val(0)->end()->script('print_source');
// http://groups.google.com/group/phpquery/browse_thread/thread/1c78f7e41fc5808c?hl=en
//$doc = phpQuery::newDocumentXML("
//<s:Schema id='RowsetSchema'>
// <s:ElementType name='row' content='eltOnly'>
// <s:AttributeType name='ComparteElementoComun_ID' rs:number='1'
//rs:maydefer='true' rs:writeunknown='true'>
// <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10'
//rs:fixedlength='true'/>
// </s:AttributeType>
// <s:AttributeType name='ComparteElementoComun' rs:number='2'
//rs:nullable='true' rs:maydefer='true' rs:writeunknown='true'>
// <s:datatype dt:type='string' dt:maxLength='100'/>
// </s:AttributeType>
// <s:extends type='rs:rowbase'/>
// </s:ElementType>
//</s:Schema>");
//foreach($doc['Schema ElementType AttributeType'] as $campo){
// if( count(pq($campo)->find('datatype'))==1 ){
// var_dump(pq($campo)->find('datatype')->attr('dt:type')); // Should print "string" but prints ""
// }
//}
// http://code.google.com/p/phpquery/issues/detail?id=97
//function jsonSuccess($data) {
// var_dump($data);
//}
//$url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json';
//phpQuery::ajaxAllowHost('api.flickr.com');
//phpQuery::getJSON($url, array('jsoncallback' => '?'), 'jsonSuccess');
//var_dump(json_decode($json));
//require_once('../phpQuery/Zend/Json/Decoder.php');
//var_dump(Zend_Json_Decoder::decode($json));
#var_dump(''.phpQuery::newDocumentFile("http://www.chefkoch.de/magazin/artikel/943,0/AEG-Electrolux/Frischer-Saft-aus-dem-Dampfgarer.html"));
// var_dump(phpQuery::newDocument(
// str_replace('<!DOCTYPE html public "-//W3C//DTD HTML 4.0 Transitional//EN">
// ', '',
// file_get_contents("http://www.chefkoch.de/magazin/artikel/943,0/AEG-Electrolux/Frischer-Saft-aus-dem-Dampfgarer.html"
// ))));
// http://code.google.com/p/phpquery/issues/detail?id=102
// $doc = phpQuery::newDocumentFileHTML('http://www.google.de');
// //$doc = phpQuery::newDocument('');
// $images = $doc['img']->dump();
//
// $foo = 'aaa';
// var_dump(mb_ereg_match('^[\w|\||-]+$', $foo) || $foo == '*');
// var_dump(preg_match('@^[\w|\||-]+$@', $foo) || $foo == '*');
// http://code.google.com/p/phpquery/issues/detail?id=67
//$doc = phpQuery::newDocumentXML("<node1/><node2/>");
//$doc['node1']->data('foo', 'bar');
//var_dump($doc['node1']->data('foo'));
//$doc['node1']->removeData('foo');
//var_dump($doc['node1']->data('foo'));
//$doc['node1']->data('foo.bar', 'bar');
//var_dump($doc['node1']->data('foo.bar'));
//var_dump(phpQuery::$documents[$doc->getDocumentID()]->data);
// xhtml fragments
//$doc = phpQuery::newDocumentXHTML("<p><br/></p>");
//print $doc;
$doc = phpQuery::newDocument('<div id="content"></div><div id="content"></div>');
//$content_string = str_repeat('a', 99988);
$content_string = str_repeat(str_repeat('a', 350)."\n", 350);
//var_dump(strlen($content_string));
?><pre class='1'><?php
//print $content_string;
?></pre><?php
pq('#content')->php('echo $content_string;');
//pq('#content')->php('echo '.var_export($content_string, true));
$doc->dumpTree();
?><pre class='2'><?php
var_dump($doc->php());
?></pre><?php
eval('?>'.$doc->php());

View file

@ -0,0 +1,37 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'Multi document append phpQuery object';
$testResult = array(
'p.body',
);
$doc1 = phpQuery::newDocumentFile('test.html');
$doc2 = phpQuery::newDocumentFile('test.html');
foreach ($doc1->find('p') as $node)
$doc2->find('body')->append(pq($node));
$testResult = $doc2->find('p');
if ( $testResult->size() == 2*$doc1->find('p')->size() )
print "Test '{$testName}' PASSED :)";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />";
$testResult->whois();
}
$testName = 'Multi document append DOMNode';
$testResult = array(
'p.body',
);
$doc1 = phpQuery::newDocumentFile('test.html');
$doc2 = phpQuery::newDocumentFile('test.html');
foreach ($doc1->find('p') as $node)
$doc2->find('body')->append($node);
$testResult = $doc2->find('p');
if ( $testResult->size() == 2*$doc1->find('p')->size() )
print "Test '{$testName}' PASSED :)";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />";
$testResult->whois();
}
?>

View file

@ -0,0 +1,36 @@
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'PHP Code output';
$expected = <<<EOF
<?php print \$r ?><a href="<?php print \$array['key']; if ("abc'd'") {}; ?>"></a>
EOF;
$result = phpQuery::newDocumentPHP(null, 'text/html;charset=utf-8')
->appendPHP('print $r')
->append('<a/>')
->find('a')
->attrPHP('href', 'print $array[\'key\']; if ("abc\'d\'") {};')
->end();
if (trim($result->php()) == $expected)
print "Test '{$testName}' passed :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!!";
print "\n";
$testName = 'PHP file open';
$result = phpQuery::newDocumentFilePHP('document-types/document-utf8.php');
var_dump($result->php());
/*
->appendPHP('print $r')
->append('<a/>')
->find('a')
->attrPHP('href', 'print $array[\'key\']; if ("abc\'d\'") {};')
->end();
if (trim($result->php()) == $expected)
print "Test '{$testName}' passed :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!!";
print "\n";
*/

View file

@ -0,0 +1,32 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'ReplaceWith';
phpQuery::newDocumentFile('test.html')
->find('p:eq(1)')
->replaceWith("<p class='newTitle'>
this is example title
</p>");
$result = pq('p:eq(1)');
if ( $result->hasClass('newTitle') )
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
$result->dump();
print "\n";
$testName = 'ReplaceAll';
$testResult = 3;
phpQuery::newDocumentFile('test.html');
pq('<div class="replacer">')
->replaceAll('li:first p');
$result = pq('.replacer');
if ( $result->size() == $testResult )
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
$result->dump();
print "\n";

View file

@ -0,0 +1,38 @@
<?php
//error_reporting(E_ALL);
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
phpQuery::plugin('Scripts');
$testName = 'Scripts/example';
$doc = phpQuery::newDocumentFile('test.html');
$testResult = 10;
if ($doc->script('example', 'p')->length == $testResult)
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
print "<pre>";
var_dump($doc->whois());
print "</pre>\n";
}
print "\n";
$testName = 'Scripts/gmail_login';
$testResult = 1;
$url = 'http://code.google.com/p/phpquery/w/edit/MultiDocumentSupport';
//phpQuery::ajaxAllowURL($url);
$editor = phpQuery::newDocument('<div/>')
->script('google_login')
->location($url);
if ($editor->find('textarea#content')->length == $testResult)
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
print "<pre>";
var_dump($doc->whois());
print "</pre>\n";
}
print "\n";
?>

View file

@ -0,0 +1,302 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'Selectors';
$tests = array(
array(
'div:first',
array(
'div.articles',
)
),
array(
"p:contains('title')",
array(
'p.title',
'p.title',
'p.noTitle',
)
),
array(
"p:contains('title 2')",
array(
'p.title',
)
),
array(
'li:eq(1)',
array(
'li#testID',
)
),
array(
'li:eq(1) p:eq(1)',
array(
'p.title',
)
),
array(
'*[rel="test"]',
array(
'p',
'p'
)
),
array(
'#testID p:first',
array(
'p'
)
),
array(
"p:not('.title'):not('.body')",
array(
'p',
'p',
'p',
'p.noTitle',
'p.after',
)
),
array(
"[content*=html]",
array(
'meta'
)
),
array(
"li#testID, div.articles",
array(
'li#testID',
'div.articles'
)
),
array(
"script[src]:not([src^=<?php])",
array(
'script'
)
),
// array(
// 'li:not([ul/li])',
// array(
// 'li',
// 'li#testID',
// 'li',
// 'li.nested',
// 'li.second',
// )
// ),
array(
'li:has(ul)',
array(
'li#i_have_nested_list',
)
),
array(
'p[rel] + p',
array(
'p.title',
'p.noTitle',
)
),
array(
'ul:first > li:first ~ *',
array(
'li#testID',
'li',
)
),
// CSS3 pseudoclasses
array(
'li:only-child',
array(
'li.nested',
)
),
array(
'p[rel=test]:parent',
array(
'p',
'p',
)
),
array(
'li:first-child',
array(
'li',
'li#i_have_nested_list',
'li.nested',
)
),
array(
':last-child',
array(
'html',
'script',
'body',
'p.body',
'p.body',
'li',
'p.body',
'p.after',
'ul',
'ul',
'li.nested',
'li.second',
)
),
array(
':nth-child(1n+1)',
array(
'html',
'head',
'meta',
'div.articles',
'ul',
'li',
'p',
'p',
'p',
'li#i_have_nested_list',
'ul',
'li.nested',
)
),
array(
':nth-child(3n+6)',
array(
'script',
'p.body',
'p.body',
'li',
'p.body',
)
),
array(
':nth-child(2n)',
array(
'title',
'script',
'body',
'p.title',
'li#testID',
'p.title',
'p.noTitle',
'p.after',
'ul',
'li.second',
)
),
array(
':nth-child(1)',
array(
'html',
'head',
'meta',
'div.articles',
'ul',
'li',
'p',
'p',
'p',
'li#i_have_nested_list',
'ul',
'li.nested',
)
),
array(
':nth-child(odd)',
array(
'html',
'head',
'meta',
'script',
'div.articles',
'ul',
'li',
'p',
'p.body',
'p',
'p.body',
'li',
'p',
'p.body',
'li#i_have_nested_list',
'ul',
'li.nested',
)
),
array(
':nth-child(even)',
array(
'title',
'script',
'body',
'p.title',
'li#testID',
'p.title',
'p.noTitle',
'p.after',
'ul',
'li.second',
)
),
array(
':empty',
array(
'meta',
'script',
'script',
'li.nested',
)
),
// array(
// '',
// array(
// '',
// )
// ),
// array(
// '',
// array(
// '',
// )
// ),
// array(
// '',
// array(
// '',
// )
// ),
);
phpQuery::newDocumentFile('test.html');
foreach( $tests as $k => $test ) {
$tests[ $k ][2] = pq( $test[0] )->whois();
}
foreach( $tests as $test ) {
if ( $test[1] == $test[2] )
print "Test '{$test[0]}' PASSED :)";
else {
print "Test '{$test[0]}' <strong>FAILED</strong> !!!";
print_r($test[2]);
}
print "<br /><br />";
}
//
$testName = 'Complicated selector 1';
phpQuery::newDocumentFile('test.html');
pq('<select name="test[]"><option value=3>test</option></select>')
->appendTo('body');
$result = pq('select[name="test[]"]:has(option[value=3])');
if ( $result->size() == 1 )
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
$result->dump();
print "\n";
?>

View file

@ -0,0 +1,83 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
phpQuery::extend('WebBrowser');
phpQuery::$ajaxAllowedHosts[] = 'gmail.com';
phpQuery::$ajaxAllowedHosts[] = 'google.com';
phpQuery::$ajaxAllowedHosts[] = 'www.google.com';
phpQuery::$ajaxAllowedHosts[] = 'www.google.pl';
phpQuery::$ajaxAllowedHosts[] = 'mail.google.com';
// Google search results
if (0) {
phpQuery::$plugins->browserGet('http://google.com/', 'success1');
/**
*
* @param $pq phpQueryObject
* @return unknown_type
*/
function success1($pq) {
print 'success1 callback';
$pq
->WebBrowser('success2')
->find('input[name=q]')
->val('phpQuery')
->parents('form')
->submit()
;
}
/**
*
* @param $html phpQueryObject
* @return unknown_type
*/
function success2($pq) {
print 'success2 callback';
print $pq
->find('script')->remove()->end();
}
}
// Gmail login (not working...)
if (0) {
phpQuery::plugin("Scripts");
phpQuery::newDocument('<div/>')
->script('google_login')
->location('http://mail.google.com/')
->toReference($pq);
if ($pq) {
print $pq->script('print_websafe');
}
}
// Gmail login v2 (not working...)
if (0) {
$browser = null;
$browserCallback = new CallbackReference($browser);
phpQuery::browserGet('http://mail.google.com/', $browserCallback);
if ($browser) {
$browser
->WebBrowser($browserCallback)
->find('#Email')
->val('XXX@gmail.com')->end()
->find('#Passwd')
->val('XXX')
->parents('form')
->submit();
if ($browser) {
print $browser->script('print_websafe');
}
}
}
// if ( $result->whois() == $testResult )
// print "Test '$testName' PASSED :)";
// else {
// print "Test '$testName' <strong>FAILED</strong> !!! ";
// print "<pre>";
// print_r($result->whois());
// print "</pre>\n";
// }
// print "\n";
?>

View file

@ -0,0 +1,75 @@
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'Wrap';
$p = phpQuery::newDocumentFile('test.html')
->find('p')
->slice(1, 3);
$p->wrap('<div class="wrapper">');
$result = true;
foreach($p as $node) {
if (! pq($node)->parent()->is('.wrapper'))
$result = false;
}
if ($result)
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
$p->dump();
print "\n";
$testName = 'WrapAll';
$testResult = 1;
phpQuery::newDocumentFile('test.html')
->find('p')
->slice(1, 3)
->wrapAll('<div class="wrapper">');
$result = pq('.wrapper');
if ( $result->size() == $testResult )
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
$result->dump();
print "\n";
$testName = 'WrapInner';
$testResult = 3;
phpQuery::newDocumentFile('test.html')
->find('li:first')
->wrapInner('<div class="wrapper">');
$result = pq('.wrapper p');
if ( $result->size() == $testResult )
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print $result->dump();
print "\n";
// TODO !
$testName = 'WrapAllTest';
/*
$doc = phpQuery::newDocumentHTML('<div id="myDiv"></div>');
$doc['#myDiv']->append('hors paragraphe<p>Test</p>hors paragraphe')
->contents()
->not('[nodeType=1]')
->wrap('<p/>');
var_dump((string)$doc);
*/
//$testResult = 3;
//phpQuery::newDocumentFile('test.html')
// ->find('li:first')
// ->wrapInner('<div class="wrapper">');
//$result = pq('.wrapper p');
//if ( $result->size() == $testResult )
// print "Test '{$testName}' PASSED :)";
//else
// print "Test '{$testName}' <strong>FAILED</strong> !!! ";
//print $result->dump();
//print "\n";
?>

View file

@ -0,0 +1,25 @@
<?php
// here you can directly run xpath queries to debug your tests
$Query = "//*[local-name()='p']";
$DOM = new DOMDocument();
$DOM->loadHTMLFile('test.html');
$X = new DOMXPath($DOM);
print $Query;
whois($X->query($Query));
function whois($nodeList) {
$return = array();
foreach( $nodeList as $node ) {
$return[] = (
$node->tagName
.($node->getAttribute('id')
? '#'.$node->getAttribute('id'):'')
.($node->getAttribute('class')
? '.'.join('.', split(' ', $node->getAttribute('class'))):'')
);
}
print "<pre>";
print_r($return);
print "</pre>";
}
?>