diff options
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils')
2 files changed, 113 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); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils/ReflectionUtilsTest.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils/ReflectionUtilsTest.php new file mode 100644 index 00000000..d94de337 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Utils/ReflectionUtilsTest.php @@ -0,0 +1,46 @@ +<?php + +namespace Civi\Test\Api4\Utils; + +use Civi\Api4\Utils\ReflectionUtils; +use Civi\Test\Api4\Mock\MockV4ReflectionGrandchild; +use Civi\Test\Api4\UnitTestCase; + +/** + * @group headless + */ +class ReflectionUtilsTest extends UnitTestCase { + + /** + * Test that class annotations are returned across @inheritDoc + */ + public function testGetDocBlockForClass() { + $grandChild = new MockV4ReflectionGrandchild(); + $reflection = new \ReflectionClass($grandChild); + $doc = ReflectionUtils::getCodeDocs($reflection); + + $this->assertEquals(TRUE, $doc['internal']); + $this->assertEquals('Grandchild class', $doc['description']); + + $expectedComment = 'This is an extended description. + +There is a line break in this description. + +This is the base class.'; + + $this->assertEquals($expectedComment, $doc['comment']); + } + + /** + * Test that property annotations are returned across @inheritDoc + */ + public function testGetDocBlockForProperty() { + $grandChild = new MockV4ReflectionGrandchild(); + $reflection = new \ReflectionClass($grandChild); + $doc = ReflectionUtils::getCodeDocs($reflection->getProperty('foo'), 'Property'); + + $this->assertEquals('This is the foo property.', $doc['description']); + $this->assertEquals("In the child class, foo has been barred.\n\nIn general, you can do nothing with it.", $doc['comment']); + } + +} |