Skip to content

Commit

Permalink
Merge pull request #17528 from seamuslee001/nfv_apiv3_mem_type_apiv4_…
Browse files Browse the repository at this point in the history
…test

[NFC] Update existing APIv3 MembershipType Tests to also test against…
  • Loading branch information
seamuslee001 authored Jun 7, 2020
2 parents aa07663 + 00dfcad commit 79a163e
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions tests/phpunit/api/v3/MembershipTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
class api_v3_MembershipTypeTest extends CiviUnitTestCase {
protected $_contactID;
protected $_contributionTypeID;
protected $_apiversion;
protected $_entity = 'MembershipType';

/**
Expand All @@ -25,16 +24,17 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase {
public function setUp() {
parent::setUp();
$this->useTransaction(TRUE);
$this->_apiversion = 3;
$this->_contactID = $this->organizationCreate();
}

/**
* Get the membership without providing an ID.
*
* This should return an empty array but not an error.
* @dataProvider versionThreeAndFour
*/
public function testGetWithoutId() {
public function testGetWithoutId($version) {
$this->_apiversion = $version;
$params = [
'name' => '60+ Membership',
'description' => 'people above 60 are given health instructions',
Expand All @@ -51,8 +51,10 @@ public function testGetWithoutId() {

/**
* Test get works.
* @dataProvider versionThreeAndFour
*/
public function testGet() {
public function testGet($version) {
$this->_apiversion = $version;
$id = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]);

$params = [
Expand All @@ -70,8 +72,10 @@ public function testGet() {

/**
* Test create with missing mandatory field.
* @dataProvider versionThreeAndFour
*/
public function testCreateWithoutMemberOfContactId() {
public function testCreateWithoutMemberOfContactId($version) {
$this->_apiversion = $version;
$params = [
'name' => '60+ Membership',
'description' => 'people above 60 are given health instructions',
Expand All @@ -84,13 +88,16 @@ public function testCreateWithoutMemberOfContactId() {
'visibility' => 'public',
];

$this->callAPIFailure('membership_type', 'create', $params, 'Mandatory key(s) missing from params array: member_of_contact_id');
$msg = $version === 4 ? 'Mandatory values missing from Api4 MembershipType::create: member_of_contact_id' : 'Mandatory key(s) missing from params array: member_of_contact_id';
$this->callAPIFailure('membership_type', 'create', $params, $msg);
}

/**
* Test successful create.
* @dataProvider versionThreeAndFour
*/
public function testCreate() {
public function testCreate($version) {
$this->_apiversion = $version;
$params = [
'name' => '40+ Membership',
'description' => 'people above 40 are given health instructions',
Expand All @@ -112,8 +119,10 @@ public function testCreate() {
/**
* Domain ID can be intuited..
* DomainID is now optional on API, check that it gets set correctly and that the domain_id is not overwritten when not specified in create.
* @dataProvider versionThreeAndFour
*/
public function testCreateWithoutDomainId() {
public function testCreateWithoutDomainId($version) {
$this->_apiversion = $version;
$params = [
'name' => '60+ Membership',
'description' => 'people above 60 are given health instructions',
Expand Down Expand Up @@ -142,8 +151,10 @@ public function testCreateWithoutDomainId() {

/**
* CRM-20010 Tests period_type is required for MemberType create
* @dataProvider versionThreeAndFour
*/
public function testMemberTypePeriodiTypeRequired() {
public function testMemberTypePeriodiTypeRequired($version) {
$this->_apiversion = $version;
$this->callAPIFailure('MembershipType', 'create', [
'domain_id' => "Default Domain Name",
'member_of_contact_id' => 1,
Expand All @@ -157,8 +168,10 @@ public function testMemberTypePeriodiTypeRequired() {

/**
* Test update.
* @dataProvider versionThreeAndFour
*/
public function testUpdate() {
public function testUpdate($version) {
$this->_apiversion = $version;
$id = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID, 'financial_type_id' => 2]);
$newMemberOrgParams = [
'organization_name' => 'New membership organisation',
Expand All @@ -183,8 +196,10 @@ public function testUpdate() {

/**
* Test successful delete.
* @dataProvider versionThreeAndFour
*/
public function testDelete() {
public function testDelete($version) {
$this->_apiversion = $version;
$membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->organizationCreate()]);
$params = [
'id' => $membershipTypeID,
Expand Down

0 comments on commit 79a163e

Please sign in to comment.