From: Bryan Tong Minh Date: Thu, 29 Sep 2011 19:08:08 +0000 (+0000) Subject: Use data providers X-Git-Tag: 1.31.0-rc.0~27366 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=e0a6ac24e3aa263b1f8edb83db882399067ebab2;p=lhc%2Fweb%2Fwiklou.git Use data providers --- diff --git a/tests/phpunit/includes/upload/UploadTest.php b/tests/phpunit/includes/upload/UploadTest.php index f74018a5a4..d0da0341fa 100644 --- a/tests/phpunit/includes/upload/UploadTest.php +++ b/tests/phpunit/includes/upload/UploadTest.php @@ -20,63 +20,14 @@ class UploadTest extends MediaWikiTestCase { $wgHooks = $this->hooks; } - /** - * Test various forms of valid and invalid titles that can be supplied. - */ - public function testTitleValidation() { - - - /* Test a valid title */ - $this->assertUploadTitleAndCode( 'ValidTitle.jpg', - 'ValidTitle.jpg', UploadBase::OK, - 'upload valid title' ); - - /* A title with a slash */ - $this->assertUploadTitleAndCode( 'A/B.jpg', - 'B.jpg', UploadBase::OK, - 'upload title with slash' ); - - /* A title with illegal char */ - $this->assertUploadTitleAndCode( 'A:B.jpg', - 'A-B.jpg', UploadBase::OK, - 'upload title with colon' ); - - /* Stripping leading File: prefix */ - $this->assertUploadTitleAndCode( 'File:C.jpg', - 'C.jpg', UploadBase::OK, - 'upload title with File prefix' ); - - /* Test illegal suggested title (r94601) */ - $this->assertUploadTitleAndCode( '%281%29.JPG', - null, UploadBase::ILLEGAL_FILENAME, - 'illegal title for upload' ); - - /* A title without extension */ - $this->assertUploadTitleAndCode( 'A', - null, UploadBase::FILETYPE_MISSING, - 'upload title without extension' ); - - /* A title with no basename */ - $this->assertUploadTitleAndCode( '.jpg', - null, UploadBase::MIN_LENGTH_PARTNAME, - 'upload title without basename' ); - - /* A title that is longer than 255 bytes */ - $this->assertUploadTitleAndCode( str_repeat( 'a', 255 ) . '.jpg', - null, UploadBase::ILLEGAL_FILENAME, - 'upload title longer than 255 bytes' ); - - /* A title that is longer than 240 bytes */ - $this->assertUploadTitleAndCode( str_repeat( 'a', 240 ) . '.jpg', - null, UploadBase::ILLEGAL_FILENAME, - 'upload title longer than 240 bytes' ); - } /** - * Helper function for testTitleValidation. First checks the return code - * of UploadBase::getTitle() and then the actual returned titl + * First checks the return code + * of UploadBase::getTitle() and then the actual returned title + * + * @dataProvider dataTestTitleValidation */ - private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) { + public function testTitleValidation( $srcFilename, $dstFilename, $code, $msg ) { /* Check the result code */ $this->assertEquals( $code, $this->upload->testTitleValidation( $srcFilename ), @@ -89,6 +40,41 @@ class UploadTest extends MediaWikiTestCase { "$msg text" ); } } + + /** + * Test various forms of valid and invalid titles that can be supplied. + */ + public function dataTestTitleValidation() { + return array( + /* Test a valid title */ + array( 'ValidTitle.jpg', 'ValidTitle.jpg', UploadBase::OK, + 'upload valid title' ), + /* A title with a slash */ + array( 'A/B.jpg', 'B.jpg', UploadBase::OK, + 'upload title with slash' ), + /* A title with illegal char */ + array( 'A:B.jpg', 'A-B.jpg', UploadBase::OK, + 'upload title with colon' ), + /* Stripping leading File: prefix */ + array( 'File:C.jpg', 'C.jpg', UploadBase::OK, + 'upload title with File prefix' ), + /* Test illegal suggested title (r94601) */ + array( '%281%29.JPG', null, UploadBase::ILLEGAL_FILENAME, + 'illegal title for upload' ), + /* A title without extension */ + array( 'A', null, UploadBase::FILETYPE_MISSING, + 'upload title without extension' ), + /* A title with no basename */ + array( '.jpg', null, UploadBase::MIN_LENGTH_PARTNAME, + 'upload title without basename' ), + /* A title that is longer than 255 bytes */ + array( str_repeat( 'a', 255 ) . '.jpg', null, UploadBase::ILLEGAL_FILENAME, + 'upload title longer than 255 bytes' ), + /* A title that is longer than 240 bytes */ + array( str_repeat( 'a', 240 ) . '.jpg', null, UploadBase::ILLEGAL_FILENAME, + 'upload title longer than 240 bytes' ), + ); + } /** * Test the upload verification functions