mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-29 21:09:10 +02:00
Merge remote-tracking branch 'origin/develop' into feature/backoffice-full-moon-design
# Conflicts: # application/ajaxwebpage.class.inc.php # application/csvpage.class.inc.php # application/displayblock.class.inc.php # application/itopwebpage.class.inc.php # application/utils.inc.php # application/webpage.class.inc.php # application/xmlpage.class.inc.php # datamodels/2.x/itop-config-mgmt/datamodel.itop-config-mgmt.xml # datamodels/2.x/itop-knownerror-light/datamodel.itop-knownerror-light.xml # datamodels/2.x/itop-service-mgmt/datamodel.itop-service-mgmt.xml # datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml # js/components/breadcrumbs.js # pages/navigator.php # test/core/DBSearchTest.php
This commit is contained in:
@@ -694,4 +694,36 @@ class DBSearchTest extends ItopDataTestCase
|
||||
// Previously we were using a output() call but this is time consuming and could cause "risky test" error !
|
||||
ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.2 2.8.0 N°3324
|
||||
*/
|
||||
public function testAllowAllData() {
|
||||
$oSimpleSearch = \DBObjectSearch::FromOQL('SELECT FunctionalCI');
|
||||
$oSimpleSearch->AllowAllData(false);
|
||||
self::assertFalse($oSimpleSearch->IsAllDataAllowed(), 'DBSearch AllowData value');
|
||||
$oSimpleSearch->AllowAllData(true);
|
||||
self::assertTrue($oSimpleSearch->IsAllDataAllowed(), 'DBSearch AllowData value');
|
||||
|
||||
$sNestedQuery = 'SELECT FunctionalCI WHERE id IN (SELECT Server)';
|
||||
$this->CheckNestedSearch($sNestedQuery, true);
|
||||
$this->CheckNestedSearch($sNestedQuery, false);
|
||||
}
|
||||
|
||||
private function CheckNestedSearch($sQuery, $bAllowAllData) {
|
||||
$oNestedQuerySearch = \DBObjectSearch::FromOQL($sQuery);
|
||||
$oNestedQuerySearch->AllowAllData($bAllowAllData);
|
||||
self::assertEquals($bAllowAllData, $oNestedQuerySearch->IsAllDataAllowed(), 'root DBSearch AllowData value');
|
||||
$oNestedSearchInExpression = null;
|
||||
$oNestedQuerySearch->GetCriteria()->Browse(function ($oExpression) use (&$oNestedSearchInExpression) {
|
||||
if ($oExpression instanceof \NestedQueryExpression) {
|
||||
$oNestedSearchInExpression = $oExpression->GetNestedQuery();
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
self::assertNotNull($oNestedSearchInExpression, 'We must have a DBSearch inside a NestedQueryExpression inside the root DBSearch');
|
||||
/** @var \DBObjectSearch $oNestedSearchInExpression */
|
||||
self::assertEquals($bAllowAllData, $oNestedSearchInExpression->IsAllDataAllowed(), 'Nested DBSearch AllowData value');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ class OQLTest extends ItopDataTestCase
|
||||
*
|
||||
* @param $sQuery
|
||||
*
|
||||
* @expectedException \TypeError
|
||||
* @expectedException \CoreException
|
||||
*
|
||||
* @throws \OQLException
|
||||
*/
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Portal\Controller\ObjectController;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use ContextTag;
|
||||
use MetaModel;
|
||||
use PHPUnit\Exception;
|
||||
use TriggerOnObjectCreate;
|
||||
|
||||
/**
|
||||
@@ -14,10 +16,17 @@ use TriggerOnObjectCreate;
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
|
||||
class TriggerTest extends ItopDataTestCase
|
||||
{
|
||||
const USE_TRANSACTION = false;
|
||||
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testIsContextValid()
|
||||
{
|
||||
/** @var TriggerOnObjectCreate $oTrigger */
|
||||
@@ -29,4 +38,65 @@ class TriggerTest extends ItopDataTestCase
|
||||
ContextTag::AddContext(ContextTag::TAG_CRON);
|
||||
$this->assertTrue($oTrigger->IsContextValid());
|
||||
}
|
||||
|
||||
public function testEnrichRaisedException_Trigger()
|
||||
{
|
||||
$oTrigger = MetaModel::NewObject('TriggerOnObjectCreate');
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
MetaModel::NewObject('Toto');
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
\utils::EnrichRaisedException($oTrigger, $e);
|
||||
}
|
||||
$this->assertTrue(false, "An exception should have been thrown");
|
||||
}
|
||||
catch(\CoreException $e1)
|
||||
{
|
||||
$this->assertEquals('CoreException', get_class($e1));
|
||||
$this->assertEquals('Unknown class \'Toto\' (<b title="Trigger">TriggerOnObjectCreate</b>::-1 ()<br/>)', $e1->getMessage());
|
||||
|
||||
$fullStackTraceAsString = $e1->getFullStackTraceAsString();
|
||||
$this->assertContains("MetaModel::NewObject", $fullStackTraceAsString,"new enriched exception should contain root cause method: " . $fullStackTraceAsString);
|
||||
}
|
||||
}
|
||||
|
||||
public function NoEnrichmentProvider()
|
||||
{
|
||||
return [
|
||||
[ null ],
|
||||
[ new NonCmdbAbstractObject() ],
|
||||
] ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $oCmdbAbstract
|
||||
* @dataProvider NoEnrichmentProvider
|
||||
*/
|
||||
public function testEnrichRaisedException_NoEnrichment($oCmdbAbstract)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
MetaModel::NewObject('CoreException');
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
\utils::EnrichRaisedException($oCmdbAbstract, $e);
|
||||
}
|
||||
$this->assertTrue(false, "An exception should have been thrown");
|
||||
}
|
||||
catch(\Exception $e1)
|
||||
{
|
||||
$this->assertEquals($e, $e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NonCmdbAbstractObject{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user