r98433 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98432‎ | r98433 | r98434 >
Date:19:08, 29 September 2011
Author:btongminh
Status:ok
Tags:
Comment:
Use data providers
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/upload/UploadTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/upload/UploadTest.php
@@ -20,63 +20,14 @@
2121 $wgHooks = $this->hooks;
2222 }
2323
24 - /**
25 - * Test various forms of valid and invalid titles that can be supplied.
26 - */
27 - public function testTitleValidation() {
2824
29 -
30 - /* Test a valid title */
31 - $this->assertUploadTitleAndCode( 'ValidTitle.jpg',
32 - 'ValidTitle.jpg', UploadBase::OK,
33 - 'upload valid title' );
34 -
35 - /* A title with a slash */
36 - $this->assertUploadTitleAndCode( 'A/B.jpg',
37 - 'B.jpg', UploadBase::OK,
38 - 'upload title with slash' );
39 -
40 - /* A title with illegal char */
41 - $this->assertUploadTitleAndCode( 'A:B.jpg',
42 - 'A-B.jpg', UploadBase::OK,
43 - 'upload title with colon' );
44 -
45 - /* Stripping leading File: prefix */
46 - $this->assertUploadTitleAndCode( 'File:C.jpg',
47 - 'C.jpg', UploadBase::OK,
48 - 'upload title with File prefix' );
49 -
50 - /* Test illegal suggested title (r94601) */
51 - $this->assertUploadTitleAndCode( '%281%29.JPG',
52 - null, UploadBase::ILLEGAL_FILENAME,
53 - 'illegal title for upload' );
54 -
55 - /* A title without extension */
56 - $this->assertUploadTitleAndCode( 'A',
57 - null, UploadBase::FILETYPE_MISSING,
58 - 'upload title without extension' );
59 -
60 - /* A title with no basename */
61 - $this->assertUploadTitleAndCode( '.jpg',
62 - null, UploadBase::MIN_LENGTH_PARTNAME,
63 - 'upload title without basename' );
64 -
65 - /* A title that is longer than 255 bytes */
66 - $this->assertUploadTitleAndCode( str_repeat( 'a', 255 ) . '.jpg',
67 - null, UploadBase::ILLEGAL_FILENAME,
68 - 'upload title longer than 255 bytes' );
69 -
70 - /* A title that is longer than 240 bytes */
71 - $this->assertUploadTitleAndCode( str_repeat( 'a', 240 ) . '.jpg',
72 - null, UploadBase::ILLEGAL_FILENAME,
73 - 'upload title longer than 240 bytes' );
74 -
75 - }
7625 /**
77 - * Helper function for testTitleValidation. First checks the return code
78 - * of UploadBase::getTitle() and then the actual returned titl
 26+ * First checks the return code
 27+ * of UploadBase::getTitle() and then the actual returned title
 28+ *
 29+ * @dataProvider dataTestTitleValidation
7930 */
80 - private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) {
 31+ public function testTitleValidation( $srcFilename, $dstFilename, $code, $msg ) {
8132 /* Check the result code */
8233 $this->assertEquals( $code,
8334 $this->upload->testTitleValidation( $srcFilename ),
@@ -89,6 +40,41 @@
9041 "$msg text" );
9142 }
9243 }
 44+
 45+ /**
 46+ * Test various forms of valid and invalid titles that can be supplied.
 47+ */
 48+ public function dataTestTitleValidation() {
 49+ return array(
 50+ /* Test a valid title */
 51+ array( 'ValidTitle.jpg', 'ValidTitle.jpg', UploadBase::OK,
 52+ 'upload valid title' ),
 53+ /* A title with a slash */
 54+ array( 'A/B.jpg', 'B.jpg', UploadBase::OK,
 55+ 'upload title with slash' ),
 56+ /* A title with illegal char */
 57+ array( 'A:B.jpg', 'A-B.jpg', UploadBase::OK,
 58+ 'upload title with colon' ),
 59+ /* Stripping leading File: prefix */
 60+ array( 'File:C.jpg', 'C.jpg', UploadBase::OK,
 61+ 'upload title with File prefix' ),
 62+ /* Test illegal suggested title (r94601) */
 63+ array( '%281%29.JPG', null, UploadBase::ILLEGAL_FILENAME,
 64+ 'illegal title for upload' ),
 65+ /* A title without extension */
 66+ array( 'A', null, UploadBase::FILETYPE_MISSING,
 67+ 'upload title without extension' ),
 68+ /* A title with no basename */
 69+ array( '.jpg', null, UploadBase::MIN_LENGTH_PARTNAME,
 70+ 'upload title without basename' ),
 71+ /* A title that is longer than 255 bytes */
 72+ array( str_repeat( 'a', 255 ) . '.jpg', null, UploadBase::ILLEGAL_FILENAME,
 73+ 'upload title longer than 255 bytes' ),
 74+ /* A title that is longer than 240 bytes */
 75+ array( str_repeat( 'a', 240 ) . '.jpg', null, UploadBase::ILLEGAL_FILENAME,
 76+ 'upload title longer than 240 bytes' ),
 77+ );
 78+ }
9379
9480 /**
9581 * Test the upload verification functions

Status & tagging log