Skip to content
Snippets Groups Projects
Unverified Commit 75c62396 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #20761 from eileenmcnaughton/mem_type

#2115 Add test cover for membership type page
parents 73fcd0b6 0b123f11
Branches
Tags
No related merge requests found
......@@ -45,6 +45,7 @@ class BaseTestClass extends \PHPUnit\Framework\TestCase implements HeadlessInter
$this->setPermissions([
'access CiviCRM',
'access CiviContribute',
'access CiviMember',
'edit contributions',
'delete in CiviContribute',
'view contributions of type Donation',
......
......@@ -16,13 +16,39 @@ class MembershipTypesTest extends BaseTestClass {
* Test buildMembershipTypes.
*/
public function testMembershipTypesHook(): void {
$types = MembershipType::save(FALSE)->setRecords([
['name' => 'Forbidden', 'financial_type_id:name' => 'Member Dues'],
['name' => 'Go for it', 'financial_type_id:name' => 'Donation'],
])->setDefaults(['period_type' => 'rolling', 'member_of_contact_id' => 1])->execute()->indexBy('name');
$this->setupLoggedInUserWithLimitedFinancialTypeAccess();
$types = $this->setUpMembershipTypesACLLimited();
$permissionedTypes = \CRM_Member_BAO_Membership::buildMembershipTypeValues(new \CRM_Member_Form_Membership());
$this->assertEquals([$types['Go for it']['id']], array_keys($permissionedTypes));
}
/**
* Test the membership type page loads correctly.
*/
public function testMembershipTypePage(): void {
$page = new \CRM_Member_Page_MembershipType();
$types = $this->setUpMembershipTypesACLLimited();
$page->browse();
$assigned = \CRM_Core_Smarty::singleton()->get_template_vars();
$this->assertArrayNotHasKey($types['Forbidden']['id'], $assigned['rows']);
$this->assertArrayHasKey($types['Go for it']['id'], $assigned['rows']);
}
/**
* @return \Civi\Api4\Generic\Result
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected function setUpMembershipTypesACLLimited(): \Civi\Api4\Generic\Result {
$types = MembershipType::save(FALSE)
->setRecords([
['name' => 'Forbidden', 'financial_type_id:name' => 'Member Dues', 'weight' => 1],
['name' => 'Go for it', 'financial_type_id:name' => 'Donation', 'weight' => 2],
])
->setDefaults(['period_type' => 'rolling', 'member_of_contact_id' => 1])
->execute()
->indexBy('name');
$this->setupLoggedInUserWithLimitedFinancialTypeAccess();
return $types;
}
}
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Test CRM_Member_Form_Membership functions.
*
* @package CiviCRM
* @group headless
*/
class CRM_Member_Page_MembershipTypeTest extends CiviUnitTestCase {
/**
* Test the membership type page loads correctly.
*/
public function testMembershipTypePage(): void {
$page = new CRM_Member_Page_MembershipType();
$id = $this->membershipTypeCreate(['weight' => 1]);
$page->browse();
$assigned = CRM_Core_Smarty::singleton()->get_template_vars();
$this->assertEquals([
$id => [
'id' => '1',
'domain_id' => '1',
'name' => 'General',
'membership_type' => 'General',
'member_of_contact_id' => '3',
'financial_type_id' => '2',
'minimum_fee' => '0.000000000',
'duration_unit' => 'year',
'duration_interval' => '1',
'period_type' => 'Rolling',
'visibility' => 'Public',
'weight' => '1',
'auto_renew' => '0',
'is_active' => '1',
'order' => NULL,
'action' => '<span><a href="/index.php?q=civicrm/admin/member/membershipType/add&amp;action=update&amp;id=' . $id . '&amp;reset=1" class="action-item crm-hover-button" title=\'Edit Membership Type\' >Edit</a><a href="#" class="action-item crm-hover-button crm-enable-disable" title=\'Disable Membership Type\' >Disable</a><a href="/index.php?q=civicrm/admin/member/membershipType/add&amp;action=delete&amp;id=1" class="action-item crm-hover-button small-popup" title=\'Delete Membership Type\' >Delete</a></span>',
],
], $assigned['rows']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment