From: Bryan Tong Minh Date: Sat, 20 Mar 2010 22:41:45 +0000 (+0000) Subject: Added some basic tests for uploading (title validation tests for now) X-Git-Tag: 1.31.0-rc.0~37405 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=3816cfe2ad4ed0e9621c2cc9aa384fb1bb3dc11d;p=lhc%2Fweb%2Fwiklou.git Added some basic tests for uploading (title validation tests for now) --- diff --git a/maintenance/tests/UploadTest.php b/maintenance/tests/UploadTest.php new file mode 100644 index 0000000000..152525ccea --- /dev/null +++ b/maintenance/tests/UploadTest.php @@ -0,0 +1,88 @@ +upload = new UploadTestHandler; + } + + /** + * Test various forms of valid and invalid titles that can be supplied. + */ + public function testTitleValidation() { + + + /* Test a valid title */ + $this->assertUploadTitleAndCode( 'ValidTitle.jpg', + 'ValidTitle.jpg', UploadTestHandler::OK, + 'upload valid title' ); + + /* A title with a slash */ + $this->assertUploadTitleAndCode( 'A/B.jpg', + 'B.jpg', UploadTestHandler::OK, + 'upload title with slash' ); + + /* A title with illegal char */ + $this->assertUploadTitleAndCode( 'A:B.jpg', + 'A-B.jpg', UploadTestHandler::OK, + 'upload title with colon' ); + + /* A title without extension */ + $this->assertUploadTitleAndCode( 'A', + null, UploadTestHandler::FILETYPE_MISSING, + 'upload title without extension' ); + + /* A title with no basename */ + $this->assertUploadTitleAndCode( '.A', + null, UploadTestHandler::MIN_LENGTH_PARTNAME, + 'upload title without basename' ); + + } + /** + * Helper function for testTitleValidation. First checks the return code + * of UploadBase::getTitle() and then the actual returned titl + */ + private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) { + /* Check the result code */ + $this->assertEquals( $code, + $this->upload->testTitleValidation( $srcFilename ), + "$msg code" ); + + /* If we expect a valid title, check the title itself. */ + if ( $code == UploadTestHandler::OK ) { + $this->assertEquals( $dstFilename, + $this->upload->getTitle()->getText(), + "$msg text" ); + } + } + + /** + * Test the upload verification functions + */ + public function testVerifyUpload() { + /* Setup with zero file size */ + $this->upload->initializePathInfo( '', '', 0 ); + $result = $this->upload->verifyUpload(); + $this->assertEquals( UploadTestHandler::EMPTY_FILE, + $result['status'], + 'upload empty file' ); + } + +} + +class UploadTestHandler extends UploadBase { + public function initializeFromRequest( &$request ) {} + public function testTitleValidation( $name ) { + $this->mTitle = false; + $this->mDesiredDestName = $name; + $this->getTitle(); + return $this->mTitleError; + } + + +} \ No newline at end of file diff --git a/maintenance/tests/phpunit.xml b/maintenance/tests/phpunit.xml index 279a4bb832..11b6b0e0e8 100644 --- a/maintenance/tests/phpunit.xml +++ b/maintenance/tests/phpunit.xml @@ -18,6 +18,7 @@ SiteConfigurationTest.php TimeAdjustTest.php TitleTest.php + UploadTest.php XmlTest.php