X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fapi%2Fv3%2FProfileTest.php;h=b3754c6ac9e9faa91e326f7a9a4a481b67c3900c;hb=903d0d389fb39dbc261b888fe46b9c808bc27038;hp=b73cbc570cde1d96b9f2d8b4e75f4406aa37e999;hpb=1af588c3575b8517b918793a727ef15778e98f36;p=civicrm-core.git diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index b73cbc570c..b3754c6ac9 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -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', @@ -80,9 +69,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { ////////////// test $this->callAPISuccess3_profile_get ////////////////// /** - * check Without ProfileId + * Check Without ProfileId */ - function testProfileGetWithoutProfileId() { + public function testProfileGetWithoutProfileId() { $params = array( 'contact_id' => 1, ); @@ -92,9 +81,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check with no invalid profile Id + * Check with no invalid profile Id */ - function testProfileGetInvalidProfileId() { + public function testProfileGetInvalidProfileId() { $params = array( 'contact_id' => 1, 'profile_id' => 1000, @@ -103,13 +92,13 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check with success + * 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); @@ -211,9 +210,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * get Billing empty contact - this will return generic defaults + * Get Billing empty contact - this will return generic defaults */ - function testProfileGetBillingEmptyContact() { + public function testProfileGetBillingEmptyContact() { $params = array( 'profile_id' => array('Billing'), @@ -235,9 +234,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check contact activity profile without activity id + * Check contact activity profile without activity id */ - function testContactActivityGetWithoutActivityId() { + public function testContactActivityGetWithoutActivityId() { list($params, $expected) = $this->_createContactWithActivity(); unset($params['activity_id']); @@ -246,9 +245,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check contact activity profile wrong activity id + * Check contact activity profile wrong activity id */ - function testContactActivityGetWrongActivityId() { + public function testContactActivityGetWrongActivityId() { list($params, $expected) = $this->_createContactWithActivity(); $params['activity_id'] = 100001; @@ -256,10 +255,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'Invalid Activity Id (aid).'); } - /* - * check contact activity profile with wrong activity type - */ - function testContactActivityGetWrongActivityType() { + /** + * Check contact activity profile with wrong activity type + */ + public function testContactActivityGetWrongActivityType() { //flush cache by calling with reset $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE); @@ -289,10 +288,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { ); } - /* - * check contact activity profile with success - */ - function testContactActivityGetSuccess() { + /** + * Check contact activity profile with success + */ + 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']); @@ -318,14 +320,16 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']); $this->assertFalse(array_key_exists('participant_status', $result['values'])); } + /** * 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]); @@ -336,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']); } @@ -353,23 +362,24 @@ 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' + ) ); } } /////////////// test $this->callAPISuccess3_profile_set ////////////////// /** - * check Without ProfileId + * Check Without ProfileId */ - function testProfileSubmitWithoutProfileId() { + public function testProfileSubmitWithoutProfileId() { $params = array( 'contact_id' => 1, ); @@ -379,9 +389,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check with no invalid profile Id + * Check with no invalid profile Id */ - function testProfileSubmitInvalidProfileId() { + public function testProfileSubmitInvalidProfileId() { $params = array( 'contact_id' => 1, 'profile_id' => 1000, @@ -390,9 +400,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check with missing required field in profile + * Check with missing required field in profile */ - function testProfileSubmitCheckProfileRequired() { + public function testProfileSubmitCheckProfileRequired() { $pofileFieldValues = $this->_createIndividualContact(); current($pofileFieldValues); $contactId = key($pofileFieldValues); @@ -414,9 +424,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check with success + * Check with success */ - function testProfileSubmit() { + public function testProfileSubmit() { $pofileFieldValues = $this->_createIndividualContact(); current($pofileFieldValues); $contactId = key($pofileFieldValues); @@ -449,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']); } @@ -458,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 + * Set is deprecated but we need to ensure it still works */ - function testLegacySet() { + public function testLegacySet() { $pofileFieldValues = $this->_createIndividualContact(); current($pofileFieldValues); $contactId = key($pofileFieldValues); @@ -535,10 +557,11 @@ class api_v3_ProfileTest extends CiviUnitTestCase { ); } } - /* - * check contact activity profile without activity id - */ - function testContactActivitySubmitWithoutActivityId() { + + /** + * Check contact activity profile without activity id + */ + public function testContactActivitySubmitWithoutActivityId() { list($params, $expected) = $this->_createContactWithActivity(); $params = array_merge($params, $expected); @@ -547,10 +570,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id'); } - /* - * check contact activity profile wrong activity id - */ - function testContactActivitySubmitWrongActivityId() { + /** + * Check contact activity profile wrong activity id + */ + public function testContactActivitySubmitWrongActivityId() { list($params, $expected) = $this->_createContactWithActivity(); $params = array_merge($params, $expected); $params['activity_id'] = 100001; @@ -558,10 +581,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).'); } - /* - * check contact activity profile with wrong activity type - */ - function testContactActivitySubmitWrongActivityType() { + /** + * Check contact activity profile with wrong activity type + */ + public function testContactActivitySubmitWrongActivityType() { //flush cache by calling with reset $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE); @@ -591,10 +614,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'This activity cannot be edited or viewed via this profile.'); } - /* - * check contact activity profile with success - */ - function testContactActivitySubmitSuccess() { + /** + * Check contact activity profile with success + */ + public function testContactActivitySubmitSuccess() { list($params, $expected) = $this->_createContactWithActivity(); $updateParams = array( @@ -618,9 +641,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check profile apply Without ProfileId + * Check profile apply Without ProfileId */ - function testProfileApplyWithoutProfileId() { + public function testProfileApplyWithoutProfileId() { $params = array( 'contact_id' => 1, ); @@ -629,9 +652,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check profile apply with no invalid profile Id + * Check profile apply with no invalid profile Id */ - function testProfileApplyInvalidProfileId() { + public function testProfileApplyInvalidProfileId() { $params = array( 'contact_id' => 1, 'profile_id' => 1000, @@ -640,9 +663,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * check with success + * Check with success */ - function testProfileApply() { + public function testProfileApply() { $pofileFieldValues = $this->_createIndividualContact(); current($pofileFieldValues); $contactId = key($pofileFieldValues); @@ -692,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})" @@ -701,39 +727,37 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } } - /* - * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields - */ /** + * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields * @param array $params * * @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); @@ -902,11 +927,14 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } /** - * @param $profileID + * @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' + )); } } -