mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 18:18:46 +02:00
New methods for creating/import test data from XML files.
This commit is contained in:
@@ -28,6 +28,7 @@ namespace Combodo\iTop\Test\UnitTest;
|
||||
|
||||
use ArchivedObjectException;
|
||||
use CMDBSource;
|
||||
use CMDBObject;
|
||||
use Contact;
|
||||
use DBObject;
|
||||
use DBObjectSet;
|
||||
@@ -47,6 +48,7 @@ use Ticket;
|
||||
use URP_UserProfile;
|
||||
use VirtualHost;
|
||||
use VirtualMachine;
|
||||
use XMLDataLoader;
|
||||
|
||||
|
||||
/** @see \Combodo\iTop\Test\UnitTest\ItopDataTestCase::CreateObjectWithTagSet() */
|
||||
@@ -806,4 +808,43 @@ class ItopDataTestCase extends ItopTestCase
|
||||
static::assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a set of XML files describing a consistent set of iTop objects
|
||||
* @param string[] $aFiles
|
||||
* @param boolean $bSearch If true, a search will be performed on each object (based on its reconciliation keys)
|
||||
* before trying to import it (existing objects will be updated)
|
||||
* @return int Number of objects created
|
||||
*/
|
||||
protected function CreateFromXMLFiles($aFiles, $bSearch = false)
|
||||
{
|
||||
$oLoader = new XMLDataLoader();
|
||||
$oLoader->StartSession(CMDBObject::GetCurrentChange());
|
||||
foreach($aFiles as $sFilePath)
|
||||
{
|
||||
$oLoader->LoadFile($sFilePath, false, $bSearch);
|
||||
}
|
||||
$oLoader->EndSession();
|
||||
|
||||
return $oLoader->GetCountCreated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a consistent set of iTop objects from the specified XML text string
|
||||
* @param string $sXmlDataset
|
||||
* @param boolean $bSearch If true, a search will be performed on each object (based on its reconciliation keys)
|
||||
* before trying to import it (existing objects will be updated)
|
||||
* @return int The number of objects created
|
||||
*/
|
||||
protected function CreateFromXMLString($sXmlDataset, $bSearch = false)
|
||||
{
|
||||
$sTmpFileName = tempnam(sys_get_temp_dir(), 'xml');
|
||||
file_put_contents($sTmpFileName, $sXmlDataset);
|
||||
|
||||
$ret = $this->CreateFromXMLFiles([$sTmpFileName], $bSearch);
|
||||
|
||||
unlink($sTmpFileName);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user