PMC-931 Add unit tests for the feature PMC-852

This commit is contained in:
Roly Rudy Gutierrez Pinto
2019-08-08 09:51:39 -04:00
parent 279e251a62
commit d81339ccec
19 changed files with 948 additions and 24 deletions

View File

@@ -0,0 +1,23 @@
<?php
use Faker\Generator as Faker;
$factory->define(\ProcessMaker\Model\EmailServer::class, function(Faker $faker) {
return [
'MESS_UID' => G::generateUniqueID(),
'MESS_ENGINE' => '',
'MESS_SERVER' => '',
'MESS_PORT' => 0,
'MESS_INCOMING_SERVER' => '',
'MESS_INCOMING_PORT' => 0,
'MESS_RAUTH' => 0,
'MESS_ACCOUNT' => '',
'MESS_PASSWORD' => '',
'MESS_FROM_MAIL' => '',
'MESS_FROM_NAME' => '',
'SMTPSECURE' => 'No',
'MESS_TRY_SEND_INMEDIATLY' => 0,
'MAIL_TO' => '',
'MESS_DEFAULT' => 0,
];
});

View File

@@ -0,0 +1,17 @@
<?php
use Faker\Generator as Faker;
$factory->define(\ProcessMaker\Model\ProcessFiles::class, function(Faker $faker) {
return [
'PRF_UID' => G::generateUniqueID(),
'PRO_UID' => '',
'USR_UID' => '',
'PRF_UPDATE_USR_UID' => '',
'PRF_PATH' => '',
'PRF_TYPE' => '',
'PRF_EDITABLE' => 1,
'PRF_CREATE_DATE' => $faker->dateTime(),
'PRF_UPDATE_DATE' => $faker->dateTime(),
];
});

View File

@@ -59,6 +59,13 @@
<env name="POPULATE_DATABASE" value="false" />
<!--Performance Mysql test-->
<env name="RUN_MYSQL_PERFORMANCE_TESTS" value="false" />
<!--email account-->
<env name="emailEngine" value="PHPMAILER" />
<env name="emailServer" value="smtp.gmail.com" />
<env name="emailPort" value="465" />
<env name="emailAccount" value="admin@processmaker.com" />
<env name="emailAccountPassword" value="" />
<env name="emailSecure" value="ssl" />
<!--Php variables-->
<var name="APP_ENV" value="testing" />
<var name="SYS_SYS" value="test" />

106
tests/CreateTestSite.php Normal file
View File

@@ -0,0 +1,106 @@
<?php
namespace Tests;
use G;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use ProcessMaker\Core\Installer;
use ProcessMaker\Core\System;
trait CreateTestSite
{
private $timezone;
private $baseUri;
private $user;
private $password;
private $workspace;
/**
* Get base uri for rest applications.
* @return string
*/
private function getBaseUri()
{
$_SERVER = $this->getServerInformation();
$baseUri = System::getServerProtocolHost();
return $baseUri;
}
/**
* Get server information.
* @return object
*/
private function getServerInformation()
{
$pathData = PATH_DATA . "sites" . PATH_SEP . config("system.workspace") . PATH_SEP . ".server_info";
if (!file_exists($pathData) && method_exists($this, 'markTestSkipped')) {
$this->markTestSkipped('Please define an active workspace.');
}
$content = file_get_contents($pathData);
$serverInfo = unserialize($content);
return $serverInfo;
}
/**
* This method creates a test workspace so that the endpoints can be functional,
* it is necessary to change the permissions of the directory so that other
* users can access and write to the directory, these users can be for
* example: apache2, www-data, httpd, etc...
* This method finds the license file of the active site and uses it to register
* this license in the LICENSE_MANAGER table. If there is no license file in
* the active workspace, an asersion failure will be notified.
*/
private function createTestSite()
{
//We copy the license, otherwise you will not be able to lift the site
$pathTest = PATH_DATA . "sites" . PATH_SEP . $this->workspace;
File::copyDirectory(PATH_DATA . "sites" . PATH_SEP . config("system.workspace"), $pathTest);
//Write permission for other users for example: apache2, www-data, httpd.
passthru('chmod 775 -R ' . $pathTest . ' >> .log 2>&1');
$installer = new Installer();
$options = [
'isset' => true,
'name' => $this->workspace,
'admin' => [
'username' => $this->user,
'password' => $this->password
],
'advanced' => [
'ao_db_drop' => true,
'ao_db_wf' => $this->workspace,
'ao_db_rb' => $this->workspace,
'ao_db_rp' => $this->workspace
]
];
//The false option creates a connection to the database, necessary to create a site.
$installer->create_site($options, false);
//Now create site
$installer->create_site($options, true);
//Important so that the dates are stored in the same timezone
file_put_contents($pathTest . "/env.ini", "time_zone ='{$this->timezone}'", FILE_APPEND);
$matchingFiles = File::glob("{$pathTest}/*.dat");
$this->assertNotEmpty($matchingFiles);
//set license
$licensePath = array_pop($matchingFiles);
DB::Table("LICENSE_MANAGER")->insert([
"LICENSE_UID" => G::generateUniqueID(),
"LICENSE_USER" => "ProcessMaker Inc",
"LICENSE_START" => "1490932800",
"LICENSE_END" => 0,
"LICENSE_SPAN" => 0,
"LICENSE_STATUS" => "ACTIVE",
"LICENSE_DATA" => file_get_contents($licensePath),
"LICENSE_PATH" => $licensePath,
"LICENSE_WORKSPACE" => $this->workspace,
"LICENSE_TYPE" => ""
]);
}
}

