r85097 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85096‎ | r85097 | r85098 >
Date:22:39, 31 March 2011
Author:dale
Status:deferred
Tags:
Comment:
phpunit testing stubs ( not working yet )
Modified paths:
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/tests/phpunit/TimedMediaHandlerApiUploadVideoTest.php (added) (history)
  • /trunk/extensions/TimedMediaHandler/tests/phpunit/TimedMediaHandlerApiVideoInfoTest.php (added) (history)
  • /trunk/extensions/TimedMediaHandler/tests/phpunit/TimedMediaHandlerTestSuite.php (added) (history)
  • /trunk/extensions/TimedMediaHandler/tests/phpunit/WebVideoApiVideoInfoTest.php (deleted) (history)
  • /trunk/extensions/TimedMediaHandler/tests/phpunit/media (added) (history)
  • /trunk/extensions/TimedMediaHandler/tests/phpunit/media/test5seconds.electricsheep.300x400.ogv (added) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/tests/phpunit/WebVideoApiVideoInfoTest.php
@@ -1,16 +0,0 @@
2 -<?php
3 -
4 -require_once 'PHPUnit/Framework/TestCase.php';
5 -require_once dirname(__FILE__) . '/commandLine.inc';
6 -
7 -/**
8 - * TMHApiVideoInfoTest test case.
9 - *
10 - * @ingroup timedmedia
11 - * @since 0.2
12 - * @author Michael Dale
13 - */
14 -class TMHApiVideoInfoTest extends PHPUnit_Framework_TestCase {
15 -
16 -
17 -}
\ No newline at end of file
Index: trunk/extensions/TimedMediaHandler/tests/phpunit/media/test5seconds.electricsheep.300x400.ogv
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/extensions/TimedMediaHandler/tests/phpunit/media/test5seconds.electricsheep.300x400.ogv
___________________________________________________________________
Added: svn:mime-type
181 + application/octet-stream
Index: trunk/extensions/TimedMediaHandler/tests/phpunit/TimedMediaHandlerTestSuite.php
@@ -0,0 +1,47 @@
 2+<?php
 3+
 4+require_once 'PHPUnit/Framework/TestSuite.php';
 5+
 6+// Guess the MW_INSTALL_PATH
 7+$IP = ( getenv( 'MW_INSTALL_PATH' ) !== false
 8+ ? getenv( 'MW_INSTALL_PATH' )
 9+ : dirname( __FILE__ ) . '/../../../../' );
 10+
 11+// Include the phpunit test system:
 12+require( "$IP/tests/phpunit/phpunit.php" );
 13+
 14+// Add needed tests files ( why don't we have test files in autoloader when running the test suite? )
 15+require( "$IP/tests/phpunit/MediaWikiTestCase.php" );
 16+require( "$IP/tests/phpunit/includes/api/ApiSetup.php" );
 17+require( "$IP/tests/phpunit/includes/api/ApiUploadTest.php" );
 18+require( dirname( __FILE__ ) . '/TimedMediaHandlerApiUploadVideoTest.php' );
 19+require( dirname( __FILE__ ) . '/TimedMediaHandlerApiVideoInfoTest.php' );
 20+
 21+/**
 22+ * Static test suite.
 23+ *
 24+ * @ingroup timedmedia
 25+ * @since 0.6.5
 26+ * @author Michael Dale
 27+ */
 28+class TimedMediaHandlerTestSuite extends PHPUnit_Framework_TestSuite {
 29+
 30+ /**
 31+ * Constructs the test suite handler.
 32+ */
 33+ public function __construct() {
 34+ $this->setName ( 'TimedMediaHandlerTestSuite' );
 35+
 36+ $this->addTestSuite ( 'TimedMediaHandlerApiUploadVideoTest' );
 37+
 38+ //$this->addTestSuite ( 'TimedMediaHandlerApiVideoInfoTest' );
 39+ }
 40+
 41+ /**
 42+ * Creates the suite.
 43+ */
 44+ public static function suite() {
 45+ return new self ( );
 46+ }
 47+}
 48+
Index: trunk/extensions/TimedMediaHandler/tests/phpunit/TimedMediaHandlerApiVideoInfoTest.php
@@ -0,0 +1,23 @@
 2+<?php
 3+require_once 'PHPUnit/Framework/TestCase.php';
 4+
 5+/**
 6+ * TimedMediaHandlerApiVideoInfoTest test case.
 7+ *
 8+ * @ingroup timedmedia
 9+ * @since 0.2
 10+ * @author Michael Dale
 11+ */
 12+class TimedMediaHandlerApiVideoInfoTest extends ApiTestSetup {
 13+
 14+ public function setUp() {
 15+ parent::setUp();
 16+
 17+ wfSetupSession();
 18+
 19+ ini_set( 'log_errors', 1 );
 20+ ini_set( 'error_reporting', 1 );
 21+ ini_set( 'display_errors', 1 );
 22+
 23+ }
 24+}
