2b8a293b02b13b0f32753a75d7c8b93af505b66a
[lhc/web/wiklou.git] / maintenance / tests / UploadFromChunksTest.php
1 <?php
2
3 require_once("ApiSetup.php");
4
5 class UploadFromChunksTest extends ApiSetup {
6
7 function setUp() {
8 global $wgEnableUploads;
9
10 $wgEnableUploads=true;
11 ini_set('file_loads', true);
12 }
13
14 function testGetTitle() {
15 $filename = tempnam( wfTempDir(), "" );
16 $c = new UploadFromChunks();
17 $c->initialize(false, "temp.txt", null, $filename, 0, null);
18 $this->assertEquals(null, $c->getTitle());
19
20 $c = new UploadFromChunks();
21 $c->initialize(false, "temp.png", null, $filename, 0, null);
22 $this->assertEquals(Title::makeTitleSafe(NS_FILE, "Temp.png"), $c->getTitle());
23 }
24
25 function testGetEditToken() {
26 }
27
28 function testInitFromSessionKey() {
29
30 }
31
32 function testInitialize() {
33 }
34
35 function testSetupChunkSession() {
36 }
37
38
39 function makeChunk() {
40 $file = tempnam( wfTempDir(), "" );
41 $fh = fopen($file, "w");
42 if($fh == false) {
43 $this->markTestIncomplete("Couldn't open $file!\n");
44 return;
45 }
46 fwrite($fh, "123");
47 fclose($fh);
48
49 $_FILES['chunk']['tmp_name'] = $file;
50 $_FILES['chunk']['size'] = 3;
51 $_FILES['chunk']['error'] = null;
52 $_FILES['chunk']['name'] = "test.txt";
53 }
54
55 function cleanChunk() {
56 unlink($_FILES['chunk']['tmp_name']);
57 }
58
59 /**
60 * @expectedException UsageException
61 */
62 function testPerformUploadInitError() {
63 global $wgUser;
64
65 $wgUser = User::newFromId(1);
66 $token = $wgUser->editToken();
67 $this->makeChunk();
68
69 $req = new FauxRequest(
70 array('action' => 'upload',
71 'enablechunks' => '1',
72 'filename' => 'test.png',
73 'token' => $token,
74 ));
75 $module = new ApiMain($req, true);
76 $module->execute();
77 }
78
79 function testPerformUploadInitSuccess() {
80 global $wgUser;
81
82 $wgUser = User::newFromId(1);
83 $token = $wgUser->editToken();
84 $this->makeChunk();
85
86 $req = new FauxRequest(
87 array('action' => 'upload',
88 'enablechunks' => '1',
89 'filename' => 'test.png',
90 'token' => $token,
91 ));
92 $module = new ApiMain($req, true);
93 $module->execute();
94 }
95
96 function testAppendToUploadFile() {
97 }
98
99 function testAppendChunk() {
100 }
101
102 function testPeformUploadChunk() {
103 }
104
105 function testPeformUploadDone() {
106 }
107
108
109
110 }