mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
Merge remote-tracking branch 'origin/feature/5655-edit-object-in-modal' into develop
# Conflicts: # pages/ajax.render.php
This commit is contained in:
@@ -420,6 +420,55 @@ class UtilsTest extends ItopTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ToCamelCaseProvider
|
||||
* @covers utils::ToCamelCase
|
||||
*
|
||||
* @param string $sInput
|
||||
* @param string $sExpectedOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testToCamelCase(string $sInput, string $sExpectedOutput)
|
||||
{
|
||||
$sTestedOutput = utils::ToCamelCase($sInput);
|
||||
$this->assertEquals($sExpectedOutput, $sTestedOutput, "Camel case transformation for '$sInput' doesn't match. Got '$sTestedOutput', expected '$sExpectedOutput'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.1.0
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function ToCamelCaseProvider(): array
|
||||
{
|
||||
return [
|
||||
'One word' => [
|
||||
'hello',
|
||||
'Hello',
|
||||
],
|
||||
'Two words separated with space' => [
|
||||
'hello world',
|
||||
'HelloWorld',
|
||||
],
|
||||
'Two words separated with underscore' => [
|
||||
'hello_world',
|
||||
'HelloWorld',
|
||||
],
|
||||
'Two words separated with dash' => [
|
||||
'hello-world',
|
||||
'HelloWorld',
|
||||
],
|
||||
'Two words separated with dot' => [
|
||||
'hello.world',
|
||||
'Hello.world',
|
||||
],
|
||||
'Three words separated with underscore and space' => [
|
||||
'hello_there world',
|
||||
'HelloThereWorld',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ToAcronymProvider
|
||||
* @covers utils::ToAcronym
|
||||
@@ -654,8 +703,8 @@ class UtilsTest extends ItopTestCase
|
||||
public function sanitizerDataProvider()
|
||||
{
|
||||
return [
|
||||
'good integer' => ['integer', '2565', '2565'],
|
||||
'bad integer' => ['integer', 'a2656', '2656'],
|
||||
'good integer' => [utils::ENUM_SANITIZATION_FILTER_INTEGER, '2565', '2565'],
|
||||
'bad integer' => [utils::ENUM_SANITIZATION_FILTER_INTEGER, 'a2656', '2656'],
|
||||
/**
|
||||
* 'class' filter needs a loaded datamodel... and is only an indirection to \MetaModel::IsValidClass so might very important to test !
|
||||
* If we switch this class to ItopDataTestCase then we are seeing :
|
||||
@@ -665,20 +714,26 @@ class UtilsTest extends ItopTestCase
|
||||
*/
|
||||
// 'good class' => ['class', 'UserRequest', 'UserRequest'],
|
||||
// 'bad class' => ['class', 'MyUserRequest',null],
|
||||
'good string' => ['string', 'Is Peter smart and funny?', 'Is Peter smart and funny?'],
|
||||
'bad string' => ['string', 'Is Peter <smart> & funny?', 'Is Peter <smart> & funny?'],
|
||||
'good transaction_id' => ['transaction_id', '8965.-dd', '8965.-dd'],
|
||||
'bad transaction_id' => ['transaction_id', '8965.-dd+', null],
|
||||
'good parameter' => ['parameter', 'JU8965-dd=_', 'JU8965-dd=_'],
|
||||
'bad parameter' => ['parameter', '8965.-dd+', null],
|
||||
'good field_name' => ['field_name', 'Name->bUzz38', 'Name->bUzz38'],
|
||||
'bad field_name' => ['field_name', 'name-buzz', null],
|
||||
'good context_param' => ['context_param', '%dssD25_=%:+-', '%dssD25_=%:+-'],
|
||||
'bad context_param' => ['context_param', '%dssD,25_=%:+-', null],
|
||||
'good element_identifier' => ['element_identifier', 'AD05nb', 'AD05nb'],
|
||||
'bad element_identifier' => ['element_identifier', 'AD05nb+', 'AD05nb'],
|
||||
'good url' => ['url', 'https://www.w3schools.com', 'https://www.w3schools.com'],
|
||||
'bad url' => ['url', 'https://www.w3schoo<6F><6F>ls.co<63>m', 'https://www.w3schools.com'],
|
||||
'good string' => [utils::ENUM_SANITIZATION_FILTER_STRING, 'Is Peter smart and funny?', 'Is Peter smart and funny?'],
|
||||
'bad string' => [utils::ENUM_SANITIZATION_FILTER_STRING, 'Is Peter <smart> & funny?', 'Is Peter <smart> & funny?'],
|
||||
'good transaction_id' => [utils::ENUM_SANITIZATION_FILTER_TRANSACTION_ID, '8965.-dd', '8965.-dd'],
|
||||
'bad transaction_id' => [utils::ENUM_SANITIZATION_FILTER_TRANSACTION_ID, '8965.-dd+', null],
|
||||
'good route' => [utils::ENUM_SANITIZATION_FILTER_ROUTE, 'object.modify', 'object.modify'],
|
||||
'good route with underscore' => [utils::ENUM_SANITIZATION_FILTER_ROUTE, 'object.apply_modify', 'object.apply_modify'],
|
||||
'bad route with space' => [utils::ENUM_SANITIZATION_FILTER_ROUTE, 'object modify', null],
|
||||
'good operation' => [utils::ENUM_SANITIZATION_FILTER_OPERATION, 'modify', 'modify'],
|
||||
'good operation with underscore' => [utils::ENUM_SANITIZATION_FILTER_OPERATION, 'apply_modify', 'apply_modify'],
|
||||
'bad operation with space' => [utils::ENUM_SANITIZATION_FILTER_OPERATION, 'apply modify', null],
|
||||
'good parameter' => [utils::ENUM_SANITIZATION_FILTER_PARAMETER, 'JU8965-dd=_', 'JU8965-dd=_'],
|
||||
'bad parameter' => [utils::ENUM_SANITIZATION_FILTER_PARAMETER, '8965.-dd+', null],
|
||||
'good field_name' => [utils::ENUM_SANITIZATION_FILTER_FIELD_NAME, 'Name->bUzz38', 'Name->bUzz38'],
|
||||
'bad field_name' => [utils::ENUM_SANITIZATION_FILTER_FIELD_NAME, 'name-buzz', null],
|
||||
'good context_param' => [utils::ENUM_SANITIZATION_FILTER_CONTEXT_PARAM, '%dssD25_=%:+-', '%dssD25_=%:+-'],
|
||||
'bad context_param' => [utils::ENUM_SANITIZATION_FILTER_CONTEXT_PARAM, '%dssD,25_=%:+-', null],
|
||||
'good element_identifier' => [utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER, 'AD05nb', 'AD05nb'],
|
||||
'bad element_identifier' => [utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER, 'AD05nb+', 'AD05nb'],
|
||||
'good url' => [utils::ENUM_SANITIZATION_FILTER_URL, 'https://www.w3schools.com', 'https://www.w3schools.com'],
|
||||
'bad url' => [utils::ENUM_SANITIZATION_FILTER_URL, 'https://www.w3schoo<6F><6F>ls.co<63>m', 'https://www.w3schools.com'],
|
||||
'raw_data' => ['raw_data', '<Test>\s😃😃😃', '<Test>\s😃😃😃'],
|
||||
];
|
||||
}
|
||||
|
||||
205
test/sources/Router/RouterTest.php
Normal file
205
test/sources/Router/RouterTest.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2022 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Router\Router;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
|
||||
/**
|
||||
* Class RouterTest
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @since 3.1.0
|
||||
* @covers \Combodo\iTop\Router\Router
|
||||
*/
|
||||
class RouterTest extends ItopTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider CanDispatchRouteProvider
|
||||
* @covers \Combodo\iTop\Router\Router::CanDispatchRoute
|
||||
*
|
||||
* @param string $sRoute
|
||||
* @param $bExpectedResult
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
// public function testCanDispatchRoute(string $sRoute, $bExpectedResult): void
|
||||
// {
|
||||
// $oRouter = Router::GetInstance();
|
||||
// $bTestedResult = $oRouter->CanDispatchRoute($sRoute);
|
||||
//
|
||||
// $sRouteNamespace = $oRouter->GetRouteNamespace($sRoute);
|
||||
// $sRouteOperation = $oRouter->GetRouteOperation($sRoute);
|
||||
// $aRouteParts = $oRouter->GetRouteParts($sRoute);
|
||||
// $sControllerFQCN = $this->InvokeNonPublicMethod(get_class($oRouter), 'FindControllerFromRouteNamespace', $oRouter, ['object']);
|
||||
// $sMethodName = $this->InvokeNonPublicMethod(get_class($oRouter), 'MakeOperationMethodNameFromOperation', $oRouter, ['modify']);
|
||||
// $aDispatchSpecs = $oRouter->GetDispatchSpecsForRoute($sRoute);
|
||||
//
|
||||
//$this->debug($sRoute);
|
||||
//$this->debug($sRouteNamespace);
|
||||
//$this->debug($sRouteOperation);
|
||||
//$this->debug($aRouteParts);
|
||||
//$this->debug($sControllerFQCN);
|
||||
//$this->debug($sMethodName);
|
||||
//$this->debug(is_callable([$sControllerFQCN, $sMethodName]) ? 'true' : 'false');
|
||||
//$this->debug($aDispatchSpecs);
|
||||
//$this->debug($bTestedResult);
|
||||
// $this->assertEquals($bExpectedResult, $bTestedResult, "Dispatch capability for '$sRoute' was not the expected one. Got ".var_export($bTestedResult, true).", expected ".var_export($bExpectedResult, true));
|
||||
// }
|
||||
|
||||
public function CanDispatchRouteProvider(): array
|
||||
{
|
||||
return [
|
||||
'Existing handler' => [
|
||||
'object.modify',
|
||||
true,
|
||||
],
|
||||
'Existing controller but unknown operation' => [
|
||||
'object.modify_me_please',
|
||||
false,
|
||||
],
|
||||
'Unknown controller' => [
|
||||
'foo.bar',
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider GetRouteNamespaceProvider
|
||||
* @covers \Combodo\iTop\Router\Router::GetRouteNamespace
|
||||
*
|
||||
* @param string $sRoute
|
||||
* @param string|null $sExpectedNamespace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetRouteNamespace(string $sRoute, ?string $sExpectedNamespace): void
|
||||
{
|
||||
$oRouter = Router::GetInstance();
|
||||
$sTestedNamespace = $oRouter->GetRouteNamespace($sRoute);
|
||||
|
||||
$this->assertEquals($sExpectedNamespace, $sTestedNamespace, "Namespace found for '$sRoute' was not the expected one. Got '$sTestedNamespace', expected '$sExpectedNamespace'.");
|
||||
}
|
||||
|
||||
public function GetRouteNamespaceProvider(): array
|
||||
{
|
||||
return [
|
||||
'Operation without namespace' => [
|
||||
'some_operation',
|
||||
null,
|
||||
],
|
||||
'Operation with namespace' => [
|
||||
'some_namespace.some_operation',
|
||||
'some_namespace',
|
||||
],
|
||||
'Operation with multi-levels namespace' => [
|
||||
'some.deep.namespace.some_operation',
|
||||
'some.deep.namespace',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider GetRouteOperationProvider
|
||||
* @covers \Combodo\iTop\Router\Router::GetRouteOperation
|
||||
*
|
||||
* @param string $sRoute
|
||||
* @param string|null $sExpectedOperation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetRouteOperation(string $sRoute, ?string $sExpectedOperation): void
|
||||
{
|
||||
$oRouter = Router::GetInstance();
|
||||
$sTestedOperation = $oRouter->GetRouteOperation($sRoute);
|
||||
|
||||
$this->assertEquals($sExpectedOperation, $sTestedOperation, "Operation found for '$sRoute' was not the expected one. Got '$sTestedOperation', expected '$sExpectedOperation'.");
|
||||
}
|
||||
|
||||
public function GetRouteOperationProvider(): array
|
||||
{
|
||||
return [
|
||||
'Operation without namespace' => [
|
||||
'some_operation',
|
||||
null,
|
||||
],
|
||||
'Operation with namespace' => [
|
||||
'some_namespace.some_operation',
|
||||
'some_operation',
|
||||
],
|
||||
'Operation with multi-levels namespace' => [
|
||||
'some.deep.namespace.some_operation',
|
||||
'some_operation',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider FindControllerFromRouteNamespaceProvider
|
||||
* @covers \Combodo\iTop\Router\Router::FindControllerFromRouteNamespace
|
||||
*
|
||||
* @param string $sRouteNamespace
|
||||
* @param string $sExpectedControllerFQCN
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFindControllerFromRouteNamespace(string $sRoute, ?string $sExpectedControllerFQCN): void
|
||||
{
|
||||
$oRouter = Router::GetInstance();
|
||||
$sRouteNamespace = $oRouter->GetRouteNamespace($sRoute);
|
||||
|
||||
$sTestedControllerFQCN = $this->InvokeNonPublicMethod(get_class($oRouter), 'FindControllerFromRouteNamespace', $oRouter, [$sRouteNamespace]);
|
||||
|
||||
$this->assertEquals($sExpectedControllerFQCN, $sTestedControllerFQCN, "Controller found for '$sRouteNamespace' was not the expected one. Got '$sTestedControllerFQCN', expected '$sExpectedControllerFQCN'.");
|
||||
}
|
||||
|
||||
public function FindControllerFromRouteNamespaceProvider(): array
|
||||
{
|
||||
return [
|
||||
'Object controller' => [
|
||||
'object.modify',
|
||||
'Combodo\iTop\Controller\Base\Layout\ObjectController',
|
||||
],
|
||||
'Unknown controller' => [
|
||||
'something_that_should_not_exist_in_the_default_package.foo',
|
||||
null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider GetOperationMethodNameFromRouteOperationProvider
|
||||
* @covers \Combodo\iTop\Router\Router::MakeOperationMethodNameFromOperation
|
||||
*
|
||||
* @param string $sRoute
|
||||
* @param string $sExpectedMethodName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetOperationMethodNameFromRouteOperation(string $sRoute, string $sExpectedMethodName): void
|
||||
{
|
||||
$oRouter = Router::GetInstance();
|
||||
$aRouteParts = $oRouter->GetRouteParts($sRoute);
|
||||
|
||||
$sTestedMethodName = $this->InvokeNonPublicMethod(get_class($oRouter), 'MakeOperationMethodNameFromOperation', $oRouter, [$aRouteParts[1]]);
|
||||
|
||||
$this->assertEquals($sExpectedMethodName, $sTestedMethodName, "Operation method name '$aRouteParts[1]' was not matching the expected one. Got '$sTestedMethodName', expected '$sExpectedMethodName'.");
|
||||
}
|
||||
|
||||
public function GetOperationMethodNameFromRouteOperationProvider(): array
|
||||
{
|
||||
return [
|
||||
'Simple operation' => [
|
||||
'object.modify',
|
||||
'OperationModify',
|
||||
],
|
||||
'Operation with an underscore' => [
|
||||
'object.apply_modify',
|
||||
'OperationApplyModify',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user