diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFilesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFilesTest.php new file mode 100644 index 000000000..171c41f27 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFilesTest.php @@ -0,0 +1,125 @@ + "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'); + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFiles.php b/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFiles.php index f2abeca72..8f028e0de 100644 --- a/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFiles.php +++ b/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFiles.php @@ -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);