mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
Merge remote-tracking branch 'origin/support/2.7' into develop
# Conflicts: # .idea/codeStyles/codeStyleConfig.xml # .idea/inspectionProfiles/Combodo.xml
This commit is contained in:
@@ -675,17 +675,49 @@ class DBSearchTest extends ItopDataTestCase
|
||||
$TwoOrgIdsOnly = array($allOrgIds[0], $allOrgIds[1]);
|
||||
$oSearch = DBSearch::FromOQL("SELECT UserRequest WHERE org_id IN (:org_ids)");
|
||||
self::assertNotNull($oSearch);
|
||||
$oSet = new \CMDBObjectSet($oSearch, array(), array('org_ids'=> $TwoOrgIdsOnly));
|
||||
$oSet = new \CMDBObjectSet($oSearch, array(), array('org_ids' => $TwoOrgIdsOnly));
|
||||
static::assertEquals(4, $oSet->Count());
|
||||
|
||||
$_SERVER['REQUEST_URI']='FAKE_REQUEST_URI' ;
|
||||
$_SERVER['REQUEST_METHOD']='FAKE_REQUEST_METHOD';
|
||||
$_SERVER['REQUEST_URI'] = 'FAKE_REQUEST_URI';
|
||||
$_SERVER['REQUEST_METHOD'] = 'FAKE_REQUEST_METHOD';
|
||||
$oP = new \iTopWebPage("test");
|
||||
$oBlock = new \DisplayBlock($oSet->GetFilter(), 'list', false);
|
||||
$sHtml = $oBlock->GetDisplay($oP, 'package_table', array ('menu'=>true, 'display_limit'=>false));
|
||||
$sHtml = $oBlock->GetDisplay($oP, 'package_table', array('menu' => true, 'display_limit' => false));
|
||||
|
||||
$iHtmlUserRequestLineCount = substr_count($sHtml, '<tr><td data-object-class="UserRequest"');
|
||||
static::assertEquals(4, $iHtmlUserRequestLineCount, "Failed Generated html :" . $sHtml);
|
||||
static::assertEquals(4, $iHtmlUserRequestLineCount, "Failed Generated html :".$sHtml);
|
||||
$oP->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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