5 class UploadTest
extends PHPUnit_Framework_TestCase
{
12 $wgContLang = Language
::factory( 'en' );
13 $this->upload
= new UploadTestHandler
;
17 * Test various forms of valid and invalid titles that can be supplied.
19 public function testTitleValidation() {
22 /* Test a valid title */
23 $this->assertUploadTitleAndCode( 'ValidTitle.jpg',
24 'ValidTitle.jpg', UploadTestHandler
::OK
,
25 'upload valid title' );
27 /* A title with a slash */
28 $this->assertUploadTitleAndCode( 'A/B.jpg',
29 'B.jpg', UploadTestHandler
::OK
,
30 'upload title with slash' );
32 /* A title with illegal char */
33 $this->assertUploadTitleAndCode( 'A:B.jpg',
34 'A-B.jpg', UploadTestHandler
::OK
,
35 'upload title with colon' );
37 /* A title without extension */
38 $this->assertUploadTitleAndCode( 'A',
39 null, UploadTestHandler
::FILETYPE_MISSING
,
40 'upload title without extension' );
42 /* A title with no basename */
43 $this->assertUploadTitleAndCode( '.jpg',
44 null, UploadTestHandler
::MIN_LENGTH_PARTNAME
,
45 'upload title without basename' );
49 * Helper function for testTitleValidation. First checks the return code
50 * of UploadBase::getTitle() and then the actual returned titl
52 private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) {
53 /* Check the result code */
54 $this->assertEquals( $code,
55 $this->upload
->testTitleValidation( $srcFilename ),
58 /* If we expect a valid title, check the title itself. */
59 if ( $code == UploadTestHandler
::OK
) {
60 $this->assertEquals( $dstFilename,
61 $this->upload
->getTitle()->getText(),
67 * Test the upload verification functions
69 public function testVerifyUpload() {
70 /* Setup with zero file size */
71 $this->upload
->initializePathInfo( '', '', 0 );
72 $result = $this->upload
->verifyUpload();
73 $this->assertEquals( UploadTestHandler
::EMPTY_FILE
,
75 'upload empty file' );
80 class UploadTestHandler
extends UploadBase
{
81 public function initializeFromRequest( &$request ) { }
82 public function testTitleValidation( $name ) {
83 $this->mTitle
= false;
84 $this->mDesiredDestName
= $name;
86 return $this->mTitleError
;