mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
Merge remote-tracking branch 'origin/support/3.1' into support/3.2
# Conflicts: # pages/csvimport.php
This commit is contained in:
@@ -10,6 +10,7 @@ use CMDBSource;
|
||||
use DeprecatedCallsLog;
|
||||
use MySQLTransactionNotClosedException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionMethod;
|
||||
use SetupUtils;
|
||||
use const DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||
|
||||
@@ -77,7 +78,54 @@ abstract class ItopTestCase extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
/**
|
||||
* @param array $args
|
||||
* @param string $sExportFileName relative to log folder
|
||||
* @param array $aExcludedParams
|
||||
* Function that aims to export the values of the parameters of a function in a file
|
||||
* You can call the function anywhere like following :
|
||||
* ```
|
||||
* require __DIR__ . '/../../../tests/php-unit-tests/vendor/autoload.php'; // required to include phpunit autoload
|
||||
* ItopTestCase::ExportFunctionParameterValues(func_get_args(), "parameters.txt");
|
||||
* ```
|
||||
* Useful to generate realistic data for tests providers
|
||||
*
|
||||
* @return string
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function ExportFunctionParameterValues(array $args, string $sExportFileName, array $aExcludedParams = []): string
|
||||
{
|
||||
// get sclass et function dans la callstrack
|
||||
|
||||
// in the callstack get the call function name
|
||||
$aCallStack = debug_backtrace();
|
||||
$sCallFunction = $aCallStack[1]['function'];
|
||||
// in the casll stack get the call class name
|
||||
$sCallClass = $aCallStack[1]['class'];
|
||||
$reflectionFunc = new ReflectionMethod($sCallClass, $sCallFunction);
|
||||
$parameters = $reflectionFunc->getParameters();
|
||||
|
||||
$aParamValues = [];
|
||||
foreach ($parameters as $index => $param) {
|
||||
$aParamValues[$param->getName()] = $args[$index] ?? null;
|
||||
}
|
||||
|
||||
$paramValues = $aParamValues;
|
||||
foreach ($aExcludedParams as $sExcludedParam) {
|
||||
unset($paramValues[$sExcludedParam]);
|
||||
}
|
||||
|
||||
// extract oPage from the array in parameters and make a foreach on exlucded parameters
|
||||
foreach ($aExcludedParams as $sExcludedParam) {
|
||||
unset($paramValues[$sExcludedParam]);
|
||||
}
|
||||
|
||||
$var_export = var_export($paramValues, true);
|
||||
file_put_contents(APPROOT.'/log/' .$sExportFileName, $var_export);
|
||||
return $var_export;
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->debug("\n----------\n---------- ".$this->getName()."\n----------\n");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use CMDBSource;
|
||||
use BulkChange;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use MetaModel;
|
||||
|
||||
@@ -43,7 +43,7 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
"contactid" =>
|
||||
array("first_name" => 0, "name" => 1, "email" => 2),
|
||||
);
|
||||
$oBulk = new \BulkChange(
|
||||
$oBulk = new BulkChange(
|
||||
"UserLocal",
|
||||
$aData,
|
||||
$aAttributes,
|
||||
@@ -70,18 +70,19 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
|
||||
/**
|
||||
* test $oBulk->Process with server 1 from demo datas
|
||||
* @dataProvider BulkChangeProvider
|
||||
*
|
||||
* @param $aData
|
||||
* @dataProvider bulkChangeWithoutInitDataProvider
|
||||
*
|
||||
* @param $aCSVData
|
||||
* @param $aAttributes
|
||||
* @param $aExtKeys
|
||||
* @param $aReconcilKeys
|
||||
*/
|
||||
public function testBulkChangeIssue($aData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult) {
|
||||
public function testBulkChangeWithoutInitData($aCSVData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, array $aResultHTML = null) {
|
||||
$this->debug("aReconcilKeys:".$aReconcilKeys[0]);
|
||||
$oBulk = new \BulkChange(
|
||||
$oBulk = new BulkChange(
|
||||
"Server",
|
||||
$aData,
|
||||
$aCSVData,
|
||||
$aAttributes,
|
||||
$aExtKeys,
|
||||
$aReconcilKeys,
|
||||
@@ -102,67 +103,117 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
foreach ($aRow as $i => $oCell) {
|
||||
if ($i !== "finalclass" && $i !== "__STATUS__" && $i !== "__ERRORS__" && array_key_exists($i, $aResult)) {
|
||||
$this->debug("i:".$i);
|
||||
$this->debug('GetDisplayableValue:'.$oCell->GetDisplayableValue());
|
||||
$this->debug('GetCLIValue:'.$oCell->GetCLIValue());
|
||||
$this->debug("aResult:".$aResult[$i]);
|
||||
$this->assertEquals($aResult[$i], $oCell->GetDisplayableValue());
|
||||
$this->assertEquals($aResult[$i], $oCell->GetCLIValue());
|
||||
if (null !== $aResultHTML) {
|
||||
$this->assertEquals($aResultHTML[$i], $oCell->GetHTMLValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function BulkChangeProvider() {
|
||||
public function bulkChangeWithoutInitDataProvider() {
|
||||
return [
|
||||
"Case 3, 5 et 8 : unchanged" => [
|
||||
[["Demo", "Server1", "1", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[0 => "Demo", "org_id" => "3", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
|
||||
"csvData" =>
|
||||
[["Demo", "Server1", "1", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconciliation Keys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[0 => "Demo", "org_id" => "3", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
|
||||
"expectedResultHTML"=>
|
||||
[0 => "Demo", "org_id" => "3", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
|
||||
],
|
||||
"Case 9 : wrong date format" => [
|
||||
[["Demo", "Server1", "1", "production", "date"]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[ 0 => "Demo", "org_id" => "n/a", 1 => "Server1", 2 => "1", 3 => "production", 4 => "'date' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
|
||||
],
|
||||
"csvData" =>
|
||||
[["Demo", "Server1", "1", "production", "<date"]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconciliation Keys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ 0 => "Demo", "org_id" => "n/a", 1 => "Server1", 2 => "1", 3 => "production", 4 => "'<date' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
|
||||
"expectedResultHTML"=>
|
||||
[ 0 => "Demo", "org_id" => "n/a", 1 => "Server1", 2 => "1", 3 => "production", 4 => "'<date' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
|
||||
],
|
||||
"Case 1 : no match" => [
|
||||
[["Bad", "Server1", "1", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[0 => 'Bad', "org_id" => "No match for value 'Bad'",1 => "Server1",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
|
||||
"csvData" =>
|
||||
[["<Bad", "Server1", "1", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconciliation Keys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[0 => '<Bad', "org_id" => "No match for value '<Bad'",1 => "Server1",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
|
||||
"expectedResultHTML"=>
|
||||
[0 => '<Bad', "org_id" => "No match for value '<Bad'",1 => "Server1",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
|
||||
],
|
||||
"Case 10 : Missing mandatory value" => [
|
||||
[["", "Server1", "1", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[0 => null, "org_id" => "Invalid value for attribute", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
|
||||
],
|
||||
"csvData" =>
|
||||
[["", "Server1", "1", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconciliation Keys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[0 => null, "org_id" => "Invalid value for attribute", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
|
||||
"expectedResultHTML"=>
|
||||
[0 => null, "org_id" => "Invalid value for attribute", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
|
||||
],
|
||||
"Case 6 : Unexpected value" => [
|
||||
[["Demo", "Server1", "1", "<svg onclick\"alert(1)\">", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => "Server1",
|
||||
2 => "1",
|
||||
3 => "'<svg onclick"alert(1)">' is an invalid value",
|
||||
4 => "",
|
||||
"id" => 1,
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Unexpected value for attribute 'status': no match found, check spelling"],
|
||||
"csvData" =>
|
||||
[["Demo", "Server1", "1", "<svg onclick\"alert(1)\">", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconciliation Keys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => "Server1",
|
||||
2 => "1",
|
||||
3 => '\'<svg onclick"alert(1)">\' is an invalid value',
|
||||
4 => "",
|
||||
"id" => 1,
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Unexpected value for attribute 'status': no match found, check spelling"
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => "Server1",
|
||||
2 => "1",
|
||||
3 => '\'<svg onclick"alert(1)">\' is an invalid value',
|
||||
4 => "",
|
||||
"id" => 1,
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Unexpected value for attribute 'status': no match found, check spelling"
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test $oBulk->Process with new server datas
|
||||
* @dataProvider CSVImportProvider
|
||||
*
|
||||
* @dataProvider bulkChangeWithExistingDataProvider
|
||||
*
|
||||
* @param $aInitData
|
||||
* @param $aCsvData
|
||||
@@ -170,7 +221,7 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
* @param $aExtKeys
|
||||
* @param $aReconcilKeys
|
||||
*/
|
||||
public function testCas1BulkChangeIssue($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult) {
|
||||
public function testBulkChangeWithExistingData($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, $aResultHTML= null) {
|
||||
//change value during the test
|
||||
$db_core_transactions_enabled=MetaModel::GetConfig()->Get('db_core_transactions_enabled');
|
||||
MetaModel::GetConfig()->Set('db_core_transactions_enabled',false);
|
||||
@@ -185,10 +236,16 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
));
|
||||
$aCsvData[0][2]=$oServer->GetKey();
|
||||
$aResult[2]=$oServer->GetKey();
|
||||
$aResult["id"]=$oServer->GetKey();
|
||||
if ($aResult["id"]==="{Id of the server created by the test}") {
|
||||
$aResult["id"]=$oServer->GetKey();
|
||||
if ($aResultHTML!==null){
|
||||
$aResultHTML[2]=$oServer->GetKey();
|
||||
$aResultHTML["id"]=$oServer->GetKey();
|
||||
}
|
||||
}
|
||||
$this->debug("oServer->GetKey():".$oServer->GetKey());
|
||||
}
|
||||
$oBulk = new \BulkChange(
|
||||
$oBulk = new BulkChange(
|
||||
"Server",
|
||||
$aCsvData,
|
||||
$aAttributes,
|
||||
@@ -209,145 +266,318 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
foreach ($aRow as $i => $oCell) {
|
||||
if ($i !== "finalclass" && $i !== "__STATUS__" && $i !== "__ERRORS__" && array_key_exists($i, $aResult)) {
|
||||
$this->debug("i:".$i);
|
||||
$this->debug('GetDisplayableValue:'.$oCell->GetDisplayableValue());
|
||||
$this->debug('GetCLIValue:'.$oCell->GetCLIValue());
|
||||
$this->debug("aResult:".$aResult[$i]);
|
||||
$this->assertEquals( $aResult[$i], $oCell->GetDisplayableValue(), "failure on " . get_class($oCell) . ' cell type');
|
||||
$this->assertEquals( $aResult[$i], $oCell->GetCLIValue(), "failure on " . get_class($oCell) . ' cell type for cell number ' . $i );
|
||||
if (null !== $aResultHTML) {
|
||||
$this->assertEquals($aResultHTML[$i], $oCell->GetHTMLValue(), "failure on " . get_class($oCell) . ' cell type for cell number ' . $i);
|
||||
}
|
||||
} else if ($i === "__ERRORS__") {
|
||||
$sErrors = array_key_exists("__ERRORS__", $aResult) ? $aResult["__ERRORS__"] : "";
|
||||
$this->assertEquals( $sErrors, $oCell->GetDescription());
|
||||
}
|
||||
}
|
||||
$this->assertEquals( $aResult[0], $aRow[0]->GetDisplayableValue());
|
||||
$this->assertEquals( $aResult[0], $aRow[0]->GetCLIValue());
|
||||
if (null !== $aResultHTML) {
|
||||
$this->assertEquals($aResultHTML[0], $aRow[0]->GetHTMLValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
MetaModel::GetConfig()->Set('db_core_transactions_enabled',$db_core_transactions_enabled);
|
||||
}
|
||||
|
||||
public function CSVImportProvider() {
|
||||
public function bulkChangeWithExistingDataProvider() {
|
||||
return [
|
||||
"Ambigous case on reconciliation" => [
|
||||
"initData"=>
|
||||
["1", "Server1", "production", ""],
|
||||
"csvData" =>
|
||||
[[">Demo", "Server1"]],
|
||||
"attributes"=>
|
||||
["name" => 1],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["name"],
|
||||
"expectedResult"=>
|
||||
[
|
||||
0 => ">Demo",
|
||||
"org_id" => "n/a",
|
||||
1 => "Server1",
|
||||
"id" => "Invalid value for attribute",
|
||||
"__STATUS__" => "Issue: ambiguous reconciliation",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[
|
||||
0 => ">Demo",
|
||||
"org_id" => "n/a",
|
||||
1 => "Server1",
|
||||
"id" => "Invalid value for attribute",
|
||||
"__STATUS__" => "Issue: ambiguous reconciliation",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
],
|
||||
"Case 6 - 1 : Unexpected value (update)" => [
|
||||
["1", "ServerTest", "production", ""],
|
||||
[["Demo", "ServerTest", "key", "BadValue", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => "ServerTest",
|
||||
2 => "1",
|
||||
3 => "'BadValue' is an invalid value",
|
||||
4 => "",
|
||||
"id" => 1,
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", ""],
|
||||
"csvData"=>
|
||||
[["Demo", ">ServerTest", "key - will be automatically overwritten by test", ">BadValue", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[
|
||||
"id" => "{Id of the server created by the test}",
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => ">ServerTest",
|
||||
2 => "1",
|
||||
3 => "'>BadValue' is an invalid value",
|
||||
4 => "",
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[
|
||||
"id" => "{Id of the server created by the test}",
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => ">ServerTest",
|
||||
2 => "1",
|
||||
3 => "'>BadValue' is an invalid value",
|
||||
4 => "",
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
|
||||
],
|
||||
"Case 6 - 2 : Unexpected value (update)" => [
|
||||
["1", "ServerTest", "production", ""],
|
||||
[["Demo", "ServerTest", "key", "<svg onclick\"alert(1)\">", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => "ServerTest",
|
||||
2 => "1",
|
||||
3 => "'<svg onclick"alert(1)">' is an invalid value",
|
||||
4 => "",
|
||||
"id" => 1,
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", ""],
|
||||
"csvData"=>
|
||||
[["Demo", ">ServerTest", "key", "<svg onclick\"alert(1)\">", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[
|
||||
"id" => "{Id of the server created by the test}",
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => ">ServerTest",
|
||||
2 => "1",
|
||||
3 => '\'<svg onclick"alert(1)">\' is an invalid value',
|
||||
4 => "",
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[
|
||||
"id" => "{Id of the server created by the test}",
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => ">ServerTest",
|
||||
2 => "1",
|
||||
3 => "'<svg onclick"alert(1)">' is an invalid value",
|
||||
4 => "",
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
],
|
||||
"Case 6 - 3 : Unexpected value (creation)" => [
|
||||
[],
|
||||
[["Demo", "ServerTest", "<svg onclick\"alert(1)\">", ""]],
|
||||
["name" => 1, "status" => 2, "purchase_date" => 3],
|
||||
["org_id" => ["name" => 0]],
|
||||
["name"],
|
||||
[
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => "\"ServerTest\"",
|
||||
2 => "'<svg onclick"alert(1)">' is an invalid value",
|
||||
3 => "",
|
||||
"id" => 1,
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
"initData"=>
|
||||
[],
|
||||
"csvData"=>
|
||||
[["Demo", ">ServerTest", "<svg onclick\"alert(1)\">", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "status" => 2, "purchase_date" => 3],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["name"],
|
||||
"expectedResult"=>
|
||||
[
|
||||
"id" => "{Id of the server created by the test}",
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => "\">ServerTest\"",
|
||||
2 => '\'<svg onclick"alert(1)">\' is an invalid value',
|
||||
3 => "",
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[
|
||||
"id" => "{Id of the server created by the test}",
|
||||
0 => "Demo",
|
||||
"org_id" => "3",
|
||||
1 => ">ServerTest",
|
||||
2 => "'<svg onclick"alert(1)">' is an invalid value",
|
||||
3 => "",
|
||||
"__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
|
||||
],
|
||||
],
|
||||
"Case 8 : unchanged name" => [
|
||||
["1", "<svg onclick\"alert(1)\">", "production", ""],
|
||||
[["Demo", "<svg onclick\"alert(1)\">", "key", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[0 => "Demo", "org_id" => "3", 1 => "<svg onclick"alert(1)">", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "updated 1 cols"],
|
||||
"initData"=>
|
||||
["1", "<svg onclick\"alert(1)\">", "production", ""],
|
||||
"csvData"=>
|
||||
[["Demo", "<svg onclick\"alert(1)\">", "key", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "3", 1 => '<svg onclick"alert(1)">', 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
|
||||
"expectedResultHTML"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "3", 1 => '<svg onclick"alert(1)">', 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
|
||||
],
|
||||
"Case 3, 5 et 8 : unchanged 2" => [
|
||||
["1", "ServerTest", "production", ""],
|
||||
[["Demo", "ServerTest", "1", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[0 => "Demo", "org_id" => "3", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "updated 1 cols"],
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", ""],
|
||||
"csvData"=>
|
||||
[["Demo", ">ServerTest", "1", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "3", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
|
||||
"expectedResultHTML"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "3", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "updated 1 cols"],
|
||||
],
|
||||
"Case 9 - 1: wrong date format" => [
|
||||
["1", "ServerTest", "production", ""],
|
||||
[["Demo", "ServerTest", "1", "production", "date"]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[ 0 => "Demo", "org_id" => "n/a", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "'date' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
|
||||
],
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", ""],
|
||||
"csvData"=>
|
||||
[["Demo", ">ServerTest", "1", "production", "date>"]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "'date>' is an invalid value", "__STATUS__" => "Issue: wrong date format"],
|
||||
"expectedResultHTML"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "'date>' is an invalid value", "__STATUS__" => "Issue: wrong date format"],
|
||||
],
|
||||
"Case 9 - 2: wrong date format" => [
|
||||
["1", "ServerTest", "production", ""],
|
||||
[["Demo", "ServerTest", "1", "production", "<svg onclick\"alert(1)\">"]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[ 0 => "Demo", "org_id" => "n/a", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "'<svg onclick"alert(1)">' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", ""],
|
||||
"csvData"=>
|
||||
[["Demo", ">ServerTest", "1", "production", "<svg onclick\"alert(1)\">"]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => '\'<svg onclick"alert(1)">\' is an invalid value',"__STATUS__" => "Issue: wrong date format"],
|
||||
"expectedResultHTML"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => '\'<svg onclick"alert(1)">\' is an invalid value',"__STATUS__" => "Issue: wrong date format"],
|
||||
|
||||
],
|
||||
"Case 1 - 1 : no match" => [
|
||||
["1", "ServerTest", "production", ""],
|
||||
[["Bad", "ServerTest", "1", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[ 0 => "Bad", "org_id" => "No match for value 'Bad'",1 => "ServerTest",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Object not found",
|
||||
],
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", ""],
|
||||
"csvData"=>
|
||||
[[">Bad", ">ServerTest", "1", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => ">Bad", "org_id" => "No match for value '>Bad'",1 => ">ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Object not found",
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => ">Bad", "org_id" => "No match for value '>Bad'",1 => ">ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Object not found",
|
||||
],
|
||||
],
|
||||
"Case 1 - 2 : no match" => [
|
||||
["1", "ServerTest", "production", ""],
|
||||
[["<svg fonclick\"alert(1)\">", "ServerTest", "1", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[ 0 => "<svg fonclick"alert(1)">", "org_id" => "No match for value '<svg fonclick\"alert(1)\">'",1 => "ServerTest",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Object not found",
|
||||
],
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", ""],
|
||||
"csvData"=>
|
||||
[["<svg onclick\"alert(1)\">", ">ServerTest", "1", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => '<svg onclick"alert(1)">', "org_id" => "No match for value '<svg onclick\"alert(1)\">'",1 => ">ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Object not found",
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => '<svg onclick"alert(1)">', "org_id" => "No match for value '<svg onclick"alert(1)">'",1 => ">ServerTest",2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Object not found",
|
||||
],
|
||||
],
|
||||
"Case 10 : Missing mandatory value" => [
|
||||
["1", "ServerTest", "production", ""],
|
||||
[["", "ServerTest", "1", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[ 0 => "", "org_id" => "Invalid value for attribute", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Null not allowed",
|
||||
],
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", ""],
|
||||
"csvData"=>
|
||||
[["", ">ServerTest", "1", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "", "org_id" => "Invalid value for attribute", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Null not allowed",
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "", "org_id" => "Invalid value for attribute", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "", "__STATUS__" => "Issue: Unexpected attribute value(s)",
|
||||
"__ERRORS__" => "Null not allowed",
|
||||
],
|
||||
],
|
||||
|
||||
"Case 0 : Date format" => [
|
||||
["1", "ServerTest", "production", "2020-02-01"],
|
||||
[["Demo", "ServerTest", "1", "production", "2020-20-03"]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[ 0 => "Demo", "org_id" => "n/a", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "'2020-20-03' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
|
||||
"Case 0 : Date format ok but incorrect date" => [
|
||||
"initData"=>
|
||||
["1", ">ServerTest", "production", "2020-02-01"],
|
||||
"csvData"=>
|
||||
[["Demo", ">ServerTest", "1", "production", "2020-20-03"]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[ "id" => "{Id of the server created by the test}",
|
||||
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "'2020-20-03' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -356,7 +586,8 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
|
||||
/**
|
||||
* test $oBulk->Process with new server and new organization datas
|
||||
* @dataProvider CSVImportProvider2
|
||||
*
|
||||
* @dataProvider bulkChangeWithExistingDataAndSpecificOrgProvider
|
||||
*
|
||||
* @param $aInitData
|
||||
* @param $aCsvData
|
||||
@@ -364,27 +595,39 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
* @param $aExtKeys
|
||||
* @param $aReconcilKeys
|
||||
*/
|
||||
public function testCas2BulkChangeIssue($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult) {
|
||||
public function testBulkChangeWithExistingDataAndSpecificOrg($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult, $aResultHTML = null) {
|
||||
//change value during the test
|
||||
$db_core_transactions_enabled=MetaModel::GetConfig()->Get('db_core_transactions_enabled');
|
||||
MetaModel::GetConfig()->Set('db_core_transactions_enabled',false);
|
||||
if (is_array($aInitData) && sizeof($aInitData) != 0) {
|
||||
/** @var Server $oServer */
|
||||
$oOrganisation = $this->createObject('Organization', array(
|
||||
'name' => $aInitData[0]
|
||||
'name' => $aInitData["orgName"]
|
||||
));
|
||||
$aResult["org_id"] = $oOrganisation->GetKey();
|
||||
if ($aResult["org_id"]==="{org id of the server created by the test}"){
|
||||
$aResult["org_id"] = $oOrganisation->GetKey();
|
||||
if ($aResultHTML!==null){
|
||||
$aResultHTML["org_id"]=$oOrganisation->GetKey();
|
||||
}
|
||||
}
|
||||
|
||||
$oServer = $this->createObject('Server', array(
|
||||
'name' => $aInitData[1],
|
||||
'status' => $aInitData[2],
|
||||
'name' => $aInitData["serverName"],
|
||||
'status' => $aInitData["serverStatus"],
|
||||
'org_id' => $oOrganisation->GetKey(),
|
||||
'purchase_date' => $aInitData[3],
|
||||
'purchase_date' => $aInitData["serverPurchaseDate"],
|
||||
));
|
||||
$aCsvData[0][2]=$oServer->GetKey();
|
||||
$aResult[2]=$oServer->GetKey();
|
||||
$aResult["id"]=$oServer->GetKey();
|
||||
if ($aResult["id"]==="{Id of the server created by the test}") {
|
||||
$aResult["id"]=$oServer->GetKey();
|
||||
if ($aResultHTML!==null){
|
||||
$aResultHTML[2]=$oServer->GetKey();
|
||||
$aResultHTML["id"]=$oServer->GetKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
$oBulk = new \BulkChange(
|
||||
$oBulk = new BulkChange(
|
||||
"Server",
|
||||
$aCsvData,
|
||||
$aAttributes,
|
||||
@@ -401,9 +644,12 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
foreach ($aRow as $i => $oCell) {
|
||||
if ($i !== "finalclass" && $i !== "__STATUS__" && $i !== "__ERRORS__" && array_key_exists($i, $aResult)) {
|
||||
$this->debug("i:".$i);
|
||||
$this->debug('GetDisplayableValue:'.$oCell->GetDisplayableValue());
|
||||
$this->debug('GetCLIValue:'.$oCell->GetCLIValue());
|
||||
$this->debug("aResult:".$aResult[$i]);
|
||||
$this->assertEquals($aResult[$i], $oCell->GetDisplayableValue());
|
||||
$this->assertEquals($aResult[$i], $oCell->GetCLIValue(), "$i cell is incorrect");
|
||||
if (null !== $aResultHTML) {
|
||||
$this->assertEquals($aResultHTML[$i], $oCell->GetHTMLValue());
|
||||
}
|
||||
} elseif ($i === "__STATUS__") {
|
||||
$sStatus = $aRow['__STATUS__'];
|
||||
$this->assertEquals($aResult["__STATUS__"], $sStatus->GetDescription());
|
||||
@@ -412,36 +658,109 @@ class BulkChangeTest extends ItopDataTestCase
|
||||
$this->assertEquals( $sErrors, $oCell->GetDescription());
|
||||
}
|
||||
}
|
||||
$this->assertEquals($aResult[0], $aRow[0]->GetDisplayableValue());
|
||||
$this->assertEquals($aResult[0], $aRow[0]->GetCLIValue());
|
||||
if (null !== $aResultHTML) {
|
||||
$this->assertEquals($aResultHTML[0], $aRow[0]->GetHTMLValue());
|
||||
}
|
||||
}
|
||||
MetaModel::GetConfig()->Set('db_core_transactions_enabled',$db_core_transactions_enabled);
|
||||
}
|
||||
|
||||
public function CSVImportProvider2() {
|
||||
public function bulkChangeWithExistingDataAndSpecificOrgProvider() {
|
||||
return [
|
||||
"Ambigous case " => [
|
||||
"initData"=>
|
||||
["orgName" => "Demo", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
|
||||
"csvData" =>
|
||||
[["Demo", ">Server1"]],
|
||||
"attributes"=>
|
||||
["name" => 1],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["org_id"],
|
||||
"expectedResult"=>
|
||||
[
|
||||
0 => "Demo",
|
||||
"org_id" => "Invalid value for attribute",
|
||||
1 => ">Server1",
|
||||
"id" => "Invalid value for attribute",
|
||||
"__STATUS__" => "Issue: failed to reconcile",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implemfentation,production,obsolete",
|
||||
],
|
||||
"expectedResultHTML"=>
|
||||
[
|
||||
0 => "Demo",
|
||||
"org_id" => "Invalid value for attribute",
|
||||
1 => ">Server1",
|
||||
"id" => "Invalid value for attribute",
|
||||
"__STATUS__" => "Issue: failed to reconcile",
|
||||
"__ERRORS__" => "Allowed 'status' value(s): stock,implemfentation,production,obsolete",
|
||||
],
|
||||
],
|
||||
"Case 3 : unchanged name" => [
|
||||
["dodo","ServerYO", "production", ""],
|
||||
[["dodo", "ServerYO", "key", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[0 => "dodo", "org_id" => "3", 1 => "ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
|
||||
"initData"=>
|
||||
["orgName" => ">dodo", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
|
||||
"csvData"=>
|
||||
[[">dodo", ">ServerYO", "key will be set by the test", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[0 => ">dodo", "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
|
||||
"expectedResultHTML"=>
|
||||
[0 => ">dodo", "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
|
||||
],
|
||||
"Case 3 bis : unchanged name" => [
|
||||
["<svg >","ServerYO", "production", ""],
|
||||
[["<svg >", "ServerYO", "key", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[0 => "<svg >", "org_id" => "3", 1 => "ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
|
||||
"initData"=>
|
||||
["orgName" =>"<svg >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
|
||||
"csvData"=>
|
||||
[["<svg >", ">ServerYO", "key", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[0 => "<svg >", "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
|
||||
"expectedResultHTML"=>
|
||||
[0 => "<svg >", "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
|
||||
],
|
||||
"Case 3 ter : unchanged name" => [
|
||||
["<svg onclick\"alert(1)\" >","ServerYO", "production", ""],
|
||||
[["<svg onclick\"alert(1)\" >", "ServerYO", "key", "production", ""]],
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
["org_id" => ["name" => 0]],
|
||||
["id"],
|
||||
[0 => "<svg onclick"alert(1)" >", "org_id" => "3", 1 => "ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
|
||||
"initData"=>
|
||||
["orgName" => "<svg onclick\"alert(1)\" >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
|
||||
"csvData"=>
|
||||
[["<svg onclick\"alert(1)\" >", ">ServerYO", "key", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["id"],
|
||||
"expectedResult"=>
|
||||
[0 => '<svg onclick"alert(1)" >', "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
|
||||
"expectedResultHTML"=>
|
||||
[0 => '<svg onclick"alert(1)" >', "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
|
||||
],
|
||||
"Case reconciliation on external key" => [
|
||||
"initData"=>
|
||||
["orgName" => "<svg onclick\"alert(1)\" >", "serverName" => ">ServerYO", "serverStatus" => "production", "serverPurchaseDate" =>""],
|
||||
"csvData"=>
|
||||
[["<svg onclick\"alert(1)\" >", ">ServerYO", "key", "production", ""]],
|
||||
"attributes"=>
|
||||
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
|
||||
"extKeys"=>
|
||||
["org_id" => ["name" => 0]],
|
||||
"reconcilKeys"=>
|
||||
["org_id", "name"],
|
||||
"expectedResult"=>
|
||||
[0 => '<svg onclick"alert(1)" >', "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
|
||||
"expectedResultHTML"=>
|
||||
[0 => '<svg onclick"alert(1)" >', "org_id" => "{org id of the server created by the test}", 1 => ">ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => "{Id of the server created by the test}", "__STATUS__" => "unchanged"],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -299,7 +299,6 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
|
||||
$this->debug("Process:");
|
||||
static::assertNotNull($aRes);
|
||||
$this->debug("assertNotNull:");
|
||||
var_dump($aRes);
|
||||
foreach ($aRes as $aRow) {
|
||||
if (array_key_exists('__STATUS__', $aRow)) {
|
||||
$sStatus = $aRow['__STATUS__'];
|
||||
@@ -308,12 +307,11 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
|
||||
foreach ($aRow as $i => $oCell) {
|
||||
if ($i != "finalclass" && $i != "__STATUS__" && $i != "__ERRORS__") {
|
||||
$this->debug("i:" . $i);
|
||||
$this->debug('GetDisplayableValue:' . $oCell->GetDisplayableValue());
|
||||
if (array_key_exists($i, $aResult)) {
|
||||
$this->debug("aResult:" . var_export($aResult[$i]));
|
||||
if ($oCell instanceof \CellStatus_SearchIssue ||
|
||||
$oCell instanceof \CellStatus_Ambiguous) {
|
||||
$this->assertEquals($aResult[$i][0], $oCell->GetDisplayableValue(),
|
||||
$this->assertEquals($aResult[$i][0], $oCell->GetCLIValue(),
|
||||
"failure on " . get_class($oCell) . ' cell type');
|
||||
$this->assertEquals($sSearchLinkUrl, $oCell->GetSearchLinkUrl(),
|
||||
"failure on " . get_class($oCell) . ' cell type');
|
||||
@@ -326,7 +324,7 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
|
||||
$this->assertEquals($sErrors, $oCell->GetDescription());
|
||||
}
|
||||
}
|
||||
$this->assertEquals($aResult[0], $aRow[0]->GetDisplayableValue());
|
||||
$this->assertEquals($aResult[0], $aRow[0]->GetCLIValue());
|
||||
}
|
||||
}
|
||||
MetaModel::GetConfig()->Set('db_core_transactions_enabled', $db_core_transactions_enabled);
|
||||
|
||||
Reference in New Issue
Block a user