Files
iTop/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusTest.php
Eric Espie 984f676d6e GivenObjectInDB() and additional improvements in the tests suite to address false positive and slow tests
Rewrite tests on impact analysis to make them readable in the first place, then simplifiy the tests to focus on risk reduction, then complete with some edge case
Rewrite tests on impact graph build when the current user has restricted access to some parts of the graph
2024-06-28 15:24:13 +02:00

55 lines
1.7 KiB
PHP

<?php
/**
* User: Guy Couronné (guy.couronne@gmail.com)
* Date: 25/01/2019
*/
namespace Combodo\iTop\Test\UnitTest\Status;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Config;
class StatusTest extends ItopTestCase
{
public function setUp(): void
{
parent::setUp();
require_once APPROOT.'core/config.class.inc.php'; // for constants
}
protected function GetPHPCommand()
{
return PHP_BINARY;
}
public function testStatusPageRepliesAsExpected()
{
$sPath = APPROOT.'/webservices/status.php';
$sPHP = $this->GetPHPCommand();
echo "About to execute: $sPHP $sPath\n";
exec("$sPHP $sPath", $aOutput, $iRet);
$this->assertEquals(0, $iRet, "Problem executing status page: $sPath, $iRet, aOutput:\n".var_export($aOutput, true));
$sAdditionalInfo = "aOutput:\n".var_export($aOutput, true).'.';
//Check response
$this->assertNotEmpty($aOutput[0], 'Empty response. '.$sAdditionalInfo);
$this->assertJson($aOutput[0], 'Not a JSON. '.$sAdditionalInfo);
$aResponseDecoded = json_decode($aOutput[0], true);
//Check status
$this->assertArrayHasKey('status', $aResponseDecoded, 'JSON does not have a \'status\' field. '.$sAdditionalInfo);
$this->assertEquals('RUNNING', $aResponseDecoded['status'], 'Status is not \'RUNNING\'. '.$sAdditionalInfo);
//Check code
$this->assertArrayHasKey('code', $aResponseDecoded, 'JSON does not have a \'code\' field. '.$sAdditionalInfo);
$this->assertEquals(0, $aResponseDecoded['code'], 'Code is not 0. '.$sAdditionalInfo);
//Check message
$this->assertArrayHasKey('message', $aResponseDecoded, 'JSON does not have a \'message\' field. '.$sAdditionalInfo);
$this->assertEmpty($aResponseDecoded['message'], 'Message is not empty. '.$sAdditionalInfo);
}
}