[pLog-svn] r4811 - in plog/branches/lifetype-1.2/class: dao test/tests/dao
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Wed Feb 21 18:04:38 EST 2007
Author: oscar
Date: 2007-02-21 18:04:38 -0500 (Wed, 21 Feb 2007)
New Revision: 4811
Added:
plog/branches/lifetype-1.2/class/test/tests/dao/trackbackclient_test.class.php
Modified:
plog/branches/lifetype-1.2/class/dao/trackbackclient.class.php
Log:
Fixed mantis issue http://bugs.lifetype.net/view.php?id=1184, we should only look at trackback:ping tags when doing trackback auto-discovery and not fall back to rdf:about tags, which could be being used for things Creative Commons license definition. I've also added a test case to make sure that I didn't break anything.
Modified: plog/branches/lifetype-1.2/class/dao/trackbackclient.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/trackbackclient.class.php 2007-02-21 22:59:18 UTC (rev 4810)
+++ plog/branches/lifetype-1.2/class/dao/trackbackclient.class.php 2007-02-21 23:04:38 UTC (rev 4811)
@@ -47,8 +47,6 @@
$regexp ="/<rdf:RDF.*?<\/rdf:RDF>/s";
$links = preg_match_all( $regexp, $page, $out, PREG_SET_ORDER );
- //print_r($out);
-
$links = Array();
foreach( $out as $result ) {
// we have to get now from within the rdf code the following identifiers:
@@ -59,35 +57,21 @@
$dcIdentifier = $dc_ident[1];
// get the trackback:ping
- if(preg_match( "/trackback:ping=\"([^\"]+)\"/", $result[0], $tb_ping))
+ if(preg_match( "/trackback:ping=\"([^\"]+)\"/", $result[0], $tb_ping)) {
$tbPing = $tb_ping[1];
- else {
- // as a fallback plan, try to get the "about"
- if(preg_match( "/about=\"([^\"]+)\"/", $result[0], $tb_ping))
- $tbPing = $tb_ping[1];
- }
- //print("dc:identifier--> ".$dcIdentifier."<br/>");
- //print("trackback:ping-->".$tbPing."<br/>");
- //print("page:".$pageUrl."<br/>");
-
- // oddly enough, we could not find anything despite the presence
- // of the rdf:RDF tag...
- if( $tbPing=="")
- return;
-
- // if we provided the url of the page, we have a mechanism to make sure
- // that we are fetching the right trackback ping
- if( $pageUrl != "" ) {
- if( $dcIdentifier == $pageUrl || $dcIdentifier == htmlentities($pageUrl)) {
- //print("identifer matches page!!");
- array_push( $links, $tbPing );
- }
- }
- else {
- //print("adding tb link to array nevertheless");
- array_push( $links, $tbPing );
- }
+ // if we provided the url of the page, we have a mechanism to make sure
+ // that we are fetching the right trackback ping
+ if( $pageUrl != "" ) {
+ if( $dcIdentifier == $pageUrl || $dcIdentifier == htmlentities($pageUrl)) {
+ //print("identifer matches page!!");
+ array_push( $links, $tbPing );
+ }
+ }
+ else {
+ array_push( $links, $tbPing );
+ }
+ }
}
return $links;
Added: plog/branches/lifetype-1.2/class/test/tests/dao/trackbackclient_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/dao/trackbackclient_test.class.php (rev 0)
+++ plog/branches/lifetype-1.2/class/test/tests/dao/trackbackclient_test.class.php 2007-02-21 23:04:38 UTC (rev 4811)
@@ -0,0 +1,128 @@
+<?php
+
+ lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/dao/trackbackclient.class.php" );
+
+ /**
+ * \ingroup Test
+ *
+ * Test cases for the TrackbackClient class
+ */
+ class TrackbackClient_Test extends LifeTypeTestCase
+ {
+ function setUp()
+ {
+ // definition of our test pages
+
+ $this->page = '
+<html><body>
+!-- <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<Work rdf:about="">
+ <license rdf:resource="http://creativecommons.org/licenses/by-nc-sa/2.5/" />
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/Text" />
+</Work>
+<License rdf:about="http://creativecommons.org/licenses/by-nc-sa/2.5/"><permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
+ <permits rdf:resource="http://web.resource.org/cc/Distribution"/><requires rdf:resource="http://web.resource.org/cc/Notice"/>
+ <requires rdf:resource="http://web.resource.org/cc/Attribution"/><prohibits rdf:resource="http://web.resource.org/cc/CommercialUse"/>
+ <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/><requires rdf:resource="http://web.resource.org/cc/ShareAlike"/></License>
+</rdf:RDF> -->
+<p>blah blah blah</p>
+<!-- <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/">
+ <rdf:Description rdf:about="http://www.lifetype.net/blog/lifetype%2Ddevelopment%2Djournal/2007/02/14/critical%2Dsecurity%2Dissue%2Dlifetype%2D1.1.6%2Dand%2Dlifetype%2D1.2%2Dbeta2%2Dreleased" dc:identifier="http://www.lifetype.net/blog/lifetype%2Ddevelopment%2Djournal/2007/02/14/critical%2Dsecurity%2Dissue%2Dlifetype%2D1.1.6%2Dand%2Dlifetype%2D1.2%2Dbeta2%2Dreleased"
+ dc:title="Critical security issue: Lifetype 1.1.6 and Lifetype 1.2\-beta2 released"
+ trackback:ping="http://www.lifetype.net/trackback.php?id=193"/></rdf:RDF> -->
+</body></html>
+';
+
+ // this one has three different trackback links
+ $this->page2 = '
+<html><body>
+!-- <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<Work rdf:about="">
+ <license rdf:resource="http://creativecommons.org/licenses/by-nc-sa/2.5/" />
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/Text" />
+</Work>
+<License rdf:about="http://creativecommons.org/licenses/by-nc-sa/2.5/"><permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
+ <permits rdf:resource="http://web.resource.org/cc/Distribution"/><requires rdf:resource="http://web.resource.org/cc/Notice"/>
+ <requires rdf:resource="http://web.resource.org/cc/Attribution"/><prohibits rdf:resource="http://web.resource.org/cc/CommercialUse"/>
+ <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/><requires rdf:resource="http://web.resource.org/cc/ShareAlike"/></License>
+</rdf:RDF> -->
+<p>blah blah blah</p>
+<!-- <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/">
+ <rdf:Description rdf:about="http://www.lifetype.net/blog/lifetype%2Ddevelopment%2Djournal/2007/02/14/critical%2Dsecurity%2Dissue%2Dlifetype%2D1.1.6%2Dand%2Dlifetype%2D1.2%2Dbeta2%2Dreleased" dc:identifier="http://www.lifetype.net/blog/lifetype%2Ddevelopment%2Djournal/2007/02/14/critical%2Dsecurity%2Dissue%2Dlifetype%2D1.1.6%2Dand%2Dlifetype%2D1.2%2Dbeta2%2Dreleased"
+ dc:title="Critical security issue: Lifetype 1.1.6 and Lifetype 1.2\-beta2 released"
+ trackback:ping="http://www.lifetype.net/trackback.php?id=194"/></rdf:RDF> -->
+ <!-- <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/">
+ <rdf:Description rdf:about="http://www.lifetype.net/blog/lifetype%2Ddevelopment%2Djournal/2007/02/14/critical%2Dsecurity%2Dissue%2Dlifetype%2D1.1.6%2Dand%2Dlifetype%2D1.2%2Dbeta2%2Dreleased" dc:identifier="http://www.lifetype.net/blog/lifetype%2Ddevelopment%2Djournal/2007/02/14/critical%2Dsecurity%2Dissue%2Dlifetype%2D1.1.6%2Dand%2Dlifetype%2D1.2%2Dbeta2%2Dreleased"
+ dc:title="Critical security issue: Lifetype 1.1.6 and Lifetype 1.2\-beta2 released"
+ trackback:ping="http://www.lifetype.net/trackback.php?id=193"/></rdf:RDF> -->
+ <!-- <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/">
+ <rdf:Description rdf:about="http://www.lifetype.net/blog/lifetype%2Ddevelopment%2Djournal/2007/02/14/critical%2Dsecurity%2Dissue%2Dlifetype%2D1.1.6%2Dand%2Dlifetype%2D1.2%2Dbeta2%2Dreleased" dc:identifier="http://www.lifetype.net/blog/lifetype%2Ddevelopment%2Djournal/2007/02/14/critical%2Dsecurity%2Dissue%2Dlifetype%2D1.1.6%2Dand%2Dlifetype%2D1.2%2Dbeta2%2Dreleased"
+ dc:title="Critical security issue: Lifetype 1.1.6 and Lifetype 1.2\-beta2 released"
+ trackback:ping="http://www.lifetype.net/trackback.php?id=195"/></rdf:RDF> -->
+</body></html>
+';
+
+ // this one has no valid trackback tags
+ $this->page3 = '
+<html><body>
+!-- <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<Work rdf:about="">
+ <license rdf:resource="http://creativecommons.org/licenses/by-nc-sa/2.5/" />
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/Text" />
+</Work>
+<License rdf:about="http://creativecommons.org/licenses/by-nc-sa/2.5/"><permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
+ <permits rdf:resource="http://web.resource.org/cc/Distribution"/><requires rdf:resource="http://web.resource.org/cc/Notice"/>
+ <requires rdf:resource="http://web.resource.org/cc/Attribution"/><prohibits rdf:resource="http://web.resource.org/cc/CommercialUse"/>
+ <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/><requires rdf:resource="http://web.resource.org/cc/ShareAlike"/></License>
+</rdf:RDF> -->
+<p>blah blah blah</p>
+</body></html>
+';
+
+ }
+
+ function testGetTrackbackLinks()
+ {
+ // get the trackback links from the given page
+ $links = TrackbackClient::getTrackbackLinks( $this->page );
+
+ // there should only be one link
+ $this->assertEquals( 1, count( $links ), "There was more than one trackback link detected in the test page!" );
+
+ // and that it is equal to the value that we're expecting
+ $this->assertEquals( "http://www.lifetype.net/trackback.php?id=193", $links[0], "The returned trackback link was not the expected one!" );
+ }
+
+ function testGetMultipleTrackbackLinks()
+ {
+ // get the trackback links from the given page
+ $links = TrackbackClient::getTrackbackLinks( $this->page2 );
+
+ // there should only be one link
+ $this->assertEquals( 3, count( $links ), "There was not 3 trackback links detected in the test page!" );
+
+ // and that it is equal to the value that we're expecting
+ $this->assertEquals( "http://www.lifetype.net/trackback.php?id=194", $links[0], "The returned trackback link was not the expected one!" );
+ $this->assertEquals( "http://www.lifetype.net/trackback.php?id=193", $links[1], "The returned trackback link was not the expected one!" );
+ $this->assertEquals( "http://www.lifetype.net/trackback.php?id=195", $links[2], "The returned trackback link was not the expected one!" );
+ }
+
+ function testNoTrackbackLinks()
+ {
+ // get the trackback links from the given page
+ $links = TrackbackClient::getTrackbackLinks( $this->page3 );
+
+ // there should only be one link
+ $this->assertEquals( 0, count( $links ), "There shouldn't be any trackback links detected in this page!" );
+ }
+ }
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list