示例#1
0
 public function testObjectPropertiesSet()
 {
     $id = 1;
     $title = "title";
     $link = "test";
     $thumbsup = 12;
     $thumbsdown = 4;
     $channelid = "ueoueoueohtn13";
     $channeltitle = "channes tieont";
     $thumbnail = "ueaunehtoaunht";
     $description = "euohtnsuhetaoutnehnoaueohtauhtneoaunhteoanht\r\n\t\tueouhtenoauhteoa\r\n\t\tueaohueoa\r\n\t\theuaoueoaueohtnauhtneoau\r\n\t\teoauhteoauhtneonhtaunehto\r\n\t\tauhteaouehtnoauneoahtnueona\r\n\t\tuehtaouhteoahuneohauhneoahtn";
     $duration = 123213;
     $video = new MediaItem();
     $video->setId($id);
     $video->setLink($link);
     $video->setTitle($title);
     $video->setThumbsUp($thumbsup);
     $video->setThumbsDown($thumbsdown);
     $video->setChannelId($channelid);
     $video->setChannelTitle($channeltitle);
     $video->setThumbnail($thumbnail);
     $video->setDescription($description);
     $video->setDuration($duration);
     $refMediaItem = new \ReflectionObject($video);
     $idProp = $refMediaItem->getProperty('_id');
     $idProp->setAccessible(true);
     $titleProp = $refMediaItem->getProperty('_title');
     $titleProp->setAccessible(true);
     $linkProp = $refMediaItem->getProperty('_link');
     $linkProp->setAccessible(true);
     $thumbsupProp = $refMediaItem->getProperty('_thumbsup');
     $thumbsupProp->setAccessible(true);
     $thumbsdownProp = $refMediaItem->getProperty('_thumbsdown');
     $thumbsdownProp->setAccessible(true);
     $channelidProp = $refMediaItem->getProperty('_channelid');
     $channelidProp->setAccessible(true);
     $channeltitleProp = $refMediaItem->getProperty('_channeltitle');
     $channeltitleProp->setAccessible(true);
     $thumbnailProp = $refMediaItem->getProperty('_thumbnail');
     $thumbnailProp->setAccessible(true);
     $descriptionProp = $refMediaItem->getProperty('_description');
     $descriptionProp->setAccessible(true);
     $durationProp = $refMediaItem->getProperty('_duration');
     $durationProp->setAccessible(true);
     $this->assertEquals($id, $idProp->getValue($video), "ID not properly set by MediaItem setter method.");
     $this->assertEquals($title, $titleProp->getValue($video), "Title not properly set by MediaItem setter method.");
     $this->assertEquals($link, $linkProp->getValue($video), "Link not properly set by MediaItem setter method.");
     $this->assertEquals($thumbsup, $thumbsupProp->getValue($video), "Thumbsup not properly set by MediaItem setter method.");
     $this->assertEquals($thumbsdown, $thumbsdownProp->getValue($video), "Thumbsdown not properly set by MediaItem setter method.");
     $this->assertEquals($channelid, $channelidProp->getValue($video), "Channel ID not properly set by MediaItem setter method.");
     $this->assertEquals($channeltitle, $channeltitleProp->getValue($video), "channeltitle not properly set by MediaItem setter method.");
     $this->assertEquals($thumbnail, $thumbnailProp->getValue($video), "thumbnail not properly set by MediaItem setter method.");
     $this->assertEquals($description, $descriptionProp->getValue($video), "description not properly set by MediaItem setter method.");
     $this->assertEquals($duration, $durationProp->getValue($video), "duration not properly set by MediaItem setter method.");
 }
示例#2
0
 public function parseMediaItemFromResponse($singleResponse)
 {
     $mediaItem = new MediaItem();
     if (isset($singleResponse["id"])) {
         $mediaItem->setLink($singleResponse["id"]);
     } else {
         $mediaItem->setLink($singleResponse["id"]["videoId"]);
     }
     $mediaItem->setTitle($singleResponse["snippet"]["title"]);
     $mediaItem->setChannelId($singleResponse["snippet"]["channelId"]);
     $mediaItem->setChannelTitle($singleResponse["snippet"]["channelTitle"]);
     $mediaItem->setThumbnail($singleResponse["snippet"]["thumbnails"]["default"]["url"]);
     $mediaItem->setDescription($singleResponse["snippet"]["description"]);
     if (isset($singleResponse["contentDetails"])) {
         $mediaItem->setDuration($this->youtubeDurationToTimestamp($singleResponse["contentDetails"]["duration"]));
     } else {
         $mediaItem->setDuration(0);
     }
     return $mediaItem;
 }