Add test cover for membership type page
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 4 Jul 2021 03:33:46 +0000 (15:33 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 4 Jul 2021 23:33:57 +0000 (11:33 +1200)
ext/financialacls/tests/phpunit/Civi/Financialacls/BaseTestClass.php
ext/financialacls/tests/phpunit/Civi/Financialacls/MembershipTypesTest.php
tests/phpunit/CRM/Member/Page/MembershipTypeTest.php [new file with mode: 0644]

index 6eb159cd810c4cfdca33978019065d230299bda3..c1434d1661a5af66770def9b5448646d92bbecf2 100644 (file)
@@ -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',
index df71a02e35532a05e4520d3aedfeca0808b4db95..131754a1292882f554e044e3e55fad590780f0f5 100644 (file)
@@ -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 (file)
index 0000000..74e92ad
--- /dev/null
@@ -0,0 +1,50 @@
+<?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']);
+  }
+
+}