Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created February 2, 2011 08:49
Show Gist options
  • Save yitsushi/807421 to your computer and use it in GitHub Desktop.
Save yitsushi/807421 to your computer and use it in GitHub Desktop.
test lib
<?php
namespace wsTestLib;
require LIB.'/wsYouTube.php';
class wsYouTube {
var $name = 'YouTube processor';
public function sunrise() {
$this->videos = array(
'available' => array(
'url' => 'http://www.youtube.com/watch?v=rhi26a7GBkA&feature=autoplay&list=PLD96D72C4F39A12B7&index=15&playnext=11',
'title' => '12 Girls Band - Flowers and Juveniles',
'thumb' => 'http://i.ytimg.com/vi/rhi26a7GBkA/0.jpg',
'watch' => 'http://www.youtube.com/watch?v=rhi26a7GBkA&feature=youtube_gdata_player'
),
'notexists' => array(
'url' => 'http://www.youtube.com/watch?v=rhi26a74BkA&feature=autoplay'
),
'adult' => array(
'url' => 'http://www.youtube.com/watch?v=zj4dix5Z248',
'title' => 'Tenacious D-Fuck Her Gently',
'thumb' => 'http://i.ytimg.com/vi/zj4dix5Z248/0.jpg',
'watch' => 'http://www.youtube.com/watch?v=zj4dix5Z248&feature=youtube_gdata_player'
)
);
}
public function test_fetch($c) {
$this->_test_video($c, "available", $this->videos['available'], true );
$this->_test_video($c, "not_exists", $this->videos['notexists'], false);
$this->_test_video($c, "adult", $this->videos['adult'], true );
}
public function sunset() {
unset($this->videos);
}
private function _test_video($c, $name, $video, $is_available) {
$yt = new \wsYouTube($video['url']);
try {
$yt->fetch();
$c->{"{$name}_video"}->is_true($is_available);
$c->{"{$name}_video_is_success"}->is_true($yt->is_success());
if ($yt->is_success()) {
$c->{"{$name}_video_title"}->assert($video['title'], $yt->title());
$c->{"{$name}_video_thumbnail_url"}->assert($video['thumb'], $yt->thumbnail_url());
$c->{"{$name}_video_watch_url"}->assert($video['watch'], $yt->watch_url());
}
} catch(\wsException $e) {
$c->{"{$name}_video"}->is_false($is_available);
$c->{"{$name}_video_is_failed"}->is_true($yt->is_success() == $is_available);
}
unset($yt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment