CRM-10210 add test for international strings
[civicrm-core.git] / tests / phpunit / api / v3 / ContactTest.php
index 4e9599f02256de5ab2b2dccd186205b7749789dd..910be009c98e2c980873eb3d59b5c5ddf6dea499 100644 (file)
@@ -115,6 +115,46 @@ class api_v3_ContactTest extends CiviUnitTestCase {
     );
   }
 
+  /**
+   * Test for international string acceptance (CRM-10210).
+   *
+   * @dataProvider getInternationalStrings
+   *
+   * @param string $string
+   *   String to be tested.
+   *
+   * @throws \Exception
+   */
+  public function testInternationalStrings($string) {
+    $this->callAPISuccess('Contact', 'create', array_merge(
+      $this->_params,
+      array('first_name' => $string)
+    ));
+    $result = $this->callAPISuccessGetSingle('Contact', array('first_name' => $string));
+    $this->assertEquals($string, $result['first_name']);
+
+    $organizationParams = array(
+      'organization_name' => $string,
+      'contact_type' => 'Organization',
+    );
+
+    $this->callAPISuccess('Contact', 'create', $organizationParams);
+    $result = $this->callAPISuccessGetSingle('Contact', $organizationParams);
+    $this->assertEquals($string, $result['organization_name']);
+  }
+
+  /**
+   * Get international string data for testing against api calls.
+   */
+  public function getInternationalStrings() {
+    $invocations = array();
+    $invocations[] = array('Scarabée');
+    $invocations[] = array('Iñtërnâtiônàlizætiøn');
+    $invocations[] = array('これは日本語のテキストです。読めますか');
+    $invocations[] = array('देखें हिन्दी कैसी नजर आती है। अरे वाह ये तो नजर आती है।');
+    return $invocations;
+  }
+
   /**
    * Test civicrm_contact_create.
    *
@@ -860,20 +900,23 @@ class api_v3_ContactTest extends CiviUnitTestCase {
   }
 
   /**
-   * Check that address name is returned if required.
+   * Check that address name, ID is returned if required.
    */
-  public function testGetReturnAddressName() {
+  public function testGetReturnAddress() {
     $contactID = $this->individualCreate();
-    $this->callAPISuccess('address', 'create', array(
+    $result = $this->callAPISuccess('address', 'create', array(
       'contact_id' => $contactID,
       'address_name' => 'My house',
       'location_type_id' => 'Home',
       'street_address' => '1 my road',
     ));
+    $addressID = $result['id'];
+
     $result = $this->callAPISuccessGetSingle('contact', array(
-      'return' => 'address_name, street_address',
+      'return' => 'address_name, street_address, address_id',
       'id' => $contactID,
     ));
+    $this->assertEquals($addressID, $result['address_id']);
     $this->assertEquals('1 my road', $result['street_address']);
     $this->assertEquals('My house', $result['address_name']);
 
@@ -2872,7 +2915,38 @@ class api_v3_ContactTest extends CiviUnitTestCase {
       'activity_type_id' => 'Contact Merged',
     ));
     $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($activity['activity_date_time'])));
+    $activity2 = $this->callAPISuccess('Activity', 'getsingle', array(
+      'target_contact_id' => $otherContact['id'],
+      'activity_type_id' => 'Contact Deleted by Merge',
+    ));
+    $this->assertEquals($activity['id'], $activity2['parent_id']);
+    $this->assertEquals('Normal', civicrm_api3('option_value', 'getvalue', array(
+      'value' => $activity['priority_id'],
+      'return' => 'label',
+      'option_group_id' => 'priority',
+    )));
+
+  }
 
+  /**
+   * Test merging 2 contacts with delete to trash off.
+   *
+   * We are checking that there is no error due to attempting to add an activity for the
+   * deleted contact.
+   *
+   * CRM-18307
+   */
+  public function testMergeNoTrash() {
+    $this->createLoggedInUser();
+    $this->callAPISuccess('Setting', 'create', array('contact_undelete' => FALSE));
+    $otherContact = $this->callAPISuccess('contact', 'create', $this->_params);
+    $retainedContact = $this->callAPISuccess('contact', 'create', $this->_params);
+    $this->callAPISuccess('contact', 'merge', array(
+      'to_keep_id' => $retainedContact['id'],
+      'to_remove_id' => $otherContact['id'],
+      'auto_flip' => FALSE,
+    ));
+    $this->callAPISuccess('Setting', 'create', array('contact_undelete' => TRUE));
   }
 
 }