View File

@@ -1,5 +1,6 @@
<?php
namespace tests;
namespace Tests;
use Illuminate\Contracts\Console\Kernel;

View File

@@ -18,7 +18,7 @@ class DBQueryTest extends TestCase
*/
protected function setUp()
{
parent::setUp();
}
/**

View File

@@ -1,4 +1,5 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
@@ -7,6 +8,67 @@ use Propel;
abstract class TestCase extends BaseTestCase
{
/**
*
* @var object
*/
protected $currentConfig;
/**
*
* @var string
*/
protected $currentArgv;
/**
* Create application
*/
use CreatesApplication;
/**
* Constructs a test case with the given name.
*
* @param string $name
* @param array $data
* @param string $dataName
*/
public function __construct($name = null, array $data = [], $dataName = '')
{
/**
* Method Tests\CreatesApplication::createApplication() restarts the application
* and the values loaded in bootstrap.php have been lost, for this reason
* it is necessary to save the following values.
*/
$this->currentConfig = app('config');
$this->currentArgv = $_SERVER['argv'];
parent::__construct($name, $data, $dataName);
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
/**
* Lost argv are restored.
*/
if (empty($_SERVER['argv'])) {
$_SERVER['argv'] = $this->currentArgv;
}
parent::setUp();
/**
* Lost config are restored.
*/
app()->instance('config', $this->currentConfig);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
parent::tearDown();
}
}

View File

@@ -23,7 +23,11 @@ if (file_exists($pathData)) {
define('PATH_DATA', dirname(__DIR__) . '/shared/rbac/');
}
define('PATH_RBAC_CORE', dirname(__DIR__) . '/rbac/engine/');
define('PATH_DB', dirname(__DIR__) . '/shared/sites/');
if (file_exists($pathData)) {
define('PATH_DB', PATH_DATA . 'sites/');
} else {
define('PATH_DB', dirname(__DIR__) . '/shared/sites/');
}
define('PATH_SEP', '/');
define('PATH_METHODS', dirname(__DIR__) . '/workflow/engine/methods/');
define('SYS_LANG', 'en');

View File

@@ -16,6 +16,7 @@ class CustomizeFormatterTest extends TestCase
*/
protected function setUp()
{
parent::setUp();
self::$directory = PATH_TRUNK . '/storage/logs/';
}

View File

