diff --git a/tests/unit/workflow/engine/src/ProcessMaker/TaskScheduler/TaskTest.php b/tests/unit/workflow/engine/src/ProcessMaker/TaskScheduler/TaskTest.php index 74cb8c234..d54a8142d 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/TaskScheduler/TaskTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/TaskScheduler/TaskTest.php @@ -357,7 +357,7 @@ class TaskTest extends TestCase ob_start(); $task->fillReportByProcess($dateInit, $dateFinish); $printing = ob_get_clean(); - $this->assertRegExp("/User Reporting/", $printing); + $this->assertRegExp("/Process Reporting/", $printing); } //assert asynchronous for job process @@ -368,4 +368,32 @@ class TaskTest extends TestCase Queue::assertPushed(TaskScheduler::class); } } + + /** + * This test verify the ldapcron activity method for synchronous and asynchronous execution. + * @test + * @covers ProcessMaker\TaskScheduler\Task::runTask() + * @covers ProcessMaker\TaskScheduler\Task::ldapcron() + * @dataProvider asynchronousCases + */ + public function it_should_test_ldapcron_method($asynchronous) + { + $task = new Task($asynchronous, ''); + + //assert synchronous for cron file + if ($asynchronous === false) { + ob_start(); + $task->ldapcron(false); + $printing = ob_get_clean(); + $this->assertRegExp("/\+---/", $printing); + } + + //assert asynchronous for job process + if ($asynchronous === true) { + Queue::fake(); + Queue::assertNothingPushed(); + $task->ldapcron(false); + Queue::assertPushed(TaskScheduler::class); + } + } } diff --git a/workflow/engine/bin/cron_single.php b/workflow/engine/bin/cron_single.php index d5c300e7c..3661e7fac 100644 --- a/workflow/engine/bin/cron_single.php +++ b/workflow/engine/bin/cron_single.php @@ -331,11 +331,8 @@ try { } break; case 'ldapcron': - require_once(PATH_HOME . 'engine' . PATH_SEP . 'methods' . PATH_SEP . 'services' . PATH_SEP . 'ldapadvanced.php'); - - $ldapadvancedClassCron = new ldapadvancedClassCron(); - - $ldapadvancedClassCron->executeCron(in_array('+debug', $argv)); + $task = new Task($asynchronous, $sObject); + $task->ldapcron(in_array('+debug', $argv)); break; case 'messageeventcron': $messageApplication = new \ProcessMaker\BusinessModel\MessageApplication(); diff --git a/workflow/engine/src/ProcessMaker/TaskScheduler/Task.php b/workflow/engine/src/ProcessMaker/TaskScheduler/Task.php index fb55143ec..f9ad802de 100644 --- a/workflow/engine/src/ProcessMaker/TaskScheduler/Task.php +++ b/workflow/engine/src/ProcessMaker/TaskScheduler/Task.php @@ -15,6 +15,7 @@ use Criteria; use Exception; use G; use Illuminate\Support\Facades\Log; +use ldapadvancedClassCron; use ProcessMaker\Core\JobsManager; use ProcessMaker\Plugins\PluginRegistry; use Propel; @@ -453,7 +454,7 @@ class Task } return false; } - $job = function() { + $job = function() use($dateInit, $dateFinish) { try { $dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s"); @@ -473,4 +474,18 @@ class Task }; $this->runTask($job); } + + /** + * This execute ldap cron. + * @param boolean $debug + */ + public function ldapcron($debug) + { + $job = function() use($debug) { + require_once(PATH_HOME . 'engine' . PATH_SEP . 'methods' . PATH_SEP . 'services' . PATH_SEP . 'ldapadvanced.php'); + $ldapadvancedClassCron = new ldapadvancedClassCron(); + $ldapadvancedClassCron->executeCron($debug); + }; + $this->runTask($job); + } }