Files
luos/tests/unit/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFilesTest.php
Andrea Adamczyk 7bd8b4a3a3 PMCORE-1171
2020-03-16 11:50:49 -04:00

131 lines
3.5 KiB
PHP

<?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
if (file_exists(PATH_DATA . '1.PNG')) {
unlink(PATH_DATA . '1.PNG');
}
if (file_exists(PATH_DATA . '1.png')) {
unlink(PATH_DATA . '1.png');
}
if (file_exists(PATH_DATA . '1.PnG')) {
unlink(PATH_DATA . '1.PnG');
}
}
}