@@ -13,9 +13,34 @@ class PmDynaformTest extends TestCase
/**
* Constructor of the class.
*/
function __construct()
public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
$_SERVER["REQUEST_URI"] = "";
if (!defined("DB_ADAPTER")) {
define("DB_ADAPTER", "mysql");
}
if (!defined("DB_HOST")) {
define("DB_HOST", env('DB_HOST'));
}
if (!defined("DB_NAME")) {
define("DB_NAME", env('DB_DATABASE'));
}
if (!defined("DB_USER")) {
define("DB_USER", env('DB_USERNAME'));
}
if (!defined("DB_PASS")) {
define("DB_PASS", env('DB_PASSWORD'));
}
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
parent::setUp();
}
/**

View File

@@ -8,8 +8,9 @@ class SpoolRunTest extends TestCase
/**
* Constructor of the class.
*/
function __construct()
public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
}
/**

File diff suppressed because it is too large Load Diff

View File

@@ -37,6 +37,7 @@ class GroupTest extends TestCase
*/
protected function setUp()
{
parent::setUp();
$this->setInstanceGroup(new Group());
}
@@ -92,8 +93,16 @@ class GroupTest extends TestCase
*/
public function testGetUsersAvailable($groupUid)
{
$result = \ProcessMaker\Model\User::where('USERS.USR_STATUS', '<>', 'CLOSED')
->whereNotIn('USERS.USR_UID', function($query) {
$query->select('GROUP_USER.USR_UID')
->from('GROUP_USER');
})
->whereNotIn('USERS.USR_UID', ['00000000000000000000000000000002'])
->get()
->toArray();
$response = $this->getInstanceGroup()->getUsers('AVAILABLE-USERS', $groupUid);
$this->assertCount(1, $response);
$this->assertCount(count($result), $response);
}
/**

View File

@@ -20,6 +20,7 @@ class SkinsTest extends TestCase
*/
protected function setUp()
{
parent::setUp();
$this->object = new Skins();
}
@@ -28,6 +29,7 @@ class SkinsTest extends TestCase
*/
protected function tearDown()
{
parent::tearDown();
G::rm_dir(PATH_DATA . 'skins');
mkdir(PATH_DATA . 'skins');
}

View File

