Index: trunk/phase3/maintenance/tests/UploadTest.php |
— | — | @@ -0,0 +1,88 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @group Upload |
| 5 | + */ |
| 6 | +class UploadTest extends PHPUnit_Framework_TestCase { |
| 7 | + protected $upload; |
| 8 | + |
| 9 | + |
| 10 | + function setUp() { |
| 11 | + parent::setup(); |
| 12 | + $this->upload = new UploadTestHandler; |
| 13 | + } |
| 14 | + |
| 15 | + /** |
| 16 | + * Test various forms of valid and invalid titles that can be supplied. |
| 17 | + */ |
| 18 | + public function testTitleValidation() { |
| 19 | + |
| 20 | + |
| 21 | + /* Test a valid title */ |
| 22 | + $this->assertUploadTitleAndCode( 'ValidTitle.jpg', |
| 23 | + 'ValidTitle.jpg', UploadTestHandler::OK, |
| 24 | + 'upload valid title' ); |
| 25 | + |
| 26 | + /* A title with a slash */ |
| 27 | + $this->assertUploadTitleAndCode( 'A/B.jpg', |
| 28 | + 'B.jpg', UploadTestHandler::OK, |
| 29 | + 'upload title with slash' ); |
| 30 | + |
| 31 | + /* A title with illegal char */ |
| 32 | + $this->assertUploadTitleAndCode( 'A:B.jpg', |
| 33 | + 'A-B.jpg', UploadTestHandler::OK, |
| 34 | + 'upload title with colon' ); |
| 35 | + |
| 36 | + /* A title without extension */ |
| 37 | + $this->assertUploadTitleAndCode( 'A', |
| 38 | + null, UploadTestHandler::FILETYPE_MISSING, |
| 39 | + 'upload title without extension' ); |
| 40 | + |
| 41 | + /* A title with no basename */ |
| 42 | + $this->assertUploadTitleAndCode( '.A', |
| 43 | + null, UploadTestHandler::MIN_LENGTH_PARTNAME, |
| 44 | + 'upload title without basename' ); |
| 45 | + |
| 46 | + } |
| 47 | + /** |
| 48 | + * Helper function for testTitleValidation. First checks the return code |
| 49 | + * of UploadBase::getTitle() and then the actual returned titl |
| 50 | + */ |
| 51 | + private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) { |
| 52 | + /* Check the result code */ |
| 53 | + $this->assertEquals( $code, |
| 54 | + $this->upload->testTitleValidation( $srcFilename ), |
| 55 | + "$msg code" ); |
| 56 | + |
| 57 | + /* If we expect a valid title, check the title itself. */ |
| 58 | + if ( $code == UploadTestHandler::OK ) { |
| 59 | + $this->assertEquals( $dstFilename, |
| 60 | + $this->upload->getTitle()->getText(), |
| 61 | + "$msg text" ); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Test the upload verification functions |
| 67 | + */ |
| 68 | + public function testVerifyUpload() { |
| 69 | + /* Setup with zero file size */ |
| 70 | + $this->upload->initializePathInfo( '', '', 0 ); |
| 71 | + $result = $this->upload->verifyUpload(); |
| 72 | + $this->assertEquals( UploadTestHandler::EMPTY_FILE, |
| 73 | + $result['status'], |
| 74 | + 'upload empty file' ); |
| 75 | + } |
| 76 | + |
| 77 | +} |
| 78 | + |
| 79 | +class UploadTestHandler extends UploadBase { |
| 80 | + public function initializeFromRequest( &$request ) {} |
| 81 | + public function testTitleValidation( $name ) { |
| 82 | + $this->mTitle = false; |
| 83 | + $this->mDesiredDestName = $name; |
| 84 | + $this->getTitle(); |
| 85 | + return $this->mTitleError; |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/maintenance/tests/UploadTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 90 | + native |
Index: trunk/phase3/maintenance/tests/phpunit.xml |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | <file>SiteConfigurationTest.php</file> |
20 | 20 | <file>TimeAdjustTest.php</file> |
21 | 21 | <file>TitleTest.php</file> |
| 22 | + <file>UploadTest.php</file> |
22 | 23 | <file>XmlTest.php</file> |
23 | 24 | </testsuite> |
24 | 25 | <groups> |