* 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;
+ }
+
}
--- /dev/null
+<?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&action=update&id=' . $id . '&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&action=delete&id=1" class="action-item crm-hover-button small-popup" title=\'Delete Membership Type\' >Delete</a></span>',
+ ],
+ ], $assigned['rows']);
+ }
+
+}