Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jitendrapurohit committed Sep 17, 2023
1 parent 1866afd commit ece0715
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 42 deletions.
18 changes: 2 additions & 16 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,19 +603,7 @@ function wf_crm_array2str($arr) {
}

/**
* Wrapper for all CiviCRM APIv4 calls
*
* @param string $entity
* API entity
* @param string $operation
* API operation
* @param array $params
* API params
* @param string|int|array $index
* Controls the Result array format.
*
* @return array
* Result of API call
* @inheritDoc
*/
function wf_civicrm_api4($entity, $operation, $params, $index = NULL) {
if (!$entity) {
Expand Down Expand Up @@ -1050,9 +1038,7 @@ public function checksumUserAccess($c, $cid) {
if ($c == 1) {
$session->set('userID', $cid);
}
else {
return TRUE;
}
return TRUE;
}
}
// If no checksum is passed and user is anonymous, reset prev checksum session values if any.
Expand Down
18 changes: 18 additions & 0 deletions src/UtilsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ function wf_crm_custom_types_map_array();
function wf_crm_get_civi_setting($setting_name, $default_value = NULL);

/**
* Check if user checksum is available in the URL.
* Set checksum user in the session.
*
* @param int $c
Expand All @@ -329,4 +330,21 @@ function wf_crm_get_civi_setting($setting_name, $default_value = NULL);
*/
function checksumUserAccess($c, $cid);

/**
* Wrapper for all CiviCRM APIv4 calls
*
* @param string $entity
* API entity
* @param string $operation
* API operation
* @param array $params
* API params
* @param string|int|array $index
* Controls the Result array format.
*
* @return array|\Civi\Api4\Generic\Result
* Result of API call
*/
function wf_civicrm_api4($entity, $operation, $params, $index = NULL);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ uuid: null
langcode: en
status: open
dependencies:
module:
- webform_civicrm
enforced:
module:
- webform_civicrm_test
module:
- webform_civicrm_test
weight: 0
open: null
close: null
Expand All @@ -16,7 +16,7 @@ archive: false
id: update_contact_details
title: 'Update Contact Details'
description: ''
category: ''
categories: { }
elements: |-
basic_information:
'#type': webform_wizard_page
Expand Down Expand Up @@ -59,6 +59,13 @@ elements: |-
width: 20
'#parent': civicrm_1_contact_1_fieldset_fieldset
'#title': 'Last Name'
civicrm_1_contact_1_email_email:
'#type': email
'#form_key': civicrm_1_contact_1_email_email
'#extra':
width: 20
'#parent': civicrm_1_contact_1_fieldset_fieldset
'#title': Email
address_information:
'#type': webform_wizard_page
'#title': 'Address Information'
Expand Down Expand Up @@ -469,12 +476,12 @@ elements: |-
1111: Kazakhstan
1112: Kenya
1113: Kiribati
1114: 'Korea, Democratic People''s Republic of'
1114: "Korea, Democratic People's Republic of"
1115: 'Korea, Republic of'
1251: Kosovo
1116: Kuwait
1117: Kyrgyzstan
1118: 'Lao People''s Democratic Republic'
1118: "Lao People's Democratic Republic"
1119: Latvia
1120: Lebanon
1121: Lesotho
Expand Down Expand Up @@ -821,12 +828,12 @@ handlers:
conditions: { }
weight: null
settings:
disable: 'Leave Fields and Save Settings'
nid: 1
number_of_contacts: '1'
1_contact_type: individual
1_webform_label: 'Contact 1'
civicrm_1_contact_1_contact_contact_sub_type:
'': ''
civicrm_1_contact_1_contact_contact_sub_type: { }
civicrm_1_contact_1_contact_existing: create_civicrm_webform_element
civicrm_1_contact_1_contact_prefix_id: 0
civicrm_1_contact_1_contact_first_name: create_civicrm_webform_element
Expand Down Expand Up @@ -870,17 +877,17 @@ handlers:
civicrm_1_contact_1_address_location_type_id: '1'
civicrm_1_contact_1_address_is_primary: '1'
contact_1_number_of_phone: '0'
contact_1_number_of_email: '0'
contact_1_number_of_email: '1'
civicrm_1_contact_1_email_email: create_civicrm_webform_element
civicrm_1_contact_1_email_location_type_id: '1'
civicrm_1_contact_1_email_is_primary: '1'
contact_1_number_of_website: '0'
contact_1_number_of_im: '0'
contact_1_number_of_cg1: '0'
contact_1_number_of_cg2: '0'
prefix_known: ''
prefix_unknown: ''
toggle_message: 0
message: ''
activity_number_of_activity: '0'
case_number_of_case: '0'
participant_reg_type: '0'
reg_options:
event_type:
Expand All @@ -898,7 +905,6 @@ handlers:
allow_url_load: 0
membership_1_number_of_membership: '0'
civicrm_1_contribution_1_contribution_enable_contribution: '0'
grant_number_of_grant: '0'
checksum_text: ''
create_fieldsets: 1
confirm_subscription: 1
Expand All @@ -918,24 +924,22 @@ handlers:
number_of_other: '0'
number_of_address: '1'
number_of_phone: '0'
number_of_email: '0'
number_of_email: '1'
number_of_website: '0'
number_of_im: '0'
number_of_cg1: '0'
number_of_cg2: '0'
address:
1:
location_type_id: '1'
is_primary: '1'
email:
1:
location_type_id: '1'
is_primary: '1'
activity:
number_of_activity: '0'
case:
number_of_case: '0'
membership:
1:
number_of_membership: '0'
grant:
number_of_grant: '0'
participant_reg_type: '0'
reg_options:
event_type:
Expand Down
19 changes: 12 additions & 7 deletions tests/src/FunctionalJavascript/LocationTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ public function testAddressUpdateUsingChecksum() {
'first_name' => 'Pabst',
'last_name' => 'Anthony',
]);
$address = $this->utils->wf_civicrm_api('Address', 'create', [
$this->utils->wf_civicrm_api('Email', 'create', [
'contact_id' => $contact['id'],
'email' => "[email protected]",
]);
$this->utils->wf_civicrm_api('Address', 'create', [
'contact_id' => $contact['id'],
'location_type_id' => "Home",
'is_primary' => 1,
Expand All @@ -180,17 +184,21 @@ public function testAddressUpdateUsingChecksum() {
'state_province_id' => "Alberta",
'postal_code' => 11111,
]);
$contact_cs = \CRM_Contact_BAO_Contact_Utils::generateChecksum($contact['id']);
$contact_cs = $this->utils->wf_civicrm_api4('Contact', 'getChecksum', [
'contactId' => $contact['id']
], 0)['checksum'];

$this->drupalGet($this->webform->toUrl('canonical', ['query' => ['cid1' => $contact['id'], 'cs' => $contact_cs]]));
$this->assertPageNoErrorMessages();

// Check if name fields are pre populated with existing values.
$this->assertSession()->fieldValueEquals('First Name', $contact['first_name']);
$this->assertSession()->fieldValueEquals('Last Name', $contact['last_name']);
$this->assertSession()->fieldValueEquals('Email', '[email protected]');

// Update the last name
// Update last name & email
$this->getSession()->getPage()->fillField('Last Name', 'Morissette');
$this->getSession()->getPage()->fillField('Email', '[email protected]');
$this->getSession()->getPage()->pressButton('Next >');
$this->assertPageNoErrorMessages();
$canada_id = $this->utils->wf_civicrm_api('Country', 'getvalue', [
Expand All @@ -210,10 +218,6 @@ public function testAddressUpdateUsingChecksum() {
$this->assertSession()->fieldValueEquals('Postal Code', 11111);

// Change the street & city value in the address fields.
$address = [
'Street Address' => '123 Defence Colony Updated',
'City' => 'Calgary',
];
$this->getSession()->getPage()->fillField('Street Address', '123 Defence Colony Updated');
$this->getSession()->getPage()->fillField('City', 'Calgary');

Expand All @@ -232,6 +236,7 @@ public function testAddressUpdateUsingChecksum() {
$expected_values = [
'first_name' => 'Pabst',
'last_name' => 'Morissette',
'email' => '[email protected]',
'street_address' => "123 Defence Colony Updated",
'city' => "Calgary",
'country_id' => $canada_id,
Expand Down

0 comments on commit ece0715

Please sign in to comment.