Skip to content
Snippets Groups Projects
Commit 032b095c authored by eileen's avatar eileen
Browse files

Add unit test that ultimately failed to hit the desired code but does add cover

parent 88786666
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ use Civi\Api4\Contact;
* @group headless
*/
class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
use CRMTraits_Custom_CustomDataTrait;
protected $_individualId;
protected $_contribution;
......@@ -119,7 +120,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
'civicrm_relationship',
'civicrm_uf_match',
'civicrm_address',
]
], TRUE
);
foreach ($this->ids['contact'] as $contactID) {
$this->callAPISuccess('contact', 'delete', ['id' => $contactID, 'skip_undelete' => TRUE]);
......@@ -404,6 +405,9 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
*/
public function testSubmitRecurCompleteInstantWithMail($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
// Visibility is 'Public Pages and Listings' in order to try to get to a specific line
// of code to ensure it's tested - it might not be a 'real' use case.
$this->createCustomGroupWithFieldOfType(['extends' => 'Membership'], 'multi_country', NULL, ['visibility' => 'Public Pages and Listings']);
$form = $this->getForm();
$this->mut = new CiviMailUtils($this, TRUE);
/** @var \CRM_Core_Payment_Dummy $processor */
......@@ -424,13 +428,19 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
$form->preProcess();
$form->_contactID = $this->_individualId;
$form->_mode = 'test';
$form->_mode = 'live';
$form->testSubmit(array_merge($this->getBaseSubmitParams(), ['is_recur' => 1, 'send_receipt' => 1, 'auto_renew' => 1]));
$form->testSubmit(array_merge($this->getBaseSubmitParams(), [
'is_recur' => 1,
'send_receipt' => 1,
'auto_renew' => 1,
$this->getCustomFieldName('multi_country') => [1006, 1007],
]));
$contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]);
$this->assertEquals(1, $contributionRecur['is_email_receipt']);
$this->mut->checkMailLog([
'$ ' . $this->formatMoneyInput(7800.90),
'Country-multi : Angola, Anguilla',
]);
$this->mut->stop();
$this->setCurrencySeparators(',');
......
......@@ -86,14 +86,16 @@ trait CRMTraits_Custom_CustomDataTrait {
* Params for the group to be created.
* @param string $customFieldType
*
* @param string $identifier
* @param string|null $identifier
*
* @param array $fieldParams
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function createCustomGroupWithFieldOfType($groupParams = [], $customFieldType = 'text', $identifier = NULL) {
$supported = ['text', 'select', 'date', 'int', 'contact_reference', 'radio'];
public function createCustomGroupWithFieldOfType($groupParams = [], $customFieldType = 'text', $identifier = NULL, $fieldParams = []) {
$supported = ['text', 'select', 'date', 'int', 'contact_reference', 'radio', 'multi_country'];
if (!in_array($customFieldType, $supported, TRUE)) {
throw new CRM_Core_Exception('we have not yet extracted other custom field types from createCustomFieldsOfAllTypes, Use consistent syntax when you do');
}
......@@ -101,7 +103,7 @@ trait CRMTraits_Custom_CustomDataTrait {
$groupParams['name'] = $identifier ?? 'Custom Group';
$this->createCustomGroup($groupParams);
$reference = &$this->ids['CustomField'][$identifier . $customFieldType];
$fieldParams = ['custom_group_id' => $this->ids['CustomGroup'][$groupParams['name']]];
$fieldParams = array_merge($fieldParams, ['custom_group_id' => $this->ids['CustomGroup'][$groupParams['name']]]);
switch ($customFieldType) {
case 'text':
$reference = $this->createTextCustomField($fieldParams)['id'];
......@@ -127,6 +129,10 @@ trait CRMTraits_Custom_CustomDataTrait {
$reference = $this->createIntegerRadioCustomField($fieldParams)['id'];
return;
case 'multi_country':
$reference = $this->createMultiCountryCustomField($fieldParams)['id'];
return;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment