Unit test for https://github.com/civicrm/civicrm-core/pull/18568
authoreileen <emcnaughton@wikimedia.org>
Thu, 24 Sep 2020 03:25:38 +0000 (15:25 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 24 Sep 2020 04:30:55 +0000 (16:30 +1200)
tests/phpunit/CRM/Price/Form/FieldTest.php

index e4c71d881900cd4ae0420da09f700a2a67961eda..a7ecdafb369b7a9ffa828f96aedcc0848767e4fc 100644 (file)
@@ -112,4 +112,192 @@ class CRM_Price_Form_FieldTest extends CiviUnitTestCase {
     return array_merge($defaultParams, $params);
   }
 
+  /**
+   * Minimal test intended to check for no glaring errors which membership types are validated.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testPriceFieldFormRuleOnMembership() {
+    $membershipTypeID = $this->membershipTypeCreate();
+    $membershipTypeID2 = $this->membershipTypeCreate(['member_of_contact_id' => $this->setupIDs['contact']]);
+
+    $priceSetID = $this->callAPISuccess('PriceSet', 'create', ['title' => 'blah', 'extends' => 'CiviMember'])['id'];
+    /* @var \CRM_Price_Form_Field $form */
+    $form = $this->getFormObject('CRM_Price_Form_Field');
+    $_REQUEST['sid'] = $priceSetID;
+    $form->preProcess();
+    $form->buildQuickForm();
+    $form->_action = CRM_Core_Action::ADD;
+    $errors = CRM_Price_Form_Field::formRule(
+      [
+        'qfKey' => '91c63cb3e611280f3cd81787847e86568f72cf1ad387c785999ff66f90c575a5_568',
+        'entryURL' => 'http://dmaster.local/civicrm/admin/price/field?reset=1&amp;action=add&amp;sid=9',
+        'sid' => '9',
+        'fid' => '',
+        '_qf_default' => 'Field:next',
+        '_qf_Field_next' => '1',
+        'label' => 'member',
+        'html_type' => 'CheckBox',
+        'price' => '5',
+        'non_deductible_amount' => '',
+        'financial_type_id' => '1',
+        'membership_type_id' =>
+          [
+            1 => $membershipTypeID,
+            2 => $membershipTypeID2,
+            3 => '',
+            4 => '',
+            5 => '',
+            6 => '',
+            7 => '',
+            8 => '',
+            9 => '',
+            10 => '',
+            11 => '',
+            12 => '',
+            13 => '',
+            14 => '',
+            15 => '',
+          ],
+        'membership_num_terms' =>
+          [
+            1 => '1',
+            2 => 1,
+            3 => '',
+            4 => '',
+            5 => '',
+            6 => '',
+            7 => '',
+            8 => '',
+            9 => '',
+            10 => '',
+            11 => '',
+            12 => '',
+            13 => '',
+            14 => '',
+            15 => '',
+          ],
+        'option_label' =>
+          [
+            1 => 'General',
+            2 => 'Student',
+            3 => '',
+            4 => '',
+            5 => '',
+            6 => '',
+            7 => '',
+            8 => '',
+            9 => '',
+            10 => '',
+            11 => '',
+            12 => '',
+            13 => '',
+            14 => '',
+            15 => '',
+          ],
+        'option_amount' =>
+          [
+            1 => '100.00',
+            2 => '50',
+            3 => '',
+            4 => '',
+            5 => '',
+            6 => '',
+            7 => '',
+            8 => '',
+            9 => '',
+            10 => '',
+            11 => '',
+            12 => '',
+            13 => '',
+            14 => '',
+            15 => '',
+          ],
+        'option_financial_type_id' =>
+          [
+            1 => '2',
+            2 => '1',
+            3 => '1',
+            4 => '1',
+            5 => '1',
+            6 => '1',
+            7 => '1',
+            8 => '1',
+            9 => '1',
+            10 => '1',
+            11 => '1',
+            12 => '1',
+            13 => '1',
+            14 => '1',
+            15 => '1',
+          ],
+        'option_weight' =>
+          [
+            1 => '1',
+            2 => '2',
+            3 => '3',
+            4 => '4',
+            5 => '5',
+            6 => '6',
+            7 => '7',
+            8 => '8',
+            9 => '9',
+            10 => '10',
+            11 => '11',
+            12 => '12',
+            13 => '13',
+            14 => '14',
+            15 => '15',
+          ],
+        'option_visibility_id' =>
+          [
+            1 => '1',
+            2 => '1',
+            3 => '1',
+            4 => '1',
+            5 => '1',
+            6 => '1',
+            7 => '1',
+            8 => '1',
+            9 => '1',
+            10 => '1',
+            11 => '1',
+            12 => '1',
+            13 => '1',
+            14 => '1',
+            15 => '1',
+          ],
+        'option_status' =>
+          [
+            1 => '1',
+            2 => '1',
+            3 => '1',
+            4 => '1',
+            5 => '1',
+            6 => '1',
+            7 => '1',
+            8 => '1',
+            9 => '1',
+            10 => '1',
+            11 => '1',
+            12 => '1',
+            13 => '1',
+            14 => '1',
+            15 => '1',
+          ],
+        'options_per_line' => '1',
+        'is_display_amounts' => '1',
+        'weight' => '1',
+        'help_pre' => '',
+        'help_post' => '',
+        'active_on' => '',
+        'expire_on' => '',
+        'visibility_id' => '1',
+        'is_active' => '1',
+      ], [], $form);
+    $this->assertEquals([
+      '_qf_default' => 'You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity.',
+    ], $errors);
+  }
+
 }