cvs: pear /Services_YouTube/tests AllTests.php YouTubeTest.php

From: Date: Sat, 30 Sep 2006 18:14:05 +0000
Subject: cvs: pear /Services_YouTube/tests AllTests.php YouTubeTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-42322@lists.php.net to get a copy of this message
shin Sat Sep 30 18:14:05 2006 UTC Added files: /pear/Services_YouTube/tests AllTests.php YouTubeTest.php Log: Added UnitTests

http://cvs.php.net/viewvc.cgi/pear/Services_YouTube/tests/AllTests.php?view=markup&rev=1.1 Index: pear/Services_YouTube/tests/AllTests.php +++ pear/Services_YouTube/tests/AllTests.php <?php if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'AllTests::main'); chdir(dirname(__FILE__)); } if (!defined('PHPUnit2_INSIDE_OWN_TESTSUITE')) { define('PHPUnit2_INSIDE_OWN_TESTSUITE', TRUE); } require_once 'PHPUnit2/Framework/TestSuite.php'; require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once 'YouTubeTest.php'; class AllTests { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('Services'); /** Add testsuites, if there is. */ $suite->addTestSuite('YouTubeTest'); return $suite; } } if (PHPUnit2_MAIN_METHOD == 'AllTests::main') { AllTests::main(); } ?> http://cvs.php.net/viewvc.cgi/pear/Services_YouTube/tests/YouTubeTest.php?view=markup&rev=1.1 Index: pear/Services_YouTube/tests/YouTubeTest.php +++ pear/Services_YouTube/tests/YouTubeTest.php <?php // All tests are require Cache_Lite. error_reporting(E_ALL|E_STRICT); require_once '../YouTube.php'; class YouTubeTest extends PHPUnit2_Framework_TestCase { const DEV_ID = 'E88fqlcDtlM'; // {{{ setter tests using Mock class public function testSetDriver() { try { $youtube = new Services_YouTubeMock(self::DEV_ID); $this->assertEquals('rest', $youtube->getDriver()); $youtube->setDriver('xmlrpc'); $this->assertEquals('xmlrpc', $youtube->getDriver()); $youtube->setDriver('rest'); $this->assertEquals('rest', $youtube->getDriver()); // throw Exception $youtube->setDriver("throw exception"); } catch (Services_YouTube_Exception $e) { $this->assertEquals('Driver has to be "xmlrpc" or "rest"', $e->getMessage()); } } public function testSetResponseFormat() { try { $youtube = new Services_YouTubeMock(self::DEV_ID); $this->assertEquals('object', $youtube->getResponseFormat()); $youtube->setResponseFormat('array'); $this->assertEquals('array', $youtube->getResponseFormat()); $youtube->setResponseFormat('object'); $this->assertEquals('object', $youtube->getResponseFormat()); // throw Exception $youtube->setResponseFormat("throw exception"); } catch (Services_YouTube_Exception $e) { $this->assertEquals('ResponseFormat has to be "object" or "array"', $e->getMessage()); } } public function testSetUseCache() { $youtube = new Services_YouTubeMock(self::DEV_ID); $this->assertFalse($youtube->getUseCache()); $this->assertEquals(array(), $youtube->getCacheOptions()); $youtube->setUseCache(true); $this->assertTrue($youtube->getUseCache()); $this->assertEquals(array(), $youtube->getCacheOptions()); $youtube->setUseCache(true, array('lifeTime' => 18000)); $this->assertTrue($youtube->getUseCache()); $this->assertEquals(array('lifeTime' => 18000), $youtube->getCacheOptions()); } // }}} // {{{ user API public function testGetProfile() { try { $youtube = new Services_YouTube(self::DEV_ID); $youtube->setUseCache(true); $data = $youtube->getProfile('ganchiku'); $profile = $data->user_profile; $this->assertEquals('Shin', $profile->first_name); $this->assertEquals('Ohno', $profile->last_name); $youtube->setResponseFormat('array'); $data = $youtube->getProfile('ganchiku'); $profile = $data['user_profile']; $this->assertEquals('Shin', $profile['first_name']); $this->assertEquals('Ohno', $profile['last_name']); } catch (Services_YouTube_Exception $e) { print $e; } } public function testListFavoriteVideos() { try { $youtube = new Services_YouTube(self::DEV_ID); $youtube->setUseCache(true); $data = $youtube->listFavoriteVideos('ganchiku'); $videos = $data->xpath('//video'); $this->assertTrue(is_array($videos)); $youtube->setResponseFormat('array'); $data = $youtube->listFavoriteVideos('ganchiku'); $this->assertTrue(is_array($data['video_list'])); } catch (Services_YouTube_Exception $e) { print $e; } } public function testListFriends() { try { $youtube = new Services_YouTube(self::DEV_ID); $youtube->setUseCache(true); $data = $youtube->listFriends('ganchiku'); $this->assertTrue(isset($data->friend_list)); // i have no friends... orz... $this->assertEquals(0, $data->friend_list); $youtube->setResponseFormat('array'); $data = $youtube->listFriends('ganchiku'); $this->assertTrue(array_key_exists('friend_list', $data)); } catch (Services_YouTube_Exception $e) { print $e; } } // }}} // {{{ video API public function testGetDetails() { try { $youtube = new Services_YouTube(self::DEV_ID); $youtube->setUseCache(true); $data = $youtube->getDetails('rdwz7QiG0lk'); $video = $data->video_details; $this->assertEquals('YouTube', $video->author); $youtube->setResponseFormat('array'); $data = $youtube->getDetails('rdwz7QiG0lk'); $video = $data['video_details']; $this->assertEquals('YouTube', $video['author']); } catch (Services_YouTube_Exception $e) { print $e; } } public function testListByTag() { try { $youtube = new Services_YouTube(self::DEV_ID); $youtube->setUseCache(true); $data = $youtube->listByTag('YouTube'); $videos = $data->xpath('//video'); $this->assertTrue(is_array($videos)); $youtube->setResponseFormat('array'); $data = $youtube->listByTag('YouTube'); $this->assertTrue(is_array($data['video_list'])); // Hmm... need to integrate pager parameters } catch (Services_YouTube_Exception $e) { print $e; } } public function testListByUser() { try { $youtube = new Services_YouTube(self::DEV_ID); $youtube->setUseCache(true); $data = $youtube->listByUser('ganchiku'); // i have not uploaded any videos... orz... $this->assertEquals(0, $data->video_list); $youtube->setResponseFormat('array'); $data = $youtube->listByUser('ganchiku'); $this->assertNull($data['video_list']); } catch (Services_YouTube_Exception $e) { print $e; } } public function testListFeatured() { try { $youtube = new Services_YouTube(self::DEV_ID); $youtube->setUseCache(true); $data = $youtube->listFeatured(); $videos = $data->xpath('//video'); $this->assertEquals(25, count($videos)); $youtube->setResponseFormat('array'); $data = $youtube->listFeatured(); $this->assertEquals(25, count($data['video_list']['video'])); } catch (Services_YouTube_Exception $e) { print $e; } } // }}} } // {{{ Mock Class FOR GETTER class Services_YouTubeMock extends Services_YouTube { public function getDriver() { return $this->driver; } public function getResponseFormat() { return $this->responseFormat; } public function getUseCache() { return $this->useCache; } public function getCacheOptions() { return $this->cacheOptions; } } // }}} ?>
« previous php.pear.cvs (#42322) next »