2
0

DocsOnlineTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata_Docs
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  23. require_once 'Zend/Gdata/Docs.php';
  24. require_once 'Zend/Http/Client.php';
  25. require_once 'Zend/Gdata/ClientLogin.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Gdata_Docs
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Gdata
  33. * @group Zend_Gdata_Docs
  34. */
  35. class Zend_Gdata_DocsOnlineTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function setUp()
  38. {
  39. $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
  40. $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
  41. $this->docTitle = constant('TESTS_ZEND_GDATA_DOCS_DOCUMENTTITLE');
  42. $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
  43. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  44. $this->gdata = new Zend_Gdata_Docs($client);
  45. }
  46. public function testGetSpreadsheetFeed()
  47. {
  48. $feed = $this->gdata->getDocumentListFeed();
  49. $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
  50. foreach ($feed->entries as $entry) {
  51. $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
  52. $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
  53. }
  54. $query = new Zend_Gdata_Docs_Query();
  55. $feed = $this->gdata->getDocumentListFeed($query);
  56. $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
  57. foreach ($feed->entries as $entry) {
  58. $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
  59. $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
  60. }
  61. $uri = $query->getQueryUrl();
  62. $feed = $this->gdata->getDocumentListFeed($uri);
  63. $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
  64. foreach ($feed->entries as $entry) {
  65. $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
  66. $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
  67. }
  68. }
  69. public function testQueryForTitle()
  70. {
  71. $query = new Zend_Gdata_Docs_Query();
  72. $query->title = $this->docTitle;
  73. $feed = $this->gdata->getDocumentListFeed($query);
  74. $this->assertTrue(strpos(strtolower($feed->entries[0]->title), strtolower($this->docTitle)) !== FALSE);
  75. }
  76. public function testGetDocumentListEntry()
  77. {
  78. $query = new Zend_Gdata_Docs_Query();
  79. $feed = $this->gdata->getDocumentListFeed($query);
  80. $selfLinkHref = $feed->entries[0]->getSelfLink()->href;
  81. $entry = $this->gdata->getDocumentListEntry($selfLinkHref);
  82. $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
  83. }
  84. public function testUploadFindAndDelete()
  85. {
  86. $documentTitle = 'spreadsheet_upload_test.csv';
  87. $newDocumentEntry = $this->gdata->uploadFile(
  88. 'Zend/Gdata/_files/DocsTest.csv', $documentTitle,
  89. $this->gdata->lookupMimeType('CSV'),
  90. Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
  91. $this->assertTrue($newDocumentEntry->title->text === $documentTitle);
  92. // Get the newly created document.
  93. // First extract the document's ID key from the Atom id.
  94. $idParts = explode('/', $newDocumentEntry->id->text);
  95. $keyParts = explode('%3A', end($idParts));
  96. $documentFromGetDoc = $this->gdata->getDoc($keyParts[1], $keyParts[0]);
  97. $this->assertTrue($documentFromGetDoc->title->text === $documentTitle);
  98. if ($keyParts[0] == 'document') {
  99. $documentFromGetDocument = $this->gdata->getDocument($keyParts[1]);
  100. $this->assertTrue(
  101. $documentFromGetDocument->title->text === $documentTitle);
  102. }
  103. if ($keyParts[0] == 'spreadsheet') {
  104. $documentFromGetSpreadsheet = $this->gdata->getSpreadsheet(
  105. $keyParts[1]);
  106. $this->assertTrue(
  107. $documentFromGetSpreadsheet->title->text === $documentTitle);
  108. }
  109. if ($keyParts[0] == 'presentation') {
  110. $documentFromGetPresentation = $this->gdata->getPresentation(
  111. $keyParts[1]);
  112. $this->assertTrue(
  113. $documentFromGetPresentation->title->text === $documentTitle);
  114. }
  115. // Cleanup and remove the new document.
  116. $newDocumentEntry->delete();
  117. }
  118. }