Merged in bugfix/PMCORE-534 (pull request #7218)
PMCORE-534 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
commit
04767138b2
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Validation;
|
||||
|
||||
use ProcessMaker\Validation\ValidationUploadedFiles;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \ProcessMaker\Validation\ValidationUploadedFiles
|
||||
*/
|
||||
class ValidationUploadedFilesTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* It copies the images for the test
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
copy(PATH_HTML . 'images/1.png', PATH_DATA . '1.PNG');
|
||||
copy(PATH_HTML . 'images/1.png', PATH_DATA . '1.png');
|
||||
copy(PATH_HTML . 'images/1.png', PATH_DATA . '1.PnG');
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the runRules method when the file extension is in upper case
|
||||
*
|
||||
* @covers ::runRules
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_run_rules_method_in_upper_case()
|
||||
{
|
||||
// Create the file
|
||||
$file = [
|
||||
"filename" => "1.PNG",
|
||||
"path" => PATH_DATA . "1.PNG"
|
||||
];
|
||||
|
||||
// Create the ValidationUploadedFiles object
|
||||
$validation = new ValidationUploadedFiles();
|
||||
|
||||
// Call the runRules method
|
||||
$result = $validation->runRules($file);
|
||||
|
||||
// Asserts the validation did not fail
|
||||
$this->assertFalse($result->fails());
|
||||
|
||||
// Asserts there is no a message
|
||||
$this->assertEmpty($result->getMessage());
|
||||
|
||||
// Asserts the status is 0
|
||||
$this->assertEquals(0, $result->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the runRules method when the file extension is in lower case
|
||||
*
|
||||
* @covers ::runRules
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_run_rules_method_in_lower_case()
|
||||
{
|
||||
// Create the file
|
||||
$file = [
|
||||
"filename" => "1.png",
|
||||
"path" => PATH_DATA . "1.png"
|
||||
];
|
||||
|
||||
// Create the ValidationUploadedFiles object
|
||||
$validation = new ValidationUploadedFiles();
|
||||
|
||||
// Call the runRules method
|
||||
$result = $validation->runRules($file);
|
||||
|
||||
// Asserts the validation did not fail
|
||||
$this->assertFalse($result->fails());
|
||||
|
||||
// Asserts there is no a message
|
||||
$this->assertEmpty($result->getMessage());
|
||||
|
||||
// Asserts the status is 0
|
||||
$this->assertEquals(0, $result->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the runRules method when the file extension is in upper and lower case
|
||||
*
|
||||
* @covers ::runRules
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_run_rules_method_in_upper_and_lower_case()
|
||||
{
|
||||
// Create the file
|
||||
$file = [
|
||||
"filename" => "1.PnG",
|
||||
"path" => PATH_DATA . "1.PnG"
|
||||
];
|
||||
|
||||
// Create the ValidationUploadedFiles object
|
||||
$validation = new ValidationUploadedFiles();
|
||||
|
||||
// Call the runRules method
|
||||
$result = $validation->runRules($file);
|
||||
|
||||
// Asserts the validation did not fail
|
||||
$this->assertFalse($result->fails());
|
||||
|
||||
// Asserts there is no a message
|
||||
$this->assertEmpty($result->getMessage());
|
||||
|
||||
// Asserts the status is 0
|
||||
$this->assertEquals(0, $result->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* It deletes the images created
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown(); // TODO: Change the autogenerated stub
|
||||
unlink(PATH_DATA . '1.PNG');
|
||||
unlink(PATH_DATA . '1.png');
|
||||
unlink(PATH_DATA . '1.PnG');
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class ValidationUploadedFiles
|
||||
$validator->addRule()
|
||||
->validate($file, function($file) {
|
||||
$filesystem = new Filesystem();
|
||||
$extension = $filesystem->extension($file->filename);
|
||||
$extension = strtolower($filesystem->extension($file->filename));
|
||||
|
||||
return Bootstrap::getDisablePhpUploadExecution() === 1 && $extension === 'php';
|
||||
})
|
||||
@@ -112,7 +112,7 @@ class ValidationUploadedFiles
|
||||
return false;
|
||||
}
|
||||
|
||||
$extension = $filesystem->extension($file->filename);
|
||||
$extension = strtolower($filesystem->extension($file->filename));
|
||||
$mimeType = $filesystem->mimeType($path);
|
||||
|
||||
$file = new File($path);
|
||||
|
||||
Reference in New Issue
Block a user