diff options
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils/ArrayInsertionServiceTest.php')
-rw-r--r-- | www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils/ArrayInsertionServiceTest.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils/ArrayInsertionServiceTest.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils/ArrayInsertionServiceTest.php new file mode 100644 index 00000000..462f07cc --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils/ArrayInsertionServiceTest.php @@ -0,0 +1,67 @@ +<?php + +namespace Civi\Test\Api4\Utils; + +use Civi\Api4\Utils\ArrayInsertionUtil; +use Civi\Test\Api4\UnitTestCase; + +/** + * @group headless + */ +class ArrayInsertionServiceTest extends UnitTestCase { + + public function testInsertWillWork() { + $arr = []; + $path = ['foo' => FALSE, 'bar' => FALSE]; + $inserter = new ArrayInsertionUtil(); + $inserter::insert($arr, $path, ['LALA']); + + $expected = [ + 'foo' => [ + 'bar' => 'LALA' + ], + ]; + + $this->assertEquals($expected, $arr); + } + + public function testInsertionOfContactEmailLocation() { + $contacts = [ + [ + 'id' => 1, + 'first_name' => 'Jim' + ], + [ + 'id' => 2, + 'first_name' => 'Karen' + ], + ]; + $emails = [ + [ + 'email' => 'jim@jim.com', + 'id' => 2, + '_parent_id' => 1 + ], + ]; + $locationTypes = [ + [ + 'name' => 'Home', + 'id' => 3, + '_parent_id' => 2 + ], + ]; + + $emailPath = ['emails' => TRUE]; + $locationPath = ['emails' => TRUE, 'location' => FALSE]; + $inserter = new ArrayInsertionUtil(); + + foreach ($contacts as &$contact) { + $inserter::insert($contact, $emailPath, $emails); + $inserter::insert($contact, $locationPath, $locationTypes); + } + + $locationType = $contacts[0]['emails'][0]['location']['name']; + $this->assertEquals('Home', $locationType); + } + +} |