Author: chabotc
Date: Sun Jun 14 14:14:16 2009
New Revision: 784564

URL: http://svn.apache.org/viewvc?rev=784564&view=rev
Log:
Fixes xml/atom output consistency errors and brings it up to 0.9 spec

Modified:
    incubator/shindig/trunk/php/src/social/converters/OutputAtomConverter.php
    incubator/shindig/trunk/php/src/social/converters/OutputXmlConverter.php
    incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php
    incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php
    incubator/shindig/trunk/php/test/social/OutputJsonConverterTest.php
    incubator/shindig/trunk/php/test/social/OutputXmlConverterTest.php

Modified: 
incubator/shindig/trunk/php/src/social/converters/OutputAtomConverter.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/converters/OutputAtomConverter.php?rev=784564&r1=784563&r2=784564&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/converters/OutputAtomConverter.php 
(original)
+++ incubator/shindig/trunk/php/src/social/converters/OutputAtomConverter.php 
Sun Jun 14 14:14:16 2009
@@ -29,8 +29,8 @@
   private static $charSet = 'UTF-8';
   private static $formatOutput = true;
   // this maps the REST url to the atom content type
-  private static $entryTypes = array('people' => 'person', 'appdata' => 
'appdata',
-      'activities' => 'activity', 'messages' => 'messages');
+  private static $entryTypes = array('people' => 'entry', 'appdata' => 'entry',
+      'activities' => 'entry', 'messages' => 'entry');
   private $doc;
 
   function outputResponse(ResponseItem $responseItem, RestRequestItem 
$requestItem) {
@@ -45,8 +45,8 @@
 
     // Check to see if this is a single entry, or a collection, and construct 
either an atom
     // feed (collection) or an entry (single)
-    if ($responseItem->getResponse() instanceof RestfulCollection) {
-      $totalResults = $responseItem->getResponse()->getTotalResults();
+    if ($data instanceof RestfulCollection) {
+      $totalResults = $data->getTotalResults();
       $itemsPerPage = $requestItem->getCount();
       $startIndex = $requestItem->getStartIndex();
 
@@ -66,7 +66,7 @@
       // Add osearch & next link to the entry
       $this->addPagingFields($entry, $startIndex, $itemsPerPage, 
$totalResults);
       // Add response entries to feed
-      $responses = $responseItem->getResponse()->getEntry();
+      $responses = $data->getEntry();
       foreach ($responses as $response) {
         // Attempt to have a real ID field, otherwise we fall back on the 
idSpec id
         $idField = is_object($response) && isset($response->id) ? 
$response->id : (is_array($response) && isset($response['id']) ? 
$response['id'] : $requestItem->getUser()->getUserId($requestItem->getToken()));
@@ -113,7 +113,7 @@
       $this->addNode($entry, 'updated', $updatedAtom);
       $content = $this->addNode($entry, 'content', '', array('type' => 
'application/xml'));
       // addData loops through the responseItem data recursively creating a 
matching XML structure
-      $this->addData($content, $requestType, $data->entry, self::$osNameSpace);
+      $this->addData($content, $requestType, $data['entry'], 
self::$osNameSpace);
     }
     $xml = $doc->saveXML();
     if ($responseItem->getResponse() instanceof RestfulCollection) {

Modified: 
incubator/shindig/trunk/php/src/social/converters/OutputXmlConverter.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/converters/OutputXmlConverter.php?rev=784564&r1=784563&r2=784564&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/converters/OutputXmlConverter.php 
(original)
+++ incubator/shindig/trunk/php/src/social/converters/OutputXmlConverter.php 
Sun Jun 14 14:14:16 2009
@@ -39,8 +39,8 @@
     
     // Check to see if this is a single entry, or a collection, and construct 
either an xml 
     // feed (collection) or an entry (single)          
-    if ($responseItem->getResponse() instanceof RestfulCollection) {
-      $totalResults = $responseItem->getResponse()->getTotalResults();
+    if ($data instanceof RestfulCollection) {
+      $totalResults = $data->getTotalResults();
       $itemsPerPage = $requestItem->getCount();
       $startIndex = $requestItem->getStartIndex();
       
@@ -51,7 +51,7 @@
       $this->addNode($entry, 'startIndex', $startIndex);
       $this->addNode($entry, 'itemsPerPage', $itemsPerPage);
       $this->addNode($entry, 'totalResults', $totalResults);
-      $responses = $responseItem->getResponse()->getEntry();
+      $responses = $data->getEntry();
       foreach ($responses as $response) {
         // recursively add responseItem data to the xml structure
         $this->addData($entry, $requestType, $response);
@@ -60,7 +60,7 @@
       // Single entry = Xml:Entry      
       $entry = $this->addNode($doc, 'response', '');
       // addData loops through the responseItem data recursively creating a 
matching XML structure
-      $this->addData($entry, 'entry', $data->entry);
+      $this->addData($entry, 'entry', $data['entry']);
     }
     $xml = $doc->saveXML();
     echo $xml;

Modified: incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php?rev=784564&r1=784563&r2=784564&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php 
(original)
+++ incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php Sun 
Jun 14 14:14:16 2009
@@ -23,7 +23,7 @@
 
   protected static $FORMAT_PARAM = "format";
   protected static $ATOM_FORMAT = "atom";
-  protected static $XML_FORMAT = "atom";
+  protected static $XML_FORMAT = "xml";
 
   public static $PEOPLE_ROUTE = "people";
   public static $ACTIVITY_ROUTE = "activities";
@@ -114,7 +114,7 @@
     if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
       $tmp = file_get_contents('php://input');
       if (!empty($tmp)) {
-        $GLOBALS['HTTP_RAW_POST_DATA'] = $tmp;  
+        $GLOBALS['HTTP_RAW_POST_DATA'] = $tmp;
       }
     }
     if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {

Modified: incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php?rev=784564&r1=784563&r2=784564&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php 
(original)
+++ incubator/shindig/trunk/php/test/social/OutputAtomConverterTest.php Sun Jun 
14 14:14:16 2009
@@ -56,7 +56,7 @@
     $requestItem->applyUrlTemplate("/people/{userId}/{groupId}/{personId}");
     $entry = array('isOwner' => false, 'isViewer' => false,
                    'displayName' => '1 1', 'id' => '1');
-    $response = new DataCollection($entry);
+    $response = array('entry' => $entry);
     $responseItem = new ResponseItem(null, null, $response);
     ob_start();
     $outputConverter->outputResponse($responseItem, $requestItem);
@@ -70,7 +70,7 @@
   <id>urn:guid:1</id>
   <updated>2008-12-11T19:58:31+01:00</updated>
   <content type="application/xml">
-    <person xmlns="http://ns.opensocial.org/2008/opensocial";>
+    <entry xmlns="http://ns.opensocial.org/2008/opensocial";>
       <isOwner></isOwner>
       <isViewer></isViewer>
       <displayName>1 1</displayName>

Modified: incubator/shindig/trunk/php/test/social/OutputJsonConverterTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/OutputJsonConverterTest.php?rev=784564&r1=784563&r2=784564&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/social/OutputJsonConverterTest.php 
(original)
+++ incubator/shindig/trunk/php/test/social/OutputJsonConverterTest.php Sun Jun 
14 14:14:16 2009
@@ -62,14 +62,16 @@
     $outputConverter->outputResponse($responseItem, $requestItem);
     $output = ob_get_clean();
     $expected = '{
-  "entry": {
-    "isOwner": false,
-    "isViewer": false,
-    "displayName": "1 1",
-    "id": "1"
-  }
-}';
-    $this->assertEquals($expected, $output);
+        "entry": {
+          "isOwner": false,
+          "isViewer": false,
+          "displayName": "1 1",
+          "id": "1"
+        }
+    }';
+    $outputJson = json_decode($output);
+    $expectedJson = json_decode($expected);
+    $this->assertEquals($expectedJson, $outputJson);
   }
 
 }

Modified: incubator/shindig/trunk/php/test/social/OutputXmlConverterTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/social/OutputXmlConverterTest.php?rev=784564&r1=784563&r2=784564&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/social/OutputXmlConverterTest.php 
(original)
+++ incubator/shindig/trunk/php/test/social/OutputXmlConverterTest.php Sun Jun 
14 14:14:16 2009
@@ -56,7 +56,7 @@
     $requestItem->applyUrlTemplate("/people/{userId}/{groupId}/{personId}");
     $entry = array('isOwner' => false, 'isViewer' => false,
                    'displayName' => '1 1', 'id' => '1');
-    $response = new DataCollection($entry);
+    $response = array('entry' => $entry);
     $responseItem = new ResponseItem(null, null, $response);
     ob_start();
     $outputConverter->outputResponse($responseItem, $requestItem);
@@ -71,7 +71,9 @@
   </entry>
 </response>
 ';
-    $this->assertEquals($expected, $output);
+    $outputXml = simplexml_load_string($output);
+    $expectedXml = simplexml_load_string($expected);
+    $this->assertEquals($expectedXml, $outputXml);
   }
 
 }


Reply via email to