\ No newline at end of file
Index: trunk/extensions/TimedMediaHandler/tests/phpunit/TimedMediaHandlerApiUploadVideoTest.php
@@ -0,0 +1,60 @@
 2+<?php
 3+/**
 4+ * TMHApiVideoInfoTest test case.
 5+ *
 6+ * @ingroup timedmedia
 7+ * @since 0.2
 8+ * @author Michael Dale
 9+ */
 10+
 11+class TimedMediaHandlerApiUploadVideoTest extends ApiUploadTest {
 12+
 13+ /**
 14+ * @depends testLogin
 15+ */
 16+ public function testVideoUpload( $session ){
 17+ global $wgUser;
 18+ $wgUser = self::$users['uploader']->user;
 19+
 20+ $extension = 'ogv';
 21+ $mimeType = 'video/ogg';
 22+
 23+ // Grab a test ogg video:
 24+ $filePath = dirname( __FILE__ ) . '/media/test5seconds.electricsheep.300x400.ogv';
 25+
 26+ $fileSize = filesize( $filePath );
 27+ $fileName = basename( $filePath );
 28+
 29+ // remove if already in thd db:
 30+ $this->deleteFileByFileName( $fileName );
 31+ $this->deleteFileByContent( $filePath );
 32+
 33+ if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePath ) ) {
 34+ $this->markTestIncomplete( "Couldn't upload file!\n" );
 35+ }
 36+
 37+ $params = array(
 38+ 'action' => 'upload',
 39+ 'filename' => $fileName,
 40+ 'file' => 'dummy content',
 41+ 'comment' => 'dummy comment',
 42+ 'text' => "This is the page text for $fileName",
 43+ );
 44+
 45+ $exception = false;
 46+ try {
 47+ list( $result, , ) = $this->doApiRequestWithToken( $params, $session );
 48+ } catch ( UsageException $e ) {
 49+ $exception = true;
 50+ }
 51+ $this->assertTrue( isset( $result['upload'] ) );
 52+ $this->assertEquals( 'Success', $result['upload']['result'] );
 53+ $this->assertEquals( $fileSize, ( int )$result['upload']['imageinfo']['size'] );
 54+ $this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] );
 55+ $this->assertFalse( $exception );
 56+
 57+ // clean up
 58+ $this->deleteFileByFilename( $fileName );
 59+ unlink( $filePath );
 60+ }
 61+}
\ No newline at end of file
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.php
@@ -127,8 +127,8 @@
128128 $wgExtensionMessagesFiles['TimedMediaHandlerMagic'] = "$timedMediaDir/TimedMediaHandler.i18n.magic.php";
129129
130130 // Register all Timed Media Handler hooks right after the cache check.
131 -// This way if you set a variable like $wgTimedTextNS after you include TimedMediaHandler its
132 -// used as the hooks are registred.
 131+// This way if you set a variable like $wgTimedTextNS in LocalSettings.php after you include TimedMediaHandler
 132+// we can still read the variable values
133133 $wgHooks['SetupAfterCache'][] = 'TimedMediaHandlerHooks::register';
134134
135135 // Extension Credits
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php
@@ -53,6 +53,9 @@
5454 $wgHooks['BeforePageDisplay'][] = 'TimedMediaHandlerHooks::pageOutputHook';
5555
5656
 57+ // Add unit tests
 58+ $wgHooks['UnitTestsList'][] = 'TimedMediaHandlerHooks::registerUnitTests';
 59+
5760 // Exclude transcoded assets from normal thumbnail purging
5861 // ( a maintenance script could handle transcode asset purging)
5962 $wgExcludeFromThumbnailPurge = array_merge( $wgExcludeFromThumbnailPurge, $tmhFileExtensions );
@@ -76,6 +79,20 @@
7780
7881 return true;
7982 }
 83+
 84+ /**
 85+ * Hook to add list of PHPUnit test cases.
 86+ *
 87+ * @since 0.7
 88+ *
 89+ * @param array $files
 90+ */
 91+ public static function registerUnitTests( array &$files ) {
 92+ $testDir = dirname( __FILE__ ) . '/tests/phpunit';
 93+ $files[] = $testDir . 'TimedMediaHandlerTestSuite.php';
 94+ return true;
 95+ }
 96+
8097 static function pageOutputHook( &$out, &$sk ){
8198 // FIXME we should only need to add this via parser output hook
8299 $out->addModules( 'PopUpMediaTransform' );

Status & tagging log