Source for file Services_Trackback_Test.php
Documentation is available at Services_Trackback_Test.php
// Includepath for local CVS development
// set_include_path('/cvs/pear/Services_Trackback'.PATH_SEPARATOR.get_include_path());
// Services_Trackback classes
require_once 'Services/Trackback.php';
require_once 'Services/Trackback/SpamCheck.php';
require_once 'PHPUnit.php';
require_once dirname (__FILE__ ). '/trackback_data.php';
class Webservices_Trackback_TestCase extends PHPUnit_TestCase
// {{{ Webservices_Trackback_TestCase()
// constructor of the test suite
function Webservices_Trackback_TestCase ($name) {
$this->PHPUnit_TestCase ($name);
'allowRedirects' => false ,
'useragent' => 'Mozilla 10.0',
$fakeTrack->_options = $options;
$fakeTrack->_data = $trackbackData['nospam'];
function test_setOptions_success () {
'allowRedirects' => false ,
'useragent' => 'Mozilla 10.0',
$fakeTrack->_options = $options;
$realTrack->setOptions ($options);
$this->assertTrue ($realTrack == $fakeTrack);
function test_getOptions_success () {
'allowRedirects' => false ,
'useragent' => 'Mozilla 10.0',
$track->_options = $options;
$this->assertTrue ($track->getOptions () == $options);
// {{{ Test autodiscover()
function test_autodiscover_success ()
'url' => 'http://pear.php.net/package/net_ftp'
$data['trackback_url'] = 'http://pear.php.net/trackback/trackback.php?id=Net_FTP';
$this->assertTrue ($track1 == $track2);
function test_autodiscover_failure ()
'url' => 'http://pear.php.net/'
$res = $track1->autodiscover ();
$this->assertTrue (PEAR ::isError ($res));
// {{{Test getAutodiscoveryCode()
function test_getAutodiscoveryCode_nocomments ()
$data = $trackbackData['nospam'];
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
$xml = sprintf($xml, $data['url'], $data['url'], $data['title'], $data['trackback_url']);
$this->assertTrue ($track->getAutodiscoveryCode (false ) == $xml);
function test_getAutodiscoveryCode_comments ()
$data = $trackbackData['nospam'];
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
$xml = sprintf($xml, $data['url'], $data['url'], $data['title'], $data['trackback_url']);
$this->assertTrue ($track->getAutodiscoveryCode () == $xml);
$postData = $trackbackData['nospam'];
// Not set during receive()
unset ($data['trackback_url']);
$recTrack->receive ($postData);
// {{{ Test getResponseSuccess()
function test_getResponseSuccess ()
<?xml version="1.0" encoding="iso-8859-1"?>
// {{{ Test getResponseError()
function test_getResponseError ()
<?xml version="1.0" encoding="iso-8859-1"?>
<message>Me & you</message>
function test_addSpamCheck_success ()
$this->assertTrue ($trackback->addSpamCheck ($spamCheck));
function test_addSpamCheck_failure ()
$this->assertTrue (PEAR ::isError ($trackback->addSpamCheck ($spamCheck)));
// {{{ Test createSpamCheck
function test_createSpamCheck_success ()
$this->assertTrue ($trackback->createSpamCheck ('DNSBL') == $spamCheck);
function test_createSpamCheck_failure ()
$this->assertTrue (PEAR ::isError ($spamCheck));
// {{{ Test removeSpamCheck
function test_removeSpamCheck_success ()
$trackback->addSpamCheck ($spamCheck);
$this->assertTrue ($trackback->removeSpamCheck ($spamCheck));
function test_removeSpamCheck_failure ()
$trackback->addSpamCheck ($spamCheck);
$this->assertTrue (PEAR ::isError ($trackback->removeSpamCheck ($spamCheck2)));
function test_fromArray () {
$fakeTrack->_data = $trackbackData['nospam'];
$realTrack->_fromArray ($trackbackData['nospam']);
$this->assertTrue ($realTrack == $fakeTrack);
// {{{ Test _getContent()
function test_getContent () {
$url = 'http://www.example.com';
<TITLE>Example Web Page</TITLE>
<p>You have reached this web page by typing "example.com",
or "example.org" into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not available
for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
$res = $trackback->_getContent ($url);
if (PEAR ::isError ($res)) {
$this->fail ($res->getMessage ());
$this->assertTrue (trim($res) == trim($fakeRes));
// {{{ Test _getEncodedData()
function test_getEncodedData () {
'foo' => 'bar & baz',
'bar' => 'foo << baz',
'baz' => 'foo && bar'
// {{{ Test _getDecodedData()
function test_getDecodedData () {
function test_checkData_true ()
$keys = array ('id', 'test');
$data = array ('id' => 1 , 'test' => 'x', 'test2' => 0 );
function test_checkData_false ()
$keys = array ('id', 'test');
$data = array ('id' => 1 , 'test2' => 0 );
function test_checkURLs_true_1 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.net/trackbike/index.htm";
function test_checkURLs_true_2 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.com/trackbike/index.htm";
function test_checkURLs_true_3 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.com/trackback/index.php";
function test_checkURLs_false_1 ()
// No real test, should always return true
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "https://test.net/trackbike/index.htm";
function test_checkURLs_false_2 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.net/trackback/index.php";
function test_checkURLs_false_3 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.com/trackback/index.htm";
function test_checkURLs_invalid_1 ()
// No real test, should always return true
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "https://test.net/trackbike/index.htm";
function test_checkURLs_invalid_2 ()
$url1 = "http:///trackback/index.php";
$url2 = "http://www.example.net/trackback/index.php";
function test_checkURLs_invalid_3 ()
// No real test, URLs are not invalid, but unequal
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.com/trackback/index.htm";
// {{{ Test _interpretTrackbackResponse()
function test_interpretTrackbackResponse_success () {
<?xml version='1.0' encoding='iso-8859-1'?>
function test_interpretTrackbackResponse_failure () {
<?xml version='1.0' encoding='iso-8859-1'?>
<message>No more trackbacks from this host</message>
$this->assertTrue (PEAR ::isError ($res));
function test_interpretTrackbackResponse_invalid_1 () {
<?xml version='1.0' encoding='iso-8859-1'?>
<message>No more trackbacks from this host</message>
$this->assertTrue (PEAR ::isError ($res));
function test_interpretTrackbackResponse_invalid_2 () {
<?xml version='1.0' encoding='iso-8859-1'?>
$this->assertTrue (PEAR ::isError ($res));
$suite = new PHPUnit_TestSuite ("Webservices_Trackback_TestCase");
$result = PHPUnit ::run ($suite);
echo $result->toString ();
Documentation generated on Mon, 11 Mar 2019 14:36:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|