$params['id'] = $ids['ufgroup'];
CRM_Core_Error::deprecatedWarning('ids parameter is deprecated');
}
- $fields = [
- 'is_active',
- 'add_captcha',
- 'is_map',
- 'is_update_dupe',
- 'is_edit_link',
- 'is_uf_link',
- 'is_cms_user',
- ];
- foreach ($fields as $field) {
- $params[$field] = CRM_Utils_Array::value($field, $params, FALSE);
- }
- $params['limit_listings_group_id'] = $params['group'] ?? NULL;
- $params['add_to_group_id'] = $params['add_contact_to_group'] ?? NULL;
+ // Convert parameter names but don't overwrite existing data on updates
+ // unless explicitly specified. And allow setting to null, so use
+ // array_key_exists. i.e. we need to treat missing and empty separately.
+ if (array_key_exists('group', $params)) {
+ $params['limit_listings_group_id'] = $params['group'];
+ }
+ if (array_key_exists('add_contact_to_group', $params)) {
+ $params['add_to_group_id'] = $params['add_contact_to_group'];
+ }
//CRM-15427
if (!empty($params['group_type']) && is_array($params['group_type'])) {
}
}
+ /**
+ * Test what happens if you don't set is_active
+ * @param int $version
+ * @dataProvider versionThreeAndFour
+ */
+ public function testUpdateUFGroupActiveMissing($version) {
+ $this->_apiversion = $version;
+ $this->callAPISuccess('uf_group', 'create', [
+ 'title' => 'Edited Test Profile',
+ 'id' => $this->_ufGroupId,
+ ]);
+ $result = $this->callAPISuccess('uf_group', 'getsingle', ['id' => $this->_ufGroupId]);
+ $this->assertSame($this->_apiversion === 3 ? '1' : TRUE, $result['is_active']);
+ }
+
/**
* @param int $version
* @dataProvider versionThreeAndFour
$this->assertEquals(0, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__);
}
+ /**
+ * Test creating a profile with an "Add contact to group" group set and
+ * then removing it. It should get removed.
+ * It's complicated by the fact that the parameter name is not the same as
+ * the field name.
+ * @param int $version
+ * @dataProvider versionThreeAndFour
+ */
+ public function testUFGroupUnsetAddToGroup($version) {
+ $this->_apiversion = $version;
+
+ // sanity check
+ $this->assertNotEmpty($this->params['add_contact_to_group']);
+
+ $ufGroup = $this->callAPISuccess('uf_group', 'create', $this->params);
+ $result = $this->callAPISuccess('uf_group', 'getsingle', ['id' => $ufGroup['id']]);
+ $this->assertEquals($this->params['add_contact_to_group'], $result['add_to_group_id']);
+
+ // now remove it
+ $this->callAPISuccess('uf_group', 'create', [
+ 'id' => $ufGroup['id'],
+ 'add_contact_to_group' => '',
+ ]);
+ $result = $this->callAPISuccess('uf_group', 'getsingle', ['id' => $ufGroup['id']]);
+ if ($this->_apiversion === 3) {
+ $this->assertFalse(array_key_exists('add_to_group_id', $result));
+ }
+ else {
+ $this->assertNull($result['add_to_group_id']);
+ }
+ }
+
}