From: Eileen McNaughton Date: Sun, 4 Jul 2021 03:33:46 +0000 (+1200) Subject: Add test cover for membership type page X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0b123f115ff52528399dfe90ab8f8edd318b4c56;p=civicrm-core.git Add test cover for membership type page --- diff --git a/ext/financialacls/tests/phpunit/Civi/Financialacls/BaseTestClass.php b/ext/financialacls/tests/phpunit/Civi/Financialacls/BaseTestClass.php index 6eb159cd81..c1434d1661 100644 --- a/ext/financialacls/tests/phpunit/Civi/Financialacls/BaseTestClass.php +++ b/ext/financialacls/tests/phpunit/Civi/Financialacls/BaseTestClass.php @@ -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', diff --git a/ext/financialacls/tests/phpunit/Civi/Financialacls/MembershipTypesTest.php b/ext/financialacls/tests/phpunit/Civi/Financialacls/MembershipTypesTest.php index df71a02e35..131754a129 100644 --- a/ext/financialacls/tests/phpunit/Civi/Financialacls/MembershipTypesTest.php +++ b/ext/financialacls/tests/phpunit/Civi/Financialacls/MembershipTypesTest.php @@ -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; + } + } diff --git a/tests/phpunit/CRM/Member/Page/MembershipTypeTest.php b/tests/phpunit/CRM/Member/Page/MembershipTypeTest.php new file mode 100644 index 0000000000..74e92ad4ef --- /dev/null +++ b/tests/phpunit/CRM/Member/Page/MembershipTypeTest.php @@ -0,0 +1,50 @@ +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' => 'EditDisableDelete', + ], + ], $assigned['rows']); + } + +}