Index: trunk/phase3/tests/phpunit/includes/upload/UploadTest.php |
— | — | @@ -20,63 +20,14 @@ |
21 | 21 | $wgHooks = $this->hooks; |
22 | 22 | } |
23 | 23 | |
24 | | - /** |
25 | | - * Test various forms of valid and invalid titles that can be supplied. |
26 | | - */ |
27 | | - public function testTitleValidation() { |
28 | 24 | |
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 | | - } |
76 | 25 | /** |
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 |
79 | 30 | */ |
80 | | - private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) { |
| 31 | + public function testTitleValidation( $srcFilename, $dstFilename, $code, $msg ) { |
81 | 32 | /* Check the result code */ |
82 | 33 | $this->assertEquals( $code, |
83 | 34 | $this->upload->testTitleValidation( $srcFilename ), |
— | — | @@ -89,6 +40,41 @@ |
90 | 41 | "$msg text" ); |
91 | 42 | } |
92 | 43 | } |
| 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 | + } |
93 | 79 | |
94 | 80 | /** |
95 | 81 | * Test the upload verification functions |