VideoEntryTest.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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_YouTube
  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/YouTube/VideoEntry.php';
  23. require_once 'Zend/Gdata/YouTube/Extension/State.php';
  24. require_once 'Zend/Gdata/YouTube.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Gdata_YouTube
  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_YouTube
  33. */
  34. class Zend_Gdata_YouTube_VideoEntryTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function setUp() {
  37. $this->entryText = file_get_contents(
  38. 'Zend/Gdata/YouTube/_files/VideoEntryDataSample1.xml',
  39. true);
  40. $this->privateEntryText = file_get_contents(
  41. 'Zend/Gdata/YouTube/_files/VideoEntryDataSamplePrivate.xml',
  42. true);
  43. $this->v2EntryText = file_get_contents(
  44. 'Zend/Gdata/YouTube/_files/VideoEntryDataSampleV2.xml',
  45. true);
  46. $this->entry = new Zend_Gdata_YouTube_VideoEntry();
  47. }
  48. private function createRandomString() {
  49. $randomString = '';
  50. for ($x = 0; $x < 10; $x++) {
  51. $randomCharacter = chr(rand(97,122));
  52. $randomString .= $randomCharacter;
  53. }
  54. return $randomString;
  55. }
  56. private function verifyAllSamplePropertiesAreCorrect ($videoEntry) {
  57. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E',
  58. $videoEntry->id->text);
  59. $this->assertEquals('UMFI1hdm96E', $videoEntry->getVideoId());
  60. $this->assertEquals('2007-01-07T01:50:15.000Z', $videoEntry->updated->text);
  61. $this->assertEquals('http://schemas.google.com/g/2005#kind', $videoEntry->category[0]->scheme);
  62. $this->assertEquals('http://gdata.youtube.com/schemas/2007#video', $videoEntry->category[0]->term);
  63. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[1]->scheme);
  64. $this->assertEquals('barkley', $videoEntry->category[1]->term);
  65. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[2]->scheme);
  66. $this->assertEquals('singing', $videoEntry->category[2]->term);
  67. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[3]->scheme);
  68. $this->assertEquals('acoustic', $videoEntry->category[3]->term);
  69. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[4]->scheme);
  70. $this->assertEquals('cover', $videoEntry->category[4]->term);
  71. $this->assertEquals('http://gdata.youtube.com/schemas/2007/categories.cat', $videoEntry->category[5]->scheme);
  72. $this->assertEquals('Music', $videoEntry->category[5]->term);
  73. $this->assertEquals('Music', $videoEntry->category[5]->label);
  74. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[6]->scheme);
  75. $this->assertEquals('gnarls', $videoEntry->category[6]->term);
  76. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[7]->scheme);
  77. $this->assertEquals('music', $videoEntry->category[7]->term);
  78. $this->assertEquals('text', $videoEntry->title->type);
  79. $this->assertEquals('"Crazy (Gnarles Barkley)" - Acoustic Cover', $videoEntry->title->text);;
  80. $this->assertEquals('html', $videoEntry->content->type);
  81. $this->assertEquals('self', $videoEntry->getLink('self')->rel);
  82. $this->assertEquals('application/atom+xml', $videoEntry->getLink('self')->type);
  83. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E', $videoEntry->getLink('self')->href);
  84. $this->assertEquals('text/html', $videoEntry->getLink('alternate')->type);
  85. $this->assertEquals('http://www.youtube.com/watch?v=UMFI1hdm96E', $videoEntry->getLink('alternate')->href);
  86. $this->assertEquals('application/atom+xml', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.responses')->type);
  87. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E/responses', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.responses')->href);
  88. $this->assertEquals('application/atom+xml', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.related')->type);
  89. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E/related', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.related')->href);
  90. $this->assertEquals('davidchoimusic', $videoEntry->author[0]->name->text);
  91. $this->assertEquals('http://gdata.youtube.com/feeds/users/davidchoimusic', $videoEntry->author[0]->uri->text);
  92. $mediaGroup = $videoEntry->mediaGroup;
  93. $this->assertEquals('plain', $mediaGroup->title->type);
  94. $this->assertEquals('"Crazy (Gnarles Barkley)" - Acoustic Cover', $mediaGroup->title->text);
  95. $this->assertEquals('plain', $mediaGroup->description->type);
  96. $this->assertEquals('Gnarles Barkley acoustic cover http://www.myspace.com/davidchoimusic', $mediaGroup->description->text);
  97. $this->assertEquals('music, singing, gnarls, barkley, acoustic, cover', $mediaGroup->keywords->text);
  98. $this->assertEquals(255, $mediaGroup->duration->seconds);
  99. $this->assertEquals('Music', $mediaGroup->category[0]->label);
  100. $this->assertEquals('http://gdata.youtube.com/schemas/2007/categories.cat', $mediaGroup->category[0]->scheme);
  101. $this->assertEquals('http://gdata.youtube.com/schemas/2007/developertags.cat', $mediaGroup->category[1]->scheme);
  102. $this->assertEquals('DeveloperTag1', $mediaGroup->category[1]->text);
  103. $this->assertEquals('video', $mediaGroup->content[0]->medium);
  104. $this->assertEquals('http://www.youtube.com/v/UMFI1hdm96E', $mediaGroup->content[0]->url);
  105. $this->assertEquals('application/x-shockwave-flash', $mediaGroup->content[0]->type);
  106. $this->assertEquals('true', $mediaGroup->content[0]->isDefault);
  107. $this->assertEquals('full', $mediaGroup->content[0]->expression);
  108. $this->assertEquals(255, $mediaGroup->content[0]->duration);
  109. $this->assertEquals(5, $mediaGroup->content[0]->format);
  110. $this->assertEquals('http://www.youtube.com/watch?v=UMFI1hdm96E', $mediaGroup->player[0]->url);
  111. $this->assertEquals('http://img.youtube.com/vi/UMFI1hdm96E/2.jpg', $mediaGroup->thumbnail[0]->url);
  112. $this->assertEquals(97, $mediaGroup->thumbnail[0]->height);
  113. $this->assertEquals(130, $mediaGroup->thumbnail[0]->width);
  114. $this->assertEquals('00:02:07.500', $mediaGroup->thumbnail[0]->time);
  115. $this->assertEquals('http://img.youtube.com/vi/UMFI1hdm96E/1.jpg', $mediaGroup->thumbnail[1]->url);
  116. $this->assertEquals(97, $mediaGroup->thumbnail[1]->height);
  117. $this->assertEquals(130, $mediaGroup->thumbnail[1]->width);
  118. $this->assertEquals('00:01:03.750', $mediaGroup->thumbnail[1]->time);
  119. $this->assertEquals('http://img.youtube.com/vi/UMFI1hdm96E/3.jpg', $mediaGroup->thumbnail[2]->url);
  120. $this->assertEquals(97, $mediaGroup->thumbnail[2]->height);
  121. $this->assertEquals(130, $mediaGroup->thumbnail[2]->width);
  122. $this->assertEquals('00:03:11.250', $mediaGroup->thumbnail[2]->time);
  123. $this->assertEquals('http://img.youtube.com/vi/UMFI1hdm96E/0.jpg', $mediaGroup->thumbnail[3]->url);
  124. $this->assertEquals(240, $mediaGroup->thumbnail[3]->height);
  125. $this->assertEquals(320, $mediaGroup->thumbnail[3]->width);
  126. $this->assertEquals('00:02:07.500', $mediaGroup->thumbnail[3]->time);
  127. $this->assertNull($mediaGroup->private);
  128. $this->assertEquals(113321, $videoEntry->statistics->viewCount);
  129. $this->assertEquals(1, $videoEntry->rating->min);
  130. $this->assertEquals(5, $videoEntry->rating->max);
  131. $this->assertEquals(1005, $videoEntry->rating->numRaters);
  132. $this->assertEquals(4.77, $videoEntry->rating->average);
  133. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E/comments', $videoEntry->comments->feedLink->href);
  134. $this->assertEquals('37.398529052734375 -122.0635986328125', $videoEntry->where->point->pos->text);
  135. $this->assertEquals('2008-09-25', $videoEntry->getVideoRecorded());
  136. }
  137. private function verifyAllPrivateSamplePropertiesAreCorrect ($videoEntry) {
  138. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E',
  139. $videoEntry->id->text);
  140. $this->assertEquals('UMFI1hdm96E', $videoEntry->getVideoId());
  141. $this->assertEquals('2007-01-07T01:50:15.000Z', $videoEntry->updated->text);
  142. $this->assertEquals('http://schemas.google.com/g/2005#kind', $videoEntry->category[0]->scheme);
  143. $this->assertEquals('http://gdata.youtube.com/schemas/2007#video', $videoEntry->category[0]->term);
  144. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[1]->scheme);
  145. $this->assertEquals('barkley', $videoEntry->category[1]->term);
  146. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[2]->scheme);
  147. $this->assertEquals('singing', $videoEntry->category[2]->term);
  148. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[3]->scheme);
  149. $this->assertEquals('acoustic', $videoEntry->category[3]->term);
  150. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[4]->scheme);
  151. $this->assertEquals('cover', $videoEntry->category[4]->term);
  152. $this->assertEquals('http://gdata.youtube.com/schemas/2007/categories.cat', $videoEntry->category[5]->scheme);
  153. $this->assertEquals('Music', $videoEntry->category[5]->term);
  154. $this->assertEquals('Music', $videoEntry->category[5]->label);
  155. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[6]->scheme);
  156. $this->assertEquals('gnarls', $videoEntry->category[6]->term);
  157. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[7]->scheme);
  158. $this->assertEquals('music', $videoEntry->category[7]->term);
  159. $this->assertEquals('text', $videoEntry->title->type);
  160. $this->assertEquals('"Crazy (Gnarles Barkley)" - Acoustic Cover', $videoEntry->title->text);;
  161. $this->assertEquals('html', $videoEntry->content->type);
  162. $this->assertEquals('self', $videoEntry->getLink('self')->rel);
  163. $this->assertEquals('application/atom+xml', $videoEntry->getLink('self')->type);
  164. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E', $videoEntry->getLink('self')->href);
  165. $this->assertEquals('text/html', $videoEntry->getLink('alternate')->type);
  166. $this->assertEquals('http://www.youtube.com/watch?v=UMFI1hdm96E', $videoEntry->getLink('alternate')->href);
  167. $this->assertEquals('application/atom+xml', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.responses')->type);
  168. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E/responses', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.responses')->href);
  169. $this->assertEquals('application/atom+xml', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.related')->type);
  170. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E/related', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.related')->href);
  171. $this->assertEquals('davidchoimusic', $videoEntry->author[0]->name->text);
  172. $this->assertEquals('http://gdata.youtube.com/feeds/users/davidchoimusic', $videoEntry->author[0]->uri->text);
  173. $mediaGroup = $videoEntry->mediaGroup;
  174. $this->assertEquals('plain', $mediaGroup->title->type);
  175. $this->assertEquals('"Crazy (Gnarles Barkley)" - Acoustic Cover', $mediaGroup->title->text);
  176. $this->assertEquals('plain', $mediaGroup->description->type);
  177. $this->assertEquals('Gnarles Barkley acoustic cover http://www.myspace.com/davidchoimusic', $mediaGroup->description->text);
  178. $this->assertEquals('music, singing, gnarls, barkley, acoustic, cover', $mediaGroup->keywords->text);
  179. $this->assertEquals(255, $mediaGroup->duration->seconds);
  180. $this->assertEquals('Music', $mediaGroup->category[0]->label);
  181. $this->assertEquals('http://gdata.youtube.com/schemas/2007/categories.cat', $mediaGroup->category[0]->scheme);
  182. $this->assertEquals('http://gdata.youtube.com/schemas/2007/developertags.cat', $mediaGroup->category[1]->scheme);
  183. $this->assertEquals('DeveloperTag1', $mediaGroup->category[1]->text);
  184. $this->assertEquals('video', $mediaGroup->content[0]->medium);
  185. $this->assertEquals('http://www.youtube.com/v/UMFI1hdm96E', $mediaGroup->content[0]->url);
  186. $this->assertEquals('application/x-shockwave-flash', $mediaGroup->content[0]->type);
  187. $this->assertEquals('true', $mediaGroup->content[0]->isDefault);
  188. $this->assertEquals('full', $mediaGroup->content[0]->expression);
  189. $this->assertEquals(255, $mediaGroup->content[0]->duration);
  190. $this->assertEquals(5, $mediaGroup->content[0]->format);
  191. $this->assertEquals('http://www.youtube.com/watch?v=UMFI1hdm96E', $mediaGroup->player[0]->url);
  192. $this->assertEquals('http://img.youtube.com/vi/UMFI1hdm96E/2.jpg', $mediaGroup->thumbnail[0]->url);
  193. $this->assertEquals(97, $mediaGroup->thumbnail[0]->height);
  194. $this->assertEquals(130, $mediaGroup->thumbnail[0]->width);
  195. $this->assertEquals('00:02:07.500', $mediaGroup->thumbnail[0]->time);
  196. $this->assertEquals('http://img.youtube.com/vi/UMFI1hdm96E/1.jpg', $mediaGroup->thumbnail[1]->url);
  197. $this->assertEquals(97, $mediaGroup->thumbnail[1]->height);
  198. $this->assertEquals(130, $mediaGroup->thumbnail[1]->width);
  199. $this->assertEquals('00:01:03.750', $mediaGroup->thumbnail[1]->time);
  200. $this->assertEquals('http://img.youtube.com/vi/UMFI1hdm96E/3.jpg', $mediaGroup->thumbnail[2]->url);
  201. $this->assertEquals(97, $mediaGroup->thumbnail[2]->height);
  202. $this->assertEquals(130, $mediaGroup->thumbnail[2]->width);
  203. $this->assertEquals('00:03:11.250', $mediaGroup->thumbnail[2]->time);
  204. $this->assertEquals('http://img.youtube.com/vi/UMFI1hdm96E/0.jpg', $mediaGroup->thumbnail[3]->url);
  205. $this->assertEquals(240, $mediaGroup->thumbnail[3]->height);
  206. $this->assertEquals(320, $mediaGroup->thumbnail[3]->width);
  207. $this->assertEquals('00:02:07.500', $mediaGroup->thumbnail[3]->time);
  208. $this->assertTrue($mediaGroup->private instanceof Zend_Gdata_YouTube_Extension_Private);
  209. $this->assertEquals(113321, $videoEntry->statistics->viewCount);
  210. $this->assertEquals(1, $videoEntry->rating->min);
  211. $this->assertEquals(5, $videoEntry->rating->max);
  212. $this->assertEquals(1005, $videoEntry->rating->numRaters);
  213. $this->assertEquals(4.77, $videoEntry->rating->average);
  214. $this->assertEquals('http://gdata.youtube.com/feeds/videos/UMFI1hdm96E/comments', $videoEntry->comments->feedLink->href);
  215. $this->assertEquals('37.398529052734375 -122.0635986328125', $videoEntry->where->point->pos->text);
  216. $this->assertEquals('2008-09-25', $videoEntry->getVideoRecorded());
  217. }
  218. public function verifyAllV2SamplePropertiesAreCorrect($videoEntry) {
  219. $this->assertEquals('tag:youtube.com,2008:video:UMFI1hdm96E',
  220. $videoEntry->id->text);
  221. $this->assertEquals('UMFI1hdm96E', $videoEntry->getVideoId());
  222. $this->assertEquals('2008-12-08T04:04:33.000Z', $videoEntry->updated->text);
  223. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[0]->scheme);
  224. $this->assertEquals('cover', $videoEntry->category[0]->term);
  225. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[1]->scheme);
  226. $this->assertEquals('acoustic', $videoEntry->category[1]->term);
  227. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[2]->scheme);
  228. $this->assertEquals('gnarls', $videoEntry->category[2]->term);
  229. $this->assertEquals('http://schemas.google.com/g/2005#kind', $videoEntry->category[3]->scheme);
  230. $this->assertEquals('http://gdata.youtube.com/schemas/2007#video', $videoEntry->category[3]->term);
  231. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[4]->scheme);
  232. $this->assertEquals('barkley', $videoEntry->category[4]->term);
  233. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[5]->scheme);
  234. $this->assertEquals('music', $videoEntry->category[5]->term);
  235. $this->assertEquals('http://gdata.youtube.com/schemas/2007/keywords.cat', $videoEntry->category[6]->scheme);
  236. $this->assertEquals('singing', $videoEntry->category[6]->term);
  237. $this->assertEquals('http://gdata.youtube.com/schemas/2007/categories.cat', $videoEntry->category[7]->scheme);
  238. $this->assertEquals('Music', $videoEntry->category[7]->term);
  239. $this->assertEquals('text', $videoEntry->title->type);
  240. $this->assertEquals('"Crazy (Gnarles Barkley)" - Acoustic Cover', $videoEntry->title->text);;
  241. $this->assertEquals('application/x-shockwave-flash', $videoEntry->content->type);
  242. $this->assertEquals('self', $videoEntry->getLink('self')->rel);
  243. $this->assertEquals('application/atom+xml', $videoEntry->getLink('self')->type);
  244. $this->assertEquals('http://gdata.youtube.com/feeds/api/videos/UMFI1hdm96E?v=2', $videoEntry->getLink('self')->href);
  245. $this->assertEquals('text/html', $videoEntry->getLink('alternate')->type);
  246. $this->assertEquals('http://www.youtube.com/watch?v=UMFI1hdm96E', $videoEntry->getLink('alternate')->href);
  247. $this->assertEquals('application/atom+xml', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.responses')->type);
  248. $this->assertEquals('http://gdata.youtube.com/feeds/api/videos/UMFI1hdm96E/responses?v=2', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.responses')->href);
  249. $this->assertEquals('application/atom+xml', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.related')->type);
  250. $this->assertEquals('http://gdata.youtube.com/feeds/api/videos/UMFI1hdm96E/related?v=2', $videoEntry->getLink('http://gdata.youtube.com/schemas/2007#video.related')->href);
  251. $this->assertEquals('davidchoimusic', $videoEntry->author[0]->name->text);
  252. $this->assertEquals('http://gdata.youtube.com/feeds/api/users/davidchoimusic', $videoEntry->author[0]->uri->text);
  253. $mediaGroup = $videoEntry->mediaGroup;
  254. $this->assertEquals('UMFI1hdm96E', $mediaGroup->getVideoId()->text);
  255. $this->assertEquals('plain', $mediaGroup->title->type);
  256. $this->assertEquals('"Crazy (Gnarles Barkley)" - Acoustic Cover', $mediaGroup->title->text);
  257. $this->assertEquals('plain', $mediaGroup->description->type);
  258. $this->assertEquals('Gnarles Barkley acoustic cover http://www.myspace.com/davidchoimusic', $mediaGroup->description->text);
  259. $this->assertEquals('acoustic, barkley, cover, gnarls, music, singing', $mediaGroup->keywords->text);
  260. $this->assertEquals(255, $mediaGroup->duration->seconds);
  261. $this->assertEquals('http://gdata.youtube.com/schemas/2007/developertags.cat', $mediaGroup->category[0]->scheme);
  262. $this->assertEquals('DeveloperTag1', $mediaGroup->category[0]->text);
  263. $this->assertEquals('http://gdata.youtube.com/schemas/2007/categories.cat', $mediaGroup->category[1]->scheme);
  264. $this->assertEquals('Music', $mediaGroup->category[1]->text);
  265. $this->assertEquals('video', $mediaGroup->content[0]->medium);
  266. $this->assertEquals('http://www.youtube.com/v/UMFI1hdm96E&f=gdata_videos', $mediaGroup->content[0]->url);
  267. $this->assertEquals('application/x-shockwave-flash', $mediaGroup->content[0]->type);
  268. $this->assertEquals('true', $mediaGroup->content[0]->isDefault);
  269. $this->assertEquals('full', $mediaGroup->content[0]->expression);
  270. $this->assertEquals(255, $mediaGroup->content[0]->duration);
  271. $this->assertEquals(5, $mediaGroup->content[0]->format);
  272. $this->assertEquals('http://www.youtube.com/watch?v=UMFI1hdm96E', $mediaGroup->player[0]->url);
  273. $this->assertEquals('HK,TW', $mediaGroup->getMediaRating()->getCountry());
  274. $this->assertEquals(1, $mediaGroup->getMediaRating()->text);
  275. $this->assertEquals('http://gdata.youtube.com/schemas/2007#mediarating',
  276. $mediaGroup->getMediaRating()->getScheme());
  277. $this->assertEquals('http://i.ytimg.com/vi/UMFI1hdm96E/2.jpg', $mediaGroup->thumbnail[0]->url);
  278. $this->assertEquals(97, $mediaGroup->thumbnail[0]->height);
  279. $this->assertEquals(130, $mediaGroup->thumbnail[0]->width);
  280. $this->assertEquals('00:02:07.500', $mediaGroup->thumbnail[0]->time);
  281. $this->assertEquals('http://i.ytimg.com/vi/UMFI1hdm96E/1.jpg', $mediaGroup->thumbnail[1]->url);
  282. $this->assertEquals(97, $mediaGroup->thumbnail[1]->height);
  283. $this->assertEquals(130, $mediaGroup->thumbnail[1]->width);
  284. $this->assertEquals('00:01:03.750', $mediaGroup->thumbnail[1]->time);
  285. $this->assertEquals('http://i.ytimg.com/vi/UMFI1hdm96E/3.jpg', $mediaGroup->thumbnail[2]->url);
  286. $this->assertEquals(97, $mediaGroup->thumbnail[2]->height);
  287. $this->assertEquals(130, $mediaGroup->thumbnail[2]->width);
  288. $this->assertEquals('00:03:11.250', $mediaGroup->thumbnail[2]->time);
  289. $this->assertEquals('http://i.ytimg.com/vi/UMFI1hdm96E/0.jpg', $mediaGroup->thumbnail[3]->url);
  290. $this->assertEquals(240, $mediaGroup->thumbnail[3]->height);
  291. $this->assertEquals(320, $mediaGroup->thumbnail[3]->width);
  292. $this->assertEquals('00:02:07.500', $mediaGroup->thumbnail[3]->time);
  293. $this->assertEquals(267971, $videoEntry->statistics->viewCount);
  294. $this->assertEquals(1, $videoEntry->rating->min);
  295. $this->assertEquals(5, $videoEntry->rating->max);
  296. $this->assertEquals(2062, $videoEntry->rating->numRaters);
  297. $this->assertEquals(4.74, $videoEntry->rating->average);
  298. $this->assertEquals('http://gdata.youtube.com/feeds/api/videos/UMFI1hdm96E/comments?v=2', $videoEntry->comments->feedLink->href);
  299. $this->assertEquals('37.398529052734375 -122.0635986328125', $videoEntry->where->point->pos->text);
  300. $this->assertEquals('2008-09-25', $videoEntry->getVideoRecorded());
  301. }
  302. public function testGetVideoId() {
  303. $videoEntry = new Zend_Gdata_YouTube_VideoEntry();
  304. // assert valid ID
  305. $videoEntry->id = new Zend_Gdata_App_Extension_Id('http://gdata.youtube.com/feeds/videos/ABCDEFG12AB');
  306. $this->assertEquals('ABCDEFG12AB', $videoEntry->getVideoId());
  307. }
  308. public function testGetVideoIdV2() {
  309. $v2VideoEntry = new Zend_Gdata_YouTube_VideoEntry();
  310. $v2VideoEntry->setMajorProtocolVersion(2);
  311. $v2MediaGroup = new Zend_Gdata_YouTube_Extension_MediaGroup();
  312. $v2MediaGroup->setVideoId(
  313. new Zend_Gdata_YouTube_Extension_VideoId('UMFI1hdm96E'));
  314. $v2VideoEntry->setMediaGroup($v2MediaGroup);
  315. $this->assertEquals('UMFI1hdm96E', $v2VideoEntry->getVideoId());
  316. }
  317. public function testGetVideoIdException() {
  318. $exceptionCaught = false;
  319. $videoEntry = new Zend_Gdata_YouTube_VideoEntry();
  320. // use invalid ID
  321. $videoEntry->id = new Zend_Gdata_App_Extension_Id('adfadfasf');
  322. try {
  323. $videoEntry->getVideoId();
  324. } catch (Zend_Gdata_App_Exception $e) {
  325. $exceptionCaught = true;
  326. }
  327. $this->assertTrue($exceptionCaught, 'Expected exception not caught: ' .
  328. 'Zend_Gdata_AppException');
  329. }
  330. public function testGetVersionExceptionOnGetRacy() {
  331. $videoEntry = new Zend_Gdata_YouTube_VideoEntry();
  332. $videoEntry->setMajorProtocolVersion(2);
  333. $exceptionCaught = false;
  334. try {
  335. $videoEntry->getRacy();
  336. } catch (Zend_Gdata_App_VersionException $e) {
  337. $exceptionCaught = true;
  338. }
  339. $this->assertTrue($exceptionCaught, 'Expected exception not caught: ' .
  340. 'Zend_Gdata_App_VersionException');
  341. }
  342. public function testGetVersionExceptionOnSetRacy() {
  343. $videoEntry = new Zend_Gdata_YouTube_VideoEntry();
  344. $videoEntry->setMajorProtocolVersion(2);
  345. $exceptionCaught = false;
  346. try {
  347. $videoEntry->getRacy();
  348. } catch (Zend_Gdata_App_VersionException $e) {
  349. $exceptionCaught = true;
  350. }
  351. $this->assertTrue($exceptionCaught, 'Expected exception not caught: ' .
  352. 'Zend_Gdata_App_VersionException');
  353. }
  354. public function testEmptyEntryShouldHaveNoExtensionElements() {
  355. $this->assertTrue(is_array($this->entry->extensionElements));
  356. $this->assertTrue(count($this->entry->extensionElements) == 0);
  357. }
  358. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  359. $this->assertTrue(is_array($this->entry->extensionAttributes));
  360. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  361. }
  362. public function testSampleEntryShouldHaveNoExtensionElements() {
  363. $this->entry->transferFromXML($this->entryText);
  364. $this->assertTrue(is_array($this->entry->extensionElements));
  365. $this->assertTrue(count($this->entry->extensionElements) == 0);
  366. }
  367. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  368. $this->entry->transferFromXML($this->entryText);
  369. $this->assertTrue(is_array($this->entry->extensionAttributes));
  370. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  371. }
  372. public function testSampleEntryShouldHaveNoExtensionElementsV2() {
  373. $this->entry->transferFromXML($this->v2EntryText);
  374. $this->assertTrue(is_array($this->entry->extensionElements));
  375. $this->assertTrue(count($this->entry->extensionElements) == 0);
  376. }
  377. public function testSampleEntryShouldHaveNoExtensionAttributesV2() {
  378. $this->entry->transferFromXML($this->v2EntryText);
  379. $this->assertTrue(is_array($this->entry->extensionAttributes));
  380. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  381. }
  382. public function testEmptyVideoEntryToAndFromStringShouldMatch() {
  383. $entryXml = $this->entry->saveXML();
  384. $newVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
  385. $newVideoEntry->transferFromXML($entryXml);
  386. $newVideoEntryXml = $newVideoEntry->saveXML();
  387. $this->assertTrue($entryXml == $newVideoEntryXml);
  388. }
  389. public function testSamplePropertiesAreCorrect () {
  390. $this->entry->transferFromXML($this->entryText);
  391. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  392. }
  393. public function testPrivateSamplePropertiesAreCorrect () {
  394. $this->entry->transferFromXML($this->privateEntryText);
  395. $this->verifyAllPrivateSamplePropertiesAreCorrect($this->entry);
  396. }
  397. public function testV2SamplePropertiesAreCorrect() {
  398. $this->entry->transferFromXML($this->v2EntryText);
  399. $this->entry->setMajorProtocolVersion(2);
  400. $this->verifyAllV2SamplePropertiesAreCorrect($this->entry);
  401. }
  402. public function testGetVideoTitle() {
  403. $this->entry->transferFromXML($this->entryText);
  404. $videoEntry = $this->entry;
  405. $this->assertEquals('"Crazy (Gnarles Barkley)" - Acoustic Cover', $videoEntry->getVideoTitle());
  406. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  407. $this->assertEquals(null, $newEntry->getVideoTitle());
  408. }
  409. public function testSetVideoTitle() {
  410. $this->entry->transferFromXML($this->entryText);
  411. $videoEntry = $this->entry;
  412. $newTitle = 'My New Title';
  413. $videoEntry->setVideoTitle($newTitle);
  414. $this->assertEquals($videoEntry->getVideoTitle(), $newTitle);
  415. }
  416. public function testGetVideoDescription() {
  417. $this->entry->transferFromXML($this->entryText);
  418. $videoEntry = $this->entry;
  419. $this->assertEquals('Gnarles Barkley acoustic cover http://www.myspace.com/davidchoimusic', $videoEntry->getVideoDescription());
  420. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  421. $this->assertEquals(null, $newEntry->getVideoDescription());
  422. }
  423. public function testSetVideoDescription() {
  424. $this->entry->transferFromXML($this->entryText);
  425. $videoEntry = $this->entry;
  426. $newDescription = 'My New Description';
  427. $videoEntry->setVideoDescription($newDescription);
  428. $this->assertEquals($videoEntry->getVideoDescription(), $newDescription);
  429. }
  430. public function testGetVideoWatchPageUrl() {
  431. $this->entry->transferFromXML($this->entryText);
  432. $videoEntry = $this->entry;
  433. $this->assertEquals('http://www.youtube.com/watch?v=UMFI1hdm96E', $videoEntry->getVideoWatchPageUrl());
  434. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  435. $this->assertEquals(null, $newEntry->getVideoWatchPageUrl());
  436. }
  437. public function testGetVideoThumbnails() {
  438. $this->entry->transferFromXML($this->entryText);
  439. $videoEntry = $this->entry;
  440. $mediaThumbnails1 = $videoEntry->getMediaGroup()->getThumbnail();
  441. $mediaThumbnails2 = $videoEntry->getVideoThumbnails();
  442. $this->assertEquals(count($mediaThumbnails1), count($mediaThumbnails2));
  443. $foundThumbnail = false;
  444. foreach ($mediaThumbnails2 as $thumbnail) {
  445. if ($thumbnail['url'] == 'http://img.youtube.com/vi/UMFI1hdm96E/1.jpg') {
  446. $foundThumbnail = true;
  447. $this->assertEquals(97, $thumbnail['height']);
  448. $this->assertEquals(130, $thumbnail['width']);
  449. $this->assertEquals('00:01:03.750', $thumbnail['time']);
  450. }
  451. }
  452. $this->assertTrue($foundThumbnail);
  453. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  454. $this->assertEquals(array(), $newEntry->getVideoThumbnails());
  455. }
  456. public function testGetVideoTags() {
  457. $this->entry->transferFromXML($this->entryText);
  458. $videoEntry = $this->entry;
  459. $keywords = $videoEntry->getMediaGroup()->getKeywords();
  460. $keywordsString = (string) $keywords;
  461. if (strlen(trim($keywordsString)) > 0) {
  462. $keywordArray = preg_split('/(, *)|,/', $keywordsString);
  463. }
  464. $tagArray = $videoEntry->getVideoTags();
  465. $this->assertEquals(count($keywordArray), count($tagArray));
  466. foreach ($keywordArray as $keyword) {
  467. $this->assertTrue(in_array($keyword, $tagArray));
  468. }
  469. foreach ($tagArray as $tag) {
  470. $this->assertTrue(in_array($tag, $keywordArray));
  471. }
  472. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  473. $this->assertEquals(array(), $newEntry->getVideoTags());
  474. }
  475. public function testSetVideoTags() {
  476. $this->entry->transferFromXML($this->entryText);
  477. $videoEntry = $this->entry;
  478. $newKeywordsString = $this->createRandomString()
  479. . ', ' . $this->createRandomString();
  480. $videoEntry->setVideoTags($newKeywordsString);
  481. if (strlen(trim($newKeywordsString)) > 0) {
  482. $keywordArray = preg_split('/(, *)|,/', $newKeywordsString);
  483. }
  484. $tagArray = $videoEntry->getVideoTags();
  485. $this->assertEquals(count($keywordArray), count($tagArray));
  486. foreach ($keywordArray as $keyword) {
  487. $this->assertTrue(in_array($keyword, $tagArray));
  488. }
  489. foreach ($tagArray as $tag) {
  490. $this->assertTrue(in_array($tag, $keywordArray));
  491. }
  492. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  493. $this->assertEquals(array(), $newEntry->getVideoTags());
  494. }
  495. public function testGetVideoDeveloperTags() {
  496. $this->entry->transferFromXML($this->entryText);
  497. $videoEntry = $this->entry;
  498. $categories = $videoEntry->getMediaGroup()->getCategory();
  499. $developerTagsArrayFromMediaGroup = null;
  500. foreach($categories as $category) {
  501. if ($category->getScheme() == 'http://gdata.youtube.com/schemas/2007/developertags.cat') {
  502. $developerTagsArrayFromMediaGroup[] = $category->getText();
  503. }
  504. }
  505. $developerTagsArray = $videoEntry->getVideoDeveloperTags();
  506. $this->assertEquals(count($developerTagsArrayFromMediaGroup), count($developerTagsArray));
  507. foreach ($developerTagsArrayFromMediaGroup as $devTagMG) {
  508. $this->assertTrue(in_array($devTagMG, $developerTagsArrayFromMediaGroup));
  509. }
  510. foreach ($developerTagsArray as $devTag) {
  511. $this->assertTrue(in_array($devTag, $developerTagsArray));
  512. }
  513. }
  514. public function testSetVideoDeveloperTags() {
  515. $this->entry->transferFromXML($this->entryText);
  516. $videoEntry = $this->entry;
  517. $existingDevTags = $videoEntry->getVideoDeveloperTags();
  518. $newDeveloperTags = array(
  519. $this->createRandomString(),
  520. $this->createRandomString());
  521. $videoEntry->setVideoDeveloperTags($newDeveloperTags);
  522. $newAndOldDeveloperTags = array_merge($newDeveloperTags, $existingDevTags);
  523. $developerTagsArray = $videoEntry->getVideoDeveloperTags();
  524. $this->assertEquals(count($newAndOldDeveloperTags), count($developerTagsArray));
  525. foreach($developerTagsArray as $developerTagOnEntry) {
  526. $this->assertTrue(in_array($developerTagOnEntry, $newAndOldDeveloperTags));
  527. }
  528. }
  529. public function testGetFlashPlayerUrl() {
  530. $this->entry->transferFromXML($this->entryText);
  531. $videoEntry = $this->entry;
  532. $this->assertEquals('http://www.youtube.com/v/UMFI1hdm96E', $videoEntry->getFlashPlayerUrl());
  533. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  534. $this->assertEquals(null, $newEntry->getFlashPlayerUrl());
  535. }
  536. public function testGetVideoDuration() {
  537. $this->entry->transferFromXML($this->entryText);
  538. $videoEntry = $this->entry;
  539. $this->assertEquals(255, $videoEntry->getVideoDuration());
  540. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  541. $this->assertEquals(null, $newEntry->getVideoDuration());
  542. }
  543. public function testGetVideoViewCount() {
  544. $this->entry->transferFromXML($this->entryText);
  545. $videoEntry = $this->entry;
  546. $this->assertEquals(113321, $videoEntry->getVideoViewCount());
  547. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  548. $this->assertEquals(null, $newEntry->getVideoViewCount());
  549. }
  550. public function testGetVideoGeoLocation() {
  551. $this->entry->transferFromXML($this->entryText);
  552. $videoEntry = $this->entry;
  553. $geoLocation = $videoEntry->getVideoGeoLocation();
  554. $this->assertEquals('37.398529052734375', $geoLocation['latitude']);
  555. $this->assertEquals('-122.0635986328125', $geoLocation['longitude']);
  556. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  557. $this->assertEquals(null, $newEntry->getVideoGeoLocation());
  558. }
  559. public function testGetVideoRatingInfo() {
  560. $this->entry->transferFromXML($this->entryText);
  561. $videoEntry = $this->entry;
  562. $ratingInfo = $videoEntry->getVideoRatingInfo();
  563. $this->assertEquals(4.77, $ratingInfo['average']);
  564. $this->assertEquals(1005, $ratingInfo['numRaters']);
  565. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  566. $this->assertEquals(null, $newEntry->getVideoRatingInfo());
  567. }
  568. public function testGetVideoCategory() {
  569. $this->entry->transferFromXML($this->entryText);
  570. $videoEntry = $this->entry;
  571. $this->assertEquals('Music', $videoEntry->getVideoCategory());
  572. $newEntry = new Zend_Gdata_YouTube_VideoEntry();
  573. $this->assertEquals(null, $newEntry->getVideoCategory());
  574. }
  575. public function testSetVideoCategory() {
  576. $this->entry->transferFromXML($this->entryText);
  577. $videoEntry = $this->entry;
  578. $newCategory = 'Comedy';
  579. $videoEntry->setVideoCategory($newCategory);
  580. $this->assertEquals($videoEntry->getVideoCategory(), $newCategory);
  581. }
  582. public function testConvertVideoEntryToAndFromString() {
  583. $this->entry->transferFromXML($this->entryText);
  584. $entryXml = $this->entry->saveXML();
  585. $newVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
  586. $newVideoEntry->transferFromXML($entryXml);
  587. $this->verifyAllSamplePropertiesAreCorrect($newVideoEntry);
  588. $newVideoEntryXml = $newVideoEntry->saveXML();
  589. $this->assertEquals($entryXml, $newVideoEntryXml);
  590. }
  591. public function testNoEmbed() {
  592. $this->entry->transferFromXML($this->entryText);
  593. $videoEntry = $this->entry;
  594. $this->assertNotEquals(null, $videoEntry->getNoEmbed());
  595. }
  596. public function testVideoState() {
  597. $this->entry->transferFromXML($this->entryText);
  598. $videoEntry = $this->entry;
  599. $videoState = $videoEntry->getVideoState();
  600. $this->assertTrue($videoState instanceof Zend_Gdata_YouTube_Extension_State);
  601. $this->assertEquals('rejected', $videoState->getName());
  602. $this->assertEquals('inappropriate', $videoState->getReasonCode());
  603. $this->assertEquals('http://www.youtube.com/t/community_guidelines', $videoState->getHelpUrl());
  604. $this->assertEquals('The content of this video may violate the terms of use.',
  605. $videoState->getText());
  606. }
  607. public function testVideoPrivate() {
  608. $this->entry->transferFromXml($this->privateEntryText);
  609. $videoEntry = $this->entry;
  610. $this->assertTrue($videoEntry->isVideoPrivate());
  611. }
  612. public function testSetVideoPrivate() {
  613. $this->entry->transferFromXml($this->entryText);
  614. $videoEntry = $this->entry;
  615. $videoEntry->setVideoPrivate();
  616. $this->assertTrue($videoEntry->isVideoPrivate());
  617. }
  618. public function testSetVideoPublic() {
  619. $this->entry->transferFromXml($this->privateEntryText);
  620. $videoEntry = $this->entry;
  621. $videoEntry->setVideoPublic();
  622. $this->assertFalse($videoEntry->isVideoPrivate());
  623. }
  624. public function testRetrieveCommentsFeedUrl() {
  625. $this->entry->transferFromXML($this->entryText);
  626. $commentsFeedUrl = $this->entry->getVideoCommentFeedUrl();
  627. $this->assertEquals($commentsFeedUrl,
  628. 'http://gdata.youtube.com/feeds/videos/UMFI1hdm96E/comments');
  629. }
  630. public function testAddVideoEntryRating()
  631. {
  632. $this->entry->transferFromXML($this->entryText);
  633. $ratingValue = 2;
  634. $entryWithRating = $this->entry->setVideoRating($ratingValue);
  635. $this->assertTrue(
  636. $entryWithRating instanceof Zend_Gdata_YouTube_VideoEntry);
  637. $rating = $entryWithRating->getRating();
  638. $this->assertTrue(
  639. $rating instanceof Zend_Gdata_Extension_Rating);
  640. $this->assertEquals($rating->getValue(), $ratingValue);
  641. }
  642. }