5 class UploadTest
extends PHPUnit_Framework_TestCase
{
11 $this->upload
= new UploadTestHandler
;
15 * Test various forms of valid and invalid titles that can be supplied.
17 public function testTitleValidation() {
20 /* Test a valid title */
21 $this->assertUploadTitleAndCode( 'ValidTitle.jpg',
22 'ValidTitle.jpg', UploadTestHandler
::OK
,
23 'upload valid title' );
25 /* A title with a slash */
26 $this->assertUploadTitleAndCode( 'A/B.jpg',
27 'B.jpg', UploadTestHandler
::OK
,
28 'upload title with slash' );
30 /* A title with illegal char */
31 $this->assertUploadTitleAndCode( 'A:B.jpg',
32 'A-B.jpg', UploadTestHandler
::OK
,
33 'upload title with colon' );
35 /* A title without extension */
36 $this->assertUploadTitleAndCode( 'A',
37 null, UploadTestHandler
::FILETYPE_MISSING
,
38 'upload title without extension' );
40 /* A title with no basename */
41 $this->assertUploadTitleAndCode( '.jpg',
42 null, UploadTestHandler
::MIN_LENGTH_PARTNAME
,
43 'upload title without basename' );
47 * Helper function for testTitleValidation. First checks the return code
48 * of UploadBase::getTitle() and then the actual returned titl
50 private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) {
51 /* Check the result code */
52 $this->assertEquals( $code,
53 $this->upload
->testTitleValidation( $srcFilename ),
56 /* If we expect a valid title, check the title itself. */
57 if ( $code == UploadTestHandler
::OK
) {
58 $this->assertEquals( $dstFilename,
59 $this->upload
->getTitle()->getText(),
65 * Test the upload verification functions
67 public function testVerifyUpload() {
68 /* Setup with zero file size */
69 $this->upload
->initializePathInfo( '', '', 0 );
70 $result = $this->upload
->verifyUpload();
71 $this->assertEquals( UploadTestHandler
::EMPTY_FILE
,
73 'upload empty file' );
78 class UploadTestHandler
extends UploadBase
{
79 public function initializeFromRequest( &$request ) {}
80 public function testTitleValidation( $name ) {
81 $this->mTitle
= false;
82 $this->mDesiredDestName
= $name;
84 return $this->mTitleError
;