X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FUtils%2FAPI%2FReloadOptionTest.php;h=44491e8ce0dc5411403d0e2455396873e51f6811;hb=4e74399f10f2aec0901675388388ce2e50786186;hp=45d0b5ef2f3a0df4dcc512930b3a22470e6f5316;hpb=d7f6c609b3af1dafb068fb3172056d0b58142b5e;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Utils/API/ReloadOptionTest.php b/tests/phpunit/CRM/Utils/API/ReloadOptionTest.php index 45d0b5ef2f..44491e8ce0 100644 --- a/tests/phpunit/CRM/Utils/API/ReloadOptionTest.php +++ b/tests/phpunit/CRM/Utils/API/ReloadOptionTest.php @@ -1,7 +1,5 @@ setHook('civicrm_post', array($this, 'onPost')); + CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_post', [$this, 'onPost']); } /** @@ -22,29 +21,30 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * fact that the hook manipulated the actual DB content. */ public function testNoReload() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - )); + ]); $this->assertEquals('First', $result['values'][$result['id']]['first_name']); - $this->assertEquals('Firstie', $result['values'][$result['id']]['nick_name']); // munged by hook, but we haven't realized it + // munged by hook, but we haven't realized it + $this->assertEquals('Firstie', $result['values'][$result['id']]['nick_name']); } /** * When the reload option is unrecognized, generate an error */ public function testReloadInvalid() { - $this->callAPIFailure('contact', 'create', array( + $this->callAPIFailure('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - 'options' => array( + 'options' => [ 'reload' => 'invalid', - ), - )); + ], + ]); } /** @@ -52,15 +52,15 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * differs from the inputted nick_name. */ public function testReloadDefault() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - 'options' => array( + 'options' => [ 'reload' => 1, - ), - )); + ], + ]); $this->assertEquals('First', $result['values'][$result['id']]['first_name']); $this->assertEquals('munged', $result['values'][$result['id']]['nick_name']); } @@ -70,18 +70,18 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * the chain results. */ public function testReloadNoChainInterference() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - 'api.Email.create' => array( + 'api.Email.create' => [ 'email' => 'test@example.com', - ), - 'options' => array( + ], + 'options' => [ 'reload' => 1, - ), - )); + ], + ]); $this->assertEquals('First', $result['values'][$result['id']]['first_name']); $this->assertEquals('munged', $result['values'][$result['id']]['nick_name']); $this->assertAPISuccess($result['values'][$result['id']]['api.Email.create']); @@ -92,41 +92,22 @@ class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase { * the chain results, even if sequential=1. */ public function testReloadNoChainInterferenceSequential() { - $result = $this->callAPISuccess('contact', 'create', array( + $result = $this->callAPISuccess('contact', 'create', [ 'sequential' => 1, 'contact_type' => 'Individual', 'first_name' => 'First', 'last_name' => 'Last', 'nick_name' => 'Firstie', - 'api.Email.create' => array( + 'api.Email.create' => [ 'email' => 'test@example.com', - ), - 'options' => array( + ], + 'options' => [ 'reload' => 1, - ), - )); + ], + ]); $this->assertEquals('First', $result['values'][0]['first_name']); $this->assertEquals('munged', $result['values'][0]['nick_name']); $this->assertAPISuccess($result['values'][0]['api.Email.create']); } - /** - * An implementation of hook_civicrm_post used with all our test cases. - * - * @param $op - * @param string $objectName - * @param int $objectId - * @param $objectRef - */ - public function onPost($op, $objectName, $objectId, &$objectRef) { - if ($op == 'create' && $objectName == 'Individual') { - CRM_Core_DAO::executeQuery( - "UPDATE civicrm_contact SET nick_name = 'munged' WHERE id = %1", - array( - 1 => array($objectId, 'Integer'), - ) - ); - } - } - }