2
0

SlideShareTest.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_Service_SlideShare
  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. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /**
  27. * @see Zend_Service_SlideShare
  28. */
  29. require_once 'Zend/Service/SlideShare.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Service_SlideShare
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Service
  37. * @group Zend_Service_SlideShare
  38. */
  39. class Zend_Service_SlideShareTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * The Slide share object instance
  43. *
  44. * @var Zend_Service_SlideShare
  45. */
  46. protected static $_ss;
  47. /**
  48. * Enter description here...
  49. *
  50. * @return Zend_Service_SlideShare
  51. */
  52. protected function _getSSObject()
  53. {
  54. $ss = new Zend_Service_SlideShare(TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY,
  55. TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET,
  56. TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME,
  57. TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD,
  58. TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID);
  59. $cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 0, 'automatic_serialization' => true),
  60. array('cache_dir' => dirname(__FILE__)."/SlideShare/_files"));
  61. $ss->setCacheObject($cache);
  62. return $ss;
  63. }
  64. public function setUp()
  65. {
  66. if(!defined("TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY") ||
  67. !defined("TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET") ||
  68. !defined("TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME") ||
  69. !defined("TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD") ||
  70. (TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY == "") ||
  71. (TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET == "") ||
  72. (TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME == "") ||
  73. (TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD == "")) {
  74. $this->markTestSkipped("You must configure an account for slideshare to run these tests");
  75. }
  76. }
  77. public function testGetSlideShow()
  78. {
  79. if(!defined("TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID") ||
  80. (TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID <= 0)) {
  81. $this->markTestSkipped("You must provide a Slideshow ID to retrieve to perform this test");
  82. }
  83. $ss = $this->_getSSObject();
  84. try {
  85. $result = $ss->getSlideShow(TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID);
  86. } catch(Exception $e) {
  87. $this->fail("Exception Caught retrieving Slideshow");
  88. }
  89. $this->assertTrue($result instanceof Zend_Service_SlideShare_SlideShow);
  90. }
  91. public function testGetSlideShowByTag()
  92. {
  93. $ss = $this->_getSSObject();
  94. try {
  95. $results = $ss->getSlideShowsByTag('zend', 0, 1);
  96. } catch(Exception $e) {
  97. $this->fail("Exception Caught retrieving Slideshow List (tag)");
  98. }
  99. $this->assertTrue(is_array($results));
  100. $this->assertTrue(count($results) == 1);
  101. $this->assertTrue($results[0] instanceof Zend_Service_SlideShare_SlideShow);
  102. }
  103. public function testGetSlideShowByTags()
  104. {
  105. $ss = $this->_getSSObject();
  106. try {
  107. $results = $ss->getSlideShowsByTag(array('zend', 'php'), 0, 1);
  108. } catch(Exception $e) {
  109. $this->fail("Exception Caught retrieving Slideshow List (tag)");
  110. }
  111. $this->assertTrue(is_array($results));
  112. if(!empty($results)) {
  113. $this->assertTrue(count($results) == 1);
  114. $this->assertTrue($results[0] instanceof Zend_Service_SlideShare_SlideShow);
  115. }
  116. }
  117. public function testGetSlideShowByUsername()
  118. {
  119. $ss = $this->_getSSObject();
  120. try {
  121. $results = $ss->getSlideShowsByUsername(TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME, 0, 1);
  122. } catch(Exception $e) {
  123. $this->fail("Exception Caught retrieving Slideshow List (tag)");
  124. }
  125. $this->assertTrue(is_array($results));
  126. $this->assertTrue(count($results) == 1);
  127. $this->assertTrue($results[0] instanceof Zend_Service_SlideShare_SlideShow);
  128. }
  129. public function testUploadSlideShow()
  130. {
  131. $ss = $this->_getSSObject();
  132. $title = "Unit Test for ZF SlideShare Component";
  133. $ppt_file = dirname(__FILE__)."/SlideShare/_files/demo.ppt";
  134. $show = new Zend_Service_SlideShare_SlideShow();
  135. $show->setFilename($ppt_file);
  136. $show->setDescription("Unit Test");
  137. $show->setTitle($title);
  138. $show->setTags(array('unittest'));
  139. $show->setID(0);
  140. try {
  141. $result = $ss->uploadSlideShow($show, false);
  142. } catch(Exception $e) {
  143. if($e->getCode() == Zend_Service_SlideShare::SERVICE_ERROR_NOT_SOURCEOBJ) {
  144. // We ignore this exception, the web service sometimes throws this
  145. // error code because it seems to be buggy. Unfortunately it seems
  146. // to be sparatic so we can't code around it and have to call this
  147. // test a success
  148. return;
  149. } else {
  150. $this->fail("Exception Caught uploading slideshow");
  151. }
  152. }
  153. $this->assertTrue($result instanceof Zend_Service_SlideShare_SlideShow);
  154. $this->assertTrue($result->getId() > 0);
  155. $this->assertTrue($result->getTitle() === $title);
  156. }
  157. public function testSlideShowObj()
  158. {
  159. $ss = new Zend_Service_SlideShare_SlideShow();
  160. $ss->setDescription("Foo");
  161. $ss->setEmbedCode("Bar");
  162. $ss->setFilename("Baz");
  163. $ss->setId(123);
  164. $ss->setLocation("Somewhere");
  165. $ss->setNumViews(4432);
  166. $ss->setPermaLink("nowhere");
  167. $ss->setStatus(124);
  168. $ss->setStatusDescription("Boo");
  169. $ss->setTags(array('bar', 'baz'));
  170. $ss->addTag('fon');
  171. $ss->setThumbnailUrl('asdf');
  172. $ss->setTitle('title');
  173. $ss->setTranscript('none');
  174. $this->assertEquals($ss->getDescription(), "Foo");
  175. $this->assertEquals($ss->getEmbedCode(), "Bar");
  176. $this->assertEquals($ss->getFilename(), "Baz");
  177. $this->assertEquals($ss->getId(), 123);
  178. $this->assertEquals($ss->getLocation(), "Somewhere");
  179. $this->assertEquals($ss->getNumViews(), 4432);
  180. $this->assertEquals($ss->getPermaLink(), "nowhere");
  181. $this->assertEquals($ss->getStatus(), 124);
  182. $this->assertEquals($ss->getStatusDescription(), "Boo");
  183. $this->assertEquals($ss->getTags(), array('bar', 'baz', 'fon'));
  184. $this->assertEquals($ss->getThumbnailUrl(), "asdf");
  185. $this->assertEquals($ss->getTitle(), "title");
  186. $this->assertEquals($ss->getTranscript(), "none");
  187. }
  188. }