Source for file Services_Trackback_Test.php
Documentation is available at Services_Trackback_Test.php
require_once 'Services/Trackback.php';
require_once 'Services/Trackback/SpamCheck.php';
require_once 'Services/Trackback/SpamCheck/Mock.php';
require_once 'PHPUnit/Framework/TestCase.php';
require_once dirname (__FILE__ ). '/trackback_data.php';
class Services_Trackback_Test extends PHPUnit_Framework_TestCase
$path = dirname(__FILE__ ) . '/data/Services_Trackback_Test/';
$dir = new DirectoryIterator ($path);
foreach ($dir as $file) {
@list ($testName, $extension) = explode('.', (string) $file);
if ($extension !== 'xml') {
$full_path = $path . "/" . $file;
$this->xml[$testName] = trim($xml);
'allowRedirects' => false ,
'useragent' => 'Mozilla 10.0',
$fakeTrack->_options = $options;
$fakeTrack->_data = $trackbackData['nospam'];
function testSetOptionsSuccess ()
'allowRedirects' => false ,
'useragent' => 'Mozilla 10.0',
$fakeTrack->_options = $options;
$realTrack->setOptions ($options);
$this->assertTrue ($realTrack == $fakeTrack);
function testGetOptionsSuccess ()
'allowRedirects' => false ,
'useragent' => 'Mozilla 10.0',
$track->_options = $options;
$this->assertTrue ($track->getOptions () == $options);
function testAutodiscoverSuccess ()
'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 testAutodiscoverFailure ()
'url' => 'http://pear.php.net/'
$res = $track1->autodiscover ();
$this->assertTrue (PEAR ::isError ($res));
function testGetAutodiscoveryCodeNoComments ()
$data = $trackbackData['nospam'];
$xml = $this->xml['testGetAutodiscoveryCodeNoComments'];
$xml = sprintf($xml, $data['url'], $data['url'], $data['title'], $data['trackback_url']);
$result = trim($track->getAutodiscoveryCode (false ));
$this->assertSame ($xml, $result);
function testGetAutodiscoveryCodeComments ()
$data = $trackbackData['nospam'];
$xml = $this->xml['testGetAutodiscoveryCodeComments'];
$xml = sprintf($xml, $data['url'], $data['url'], $data['title'], $data['trackback_url']);
$result = trim($track->getAutodiscoveryCode ());
$this->assertSame ($xml, $result);
$postData = $trackbackData['nospam'];
// Not set during receive()
unset ($data['trackback_url']);
$recTrack->receive ($postData);
$fakeTrack->set ('extra', $_SERVER);
$this->assertTrue ($recTrack == $fakeTrack);
function testGetResponseSuccess ()
$xml = $this->xml['testGetResponseSuccess'];
$this->assertTrue (!empty ($xml), "Test was unable to locate sample data");
$this->assertSame ($xml, $generated_response);
function testGetResponseError ()
$xml = $this->xml['testGetResponseError'];
$this->assertTrue (!empty ($xml), "Test was unable to locate sample data");
$this->assertSame ($xml, $generated_error);
function testAddSpamCheckSuccess ()
$result = $trackback->addSpamCheck ($spamCheck);
$this->assertFalse (PEAR ::isError ($result));
function testAddSpamCheckFailure ()
$this->assertTrue (PEAR ::isError ($trackback->addSpamCheck ($spamCheck)));
function testCreateSpamCheckSuccess ()
$this->assertTrue ($trackback->createSpamCheck ('DNSBL') == $spamCheck);
function testCreateSpamCheckFailure ()
$this->assertTrue (PEAR ::isError ($spamCheck));
function testRemoveSpamCheckSuccess ()
$trackback->addSpamCheck ($spamCheck);
$this->assertFalse (PEAR ::isError ($result), "Failed to add SpamCheck, can't complete test");
$result = $trackback->removeSpamCheck ($spamCheck);
$this->assertFalse (PEAR ::isError ($result));
function testRemoveSpamCheckFailure ()
$trackback->addSpamCheck ($spamCheck);
$this->assertTrue (PEAR ::isError ($trackback->removeSpamCheck ($spamCheck2)));
$fakeTrack->_data = $trackbackData['nospam'];
$realTrack->_fromArray ($trackbackData['nospam']);
$this->assertTrue ($realTrack == $fakeTrack);
function testGetContent ()
$this->markTestSkipped ("See Bug #13456");
$url = 'http://schlitt.info/projects/PEAR/Services_Trackback/test_getContent.txt';
$fakeRes = "Test text.\n";
$res = $trackback->_getContent ($url);
if (PEAR ::isError ($res)) {
$this->fail ($res->getMessage ());
$this->assertTrue (trim($res) == trim($fakeRes));
function testGetEncodedData ()
'foo' => 'bar & baz',
'bar' => 'foo << baz',
'baz' => 'foo && bar'
function testGetDecodedData ()
function testCheckDataTrue ()
$keys = array ('id', 'test');
$data = array ('id' => 1 , 'test' => 'x', 'test2' => 0 );
function testCheckDataFalse ()
$keys = array ('id', 'test');
$data = array ('id' => 1 , 'test2' => 0 );
function testCheckURLsTrue1 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.net/trackbike/index.htm";
function testCheckURLsTrue2 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.com/trackbike/index.htm";
function testCheckURLsTrue3 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.com/trackback/index.php";
function testCheckURLsFalse1 ()
// No real test, should always return true
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "https://test.net/trackbike/index.htm";
function testCheckURLsFalse2 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.net/trackback/index.php";
function testCheckURLsFalse3 ()
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "http://www.example.com/trackback/index.htm";
function testCheckURLsInvalid1 ()
// No real test, should always return true
$url1 = "http://www.example.com/trackback/index.php";
$url2 = "https://test.net/trackbike/index.htm";
function testCheckURLsInvalid2 ()
$url1 = "http:///trackback/index.php";
$url2 = "http://www.example.net/trackback/index.php";
function testCheckURLsInvalid3 ()
// 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";
function testInterpretTrackbackResponseSuccess ()
$xml = $this->xml['testInterpretTrackbackResponseSuccess'];
function testInterpretTrackbackResponseFailure ()
$xml = $this->xml['testInterpretTrackbackResponseFailure'];
$this->assertTrue (PEAR ::isError ($res));
function testInterpretTrackbackResponseInvalid1 ()
$xml = $this->xml['testInterpretTrackbackResponseInvalid1'];
$this->assertTrue (PEAR ::isError ($res));
function testInterpretTrackbackResponseInvalid2 ()
$xml = $this->xml['testInterpretTrackbackResponseInvalid2'];
$this->assertTrue (PEAR ::isError ($res));
Documentation generated on Mon, 11 Mar 2019 15:25:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|