2010-06-22 03:13:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package blog
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class BlogTrackbackTest extends SapphireTest {
|
2010-06-23 07:50:02 +02:00
|
|
|
static $fixture_file = 'blog/tests/BlogTrackbackTest.yml';
|
2010-06-22 03:13:10 +02:00
|
|
|
|
|
|
|
function testTrackback() {
|
|
|
|
$blog = $this->objFromFixture('BlogHolder', 'mainblog');
|
|
|
|
$blog->TrackBacksEnabled = true;
|
|
|
|
$blog->write();
|
|
|
|
|
|
|
|
$entry = $this->objFromFixture('BlogEntry', 'testpost');
|
|
|
|
$response = $entry->trackbackping();
|
|
|
|
|
|
|
|
$this->assertContains("<error>1</error>", $response);
|
|
|
|
|
|
|
|
$_POST['url'] = 'test trackback post url';
|
|
|
|
$_POST['title'] = 'test trackback post title';
|
|
|
|
$_POST['excerpt'] = 'test trackback post excerpt';
|
|
|
|
$_POST['blog_name'] = 'test trackback blog name';
|
|
|
|
|
|
|
|
$response = $entry->trackbackping();
|
|
|
|
$this->assertContains("<error>0</error>", $response);
|
|
|
|
|
|
|
|
$trackback = DataObject::get_one('TrackBackPing');
|
|
|
|
$this->assertEquals('test trackback post url', $trackback->Url);
|
|
|
|
$this->assertEquals('test trackback post title', $trackback->Title);
|
|
|
|
$this->assertEquals('test trackback post excerpt', $trackback->Excerpt);
|
|
|
|
$this->assertEquals('test trackback blog name', $trackback->BlogName);
|
|
|
|
|
|
|
|
unset($_POST);
|
|
|
|
}
|
|
|
|
|
2010-06-23 07:50:02 +02:00
|
|
|
function testTrackbackNotify() {
|
|
|
|
$tmpServerClass = TrackBackDecorator::$trackback_server_class;
|
|
|
|
TrackBackDecorator::$trackback_server_class = "TestTrackbackHTTPServer";
|
|
|
|
|
2010-06-22 03:13:10 +02:00
|
|
|
$blog = $this->objFromFixture('BlogHolder', 'mainblog');
|
|
|
|
$blog->TrackBacksEnabled = true;
|
2010-06-23 07:50:02 +02:00
|
|
|
$blog->write();
|
2010-06-22 03:13:10 +02:00
|
|
|
|
|
|
|
$entry = $this->objFromFixture('BlogEntry', 'testpost');
|
2010-06-23 07:50:02 +02:00
|
|
|
$this->assertTrue($entry->trackbackNotify('testGoodTrackbackURL'));
|
|
|
|
$this->assertFalse($entry->trackbackNotify('testBadTrackbackURL'));
|
|
|
|
$this->assertFalse($entry->trackbackNotify('testNonExistingTrackbackURL'));
|
2010-06-22 03:13:10 +02:00
|
|
|
|
2010-06-23 07:50:02 +02:00
|
|
|
TrackBackDecorator::$trackback_server_class = $tmpServerClass;
|
2010-06-22 03:13:10 +02:00
|
|
|
}
|
2010-06-23 07:50:02 +02:00
|
|
|
|
|
|
|
function testOnBeforePublish() {
|
2010-06-22 03:13:10 +02:00
|
|
|
$tmpServerClass = TrackBackDecorator::$trackback_server_class;
|
|
|
|
TrackBackDecorator::$trackback_server_class = "TestTrackbackHTTPServer";
|
2010-06-23 07:50:02 +02:00
|
|
|
|
2010-06-22 03:13:10 +02:00
|
|
|
$blog = $this->objFromFixture('BlogHolder', 'mainblog');
|
|
|
|
$blog->TrackBacksEnabled = true;
|
2010-06-23 07:50:02 +02:00
|
|
|
$blog->write();
|
2010-06-22 03:13:10 +02:00
|
|
|
|
2010-06-23 07:50:02 +02:00
|
|
|
$entry1 = $this->objFromFixture('BlogEntry', 'testpost');
|
|
|
|
$entry1->doPublish();
|
|
|
|
$this->assertEquals(2, $entry1->TrackBackURLs()->Count());
|
|
|
|
$this->assertEquals(array('testGoodTrackbackURL' => 1), $entry1->TrackBackURLs()->map('URL', 'Pung'));
|
2010-06-22 03:13:10 +02:00
|
|
|
|
2010-06-23 07:50:02 +02:00
|
|
|
$entry2 = $this->objFromFixture('BlogEntry', 'testpost2');
|
|
|
|
$entry2->doPublish();
|
|
|
|
$this->assertEquals(4, $entry2->TrackBackURLs()->Count());
|
|
|
|
$this->assertEquals(array('testBadTrackbackURL' => 0, 'testGoodTrackbackURL2' => 1, 'noneExistingURL' => 0, 'testGoodTrackbackURL3' => 1), $entry2->TrackBackURLs()->map('URL', 'Pung'));
|
|
|
|
|
|
|
|
TrackBackDecorator::$trackback_server_class = $tmpServerClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDuplicateIsTrackBackURL() {
|
|
|
|
$url1 = $this->objFromFixture('TrackBackURL', 'goodTrackBackURL1');
|
|
|
|
$urlDup = $this->objFromFixture('TrackBackURL', 'dupTrackBackURL');
|
2010-06-22 03:13:10 +02:00
|
|
|
|
2010-06-23 07:50:02 +02:00
|
|
|
$url2 = $this->objFromFixture('TrackBackURL', 'goodTrackBackURL2');
|
|
|
|
$this->assertFalse($url2->isDuplicate());
|
|
|
|
$this->assertFalse($url2->isDuplicate(true));
|
2010-06-22 03:13:10 +02:00
|
|
|
|
2010-06-23 07:50:02 +02:00
|
|
|
$this->assertTrue($urlDup->isDuplicate());
|
|
|
|
$this->assertFalse($urlDup->isDuplicate(true));
|
|
|
|
|
|
|
|
$url1->Pung = true;
|
|
|
|
$url1->write();
|
|
|
|
$this->assertTrue($urlDup->isDuplicate(true));
|
|
|
|
|
|
|
|
|
2010-06-22 03:13:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestTrackbackHTTPServer extends TrackbackHTTPServer implements TestOnly {
|
|
|
|
|
|
|
|
function request($url, $data) {
|
2010-06-23 07:50:02 +02:00
|
|
|
if(in_array($url, array('testGoodTrackbackURL', 'testGoodTrackbackURL2', 'testGoodTrackbackURL3'))) {
|
2010-06-22 03:13:10 +02:00
|
|
|
$response = $this->goodTrackback();
|
|
|
|
$statusCode = '200';
|
|
|
|
}
|
|
|
|
else if($url == 'testBadTrackbackURL') {
|
|
|
|
$response = $this->badTrackback();
|
|
|
|
$statusCode = '200';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$response = $this->badTrackback();
|
|
|
|
$statusCode = '404';
|
|
|
|
}
|
|
|
|
|
|
|
|
return new SS_HTTPResponse($response, $statusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function goodTrackback() {
|
|
|
|
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
|
|
|
<response>
|
|
|
|
<error>0</error>
|
|
|
|
<message></message>
|
|
|
|
</response>";
|
|
|
|
}
|
|
|
|
|
|
|
|
private function badTrackback() {
|
|
|
|
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
|
|
|
<response>
|
|
|
|
<error>1</error>
|
|
|
|
<message>Some error text</message>
|
|
|
|
</response>";
|
|
|
|
}
|
|
|
|
}
|