Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make domain_id optional in membership_type api. #12461

Merged
merged 1 commit into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions api/v3/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ function civicrm_api3_membership_type_create($params) {
* Array of parameters determined by getfields.
*/
function _civicrm_api3_membership_type_create_spec(&$params) {
// todo could set default here probably
$params['domain_id']['api.required'] = 1;
$params['domain_id']['api.default'] = CRM_Core_Config::domainID();
$params['member_of_contact_id']['api.required'] = 1;
$params['financial_type_id']['api.required'] = 1;
$params['name']['api.required'] = 1;
Expand Down
18 changes: 14 additions & 4 deletions tests/phpunit/api/v3/MembershipTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public function testCreate() {
}

/**
* Test update fails with no ID.
* Domain ID can be intuited..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intuited?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so it's in the dictionary... :-) I know I'm being picky but it'd be nice to have a more descriptive comment for the test - how about: "Domain ID is optional, check that it is set correctly when set automatically and manually."

*/
public function testUpdateWithoutId() {
public function testCreateWithoutDomainId() {
$params = array(
'name' => '60+ Membership',
'description' => 'people above 60 are given health instructions',
Expand All @@ -141,8 +141,18 @@ public function testUpdateWithoutId() {
'visibility' => 'public',
);

$membershipType = $this->callAPIFailure('membership_type', 'create', $params);
$this->assertEquals($membershipType['error_message'], 'Mandatory key(s) missing from params array: domain_id');
$membershipType = $this->callAPISuccess('membership_type', 'create', $params);
$domainID = $this->callAPISuccessGetValue('MembershipType', ['return' => 'domain_id', 'id' => $membershipType['id']]);
$this->assertEquals(CRM_Core_Config::domainID(), $domainID);

$this->callAPISuccess('membership_type', 'create', ['domain_id' => 2, 'id' => $membershipType['id']]);
$domainID = $this->callAPISuccessGetValue('MembershipType', ['return' => 'domain_id', 'id' => $membershipType['id']]);
$this->assertEquals(2, $domainID);

$this->callAPISuccess('membership_type', 'create', ['id' => $membershipType['id'], 'description' => 'Cool member']);
$domainID = $this->callAPISuccessGetValue('MembershipType', ['return' => 'domain_id', 'id' => $membershipType['id']]);
$this->assertEquals(2, $domainID);

}

/**
Expand Down