public function ContactSubmissionTest::createGroupWithContacts in Webform CiviCRM Integration 8.5
Create 5 contacts and a group. Add 4 contacts to the group. $this->contacts is an array of contacts created. $this->group holds the group information.
1 call to ContactSubmissionTest::createGroupWithContacts()
- ContactSubmissionTest::testSelectContactElement in tests/
src/ FunctionalJavascript/ ContactSubmissionTest.php - Test select contact widget for existingcontact element.
File
- tests/
src/ FunctionalJavascript/ ContactSubmissionTest.php, line 31
Class
- ContactSubmissionTest
- Tests submitting a Webform with CiviCRM and a single contact.
Namespace
Drupal\Tests\webform_civicrm\FunctionalJavascriptCode
public function createGroupWithContacts() {
$this->group = civicrm_api3('Group', 'create', [
'title' => substr(sha1(rand()), 0, 7),
]);
$this->contacts = [];
foreach ([
1,
2,
3,
4,
5,
] as $k) {
$this->contacts[$k] = [
'contact_type' => 'Individual',
'first_name' => substr(sha1(rand()), 0, 7),
'last_name' => substr(sha1(rand()), 0, 7),
];
$contact = $this->utils
->wf_civicrm_api('contact', 'create', $this->contacts[$k]);
$this->contacts[$k]['id'] = $contact['id'];
//Add all contacts to group except the last contact.
if ($k != 5) {
$this->utils
->wf_civicrm_api('GroupContact', 'create', [
'group_id' => $this->group['id'],
'contact_id' => $this->contacts[$k]['id'],
]);
}
}
}