@@ -0,0 +1,151 @@
<?php
namespace ProcessMaker\Core;
use Tests\TestCase;
class JobsManagerTest extends TestCase
{
/**
* @var JobsManager
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
parent::setUp();
$this->object = new JobsManager;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
parent::tearDown();
}
/**
* This should return the configured value of delay in env.ini
*
* @test
* @covers ProcessMaker\Core\JobsManager::getDelay
*/
public function testGetDelay()
{
$this->object->init();
$actual = $this->object->getDelay();
$envs = System::getSystemConfiguration('', '', config("system.workspace"));
$this->assertEquals($envs['delay'], $actual);
}
/**
* This should return the configured value of tries in env.ini
*
* @test
* @covers ProcessMaker\Core\JobsManager::getTries
*/
public function testGetTries()
{
$this->object->init();
$actual = $this->object->getTries();
$envs = System::getSystemConfiguration('', '', config("system.workspace"));
$this->assertEquals($envs['tries'], $actual);
}
/**
* This should return the configured value of retry_after in env.ini
*
* @test
* @covers ProcessMaker\Core\JobsManager::getRetryAfter
*/
public function testGetRetryAfter()
{
$this->object->init();
$actual = $this->object->getRetryAfter();
$envs = System::getSystemConfiguration('', '', config("system.workspace"));
$this->assertEquals($envs['retry_after'], $actual);
}
/**
* This returns a single instance of the object (this is a singleton).
* @test
* @covers ProcessMaker\Core\JobsManager::getSingleton
*/
public function testGetSingleton()
{
$object1 = $this->object->getSingleton();
$this->assertEquals($this->object, $object1);
$object2 = $this->object->getSingleton();
$this->assertEquals($this->object, $object2);
}
/**
* If the object was started correctly returns the instance of this object.
*
* @test
* @covers ProcessMaker\Core\JobsManager::init
*/
public function testInit()
{
$actual = $this->object->init();
$this->assertEquals($this->object, $actual);
}
/**
* This must return the instance of the object that prepares the work for dispatch.
*
* @test
* @covers ProcessMaker\Core\JobsManager::dispatch
*/
public function testDispatch()
{
$callback = function() {
};
$actual = $this->object->dispatch('Email', $callback);
$this->assertInstanceOf(\Illuminate\Foundation\Bus\PendingDispatch::class, $actual);
}
/**
* This gets the value of the option specified in the second parameter from an
* array that represents the arguments.
*
* @test
* @covers ProcessMaker\Core\JobsManager::getOptionValueFromArguments
*/
public function testGetOptionValueFromArguments()
{
$optionName = "--workspace";
$valueOption = "workflow";
$allocationSeparator = "=";
$parameter0 = "queue:work";
$parameter1 = $optionName . $allocationSeparator . $valueOption;
$arguments = [$parameter0, $parameter1];
$actual = $this->object->getOptionValueFromArguments($arguments, $optionName);
$this->assertEquals($valueOption, $actual);
$actual = $this->object->getOptionValueFromArguments($arguments, $optionName, $allocationSeparator);
$this->assertEquals($valueOption, $actual);
$actual = $this->object->getOptionValueFromArguments($arguments, "missing");
$this->assertEquals(false, $actual);
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace Tests\unit\workflow\src\ProcessMaker\Model;
use Faker\Factory;
use G;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
@@ -580,23 +581,24 @@ class DelegationTest extends TestCase
*/
public function it_should_sort_by_process()
{
$faker = Factory::create();
factory(User::class, 100)->create();
$process = factory(Process::class)->create([
'PRO_ID' => 2,
'PRO_ID' => $faker->unique()->numberBetween(1, 10000000),
'PRO_TITLE' => 'Egypt Supplier Payment Proposal'
]);
factory(Delegation::class)->create([
'PRO_ID' => $process->id
]);
$process = factory(Process::class)->create([
'PRO_ID' => 1,
'PRO_ID' => $faker->unique()->numberBetween(1, 10000000),
'PRO_TITLE' => 'China Supplier Payment Proposal'
]);
factory(Delegation::class)->create([
'PRO_ID' => $process->id
]);
$process = factory(Process::class)->create([
'PRO_ID' => 3,
'PRO_ID' => $faker->unique()->numberBetween(1, 10000000),
'PRO_TITLE' => 'Russia Supplier Payment Proposal'
]);
factory(Delegation::class)->create([
@@ -1134,12 +1136,15 @@ class DelegationTest extends TestCase
factory(User::class, 100)->create();
$process = factory(Process::class)->create();
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID,
'APP_UID' => G::generateUniqueID()
]);
factory(Delegation::class)->states('closed')->create([
'PRO_UID' => $process->PRO_UID,
'APP_UID' => $application->APP_UID
]);
factory(Delegation::class)->states('open')->create([
'PRO_UID' => $process->PRO_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => 2
]);

View File

@@ -174,7 +174,7 @@ class Padl
*
* @access private
* */
public function padl()
public function __construct()
{
# check to see if the class has been secured
$this->_check_secure();
@@ -531,21 +531,21 @@ class Padl
# check to see if mycrypt exists
if ($this->USE_MCRYPT) {
# openup mcrypt
$td = mcrypt_module_open($this->ALGORITHM, '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$td = @mcrypt_module_open($this->ALGORITHM, '', 'ecb', '');
$iv = @mcrypt_create_iv(@mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
# process the key
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$key = substr($key, 0, @mcrypt_enc_get_key_size($td));
# init mcrypt
mcrypt_generic_init($td, $key, $iv);
@mcrypt_generic_init($td, $key, $iv);
# encrypt data
# double base64 gets makes all the characters alpha numeric
# and gets rig of the special characters
$crypt = mcrypt_generic($td, serialize($src_array));
$crypt = @mcrypt_generic($td, serialize($src_array));
# shutdown mcrypt
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
@mcrypt_generic_deinit($td);
@mcrypt_module_close($td);
} else {
# if mcrypt doesn't exist use regular encryption method
# init the vars
@@ -586,19 +586,19 @@ class Padl
# check to see if mycrypt exists
if ($this->USE_MCRYPT) {
# openup mcrypt
$td = mcrypt_module_open($this->ALGORITHM, '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$td = @mcrypt_module_open($this->ALGORITHM, '', 'ecb', '');
$iv = @mcrypt_create_iv(@mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
# process the key
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$key = substr($key, 0, @mcrypt_enc_get_key_size($td));
# init mcrypt
mcrypt_generic_init($td, $key, $iv);
@mcrypt_generic_init($td, $key, $iv);
# decrypt the data and return
$decrypt = mdecrypt_generic($td, $str);
$decrypt = @mdecrypt_generic($td, $str);
# shutdown mcrypt
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
@mcrypt_generic_deinit($td);
@mcrypt_module_close($td);
} else {
# if mcrypt doesn't exist use regular decryption method
# init the decrypt vars

View File

@@ -0,0 +1,13 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class EmailServer extends Model
{
protected $table = 'EMAIL_SERVER';
protected $primaryKey = 'MESS_UID';
public $timestamps = false;
}

View File

@@ -0,0 +1,13 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class ProcessFiles extends Model
{
protected $table = 'PROCESS_FILES';
protected $primaryKey = 'PRF_UID';
public $timestamps = false;
}