DocsOnlineTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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-2015 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 'Zend/Gdata/Docs.php';
  23. require_once 'Zend/Http/Client.php';
  24. require_once 'Zend/Gdata/ClientLogin.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Gdata_Docs
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Gdata
  32. * @group Zend_Gdata_Docs
  33. */
  34. class Zend_Gdata_DocsOnlineTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function setUp()
  37. {
  38. $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
  39. $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
  40. $this->docTitle = constant('TESTS_ZEND_GDATA_DOCS_DOCUMENTTITLE');
  41. $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
  42. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  43. $this->gdata = new Zend_Gdata_Docs($client);
  44. }
  45. public function testGetSpreadsheetFeed()
  46. {
  47. $feed = $this->gdata->getDocumentListFeed();
  48. $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
  49. foreach ($feed->entries as $entry) {
  50. $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
  51. $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
  52. }
  53. $query = new Zend_Gdata_Docs_Query();
  54. $feed = $this->gdata->getDocumentListFeed($query);
  55. $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
  56. foreach ($feed->entries as $entry) {
  57. $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
  58. $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
  59. }
  60. $uri = $query->getQueryUrl();
  61. $feed = $this->gdata->getDocumentListFeed($uri);
  62. $this->assertTrue($feed instanceof Zend_Gdata_Docs_DocumentListFeed);
  63. foreach ($feed->entries as $entry) {
  64. $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
  65. $this->assertTrue($entry->getHttpClient() == $feed->getHttpClient());
  66. }
  67. }
  68. public function testQueryForTitle()
  69. {
  70. $query = new Zend_Gdata_Docs_Query();
  71. $query->title = $this->docTitle;
  72. $feed = $this->gdata->getDocumentListFeed($query);
  73. $this->assertTrue(strpos(strtolower($feed->entries[0]->title), strtolower($this->docTitle)) !== FALSE);
  74. }
  75. public function testGetDocumentListEntry()
  76. {
  77. $query = new Zend_Gdata_Docs_Query();
  78. $feed = $this->gdata->getDocumentListFeed($query);
  79. $selfLinkHref = $feed->entries[0]->getSelfLink()->href;
  80. $entry = $this->gdata->getDocumentListEntry($selfLinkHref);
  81. $this->assertTrue($entry instanceof Zend_Gdata_Docs_DocumentListEntry);
  82. }
  83. public function testUploadFindAndDelete()
  84. {
  85. $documentTitle = 'spreadsheet_upload_test.csv';
  86. $newDocumentEntry = $this->gdata->uploadFile(
  87. 'Zend/Gdata/_files/DocsTest.csv', $documentTitle,
  88. $this->gdata->lookupMimeType('CSV'),
  89. Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
  90. $this->assertTrue($newDocumentEntry->title->text === $documentTitle);
  91. // Get the newly created document.
  92. // First extract the document's ID key from the Atom id.
  93. $idParts = explode('/', $newDocumentEntry->id->text);
  94. $keyParts = explode('%3A', end($idParts));
  95. $documentFromGetDoc = $this->gdata->getDoc($keyParts[1], $keyParts[0]);
  96. $this->assertTrue($documentFromGetDoc->title->text === $documentTitle);
  97. if ($keyParts[0] == 'document') {
  98. $documentFromGetDocument = $this->gdata->getDocument($keyParts[1]);
  99. $this->assertTrue(
  100. $documentFromGetDocument->title->text === $documentTitle);
  101. }
  102. if ($keyParts[0] == 'spreadsheet') {
  103. $documentFromGetSpreadsheet = $this->gdata->getSpreadsheet(
  104. $keyParts[1]);
  105. $this->assertTrue(
  106. $documentFromGetSpreadsheet->title->text === $documentTitle);
  107. }
  108. if ($keyParts[0] == 'presentation') {
  109. $documentFromGetPresentation = $this->gdata->getPresentation(
  110. $keyParts[1]);
  111. $this->assertTrue(
  112. $documentFromGetPresentation->title->text === $documentTitle);
  113. }
  114. // Cleanup and remove the new document.
  115. $newDocumentEntry->delete();
  116. }
  117. }