SlideShareTest.php 8.4 KB

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