Merge pull request #14320 from sushantpaste/reporthook
[civicrm-core.git] / tests / phpunit / CRM / Utils / API / ReloadOptionTest.php
index 45d0b5ef2f3a0df4dcc512930b3a22470e6f5316..44491e8ce0dc5411403d0e2455396873e51f6811 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-require_once 'CiviTest/CiviUnitTestCase.php';
-
 /**
  * Test that the API accepts the 'reload' option.
  *
@@ -9,12 +7,13 @@ require_once 'CiviTest/CiviUnitTestCase.php';
  * to munge the database. If the reload option is present, then the return value should reflect
  * the final SQL content (after calling hook_civicrm_post). If the reload option is missing,
  * then the return should reflect the inputted (unmodified) data.
+ * @group headless
  */
 class CRM_Utils_API_ReloadOptionTest extends CiviUnitTestCase {
 
   public function setUp() {
     parent::setUp();
-    CRM_Utils_Hook_UnitTests::singleton()->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'),
-        )
-      );
-    }
-  }
-
 }