]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
AtomPub tetss: confirming edit URL linked properly in individual entry return
authorBrion Vibber <brion@pobox.com>
Tue, 14 Dec 2010 21:52:44 +0000 (13:52 -0800)
committerBrion Vibber <brion@pobox.com>
Tue, 14 Dec 2010 21:52:44 +0000 (13:52 -0800)
tests/atompub/atompub_test.php

index 36a1ceec25a426718bae1d5aca1bb8291c08a35c..77934c64286aefde6a489ba8acf116c905ac518c 100644 (file)
@@ -188,6 +188,25 @@ class AtomPubClient
         $activity = new Activity($dom->documentRoot);
         return true;
     }
+
+    static function entryEditURL($str) {
+        $dom = new DOMDocument;
+        $dom->loadXML($str);
+        $path = new DOMXPath($dom);
+        $path->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
+
+        $links = $path->query('/atom:entry/atom:link[@rel="edit"]', $dom->documentRoot);
+        if ($links && $links->length) {
+            if ($links->length > 1) {
+                throw new Exception('Bad Atom entry; has multiple rel=edit links.');
+            }
+            $link = $links->item(0);
+            $url = $link->getAttribute('href');
+            return $url;
+        } else {
+            throw new Exception('Atom entry lists no rel=edit link.');
+        }
+    }
 }
 
 
@@ -254,10 +273,12 @@ $body = $notice->get();
 AtomPubClient::validateAtomEntry($body);
 echo "ok\n";
 
-echo "Confirming new entry looks right... ";
-// confirm that it actually is what we expected
-// confirm it has an edit URL that matches $target
-echo "NYI\n";
+echo "Confirming new entry points to itself right... ";
+$editUrl = AtomPubClient::entryEditURL($body);
+if ($editUrl != $noticeUrl) {
+    die("Entry lists edit URL as $editUrl, no match!\n");
+}
+echo "OK\n";
 
 echo "Refetching the collection... ";
 $feed = $collection->get();