VideoEntryTest.php 39 KB

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