diff --git a/database/factories/EmailServerFactory.php b/database/factories/EmailServerFactory.php new file mode 100644 index 000000000..7063df7c7 --- /dev/null +++ b/database/factories/EmailServerFactory.php @@ -0,0 +1,23 @@ +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, + ]; +}); diff --git a/database/factories/ProcessFilesFactory.php b/database/factories/ProcessFilesFactory.php new file mode 100644 index 000000000..61161d899 --- /dev/null +++ b/database/factories/ProcessFilesFactory.php @@ -0,0 +1,17 @@ +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(), + ]; +}); diff --git a/phpunit.xml b/phpunit.xml index d26d098d8..00bbf36fa 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -59,6 +59,13 @@ + + + + + + + diff --git a/tests/CreateTestSite.php b/tests/CreateTestSite.php new file mode 100644 index 000000000..cc8328317 --- /dev/null +++ b/tests/CreateTestSite.php @@ -0,0 +1,106 @@ +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" => "" + ]); + } +} diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 1f6324863..dd938f100 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -1,5 +1,6 @@ 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(); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1314d19e7..3bcae74e3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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'); diff --git a/tests/unit/app/CustomizeFormatterTest.php b/tests/unit/app/CustomizeFormatterTest.php index 8a742e750..b5806a5a3 100644 --- a/tests/unit/app/CustomizeFormatterTest.php +++ b/tests/unit/app/CustomizeFormatterTest.php @@ -16,6 +16,7 @@ class CustomizeFormatterTest extends TestCase */ protected function setUp() { + parent::setUp(); self::$directory = PATH_TRUNK . '/storage/logs/'; } diff --git a/tests/unit/workflow/engine/classes/PmDynaformTest.php b/tests/unit/workflow/engine/classes/PmDynaformTest.php index 8e1e07be4..573b694ea 100644 --- a/tests/unit/workflow/engine/classes/PmDynaformTest.php +++ b/tests/unit/workflow/engine/classes/PmDynaformTest.php @@ -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(); } /** diff --git a/tests/unit/workflow/engine/classes/SpoolRunTest.php b/tests/unit/workflow/engine/classes/SpoolRunTest.php index 6f3f728c1..86563df0c 100644 --- a/tests/unit/workflow/engine/classes/SpoolRunTest.php +++ b/tests/unit/workflow/engine/classes/SpoolRunTest.php @@ -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); } /** diff --git a/tests/unit/workflow/engine/classes/WsBaseTest.php b/tests/unit/workflow/engine/classes/WsBaseTest.php new file mode 100644 index 000000000..1ead60f97 --- /dev/null +++ b/tests/unit/workflow/engine/classes/WsBaseTest.php @@ -0,0 +1,484 @@ +timezone = config('app.timezone'); + $_SESSION['USR_TIME_ZONE'] = $this->timezone; + $this->baseUri = $this->getBaseUri(); + $this->user = 'admin'; + $this->password = 'admin'; + $this->workspace = env("DB_DATABASE", "test"); + $this->createTestSite(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + parent::tearDown(); + } + + /** + * Create an application. + * + * @param int $applicationNumber + * @return \stdClass + */ + private function createNewCase($applicationNumber = null) + { + if (empty($applicationNumber)) { + $faker = Factory::create(); + $applicationNumber = $faker->unique()->numberBetween(1, 10000000); + } + $userUid = G::generateUniqueID(); + $processUid = G::generateUniqueID(); + $taskUid = G::generateUniqueID(); + $applicationUid = G::generateUniqueID(); + + $appData = [ + 'SYS_LANG' => 'en', + 'SYS_SKIN' => 'neoclassic', + 'SYS_SYS' => 'workflow', + 'APPLICATION' => G::generateUniqueID(), + 'PROCESS' => G::generateUniqueID(), + 'TASK' => '', + 'INDEX' => 2, + 'USER_LOGGED' => $userUid, + 'USR_USERNAME' => 'admin', + 'APP_NUMBER' => $applicationNumber, + 'PIN' => '97ZN' + ]; + + $user = factory(User::class)->create([ + 'USR_UID' => $userUid + ]); + + $process = factory(Process::class)->create([ + 'PRO_UID' => $processUid + ]); + + $task = factory(Task::class)->create([ + 'PRO_UID' => $process->PRO_UID + ]); + + $application = factory(Application::class)->create([ + 'PRO_UID' => $process->PRO_UID, + 'APP_UID' => $applicationUid, + 'APP_NUMBER' => $applicationNumber, + 'APP_DATA' => serialize($appData) + ]); + + $result = new stdClass(); + $result->userUid = $userUid; + $result->processUid = $processUid; + $result->taskUid = $taskUid; + $result->applicationUid = $applicationUid; + $result->applicationNumber = $applicationNumber; + $result->appData = $appData; + $result->user = $user; + $result->process = $process; + $result->task = $task; + $result->application = $application; + return $result; + } + + /** + * Create a email server configuration. + * + * @return ProcessMaker\Model\EmailServer; + */ + private function createEmailServer() + { + $passwordEnv = env('emailAccountPassword'); + $password = G::encrypt("hash:" . $passwordEnv, 'EMAILENCRYPT'); + $emailServer = factory(EmailServer::class)->create([ + 'MESS_ENGINE' => env('emailEngine'), + 'MESS_SERVER' => env('emailServer'), + 'MESS_PORT' => env('emailPort'), + 'MESS_INCOMING_SERVER' => '', + 'MESS_INCOMING_PORT' => 0, + 'MESS_RAUTH' => 1, + 'MESS_ACCOUNT' => env('emailAccount'), + 'MESS_PASSWORD' => $password, + 'MESS_FROM_MAIL' => env('emailAccount'), + 'MESS_FROM_NAME' => '', + 'SMTPSECURE' => 'ssl', + 'MESS_TRY_SEND_INMEDIATLY' => 1, + 'MAIL_TO' => $password, + 'MESS_DEFAULT' => 1, + ]); + return $emailServer; + } + + /** + * Create a new template for send email. + * + * @param string $proUid + * @param string $usrUid + * @return \ProcessMaker\Model\ProcessFiles + */ + private function createTemplate($proUid, $usrUid) + { + $path1 = PATH_DATA . "sites" . PATH_SEP . config("system.workspace") . PATH_SEP . "mailTemplates" . PATH_SEP . "{$proUid}"; + mkdir($path1); + $path2 = $path1 . PATH_SEP . "emailEvent_" . G::generateUniqueID() . ".html"; + + $htmlContent = $this->createDefaultHtmlContent('Test'); + file_put_contents($path2, $htmlContent); + + $template = factory(\ProcessMaker\Model\ProcessFiles::class)->create([ + 'PRO_UID' => $proUid, + 'USR_UID' => $usrUid, + 'PRF_PATH' => $path2 + ]); + return $template; + } + + /** + * Create empty html. + * + * @param string $content + * @return string + */ + private function createDefaultHtmlContent($content = '') + { + $string = '' + . '' + . '' + . '' + . '' + . '' + . $content + . '' + . ''; + return $string; + } + + /** + * This represents a collection of "messageType" for queue elements. + */ + public function messageTypesWithQueue() + { + return [ + [WsBase::MESSAGE_TYPE_EMAIL_EVENT], + [WsBase::MESSAGE_TYPE_PM_FUNCTION], + ]; + } + + /** + * This represents a collection of "messageType" for no queueable elements. + */ + public function messageTypesWithoutQueue() + { + return [ + [WsBase::MESSAGE_TYPE_ACTIONS_BY_EMAIL], + [WsBase::MESSAGE_TYPE_CASE_NOTE], + [WsBase::MESSAGE_TYPE_EXTERNAL_REGISTRATION], + [WsBase::MESSAGE_TYPE_RETRIEVE_PASSWORD], + [WsBase::MESSAGE_TYPE_SOAP], + [WsBase::MESSAGE_TYPE_TASK_NOTIFICATION], + [WsBase::MESSAGE_TYPE_TEST_EMAIL], + ]; + } + + /** + * This should send an email of types elements to the work queue jobs. + * Queue-fake has been used, see more at: https://laravel.com/docs/5.7/mocking#queue-fake + * @test + * @dataProvider messageTypesWithQueue + * @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType) + */ + public function it_should_send_an_sendMessage_with_queue_jobs($messageType) + { + //data + $emailServer = $this->createEmailServer(); + $case = $this->createNewCase(); + $template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID); + + //parameters + $appUid = $case->applicationUid; + $from = $emailServer->MESS_ACCOUNT; + $to = $emailServer->MESS_ACCOUNT; + $cc = ""; + $bcc = ""; + $subject = "test"; + $templateName = basename($template->PRF_PATH); + $appFields = []; + $attachment = []; + $showMessage = true; + $delIndex = 0; + $config = $emailServer->toArray(); + $gmail = 0; + $appMsgType = $messageType; + + //assertions + Queue::fake(); + Queue::assertNothingPushed(); + + $wsBase = new WsBase(); + $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType); + Queue::assertPushed(EmailEvent::class); + } + + /** + * This should send an email of types elements without work queue jobs. + * Queue-fake has been used, see more at: https://laravel.com/docs/5.7/mocking#queue-fake + * @test + * @dataProvider messageTypesWithoutQueue + * @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType) + */ + public function it_should_execute_an_sendMessage_without_queue_jobs($messageTypes) + { + //data + $emailServer = $this->createEmailServer(); + $case = $this->createNewCase(); + $template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID); + + //parameters + $appUid = $case->applicationUid; + $from = $emailServer->MESS_ACCOUNT; + $to = ""; + $cc = ""; + $bcc = ""; + $subject = "test"; + $templateName = basename($template->PRF_PATH); + $appFields = []; + $attachment = []; + $showMessage = true; + $delIndex = 0; + $config = $emailServer->toArray(); + $gmail = 0; + $appMsgType = $messageTypes; + + //assertions + Queue::fake(); + Queue::assertNothingPushed(); + + $wsBase = new WsBase(); + $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType); + Queue::assertNotPushed(EmailEvent::class); + } + + /** + * It should send an sendMessage with queue jobs and empty config parameter. + * @test + * @dataProvider messageTypesWithQueue + * @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType) + */ + public function it_should_send_an_sendMessage_with_queue_jobs_and_empty_config_parameter($messageTypes) + { + //data + $emailServer = $this->createEmailServer(); + $case = $this->createNewCase(); + $template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID); + + //parameters + $appUid = $case->applicationUid; + $from = $emailServer->MESS_ACCOUNT; + $to = $emailServer->MESS_ACCOUNT; + $cc = ""; + $bcc = ""; + $subject = "test"; + $templateName = basename($template->PRF_PATH); + $appFields = []; + $attachment = []; + $showMessage = true; + $delIndex = 0; + $config = []; //with empty configuration + $gmail = 0; + $appMsgType = $messageTypes; + + //assertions + Queue::fake(); + Queue::assertNothingPushed(); + + $wsBase = new WsBase(); + $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType); + Queue::assertPushed(EmailEvent::class); + } + + /** + * It should send an sendMessage without queue jobs and empty config parameter. + * @test + * @dataProvider messageTypesWithoutQueue + * @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType) + */ + public function it_should_send_an_sendMessage_without_queue_jobs_and_empty_config_parameter($messageTypes) + { + //data + $emailServer = $this->createEmailServer(); + $case = $this->createNewCase(); + $template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID); + + //parameters + $appUid = $case->applicationUid; + $from = $emailServer->MESS_ACCOUNT; + $to = ""; + $cc = ""; + $bcc = ""; + $subject = "test"; + $templateName = basename($template->PRF_PATH); + $appFields = []; + $attachment = []; + $showMessage = true; + $delIndex = 0; + $config = []; //with empty configuration + $gmail = 0; + $appMsgType = $messageTypes; + + //assertions + Queue::fake(); + Queue::assertNothingPushed(); + + $wsBase = new WsBase(); + $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType); + Queue::assertNotPushed(EmailEvent::class); + } + + /** + * It should send an sendMessage with queue jobs and config parameter like id. + * @test + * @dataProvider messageTypesWithQueue + * @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType) + */ + public function it_should_send_an_sendMessage_with_queue_jobs_and_config_parameter_like_id($messageTypes) + { + //data + $emailServer = $this->createEmailServer(); + $case = $this->createNewCase(); + $template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID); + + //parameters + $appUid = $case->applicationUid; + $from = $emailServer->MESS_ACCOUNT; + $to = $emailServer->MESS_ACCOUNT; + $cc = ""; + $bcc = ""; + $subject = "test"; + $templateName = basename($template->PRF_PATH); + $appFields = []; + $attachment = []; + $showMessage = true; + $delIndex = 0; + $config = $emailServer->MESS_UID; //With a valid Email Server Uid + $gmail = 0; + $appMsgType = $messageTypes; + + //assertions + Queue::fake(); + Queue::assertNothingPushed(); + + $wsBase = new WsBase(); + $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType); + Queue::assertPushed(EmailEvent::class); + } + + /** + * It should send an sendMessage without queue jobs and config parameter like id. + * @test + * @dataProvider messageTypesWithoutQueue + * @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType) + */ + public function it_should_send_an_sendMessage_without_queue_jobs_and_config_parameter_like_id($messageTypes) + { + //data + $emailServer = $this->createEmailServer(); + $case = $this->createNewCase(); + $template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID); + + //parameters + $appUid = $case->applicationUid; + $from = $emailServer->MESS_ACCOUNT; + $to = ""; + $cc = ""; + $bcc = ""; + $subject = "test"; + $templateName = basename($template->PRF_PATH); + $appFields = []; + $attachment = []; + $showMessage = true; + $delIndex = 0; + $config = $emailServer->MESS_UID; //With a valid Email Server Uid + $gmail = 0; + $appMsgType = $messageTypes; + + //assertions + Queue::fake(); + Queue::assertNothingPushed(); + + $wsBase = new WsBase(); + $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType); + Queue::assertNotPushed(EmailEvent::class); + } + + /** + * It should send an sendMessage without queue jobs and gmail parameter like one. + * @test + * @dataProvider messageTypesWithoutQueue + * @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType) + */ + public function it_should_send_an_sendMessage_without_queue_jobs_and_gmail_parameter_like_one($messageTypes) + { + //data + $emailServer = $this->createEmailServer(); + $case = $this->createNewCase(); + $template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID); + + //parameters + $appUid = $case->applicationUid; + $from = $emailServer->MESS_ACCOUNT; + $to = ""; + $cc = ""; + $bcc = ""; + $subject = "test"; + $templateName = basename($template->PRF_PATH); + $appFields = []; + $attachment = []; + $showMessage = true; + $delIndex = 0; + $config = $emailServer->MESS_UID; + $gmail = 1; //GMail flag enabled + $appMsgType = $messageTypes; + + //assertions + Queue::fake(); + Queue::assertNothingPushed(); + + $wsBase = new WsBase(); + $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType); + Queue::assertNotPushed(EmailEvent::class); + } +} diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/GroupTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/GroupTest.php index 38311b826..dc119cfdb 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/GroupTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/GroupTest.php @@ -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); } /** diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/SkinsTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/SkinsTest.php index d4fb18758..a7316ca0d 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/SkinsTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/SkinsTest.php @@ -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'); } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Core/JobsManagerTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Core/JobsManagerTest.php new file mode 100644 index 000000000..423c722c7 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Core/JobsManagerTest.php @@ -0,0 +1,151 @@ +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); + } +} diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 13de8e836..f16721a2d 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -1,6 +1,7 @@ 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 ]); diff --git a/workflow/engine/classes/Padl.php b/workflow/engine/classes/Padl.php index 6aa8ebe1f..2bdc5c39e 100644 --- a/workflow/engine/classes/Padl.php +++ b/workflow/engine/classes/Padl.php @@ -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 diff --git a/workflow/engine/src/ProcessMaker/Model/EmailServer.php b/workflow/engine/src/ProcessMaker/Model/EmailServer.php new file mode 100644 index 000000000..806bcd9d3 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/EmailServer.php @@ -0,0 +1,13 @@ +