*
* @param array $values
* The array of values belonging to this line.
+ *
+ * @throws \CRM_Core_Exception
*/
public function validateValues($values): void {
$params = $this->getMappedRow($values);
if (empty($params['start_date']) && empty($params['join_date'])) {
$errors[] = 'Membership Start Date is required to create a memberships.';
}
+ //fix for CRM-2219 Update Membership
+ if ($this->isUpdateExisting() && !empty($params['is_override']) && empty($params['status_id'])) {
+ $errors[] = 'Required parameter missing: Status';
+ }
if ($errors) {
throw new CRM_Core_Exception('Invalid value for field(s) : ' . implode(',', $errors));
}
//format params to meet api v2 requirements.
//@todo find a way to test removing this formatting
- $formatError = $this->membership_format_params($formatValues, $formatted, TRUE);
+ $this->membership_format_params($formatValues, $formatted, TRUE);
- if ($this->isUpdateExisting()) {
+ if (!$this->isUpdateExisting()) {
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted,
NULL,
'Membership'
);
}
else {
- //fix for CRM-2219 Update Membership
- // onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
- if (!empty($formatted['is_override']) && empty($formatted['status_id'])) {
- throw new CRM_Core_Exception('Required parameter missing: Status', CRM_Import_Parser::ERROR);
- }
if (!empty($formatValues['membership_id'])) {
$dao = new CRM_Member_BAO_Membership();
/**
* Test overriding a membership but not providing status.
- *
- * @throws \CRM_Core_Exception
*/
public function testImportOverriddenMembershipButWithoutStatus(): void {
$this->individualCreate(['email' => 'anthony_anderson2@civicrm.org']);
'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE,
]));
$membershipImporter->init();
- $membershipImporter->_contactType = 'Individual';
$importValues = [
'anthony_anderson2@civicrm.org',
date('Y-m-d'),
TRUE,
];
+ try {
+ $membershipImporter->validateValues($importValues);
+ $this->fail('validation error expected.');
+ }
+ catch (CRM_Core_Exception $e) {
+ $this->assertContains('Required parameter missing: Status', $e->getMessage());
+ return;
+ }
- $importResponse = $membershipImporter->import($importValues);
- $this->assertEquals(CRM_Import_Parser::ERROR, $importResponse);
- $this->assertContains('Required parameter missing: Status', $importValues);
}
/**
* Test that the passed in status is respected.
- *
- * @throws \CRM_Core_Exception
*/
- public function testImportOverriddenMembershipWithStatus() {
+ public function testImportOverriddenMembershipWithStatus(): void {
$this->individualCreate(['email' => 'anthony_anderson3@civicrm.org']);
$membershipImporter = $this->createImportObject([
'email',
'abc',
];
try {
- $importResponse = $membershipImporter->validateValues($importValues);
+ $membershipImporter->validateValues($importValues);
}
catch (CRM_Core_Exception $e) {
$this->assertEquals('Invalid value for field(s) : Status Override End Date', $e->getMessage());
/**
* Test that memberships can still be imported if the status is renamed.
*
- * @throws \CRM_Core_Exception
*/
- public function testImportMembershipWithRenamedStatus() {
+ public function testImportMembershipWithRenamedStatus(): void {
$this->individualCreate(['email' => 'anthony_anderson3@civicrm.org']);
$this->callAPISuccess('MembershipStatus', 'get', [