test break fixes
[civicrm-core.git] / tests / phpunit / api / v3 / ProfileTest.php
index 52d078ab15723dbf41dc795175f72ba68591e734..b3754c6ac9e9faa91e326f7a9a4a481b67c3900c 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
-| CiviCRM version 4.5                                                |
+| CiviCRM version 4.6                                                |
 +--------------------------------------------------------------------+
 | Copyright CiviCRM LLC (c) 2004-2014                                |
 +--------------------------------------------------------------------+
@@ -34,7 +34,7 @@ require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
 /**
  *  Test APIv3 civicrm_profile_* functions
  *
- *  @package   CiviCRM
+ * @package   CiviCRM
  */
 class api_v3_ProfileTest extends CiviUnitTestCase {
   protected $_apiversion;
@@ -42,18 +42,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   protected $_membershipTypeID;
   protected $_contactID;
 
-  /**
-   * @return array
-   */
-  function get_info() {
-    return array(
-      'name' => 'Profile Test',
-      'description' => 'Test all profile API methods.',
-      'group' => 'CiviCRM API Tests',
-    );
-  }
-
-  function setUp() {
+  public function setUp() {
     $this->_apiversion = 3;
     parent::setUp();
     $config = CRM_Core_Config::singleton();
@@ -63,7 +52,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $this->_membershipTypeID = $this->membershipTypeCreate();
   }
 
-  function tearDown() {
+  public function tearDown() {
 
     $this->quickCleanup(array(
       'civicrm_contact',
@@ -82,7 +71,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check Without ProfileId
    */
-  function testProfileGetWithoutProfileId() {
+  public function testProfileGetWithoutProfileId() {
     $params = array(
       'contact_id' => 1,
     );
@@ -94,7 +83,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check with no invalid profile Id
    */
-  function testProfileGetInvalidProfileId() {
+  public function testProfileGetInvalidProfileId() {
     $params = array(
       'contact_id' => 1,
       'profile_id' => 1000,
@@ -105,11 +94,11 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check with success
    */
-  function testProfileGet() {
+  public function testProfileGet() {
     $pofileFieldValues = $this->_createIndividualContact();
-    $expected          = current($pofileFieldValues);
-    $contactId         = key($pofileFieldValues);
-    $params            = array(
+    $expected = current($pofileFieldValues);
+    $contactId = key($pofileFieldValues);
+    $params = array(
       'profile_id' => $this->_profileID,
       'contact_id' => $contactId,
     );
@@ -119,11 +108,11 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     }
   }
 
-  function testProfileGetMultiple() {
+  public function testProfileGetMultiple() {
     $pofileFieldValues = $this->_createIndividualContact();
-    $expected          = current($pofileFieldValues);
-    $contactId         = key($pofileFieldValues);
-    $params            = array(
+    $expected = current($pofileFieldValues);
+    $contactId = key($pofileFieldValues);
+    $params = array(
       'profile_id' => array($this->_profileID, 1, 'Billing'),
       'contact_id' => $contactId,
     );
@@ -148,9 +137,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     ));
   }
 
-  function testProfileGetBillingUseIsBillingLocation() {
+  public function testProfileGetBillingUseIsBillingLocation() {
     $individual = $this->_createIndividualContact();
-    $contactId  = key($individual);
+    $contactId = key($individual);
     $this->callAPISuccess('address', 'create', array(
       'is_billing' => 1,
       'street_address' => 'is billing st',
@@ -181,11 +170,21 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     ), $result['values']['Billing']);
   }
 
-  function testProfileGetMultipleHasBillingLocation() {
+  public function testProfileGetMultipleHasBillingLocation() {
     $individual = $this->_createIndividualContact();
-    $contactId  = key($individual);
-    $this->callAPISuccess('address', 'create', array('contact_id' => $contactId , 'street_address' => '25 Big Street', 'city' => 'big city', 'location_type_id' => 5));
-    $this->callAPISuccess('email', 'create', array('contact_id' => $contactId , 'email' => 'big@once.com', 'location_type_id' => 2, 'is_billing' => 1));
+    $contactId = key($individual);
+    $this->callAPISuccess('address', 'create', array(
+        'contact_id' => $contactId,
+        'street_address' => '25 Big Street',
+        'city' => 'big city',
+        'location_type_id' => 5
+      ));
+    $this->callAPISuccess('email', 'create', array(
+        'contact_id' => $contactId,
+        'email' => 'big@once.com',
+        'location_type_id' => 2,
+        'is_billing' => 1
+      ));
 
     $expected = current($individual);
 
@@ -213,7 +212,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Get Billing empty contact - this will return generic defaults
    */
-  function testProfileGetBillingEmptyContact() {
+  public function testProfileGetBillingEmptyContact() {
 
     $params = array(
       'profile_id' => array('Billing'),
@@ -237,7 +236,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check contact activity profile without activity id
    */
-  function testContactActivityGetWithoutActivityId() {
+  public function testContactActivityGetWithoutActivityId() {
     list($params, $expected) = $this->_createContactWithActivity();
 
     unset($params['activity_id']);
@@ -248,7 +247,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check contact activity profile wrong activity id
    */
-  function testContactActivityGetWrongActivityId() {
+  public function testContactActivityGetWrongActivityId() {
     list($params, $expected) = $this->_createContactWithActivity();
 
     $params['activity_id'] = 100001;
@@ -259,7 +258,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check contact activity profile with wrong activity type
    */
-  function testContactActivityGetWrongActivityType() {
+  public function testContactActivityGetWrongActivityType() {
     //flush cache by calling with reset
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
 
@@ -292,7 +291,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check contact activity profile with success
    */
-  function testContactActivityGetSuccess() {
+  public function testContactActivityGetSuccess() {
     list($params, $expected) = $this->_createContactWithActivity();
 
     $result = $this->callAPISuccess('profile', 'get', $params);
@@ -306,10 +305,13 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check getfields works & gives us our fields
    */
-  function testGetFields() {
+  public function testGetFields() {
     $this->_createIndividualProfile();
     $this->_addCustomFieldToProfile($this->_profileID);
-    $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => $this->_profileID), __FUNCTION__, __FILE__,
+    $result = $this->callAPIAndDocument('profile', 'getfields', array(
+        'action' => 'submit',
+        'profile_id' => $this->_profileID
+      ), __FUNCTION__, __FILE__,
       'demonstrates retrieving profile fields passing in an id');
     $this->assertArrayKeyExists('first_name', $result['values']);
     $this->assertEquals('2', $result['values']['first_name']['type']);
@@ -322,11 +324,12 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check getfields works & gives us our fields - partipant profile
    */
-  function testGetFieldsParticipantProfile() {
+  public function testGetFieldsParticipantProfile() {
     $result = $this->callAPISuccess('profile', 'getfields', array(
-      'action' => 'submit',
-      'profile_id' => 'participant_status',
-      'get_options' => 'all')
+        'action' => 'submit',
+        'profile_id' => 'participant_status',
+        'get_options' => 'all'
+      )
     );
     $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
     $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
@@ -337,15 +340,20 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    * Check getfields works & gives us our fields - membership_batch_entry
    * (getting to the end with no e-notices is pretty good evidence it's working)
    */
-  function testGetFieldsMembershipBatchProfile() {
+  public function testGetFieldsMembershipBatchProfile() {
     $result = $this->callAPISuccess('profile', 'getfields', array(
-      'action' => 'submit',
-      'profile_id' => 'membership_batch_entry',
-      'get_options' => 'all')
+        'action' => 'submit',
+        'profile_id' => 'membership_batch_entry',
+        'get_options' => 'all'
+      )
     );
     $this->assertTrue(array_key_exists('total_amount', $result['values']));
     $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
-    $this->assertEquals(array('contribution_type_id', 'contribution_type', 'financial_type'), $result['values']['financial_type_id']['api.aliases']);
+    $this->assertEquals(array(
+        'contribution_type_id',
+        'contribution_type',
+        'financial_type'
+      ), $result['values']['financial_type_id']['api.aliases']);
     $this->assertTrue(!array_key_exists('financial_type', $result['values']));
     $this->assertEquals(12, $result['values']['receive_date']['type']);
   }
@@ -354,14 +362,15 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    * Check getfields works & gives us our fields - do them all
    * (getting to the end with no e-notices is pretty good evidence it's working)
    */
-  function testGetFieldsAllProfiles() {
+  public function testGetFieldsAllProfiles() {
     $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
     $profileIDs = array_keys($result['values']);
     foreach ($profileIDs as $profileID) {
       $result = $this->callAPISuccess('profile', 'getfields', array(
-        'action' => 'submit',
-        'profile_id' => $profileID,
-        'get_options' => 'all')
+          'action' => 'submit',
+          'profile_id' => $profileID,
+          'get_options' => 'all'
+        )
       );
     }
   }
@@ -370,7 +379,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check Without ProfileId
    */
-  function testProfileSubmitWithoutProfileId() {
+  public function testProfileSubmitWithoutProfileId() {
     $params = array(
       'contact_id' => 1,
     );
@@ -382,7 +391,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check with no invalid profile Id
    */
-  function testProfileSubmitInvalidProfileId() {
+  public function testProfileSubmitInvalidProfileId() {
     $params = array(
       'contact_id' => 1,
       'profile_id' => 1000,
@@ -393,7 +402,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check with missing required field in profile
    */
-  function testProfileSubmitCheckProfileRequired() {
+  public function testProfileSubmitCheckProfileRequired() {
     $pofileFieldValues = $this->_createIndividualContact();
     current($pofileFieldValues);
     $contactId = key($pofileFieldValues);
@@ -417,7 +426,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check with success
    */
-  function testProfileSubmit() {
+  public function testProfileSubmit() {
     $pofileFieldValues = $this->_createIndividualContact();
     current($pofileFieldValues);
     $contactId = key($pofileFieldValues);
@@ -450,7 +459,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     }
     unset($params['email-primary']);
     $params['email-Primary'] = 'my@mail.com';
-    $this->callAPISuccess('profile', 'submit',  $params);
+    $this->callAPISuccess('profile', 'submit', $params);
     $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
     $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
   }
@@ -459,52 +468,64 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
    * First we delete & create to increment the version & then check for caching probs
    */
-  function testProfileSubmitCheckCaching() {
+  public function testProfileSubmitCheckCaching() {
     $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID));
     $this->_membershipTypeID = $this->membershipTypeCreate();
 
     $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
-    $profileFields = $this->callAPISuccess('profile', 'getfields', array('get_options' => 'all', 'action' => 'submit', 'profile_id' => 'membership_batch_entry'));
-    $getoptions = $this->callAPISuccess('membership', 'getoptions', array('field' => 'membership_type', 'context' => 'validate'));
+    $profileFields = $this->callAPISuccess('profile', 'getfields', array(
+        'get_options' => 'all',
+        'action' => 'submit',
+        'profile_id' => 'membership_batch_entry'
+      ));
+    $getoptions = $this->callAPISuccess('membership', 'getoptions', array(
+        'field' => 'membership_type',
+        'context' => 'validate'
+      ));
     $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
     $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
 
-}
+  }
 
   /**
    * Test that the fields are returned in the right order despite the faffing around that goes on
    */
-  function testMembershipGetFieldsOrder() {
-    $result = $this->callAPISuccess('profile', 'getfields', array('action' => 'submit', 'profile_id' => 'membership_batch_entry'));
+  public function testMembershipGetFieldsOrder() {
+    $result = $this->callAPISuccess('profile', 'getfields', array(
+        'action' => 'submit',
+        'profile_id' => 'membership_batch_entry'
+      ));
     $weight = 1;
-    foreach($result['values'] as $fieldName => $field) {
-      if($fieldName == 'profile_id') {
+    foreach ($result['values'] as $fieldName => $field) {
+      if ($fieldName == 'profile_id') {
         continue;
       }
       $this->assertEquals($field['weight'], $weight);
       $weight++;
     }
   }
+
   /**
    * Check we can submit membership batch profiles (create mode)
    */
-  function testProfileSubmitMembershipBatch() {
+  public function testProfileSubmitMembershipBatch() {
     $this->_contactID = $this->individualCreate();
     $this->callAPISuccess('profile', 'submit', array(
-     'profile_id' => 'membership_batch_entry',
-     'financial_type_id' => 1,
-     'membership_type' => $this->_membershipTypeID,
-     'join_date' => 'now',
-     'total_amount' => 10,
-     'contribution_status_id' => 1,
-     'receive_date' => 'now',
-     'contact_id' => $this->_contactID,
+      'profile_id' => 'membership_batch_entry',
+      'financial_type_id' => 1,
+      'membership_type' => $this->_membershipTypeID,
+      'join_date' => 'now',
+      'total_amount' => 10,
+      'contribution_status_id' => 1,
+      'receive_date' => 'now',
+      'contact_id' => $this->_contactID,
     ));
   }
+
   /**
    * Set is deprecated but we need to ensure it still works
    */
-  function testLegacySet() {
+  public function testLegacySet() {
     $pofileFieldValues = $this->_createIndividualContact();
     current($pofileFieldValues);
     $contactId = key($pofileFieldValues);
@@ -540,7 +561,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check contact activity profile without activity id
    */
-  function testContactActivitySubmitWithoutActivityId() {
+  public function testContactActivitySubmitWithoutActivityId() {
     list($params, $expected) = $this->_createContactWithActivity();
 
     $params = array_merge($params, $expected);
@@ -552,7 +573,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check contact activity profile wrong activity id
    */
-  function testContactActivitySubmitWrongActivityId() {
+  public function testContactActivitySubmitWrongActivityId() {
     list($params, $expected) = $this->_createContactWithActivity();
     $params = array_merge($params, $expected);
     $params['activity_id'] = 100001;
@@ -563,7 +584,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check contact activity profile with wrong activity type
    */
-  function testContactActivitySubmitWrongActivityType() {
+  public function testContactActivitySubmitWrongActivityType() {
     //flush cache by calling with reset
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
 
@@ -596,7 +617,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check contact activity profile with success
    */
-  function testContactActivitySubmitSuccess() {
+  public function testContactActivitySubmitSuccess() {
     list($params, $expected) = $this->_createContactWithActivity();
 
     $updateParams = array(
@@ -622,7 +643,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check profile apply Without ProfileId
    */
-  function testProfileApplyWithoutProfileId() {
+  public function testProfileApplyWithoutProfileId() {
     $params = array(
       'contact_id' => 1,
     );
@@ -633,7 +654,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check profile apply with no invalid profile Id
    */
-  function testProfileApplyInvalidProfileId() {
+  public function testProfileApplyInvalidProfileId() {
     $params = array(
       'contact_id' => 1,
       'profile_id' => 1000,
@@ -644,7 +665,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * Check with success
    */
-  function testProfileApply() {
+  public function testProfileApply() {
     $pofileFieldValues = $this->_createIndividualContact();
     current($pofileFieldValues);
     $contactId = key($pofileFieldValues);
@@ -694,7 +715,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     }
 
     foreach (array(
-      'email', 'phone', 'address') as $fieldType) {
+               'email',
+               'phone',
+               'address'
+             ) as $fieldType) {
       $typeValues = array_pop($result['values'][$fieldType]);
       foreach ($expected[$fieldType] as $field => $value) {
         $this->assertEquals($value, CRM_Utils_Array::value($field, $typeValues), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
@@ -709,31 +733,31 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    *
    * @return mixed
    */
-  function _createIndividualContact($params = array()) {
+  public function _createIndividualContact($params = array()) {
     $contactParams = array_merge(array(
-      'first_name' => 'abc1',
-      'last_name' => 'xyz1',
-      'email' => 'abc1.xyz1@yahoo.com',
-      'api.address.create' => array(
-        'location_type_id' => 1,
-        'is_primary' => 1,
-        'street_address' => '5 Saint Helier St',
-        'county' => 'Marin',
-        'country' => 'United States',
-        'state_province' => 'Michigan',
-        'supplemental_address_1' => 'Hallmark Ct',
-        'supplemental_address_2' => 'Jersey Village',
-        'postal_code' => '90210',
-        'city' => 'Gotham City',
-        'is_billing' => 0,
-      ),
-      'api.phone.create' => array(
-        'location_type_id' => '1',
-        'phone' => '021 512 755',
-        'phone_type_id' => '1',
-        'is_primary' => '1',
-      ),
-     ), $params
+        'first_name' => 'abc1',
+        'last_name' => 'xyz1',
+        'email' => 'abc1.xyz1@yahoo.com',
+        'api.address.create' => array(
+          'location_type_id' => 1,
+          'is_primary' => 1,
+          'street_address' => '5 Saint Helier St',
+          'county' => 'Marin',
+          'country' => 'United States',
+          'state_province' => 'Michigan',
+          'supplemental_address_1' => 'Hallmark Ct',
+          'supplemental_address_2' => 'Jersey Village',
+          'postal_code' => '90210',
+          'city' => 'Gotham City',
+          'is_billing' => 0,
+        ),
+        'api.phone.create' => array(
+          'location_type_id' => '1',
+          'phone' => '021 512 755',
+          'phone_type_id' => '1',
+          'is_primary' => '1',
+        ),
+      ), $params
     );
 
     $this->_contactID = $this->individualCreate($contactParams);
@@ -754,7 +778,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * @return array
    */
-  function _createContactWithActivity() {
+  public function _createContactWithActivity() {
     // @TODO: Create profile with custom fields
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn,
@@ -829,16 +853,17 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
 
     return array($profileParams, $expected);
   }
+
   /**
    * Create a profile
    */
-  function _createIndividualProfile() {
+  public function _createIndividualProfile() {
 
     // creating these via the api as we want to utilise & test the flushing of caches when fields created
     // via the api
 
     $ufGroupParams = array(
-      'group_type' => 'Individual,Contact',// really we should remove this & test the ufField create sets it
+      'group_type' => 'Individual,Contact', // really we should remove this & test the ufField create sets it
       'name' => 'test_individual_contact_profile',
       'title' => 'Flat Coffee',
       'api.uf_field.create' => array(
@@ -870,7 +895,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
           'field_type' => 'Contact',
           'location_type_id' => 1,
           'phone_type_id' => 1,
-          'label' => 'Phone'
+          'label' => 'Phone',
         ),
         array(
           'field_name' => 'country',
@@ -878,7 +903,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
           'visibility' => 'Public Pages and Listings',
           'field_type' => 'Contact',
           'location_type_id' => 1,
-          'label' => 'Country'
+          'label' => 'Country',
         ),
         array(
           'field_name' => 'state_province',
@@ -886,15 +911,15 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
           'visibility' => 'Public Pages and Listings',
           'field_type' => 'Contact',
           'location_type_id' => 1,
-          'label' => 'State Province'
+          'label' => 'State Province',
         ),
         array(
           'field_name' => 'postal_code',
           'is_required' => 0,
           'field_type' => 'Contact',
           'location_type_id' => 1,
-          'label' => 'State Province'
-         ),
+          'label' => 'State Province',
+        ),
       ),
     );
     $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
@@ -904,9 +929,12 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   /**
    * @param int $profileID
    */
-  function _addCustomFieldToProfile($profileID) {
+  public function _addCustomFieldToProfile($profileID) {
     $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, '');
-    $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));
+    $this->uFFieldCreate(array(
+        'uf_group_id' => $profileID,
+        'field_name' => 'custom_' . $ids['custom_field_id'],
+        'contact_type' => 'Contact'
+      ));
   }
 }
-