mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
N°9104 - Be able to trigger cron remotely and asynchronously
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Webservices;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Exception;
|
||||
use iTopMutex;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @group itopRequestMgmt
|
||||
* @group restApi
|
||||
* @group defaultProfiles
|
||||
*/
|
||||
class CronServiceTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
$this->RequireOnceItopFile('webservices/CronService.php');
|
||||
}
|
||||
|
||||
public function testIsStarted()
|
||||
{
|
||||
$sPath = $this->GetTemporaryFilePath();
|
||||
file_put_contents($sPath, file_get_contents(__DIR__.'/resources/cron_starting.log'));
|
||||
|
||||
$this->assertEquals(true, \CronService::GetInstance()->IsStarted($sPath));
|
||||
}
|
||||
|
||||
public function testIsFailed_MissingCredentialsFailure()
|
||||
{
|
||||
$sPath = $this->GetTemporaryFilePath();
|
||||
file_put_contents($sPath, file_get_contents(__DIR__.'/resources/cron_missingcreds_error.log'));
|
||||
|
||||
$this->assertEquals("Missing argument 'auth_user'", \CronService::GetInstance()->GetErrorMessage($sPath));
|
||||
$this->assertEquals(true, \CronService::GetInstance()->IsFailed($sPath));
|
||||
}
|
||||
|
||||
public static function ErrorProvider()
|
||||
{
|
||||
return [
|
||||
["Access wrong credentials ('user123')"],
|
||||
['gabuzomeu'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ErrorProvider
|
||||
*/
|
||||
public function testIsFailed_AuthenticationFailure($sError)
|
||||
{
|
||||
$sPath = $this->GetTemporaryFilePath();
|
||||
$sContent = <<<LOG
|
||||
..
|
||||
..
|
||||
ERROR: $sError
|
||||
LOG;
|
||||
|
||||
file_put_contents($sPath, $sContent);
|
||||
|
||||
$this->assertEquals($sError, \CronService::GetInstance()->GetErrorMessage($sPath));
|
||||
$this->assertEquals(true, \CronService::GetInstance()->IsFailed($sPath));
|
||||
}
|
||||
|
||||
public static function CannotStartProvider()
|
||||
{
|
||||
return [
|
||||
["cron_alreadyrunning.log", 'Already running...'],
|
||||
['cron_maintenance.log', 'A maintenance is ongoing'],
|
||||
['cron_notanadmin.log', 'Access restricted to administrators'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider CannotStartProvider
|
||||
*/
|
||||
public function testCronCannotStart(string $sLogFile, $sError)
|
||||
{
|
||||
$sPath = $this->GetTemporaryFilePath();
|
||||
file_put_contents($sPath, file_get_contents(__DIR__.'/resources/'.$sLogFile));
|
||||
|
||||
$this->assertEquals($sError, \CronService::GetInstance()->GetErrorMessage($sPath));
|
||||
$this->assertEquals(true, \CronService::GetInstance()->IsFailed($sPath));
|
||||
}
|
||||
|
||||
public function testCronRunning()
|
||||
{
|
||||
$sPath = $this->GetTemporaryFilePath();
|
||||
$sContent = <<<LOG
|
||||
..
|
||||
..
|
||||
..
|
||||
..
|
||||
Starting: 1772551316 (2026-03-03 16:21:56)
|
||||
Creating backup: '/var/www/html/iTopLegacy/data/backups/auto/gabuzomeuuninstall-2026-03-03_16_21.tar.gz'
|
||||
backup: creating tmp dir '/var/www/html/iTopLegacy/data/tmp-backup-1024104636'
|
||||
backup: adding resource '/var/www/html/iTopLegacy/conf/production/config-itop.php'
|
||||
backup: adding resource '/var/www/html/iTopLegacy/data/production-modules/'
|
||||
Starting backup of localhost/gabuzomeuuninstall(suffix:'')
|
||||
backup: generate data file with command: "mysqldump" --defaults-extra-file="/tmp/itop-mysqldump-CVvm4G" --opt --skip-lock-tables --default-character-set=utf8mb4 --add-drop-database --single-transaction --host='localhost' --user=xxxxx --result-file='/var/www/html/iTopLegacy/data/tmp-backup-1024104636/itop-dump.sql' 'gabuzomeuuninstall'
|
||||
LOG;
|
||||
|
||||
file_put_contents($sPath, $sContent);
|
||||
|
||||
$this->assertEquals(null, \CronService::GetInstance()->GetErrorMessage($sPath));
|
||||
$this->assertEquals(false, \CronService::GetInstance()->IsFailed($sPath));
|
||||
}
|
||||
|
||||
public function testCronStopped()
|
||||
{
|
||||
|
||||
$sPath = $this->GetTemporaryFilePath();
|
||||
file_put_contents($sPath, file_get_contents(__DIR__.'/resources/cron_stopped.log'));
|
||||
|
||||
$this->assertEquals(null, \CronService::GetInstance()->GetErrorMessage($sPath));
|
||||
$this->assertEquals(false, \CronService::GetInstance()->IsFailed($sPath));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user