mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
🐛 N°7313 - Bad display of single quotes in charts (#627)
* 🐛 N°7313 - Bad display of single quotes in charts
* Fix and improve ItopCustomDatamodelTestCase
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0">
|
||||
<classes>
|
||||
<class id="UserRequest">
|
||||
<fields>
|
||||
<field id="status" xsi:type="AttributeEnum">
|
||||
<always_load_in_tables>true</always_load_in_tables>
|
||||
<sort_type>rank</sort_type>
|
||||
<values>
|
||||
<value id="New_org_name_with_quote" _delta="define">
|
||||
<code>New'status</code>
|
||||
<rank>32</rank>
|
||||
</value>
|
||||
</values>
|
||||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
</classes>
|
||||
</itop_design>
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Application;
|
||||
|
||||
use Combodo\iTop\Application\UI\DisplayBlock\BlockChartAjaxPie\BlockChartAjaxPie;
|
||||
use Combodo\iTop\Test\UnitTest\ItopCustomDatamodelTestCase;
|
||||
use DBSearch;
|
||||
use DisplayBlock;
|
||||
use MetaModel;
|
||||
use UserRequest;
|
||||
|
||||
class DisplayBlockTest extends ItopCustomDatamodelTestCase
|
||||
{
|
||||
const CREATE_TEST_ORG = true;
|
||||
public function GetDatamodelDeltaAbsPath(): string
|
||||
{
|
||||
return __DIR__ . '/Delta/add-enum-value-with-quote.xml';
|
||||
}
|
||||
|
||||
public function renderChartAjaxProvider(): array
|
||||
{
|
||||
return [
|
||||
'simple string : name' => [ // chart with UserRequest title (evaluating string/scalar escaping)
|
||||
'class to display' => 'UserRequest',
|
||||
'class attribute to display' => 'title',
|
||||
'class to edit' => 'UserRequest',
|
||||
'related class attribute to edit' => 'title',
|
||||
'expected' => "New'name",
|
||||
'nonExpected' => 'New'name',
|
||||
],
|
||||
'enum : status' => [ // chart with UserRequest status (evaluating enum escaping)
|
||||
// not working because we need to allow a new value for the enum
|
||||
'class to display' => 'UserRequest',
|
||||
'attribute to display' => 'status',
|
||||
'class to edit' => 'UserRequest',
|
||||
'related class attribute to edit' => 'status',
|
||||
'expected' => "New'status",
|
||||
'nonExpected' => 'New'status',
|
||||
],
|
||||
'relation : Org name' => [ // chart with related organization name title (evaluating ext key escaping)
|
||||
'class to display' => 'UserRequest',
|
||||
'class attribute to display' => 'org_name',
|
||||
'class to edit' => 'Organization',
|
||||
'related class attribute to edit' => 'name',
|
||||
'expected' => "New'org_name",
|
||||
'nonExpected' => 'New'org_name',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider renderChartAjaxProvider
|
||||
*/
|
||||
public function testRenderChartAjax(string $sClassToDisplay, string $sAttributeToDisplay, string $sRelatedClass, string $sRelatedClassAttributeToEdit, string $sExpected, string $sNonExpected): void
|
||||
{
|
||||
$oUserRequest = new UserRequest();
|
||||
$oUserRequest->Set('title', 'MyTitle');
|
||||
$oUserRequest->Set('org_id', $this->getTestOrgId());
|
||||
$oUserRequest->Set('description', "MyDescription");
|
||||
$oUserRequest->DBInsert();
|
||||
|
||||
if ($sRelatedClass !== "UserRequest") {
|
||||
$oInstanceRelatedClass = MetaModel::GetObject($sRelatedClass, $this->getTestOrgId());
|
||||
} else {
|
||||
$oInstanceRelatedClass = $oUserRequest;
|
||||
}
|
||||
|
||||
$oInstanceRelatedClass->Set($sRelatedClassAttributeToEdit, $sExpected); // attribute that shouldn't be encoded
|
||||
$oInstanceRelatedClass->DBUpdate();
|
||||
|
||||
$oDisplayBlock = new DisplayBlock(
|
||||
DBSearch::FromOQL("SELECT $sClassToDisplay"),
|
||||
DisplayBlock::ENUM_STYLE_CHART_AJAX
|
||||
);
|
||||
|
||||
$aExtraParams = [
|
||||
"group_by" => $sAttributeToDisplay,
|
||||
"currentId" => "fake-dashlet-id",
|
||||
"order_direction" => "asc",
|
||||
"order_by" => $sAttributeToDisplay,
|
||||
"limit" => 10,
|
||||
];
|
||||
/** @var BlockChartAjaxPie $oBlock */
|
||||
$oBlock = $this->InvokeNonPublicMethod(get_class($oDisplayBlock), "RenderChartAjax", $oDisplayBlock, [$aExtraParams]);
|
||||
|
||||
$aJSNames = json_decode($oBlock->sJSNames, true);
|
||||
|
||||
$this->assertFalse(in_array($sNonExpected, $aJSNames));
|
||||
$this->assertTrue(in_array($sExpected, $aJSNames));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user