mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-12 04:24:12 +01:00
N°2586 Test for iTopDesignFormat
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// Copyright (C) 2014-2017 Combodo SARL
|
||||
// Copyright (C) 2014-2019 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
@@ -16,10 +16,14 @@
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
define('ITOP_DESIGN_LATEST_VERSION', '1.7'); // iTop >= 2.7.0
|
||||
|
||||
/**
|
||||
* Utility to upgrade the format of a given XML datamodel to the latest version
|
||||
* The datamodel is supplied as a loaded DOMDocument and modified in-place.
|
||||
*
|
||||
*
|
||||
* To test migration methods check {@link \Combodo\iTop\Test\UnitTest\Setup\TestForITopDesignFormatClass}
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $oDocument = new DOMDocument();
|
||||
@@ -34,9 +38,6 @@
|
||||
* echo "Error, failed to upgrade the format, reason(s):\n".implode("\n", $oFormat->GetErrors());
|
||||
* }
|
||||
*/
|
||||
|
||||
define('ITOP_DESIGN_LATEST_VERSION', '1.7'); // iTop >= 2.7.0
|
||||
|
||||
class iTopDesignFormat
|
||||
{
|
||||
protected static $aVersions = array(
|
||||
|
||||
15
test/setup/iTopDesignFormat/1.7_to_1.6.expected.xml
Normal file
15
test/setup/iTopDesignFormat/1.7_to_1.6.expected.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.6">
|
||||
<menus>
|
||||
<menu id="WelcomeMenuLink1" xsi:type="WebPageMenuNode" _delta="define">
|
||||
<rank>100</rank>
|
||||
<parent>WelcomeMenu</parent>
|
||||
<url>$$http://fr.wikipedia.org/</url>
|
||||
</menu>
|
||||
<menu id="WelcomeMenuLink2" xsi:type="WebPageMenuNode" _delta="define">
|
||||
<rank>100</rank>
|
||||
<parent>WelcomeMenu</parent>
|
||||
<url>$$http://fr.wikipedia.org/</url>
|
||||
</menu>
|
||||
</menus>
|
||||
</itop_design>
|
||||
16
test/setup/iTopDesignFormat/1.7_to_1.6.input.xml
Normal file
16
test/setup/iTopDesignFormat/1.7_to_1.6.input.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.7">
|
||||
<menus>
|
||||
<menu id="WelcomeMenuLink1" xsi:type="WebPageMenuNode" _delta="define">
|
||||
<rank>100</rank>
|
||||
<parent>WelcomeMenu</parent>
|
||||
<url>$$http://fr.wikipedia.org/</url>
|
||||
<in_new_window>true</in_new_window>
|
||||
</menu>
|
||||
<menu id="WelcomeMenuLink2" xsi:type="WebPageMenuNode" _delta="define">
|
||||
<rank>100</rank>
|
||||
<parent>WelcomeMenu</parent>
|
||||
<url>$$http://fr.wikipedia.org/</url>
|
||||
</menu>
|
||||
</menus>
|
||||
</itop_design>
|
||||
73
test/setup/iTopDesignFormat/iTopDesignFormatTest.php
Normal file
73
test/setup/iTopDesignFormat/iTopDesignFormatTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use DOMDocument;
|
||||
use iTopDesignFormat;
|
||||
|
||||
|
||||
/**
|
||||
* Class iTopDesignFormatTest
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*
|
||||
* @covers iTopDesignFormat
|
||||
*
|
||||
* @since 2.7.0 N°2586
|
||||
* @package Combodo\iTop\Test\UnitTest\Setup
|
||||
*/
|
||||
class TestForITopDesignFormatClass extends ItopTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
require_once APPROOT.'setup/modelfactory.class.inc.php';
|
||||
require_once APPROOT.'setup/itopdesignformat.class.inc.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers iTopDesignFormat::Convert
|
||||
* @dataProvider testMigrationMethodProvider
|
||||
*
|
||||
* @param string $sTargetVersion
|
||||
* @param string $sInputXmlFileName example "1.7_to_1.6.input"
|
||||
* @param string $sExpectedXmlFileName example "1.7_to_1.6.expected"
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testMigrationMethod($sTargetVersion, $sInputXmlFileName, $sExpectedXmlFileName)
|
||||
{
|
||||
$sInputXml = $this->GetFileContent($sInputXmlFileName);
|
||||
$sExpectedXml = $this->GetFileContent($sExpectedXmlFileName);
|
||||
|
||||
$oInputDocument = new DOMDocument();
|
||||
libxml_clear_errors();
|
||||
$oInputDocument->preserveWhiteSpace = false;
|
||||
$oInputDocument->loadXML($sInputXml);
|
||||
$oInputDocument->formatOutput = true;
|
||||
$oDesignFormat = new iTopDesignFormat($oInputDocument);
|
||||
$oDesignFormat->Convert($sTargetVersion);
|
||||
|
||||
$sConvertedXml = $oInputDocument->saveXML();
|
||||
|
||||
$this->assertEquals($sExpectedXml, $sConvertedXml);
|
||||
}
|
||||
|
||||
private function GetFileContent($sFileName)
|
||||
{
|
||||
$sCurrentPath = __DIR__;
|
||||
|
||||
return file_get_contents($sCurrentPath.DIRECTORY_SEPARATOR.$sFileName.'.xml');
|
||||
}
|
||||
|
||||
public function testMigrationMethodProvider()
|
||||
{
|
||||
return array(
|
||||
'1.7 to 1.6' => array('1.6', '1.7_to_1.6.input', '1.7_to_1.6.expected'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user