284 lines
8.7 KiB
PHP
284 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\unit\workflow\engine\src\ProcessMaker\TaskScheduler;
|
|
|
|
use App\Jobs\TaskScheduler;
|
|
use Faker\Factory;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use ProcessMaker\TaskScheduler\Task;
|
|
use Tests\TestCase;
|
|
|
|
class TaskTest extends TestCase
|
|
{
|
|
private $faker;
|
|
|
|
/**
|
|
* Method setUp.
|
|
*/
|
|
protected function setUp()
|
|
{
|
|
parent::setUp();
|
|
$this->faker = Factory::create();
|
|
}
|
|
|
|
/**
|
|
* Method tearDown.
|
|
*/
|
|
protected function tearDown()
|
|
{
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* Test synchronous asynchronous cases.
|
|
*/
|
|
public function asynchronousCases()
|
|
{
|
|
return [
|
|
[true],
|
|
[false]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* This test verify the setExecutionMessage method.
|
|
* @test
|
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
|
* @covers ProcessMaker\TaskScheduler\Task::setExecutionMessage()
|
|
* @dataProvider asynchronousCases
|
|
*/
|
|
public function it_should_test_setExecutionMessage_method($asynchronous)
|
|
{
|
|
$task = new Task($asynchronous, '');
|
|
$message = $this->faker->paragraph;
|
|
|
|
ob_start();
|
|
$task->setExecutionMessage($message);
|
|
$printing = ob_get_clean();
|
|
|
|
//assert if message is contained in output buffer
|
|
if ($asynchronous === false) {
|
|
$this->assertRegExp("/{$message}/", $printing);
|
|
}
|
|
//assert if not showing message
|
|
if ($asynchronous === true) {
|
|
$this->assertEmpty($printing);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This test verify the setExecutionResultMessage method.
|
|
* @test
|
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
|
* @covers ProcessMaker\TaskScheduler\Task::setExecutionResultMessage()
|
|
* @dataProvider asynchronousCases
|
|
*/
|
|
public function it_should_test_setExecutionResultMessage_method($asynchronous)
|
|
{
|
|
$task = new Task($asynchronous, '');
|
|
$message = $this->faker->paragraph;
|
|
|
|
ob_start();
|
|
$task->setExecutionResultMessage($message, 'error');
|
|
$printing = ob_get_clean();
|
|
//assert if message is contained in output buffer
|
|
if ($asynchronous === false) {
|
|
$this->assertRegExp("/{$message}/", $printing);
|
|
}
|
|
//assert if not showing message
|
|
if ($asynchronous === true) {
|
|
$this->assertEmpty($printing);
|
|
}
|
|
|
|
ob_start();
|
|
$task->setExecutionResultMessage($message, 'info');
|
|
$printing = ob_get_clean();
|
|
//assert if message is contained in output buffer
|
|
if ($asynchronous === false) {
|
|
$this->assertRegExp("/{$message}/", $printing);
|
|
}
|
|
//assert if not showing message
|
|
if ($asynchronous === true) {
|
|
$this->assertEmpty($printing);
|
|
}
|
|
|
|
ob_start();
|
|
$task->setExecutionResultMessage($message, 'warning');
|
|
$printing = ob_get_clean();
|
|
//assert if message is contained in output buffer
|
|
if ($asynchronous === false) {
|
|
$this->assertRegExp("/{$message}/", $printing);
|
|
}
|
|
//assert if not showing message
|
|
if ($asynchronous === true) {
|
|
$this->assertEmpty($printing);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This test verify the saveLog method.
|
|
* @test
|
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
|
* @covers ProcessMaker\TaskScheduler\Task::saveLog()
|
|
* @dataProvider asynchronousCases
|
|
*/
|
|
public function it_should_test_saveLog_method($asynchronous)
|
|
{
|
|
$task = new Task($asynchronous, '');
|
|
$description = $this->faker->paragraph;
|
|
|
|
$task->saveLog('', '', $description);
|
|
$file = PATH_DATA . "log/cron.log";
|
|
$this->assertFileExists($file);
|
|
if ($asynchronous === false) {
|
|
$contentLog = file_get_contents($file);
|
|
$this->assertRegExp("/{$description}/", $contentLog);
|
|
}
|
|
if ($asynchronous === true) {
|
|
$contentLog = file_get_contents($file);
|
|
$this->assertNotRegExp("/{$description}/", $contentLog);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This test verify the resendEmails activity method for synchronous and asynchronous execution.
|
|
* @test
|
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
|
* @covers ProcessMaker\TaskScheduler\Task::resendEmails()
|
|
* @dataProvider asynchronousCases
|
|
*/
|
|
public function it_should_test_resendEmails_method($asynchronous)
|
|
{
|
|
$task = new Task($asynchronous, '');
|
|
$dateSystem = $this->faker->date();
|
|
|
|
//assert synchronous for cron file
|
|
if ($asynchronous === false) {
|
|
ob_start();
|
|
$task->resendEmails('', $dateSystem);
|
|
$printing = ob_get_clean();
|
|
$this->assertRegExp("/DONE/", $printing);
|
|
}
|
|
|
|
//assert asynchronous for job process
|
|
if ($asynchronous === true) {
|
|
Queue::fake();
|
|
Queue::assertNothingPushed();
|
|
$task->resendEmails('', $dateSystem);
|
|
Queue::assertPushed(TaskScheduler::class);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This test verify the unpauseApplications activity method for synchronous and asynchronous execution.
|
|
* @test
|
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
|
* @covers ProcessMaker\TaskScheduler\Task::unpauseApplications()
|
|
* @dataProvider asynchronousCases
|
|
*/
|
|
public function it_should_test_unpauseApplications_method($asynchronous)
|
|
{
|
|
$task = new Task($asynchronous, '');
|
|
|
|
//assert synchronous for cron file
|
|
if ($asynchronous === false) {
|
|
ob_start();
|
|
$task->unpauseApplications('');
|
|
$printing = ob_get_clean();
|
|
$this->assertRegExp("/DONE/", $printing);
|
|
}
|
|
|
|
//assert asynchronous for job process
|
|
if ($asynchronous === true) {
|
|
Queue::fake();
|
|
Queue::assertNothingPushed();
|
|
$task->unpauseApplications('');
|
|
Queue::assertPushed(TaskScheduler::class);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This test verify the calculateDuration activity method for synchronous and asynchronous execution.
|
|
* @test
|
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
|
* @covers ProcessMaker\TaskScheduler\Task::calculateDuration()
|
|
* @dataProvider asynchronousCases
|
|
*/
|
|
public function it_should_test_calculateDuration_method($asynchronous)
|
|
{
|
|
$task = new Task($asynchronous, '');
|
|
|
|
//assert synchronous for cron file
|
|
if ($asynchronous === false) {
|
|
ob_start();
|
|
$task->calculateDuration();
|
|
$printing = ob_get_clean();
|
|
$this->assertRegExp("/DONE/", $printing);
|
|
}
|
|
|
|
//assert asynchronous for job process
|
|
if ($asynchronous === true) {
|
|
Queue::fake();
|
|
Queue::assertNothingPushed();
|
|
$task->calculateDuration();
|
|
Queue::assertPushed(TaskScheduler::class);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This test verify the calculateAppDuration activity method for synchronous and asynchronous execution.
|
|
* @test
|
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
|
* @covers ProcessMaker\TaskScheduler\Task::calculateAppDuration()
|
|
* @dataProvider asynchronousCases
|
|
*/
|
|
public function it_should_test_calculateAppDuration_method($asynchronous)
|
|
{
|
|
$task = new Task($asynchronous, '');
|
|
|
|
//assert synchronous for cron file
|
|
if ($asynchronous === false) {
|
|
ob_start();
|
|
$task->calculateAppDuration();
|
|
$printing = ob_get_clean();
|
|
$this->assertRegExp("/DONE/", $printing);
|
|
}
|
|
|
|
//assert asynchronous for job process
|
|
if ($asynchronous === true) {
|
|
Queue::fake();
|
|
Queue::assertNothingPushed();
|
|
$task->calculateAppDuration();
|
|
Queue::assertPushed(TaskScheduler::class);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This test verify the cleanSelfServiceTables activity method for synchronous and asynchronous execution.
|
|
* @test
|
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
|
* @covers ProcessMaker\TaskScheduler\Task::cleanSelfServiceTables()
|
|
* @dataProvider asynchronousCases
|
|
*/
|
|
public function it_should_test_cleanSelfServiceTables_method($asynchronous)
|
|
{
|
|
$task = new Task($asynchronous, '');
|
|
|
|
//assert synchronous for cron file
|
|
if ($asynchronous === false) {
|
|
ob_start();
|
|
$task->cleanSelfServiceTables();
|
|
$printing = ob_get_clean();
|
|
$this->assertRegExp("/DONE/", $printing);
|
|
}
|
|
|
|
//assert asynchronous for job process
|
|
if ($asynchronous === true) {
|
|
Queue::fake();
|
|
Queue::assertNothingPushed();
|
|
$task->cleanSelfServiceTables();
|
|
Queue::assertPushed(TaskScheduler::class);
|
|
}
|
|
}
|
|
}
|