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
|
<?php
/**
* Unit tests.
*
* @author Niklas Laxström
* @file
* @license GPL-2.0+
*/
class ArrayFlattenerTest extends MediaWikiTestCase {
/**
* @dataProvider provideTestFlatten
*/
public function testFlatten( $sep, $input, $expected ) {
$flattener = new ArrayFlattener( $sep );
$output = $flattener->flatten( $input );
$this->assertEquals( $expected, $output );
}
/**
* @dataProvider provideTestFlatten
*/
public function testUnflatten( $sep, $expected, $input ) {
$flattener = new ArrayFlattener( $sep );
$output = $flattener->unflatten( $input );
$this->assertEquals( $expected, $output );
}
public static function provideTestFlatten() {
$cases = array();
$cases[] = array(
'.',
array( 'a' => 1 ),
array( 'a' => 1 ),
);
$cases[] = array(
'.',
array( 'a' => array( 'b' => array( 'c' => 1, 'd' => 2 ) ) ),
array( 'a.b.c' => 1, 'a.b.d' => 2 ),
);
return $cases;
}
}
|