-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathParametersTest.php
More file actions
63 lines (52 loc) · 1.69 KB
/
ParametersTest.php
File metadata and controls
63 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
* @copyright Copyright (C) 2010-2023 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace UnitTestFiles\Test;
use Parameters;
use PHPUnit\Framework\TestCase;
@define('APPROOT', dirname(__DIR__).'/');
require_once(APPROOT.'core/parameters.class.inc.php');
class ParametersTest extends TestCase
{
/**
* @dataProvider ToXMLProvider
*/
public function testToXML(array $aData, string $sExpectedDump)
{
$oParameters = new Parameters();
$this->SetNonPublicProperty($oParameters, 'aData', $aData);
$sDumpParameters = $oParameters->Dump();
$this->assertStringContainsString($sExpectedDump, $sDumpParameters);
}
public function ToXMLProvider()
{
return [
'Parameter with &' => [
'aData' => ['escaped_param' => '(&(objectClass=person)(mail=*))'],
'sExpectedDump' => '<escaped_param>(&(objectClass=person)(mail=*))</escaped_param>',
],
'Parameter with array' => [
'aData' => ['paramroot' => ['param1' => 'param1val', 'param2' => 'param2val']],
'sExpectedDump' => "<paramroot>\n <param1>param1val</param1>\n <param2>param2val</param2>\n </paramroot>",
],
'Parameter with integer' => [
'aData' => ['my_int' => 42],
'sExpectedDump' => '<my_int type="int">42</my_int>',
],
];
}
public function SetNonPublicProperty(object $oObject, string $sProperty, $value)
{
$oProperty = $this->GetProperty(get_class($oObject), $sProperty);
$oProperty->setValue($oObject, $value);
}
private function GetProperty(string $sClass, string $sProperty): \ReflectionProperty
{
$class = new \ReflectionClass($sClass);
$property = $class->getProperty($sProperty);
$property->setAccessible(true);
return $property;
}
}