فهرست منبع

ZF-4976: Add createFolder() method to Zend_Gdata_Docs.

Tests and a minor doc changes added by me. All other changes submitted
via patch.

Patch by: Matthew Romaine (mromaine)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20112 44c647ce-9c0f-0410-b52a-842ac1e357ba
tjohns 16 سال پیش
والد
کامیت
cdfd244209
2فایلهای تغییر یافته به همراه100 افزوده شده و 6 حذف شده
  1. 49 2
      library/Zend/Gdata/Docs.php
  2. 51 4
      tests/Zend/Gdata/DocsTest.php

+ 49 - 2
library/Zend/Gdata/Docs.php

@@ -37,6 +37,16 @@ require_once 'Zend/Gdata/Docs/DocumentListFeed.php';
 require_once 'Zend/Gdata/Docs/DocumentListEntry.php';
 
 /**
+ * @see Zend_Gdata_App_Extension_Category
+ */
+require_once 'Zend/Gdata/App/Extension/Category.php';
+
+/**
+ * @see Zend_Gdata_App_Extension_Title
+ */
+require_once 'Zend/Gdata/App/Extension/Title.php';
+
+/**
  * Service class for interacting with the Google Document List data API
  * @link http://code.google.com/apis/documents/
  *
@@ -50,19 +60,29 @@ class Zend_Gdata_Docs extends Zend_Gdata
 {
 
     const DOCUMENTS_LIST_FEED_URI = 'http://docs.google.com/feeds/documents/private/full';
+    const DOCUMENTS_FOLDER_FEED_URI = 'http://docs.google.com/feeds/folders/private/full';
+    const DOCUMENTS_CATEGORY_SCHEMA = 'http://schemas.google.com/g/2005#kind';
+    const DOCUMENTS_CATEGORY_TERM = 'http://schemas.google.com/docs/2007#folder';
     const AUTH_SERVICE_NAME = 'writely';
 
     protected $_defaultPostUri = self::DOCUMENTS_LIST_FEED_URI;
 
     private static $SUPPORTED_FILETYPES = array(
+      'TXT'=>'text/plain',
       'CSV'=>'text/csv',
+      'TSV'=>'text/tab-separated-values',
+      'TAB'=>'text/tab-separated-values',
+      'HTML'=>'text/html',
+      'HTM'=>'text/html',
       'DOC'=>'application/msword',
       'ODS'=>'application/vnd.oasis.opendocument.spreadsheet',
       'ODT'=>'application/vnd.oasis.opendocument.text',
       'RTF'=>'application/rtf',
       'SXW'=>'application/vnd.sun.xml.writer',
-      'TXT'=>'text/plain',
-      'XLS'=>'application/vnd.ms-excel');
+      'XLS'=>'application/vnd.ms-excel',
+      'XLSX'=>'application/vnd.ms-excel',
+      'PPT'=>'application/vnd.ms-powerpoint',
+      'PPS'=>'application/vnd.ms-powerpoint');
 
     /**
      * Create Gdata_Docs object
@@ -235,6 +255,33 @@ class Zend_Gdata_Docs extends Zend_Gdata
     }
 
     /**
+     * Creates a new folder in Google Docs
+     *
+     * @param string $folderName The folder name to create
+     * @param string|null $folderResourceId The parent folder to create it in
+     *        ("folder%3Amy_parent_folder")
+     * @return Zend_Gdata_Entry The folder entry created.
+     * @todo ZF-8732: This should return a *subclass* of Zend_Gdata_Entry, but
+     *       the appropriate type doesn't exist yet.
+     */
+    public function createFolder($folderName, $folderResourceId=null) {
+        $category = new Zend_Gdata_App_Extension_Category(self::DOCUMENTS_CATEGORY_TERM, 
+                                                          self::DOCUMENTS_CATEGORY_SCHEMA);
+        $title = new Zend_Gdata_App_Extension_Title($folderName);
+        $entry = new Zend_Gdata_Entry();
+
+        $entry->setCategory(array($category));
+        $entry->setTitle($title);
+
+        $uri = self::DOCUMENTS_LIST_FEED_URI;
+        if ($folderResourceId != null) {
+            $uri = self::DOCUMENTS_FOLDER_FEED_URI . '/' . $folderResourceId;
+        }
+
+        return $this->insertEntry($entry, $uri);
+    }
+
+    /**
      * Inserts an entry to a given URI and returns the response as an Entry.
      *
      * @param mixed  $data The Zend_Gdata_Docs_DocumentListEntry or media

+ 51 - 4
tests/Zend/Gdata/DocsTest.php

@@ -21,7 +21,8 @@
  */
 
 require_once 'Zend/Gdata/Docs.php';
-require_once 'Zend/Http/Client.php';
+require_once 'Zend/Gdata/HttpClient.php';
+require_once 'Zend/Gdata/TestUtility/MockHttpClient.php';
 
 /**
  * @category   Zend
@@ -37,12 +38,58 @@ class Zend_Gdata_DocsTest extends PHPUnit_Framework_TestCase
 
     public function setUp()
     {
-        $this->gdata = new Zend_Gdata_Docs(new Zend_Http_Client());
+        $this->adapter = new Test_Zend_Gdata_MockHttpClient();
+        $this->client = new Zend_Gdata_HttpClient();
+        $this->client->setAdapter($this->adapter);
+        $this->gdata = new Zend_Gdata_Docs($this->client);
     }
 
-    public function testDocs()
+    public function testCreateFolder()
     {
-        $this->assertTrue(true);
+        $this->adapter->setResponse(array('HTTP/1.1 200 OK\r\n\r\n'));
+        $this->gdata->createFolder("Test Folder");
+        $request = $this->adapter->popRequest();
+        
+        // Check to make sure the correct URI is in use
+        $this->assertEquals(
+                "docs.google.com",
+                $request->uri->getHost());
+        $this->assertEquals(
+                "/feeds/documents/private/full",
+                $request->uri->getPath());
+        
+        // Check to make sure that this is a folder
+        $this->assertNotEquals( false, strpos($request->body, 
+                "<atom:category term=\"http://schemas.google.com/docs/2007#folder\" scheme=\"http://schemas.google.com/g/2005#kind\""));
+        
+        // Check to make sure the title is set
+        $this->assertNotEquals(false, strpos($request->body,
+                "<atom:title type=\"text\">Test Folder</atom:title>"));
     }
 
+    public function testCreateSubfolder()
+    {
+        $subfolderName = "MySubfolder";
+        $this->adapter->setResponse(array('HTTP/1.1 200 OK\r\n\r\n'));
+        $this->gdata->createFolder("Test Folder", $subfolderName);
+        $request = $this->adapter->popRequest();
+        
+        // Check to make sure the correct URI is in use
+        $this->assertEquals(
+                "docs.google.com",
+                $request->uri->getHost());
+        $this->assertEquals(
+                "/feeds/folders/private/full/" . $subfolderName,
+                $request->uri->getPath());
+        
+        // Check to make sure that this is a folder
+        $this->assertNotEquals( false, strpos($request->body, 
+                "<atom:category term=\"http://schemas.google.com/docs/2007#folder\" scheme=\"http://schemas.google.com/g/2005#kind\""));
+        
+        // Check to make sure the title is set
+        $this->assertNotEquals(false, strpos($request->body,
+                "<atom:title type=\"text\">Test Folder</atom:title>"));
+    }
+
+
 }