From 127d8f6b8b891ffbdaa93ddae8bdc4c6a3f7baa5 Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Wed, 31 Oct 2018 19:07:09 +0000 Subject: [PATCH] Add test for CRM_Utils_Array::flatten() --- tests/phpunit/CRM/Utils/ArrayTest.php | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/phpunit/CRM/Utils/ArrayTest.php b/tests/phpunit/CRM/Utils/ArrayTest.php index 135b0f05c5..212b523ceb 100644 --- a/tests/phpunit/CRM/Utils/ArrayTest.php +++ b/tests/phpunit/CRM/Utils/ArrayTest.php @@ -328,4 +328,43 @@ class CRM_Utils_ArrayTest extends CiviUnitTestCase { $this->assertEquals($expected, $source); } + /** + * Test the flatten function + */ + public function testFlatten() { + $data = [ + 'my_array' => [ + '0' => 'bar', + '1' => 'baz', + '2' => 'boz', + ], + 'my_complex' => [ + 'dog' => 'woof', + 'asdf' => [ + 'my_zero' => 0, + 'my_int' => 1, + 'my_null' => NULL, + 'my_empty' => '', + ], + ], + 'my_simple' => 999, + ]; + + $expected = [ + 'my_array.0' => 'bar', + 'my_array.1' => 'baz', + 'my_array.2' => 'boz', + 'my_complex.dog' => 'woof', + 'my_complex.asdf.my_zero' => 0, + 'my_complex.asdf.my_int' => 1, + 'my_complex.asdf.my_null' => NULL, + 'my_complex.asdf.my_empty' => '', + 'my_simple' => 999, + ]; + + $flat = []; + CRM_Utils_Array::flatten($data, $flat); + $this->assertEquals($flat, $expected); + } + } -- 2.25.1