From 9da2e77c344e71aab6b76e33ae456b01c8907799 Mon Sep 17 00:00:00 2001 From: Eileen Date: Fri, 13 Sep 2013 18:19:17 +1200 Subject: [PATCH] CRM-13234 tests/apiv3/profile switch to creating ufFields via api so we can leverage the cache clearing functionality As always expanding api usage in the tests extends api test coverage & required a few fixes --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 5 +- tests/phpunit/api/v3/ProfileTest.php | 116 +++++++++---- .../api/v3/dataset/uf_field_uf_group_25.xml | 156 ------------------ tests/phpunit/api/v3/dataset/uf_group_25.xml | 52 ------ 4 files changed, 87 insertions(+), 242 deletions(-) delete mode 100644 tests/phpunit/api/v3/dataset/uf_field_uf_group_25.xml delete mode 100644 tests/phpunit/api/v3/dataset/uf_group_25.xml diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 108edd3773..c318b003a3 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -899,7 +899,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Private helper function for calling civicrm_contact_add * - * @param array parameters for civicrm_contact_add api function call + * @param $params + * + * @throws Exception + * @internal param \parameters $array for civicrm_contact_add api function call * * @return int id of Household created */ diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index 9f3df540d5..a77247a29c 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -38,7 +38,7 @@ require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php'; */ class api_v3_ProfileTest extends CiviUnitTestCase { protected $_apiversion; - protected $_profileID; + protected $_profileID = 0; function get_info() { return array( 'name' => 'Profile Test', @@ -53,6 +53,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $config = CRM_Core_Config::singleton(); $config->countryLimit[1] = 1013; $config->stateLimit[1] = 1013; + $this->createLoggedInUser(); } function tearDown() { @@ -63,7 +64,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'civicrm_address', ), TRUE); // ok can't be bothered wring an api to do this & truncating is crazy - CRM_Core_DAO::executeQuery(' DELETE FROM civicrm_uf_group WHERE id IN (25, 26)'); + CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)"); } ////////////// test $this->callAPISuccess3_profile_get ////////////////// @@ -99,13 +100,12 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $expected = current($pofileFieldValues); $contactId = key($pofileFieldValues); $params = array( - 'profile_id' => 25, + 'profile_id' => $this->_profileID, 'contact_id' => $contactId, ); $result = $this->callAPISuccess('profile', 'get', $params); foreach ($expected as $profileField => $value) { - $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}" - ); + $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values'])); } } @@ -114,13 +114,13 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $expected = current($pofileFieldValues); $contactId = key($pofileFieldValues); $params = array( - 'profile_id' => array(25, 1, 'Billing'), + 'profile_id' => array($this->_profileID, 1, 'Billing'), 'contact_id' => $contactId, ); $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__, __FILE__); foreach ($expected as $profileField => $value) { - $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values'][25]), " error message: " . "missing/mismatching value for {$profileField}"); + $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values'][$this->_profileID]), " error message: " . "missing/mismatching value for {$profileField}"); } $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}"); $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email'); @@ -152,7 +152,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $expected = current($individual); $params = array( - 'profile_id' => array(25, 1, 'Billing'), + 'profile_id' => array($this->_profileID, 1, 'Billing'), 'contact_id' => $contactId, ); @@ -181,7 +181,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $expected = current($individual); $params = array( - 'profile_id' => array(25, 1, 'Billing'), + 'profile_id' => array($this->_profileID, 1, 'Billing'), 'contact_id' => $contactId, ); @@ -300,11 +300,11 @@ class api_v3_ProfileTest extends CiviUnitTestCase { function testGetFields() { $this->_createIndividualProfile(); $this->_addCustomFieldToProfile($this->_profileID); - $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => 25), __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']); - $this->assertEquals('Email', $result['values']['email']['title']); + $this->assertEquals('Email', $result['values']['email-primary']['title']); $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']); $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']); $this->assertFalse(array_key_exists('participant_status', $result['values'])); @@ -391,12 +391,12 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'state_province-1' => '1000', ); - $params = array_merge(array('profile_id' => 25, 'contact_id' => $contactId), + $params = array_merge(array('profile_id' => $this->_profileID, 'contact_id' => $contactId), $updateParams ); $result = $this->callAPIFailure('profile', 'submit', $params, - 'Missing required parameters for profile id 25: email-Primary' + "Missing required parameters for profile id $this->_profileID: email-Primary" ); } @@ -418,14 +418,14 @@ class api_v3_ProfileTest extends CiviUnitTestCase { ); $params = array_merge(array( - 'profile_id' => 25, + 'profile_id' => $this->_profileID, 'contact_id' => $contactId, ), $updateParams); $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__, __FILE__); $getParams = array( - 'profile_id' => 25, + 'profile_id' => $this->_profileID, 'contact_id' => $contactId, ); $profileDetails = $this->callAPISuccess('profile', 'get', $getParams); @@ -459,14 +459,14 @@ class api_v3_ProfileTest extends CiviUnitTestCase { ); $params = array_merge(array( - 'profile_id' => 25, + 'profile_id' => $this->_profileID, 'contact_id' => $contactId, ), $updateParams); $result = $this->callAPISuccess('profile', 'set', $params); $this->assertArrayKeyExists('values', $result); $getParams = array( - 'profile_id' => 25, + 'profile_id' => $this->_profileID, 'contact_id' => $contactId, ); $profileDetails = $this->callAPISuccess('profile', 'get', $getParams); @@ -589,7 +589,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $contactId = key($pofileFieldValues); $params = array( - 'profile_id' => 25, + 'profile_id' => $this->_profileID, 'contact_id' => $contactId, 'first_name' => 'abc2', 'last_name' => 'xyz2', @@ -678,7 +678,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $profileData[$contactID] = array( 'first_name' => 'abc1', 'last_name' => 'xyz1', - 'email-Primary' => 'abc1.xyz1@yahoo.com', + 'email-primary' => 'abc1.xyz1@yahoo.com', 'phone-1-1' => '021 512 755', 'country-1' => '1228', 'state_province-1' => '1021', @@ -766,21 +766,71 @@ class api_v3_ProfileTest extends CiviUnitTestCase { * Create a profile */ function _createIndividualProfile() { - // Create new profile having group_type: Contact,Individual - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - new PHPUnit_Extensions_Database_DataSet_XMLDataSet( - dirname(__FILE__) . "/dataset/uf_group_25.xml" - ) - ); - // Create Contact + Idividual fields for profile - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - new PHPUnit_Extensions_Database_DataSet_XMLDataSet( - dirname(__FILE__) . "/dataset/uf_field_uf_group_25.xml" - ) + + // 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 + 'name' => 'test_individual_contact_profile', + 'title' => 'Flat Coffee', + 'api.uf_field.create' => array( + array( + 'field_name' => 'first_name', + 'is_required' => 1, + 'visibility' => 'Public Pages and Listings', + 'field_type' => 'Individual', + //is_active = 1, is_view 0, weight SHOULD be set by api (& tested), ditto is_reserved 0 + ), + array( + 'field_name' => 'last_name', + 'is_required' => 1, + 'visibility' => 'Public Pages and Listings', + 'field_type' => 'Individual', + ), + array( + 'field_name' => 'email', + 'is_required' => 1, + 'visibility' => 'Public Pages and Listings', + 'field_type' => 'Contact', + 'label' => 'Email', + ), + array( + 'field_name' => 'phone', + 'is_required' => 1, + 'visibility' => 'Public Pages and Listings', + 'field_type' => 'Contact', + 'location_type_id' => 1, + 'phone_type_id' => 1, + 'label' => 'Phone' + ), + array( + 'field_name' => 'country', + 'is_required' => 1, + 'visibility' => 'Public Pages and Listings', + 'field_type' => 'Contact', + 'location_type_id' => 1, + 'label' => 'Country' + ), + array( + 'field_name' => 'state_province', + 'is_required' => 1, + 'visibility' => 'Public Pages and Listings', + 'field_type' => 'Contact', + 'location_type_id' => 1, + 'label' => 'State Province' + ), + array( + 'field_name' => 'postal_code', + 'is_required' => 0, + 'field_type' => 'Contact', + 'location_type_id' => 1, + 'label' => 'State Province' + ), + ), ); - $this->_profileID = 25; + $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams); + $this->_profileID = $profile['id']; } function _addCustomFieldToProfile($profileID) { diff --git a/tests/phpunit/api/v3/dataset/uf_field_uf_group_25.xml b/tests/phpunit/api/v3/dataset/uf_field_uf_group_25.xml deleted file mode 100644 index 4b7c5aec14..0000000000 --- a/tests/phpunit/api/v3/dataset/uf_field_uf_group_25.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - - - id - uf_group_id - field_name - is_active - is_view - is_required - weight - help_post - help_pre - visibility - in_selector - is_searchable - location_type_id - phone_type_id - label - field_type - is_reserved - - 100 - 25 - first_name - 1 - 0 - 1 - 1 - - - Public Pages and Listings - 0 - 1 - - - First Name - Individual - 0 - - - 101 - 25 - last_name - 1 - 0 - 1 - 2 - - - Public Pages and Listings - 0 - 1 - - - Last Name - Individual - 0 - - - 102 - 25 - email - 1 - 0 - 1 - 3 - - - Public Pages and Listings - 0 - 1 - - - Email - Contact - 0 - - - 103 - 25 - phone - 1 - 0 - 1 - 4 - - - Public Pages and Listings - 0 - 1 - 1 - 1 - Phone - Contact - 0 - - - 104 - 25 - country - 1 - 0 - 0 - 5 - - - Public Pages and Listings - 0 - 1 - 1 - - Country - Contact - 0 - - - 105 - 25 - state_province - 1 - 0 - 1 - 6 - - - Public Pages and Listings - 0 - 1 - 1 - - State - Contact - 0 - - - 106 - 25 - postal_code - 1 - 0 - 0 - 7 - - - Public Pages and Listings - 0 - 1 - 1 - - Postal Code - Contact - 0 - -
-
diff --git a/tests/phpunit/api/v3/dataset/uf_group_25.xml b/tests/phpunit/api/v3/dataset/uf_group_25.xml deleted file mode 100644 index cb651a393b..0000000000 --- a/tests/phpunit/api/v3/dataset/uf_group_25.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - id - is_active - group_type - title - help_pre - help_post - limit_listings_group_id - post_URL - add_to_group_id - add_captcha - is_map - is_edit_link - is_uf_link - is_update_dupe - cancel_URL - is_cms_user - notify - is_reserved - name - created_id - created_date - is_proximity_search - - 25 - 1 - Individual,Contact - Test Individual-Contact Profile - - - - - - - - - - - - - - - test_individual_contact_profile - - - - -
-
-- 2.25.1