Skip to content

Commit

Permalink
Merge pull request #22 from agungsijawir/master
Browse files Browse the repository at this point in the history
Patch for Issues #21
  • Loading branch information
dilab authored Oct 19, 2017
2 parents 9f9663c + 899daa8 commit 5624d5a
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Network/SimpleResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function header($statusCode)
} else if (404==$statusCode) {
return header("HTTP/1.0 404 Not Found");
}
return header("HTTP/1.0 404 Not Found");
return header("HTTP/1.0 204 No Content");
}

}
4 changes: 2 additions & 2 deletions src/Resumable.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function handleTestChunk()
$chunkNumber = $this->resumableParam('chunkNumber');

if (!$this->isChunkUploaded($identifier, $filename, $chunkNumber)) {
return $this->response->header(404);
return $this->response->header(204);
} else {
return $this->response->header(200);
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public function tmpChunkDir($identifier)

public function tmpChunkFilename($filename, $chunkNumber)
{
return $filename . '.part' . $chunkNumber;
return $filename . '.' . str_pad($chunkNumber, 4, 0, STR_PAD_LEFT);
}

public function createFileFromChunks($chunkFiles, $destFile)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/src/Network/SimpleRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testFile()
$file = array(
'name'=> 'mock.png',
'type'=> 'application/octet-stream',
'tmp_name'=> 'test/files/mock.png.part3',
'tmp_name'=> 'test/files/mock.png.0003',
'error'=> 0,
'size'=> 1048576,
);
Expand Down
3 changes: 2 additions & 1 deletion test/src/Network/SimpleResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public function headerProvider()
{
return array(
array(404,404),
array(204,204),
array(200,200),
array(500,404),
array(500,204),
);
}

Expand Down
24 changes: 12 additions & 12 deletions test/src/ResumableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testProcessHandleChunk()
$this->request->method('file')
->will($this->returnValue(array(
'name'=> 'mock.png',
'tmp_name'=> 'test/files/mock.png.part3',
'tmp_name'=> 'test/files/mock.png.003',
'error'=> 0,
'size'=> 27000,
)));
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testHandleChunk() {
$this->request->method('file')
->willReturn(array(
'name'=> 'mock.png',
'tmp_name'=> 'test/files/mock.png.part3',
'tmp_name'=> 'test/files/mock.png.003',
'error'=> 0,
'size'=> 27000,
));
Expand All @@ -154,7 +154,7 @@ public function testHandleChunk() {
$this->resumbable->handleChunk();

$this->assertFileExists('test/uploads/mock.png');
unlink('test/tmp/identifier/mock.png.part3');
unlink('test/tmp/identifier/mock.png.003');
unlink('test/uploads/mock.png');
}

Expand Down Expand Up @@ -226,22 +226,22 @@ public function testTmpChunkFile()
{
$this->resumbable = new Resumable($this->request,$this->response);
$filename = 'mock-file.png';
$chunkNumber = 1;
$expected = $filename.'.part'.$chunkNumber;
$chunkNumber = str_pad(1, 4, 0, STR_PAD_LEFT);
$expected = $filename.'.'.$chunkNumber;
$this->assertEquals($expected, $this->resumbable->tmpChunkFilename($filename,$chunkNumber));
}

public function testCreateFileFromChunks()
{
$files = array(
'test/files/mock.png.part1',
'test/files/mock.png.part2',
'test/files/mock.png.part3',
'test/files/mock.png.0001',
'test/files/mock.png.0002',
'test/files/mock.png.0003',
);
$totalFileSize = array_sum(array(
filesize('test/files/mock.png.part1'),
filesize('test/files/mock.png.part2'),
filesize('test/files/mock.png.part3')
filesize('test/files/mock.png.0001'),
filesize('test/files/mock.png.0002'),
filesize('test/files/mock.png.0003')
));
$destFile = 'test/files/5.png';

Expand All @@ -256,7 +256,7 @@ public function testMoveUploadedFile()
{
$destFile = 'test/files/4.png';
$this->resumbable = new Resumable($this->request,$this->response);
$this->resumbable->moveUploadedFile('test/files/mock.png.part1', $destFile);
$this->resumbable->moveUploadedFile('test/files/mock.png.0001', $destFile);
$this->assertFileExists($destFile);
unlink($destFile);
}
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 5624d5a

Please sign in to comment.