/*
+--------------------------------------------------------------------+
-| CiviCRM version 4.4 |
+| CiviCRM version 4.5 |
+--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-2013 |
+| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
class api_v3_ProfileTest extends CiviUnitTestCase {
protected $_apiversion;
protected $_profileID = 0;
+ protected $_membershipTypeID;
+ protected $_contactID;
+
+ /**
+ * @return array
+ */
function get_info() {
return array(
'name' => 'Profile Test',
$config->countryLimit[1] = 1013;
$config->stateLimit[1] = 1013;
$this->createLoggedInUser();
+ $this->_membershipTypeID = $this->membershipTypeCreate();
}
function tearDown() {
'civicrm_contact',
'civicrm_phone',
'civicrm_address',
+ 'civicrm_membership',
+ 'civicrm_contribution',
), TRUE);
+ $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID));
// 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 ($this->_profileID, 26)");
}
'billing_city-5' => 'Gotham City',
'billing_state_province_id-5' => '1021',
'billing_country_id-5' => '1228',
- 'billing-email-5' => 'abc1.xyz1@yahoo.com',
'billing_postal_code-5' => '90210',
'billing-email-5' => 'abc1.xyz1@yahoo.com',
'email-5' => 'abc1.xyz1@yahoo.com',
'profile_id' => 'participant_status',
'get_options' => 'all')
);
- $this->assertTrue(array_key_exists('participant_status', $result['values']));
- $this->assertEquals('Attended', $result['values']['participant_status']['options'][2]);
+ $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
+ $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
+ $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
}
/**
'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->assertTrue(!array_key_exists('financial_type', $result['values']));
$this->assertEquals(12, $result['values']['receive_date']['type']);
}
$this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
}
+ /**
+ * 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() {
+ $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'));
+ $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'));
+ $weight = 1;
+ 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() {
+ $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,
+ ));
+ }
/**
* set is deprecated but we need to ensure it still works
*/
/*
* 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()) {
$contactParams = array_merge(array(
'first_name' => 'abc1',
), $params
);
- $contactID = $this->individualCreate($contactParams);
+ $this->_contactID = $this->individualCreate($contactParams);
$this->_createIndividualProfile();
// expected result of above created profile with contact Id $contactId
- $profileData[$contactID] = array(
+ $profileData[$this->_contactID] = array(
'first_name' => 'abc1',
'last_name' => 'xyz1',
'email-primary' => 'abc1.xyz1@yahoo.com',
return $profileData;
}
+ /**
+ * @return array
+ */
function _createContactWithActivity() {
// @TODO: Create profile with custom fields
$op = new PHPUnit_Extensions_Database_Operation_Insert();
'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
+ 'label' => 'First Name',
),
array(
'field_name' => 'last_name',
'is_required' => 1,
'visibility' => 'Public Pages and Listings',
'field_type' => 'Individual',
+ 'label' => 'Last Name',
),
array(
'field_name' => 'email',
$this->_profileID = $profile['id'];
}
+ /**
+ * @param $profileID
+ */
function _addCustomFieldToProfile($profileID) {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, '');
$this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));