(bug 23375) Added ogv, oga, spx as extensions for ogg files. Patch by Derk-Jan Hartman.
[lhc/web/wiklou.git] / maintenance / tests / UploadTest.php
1 <?php
2 /**
3 * @group Upload
4 */
5 class UploadTest extends PHPUnit_Framework_TestCase {
6 protected $upload;
7
8
9 function setUp() {
10 parent::setup();
11 $this->upload = new UploadTestHandler;
12 }
13
14 /**
15 * Test various forms of valid and invalid titles that can be supplied.
16 */
17 public function testTitleValidation() {
18
19
20 /* Test a valid title */
21 $this->assertUploadTitleAndCode( 'ValidTitle.jpg',
22 'ValidTitle.jpg', UploadTestHandler::OK,
23 'upload valid title' );
24
25 /* A title with a slash */
26 $this->assertUploadTitleAndCode( 'A/B.jpg',
27 'B.jpg', UploadTestHandler::OK,
28 'upload title with slash' );
29
30 /* A title with illegal char */
31 $this->assertUploadTitleAndCode( 'A:B.jpg',
32 'A-B.jpg', UploadTestHandler::OK,
33 'upload title with colon' );
34
35 /* A title without extension */
36 $this->assertUploadTitleAndCode( 'A',
37 null, UploadTestHandler::FILETYPE_MISSING,
38 'upload title without extension' );
39
40 /* A title with no basename */
41 $this->assertUploadTitleAndCode( '.jpg',
42 null, UploadTestHandler::MIN_LENGTH_PARTNAME,
43 'upload title without basename' );
44
45 }
46 /**
47 * Helper function for testTitleValidation. First checks the return code
48 * of UploadBase::getTitle() and then the actual returned titl
49 */
50 private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) {
51 /* Check the result code */
52 $this->assertEquals( $code,
53 $this->upload->testTitleValidation( $srcFilename ),
54 "$msg code" );
55
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(),
60 "$msg text" );
61 }
62 }
63
64 /**
65 * Test the upload verification functions
66 */
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,
72 $result['status'],
73 'upload empty file' );
74 }
75
76 }
77
78 class UploadTestHandler extends UploadBase {
79 public function initializeFromRequest( &$request ) {}
80 public function testTitleValidation( $name ) {
81 $this->mTitle = false;
82 $this->mDesiredDestName = $name;
83 $this->getTitle();
84 return $this->mTitleError;
85 }
86
87
88 }