VideoEntryTest.php 39 KB

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