2
0

SlideShareTest.php 7.5 KB

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