webtestLogin(); $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7); $this->WebtestAddGroup($newGroupName); // Create two new contacts with a common random string in email address $emailString = substr(sha1(rand()), 0, 7) . '@example.com_'; $cids = array(); for ($i = 0; $i < 2; $i++) { // create new contact $this->webtestAddContact(); // get cid of new contact $cids[] = $this->urlArg('cid'); // update email of new contact $this->waitForElementPresent("//ul[@id='actions']/li/a/span[text()='Edit']"); $this->click("//ul[@id='actions']/li/a/span[text()='Edit']"); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->type("email_1_email", $emailString . $i . 'webtest'); $this->click("_qf_Contact_upload_view"); $this->waitForPageToLoad($this->getTimeoutMsec()); } // goto advanced search $this->openCiviPage("contact/search/advanced", "reset=1", "email"); $this->type("email", $emailString); $this->click("_qf_Advanced_refresh"); $this->waitForPageToLoad($this->getTimeoutMsec()); // Verify exactly two contacts found $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results with email like ' . $emailString); // Click "check all" box and act on "Add to group" action $this->click('toggleSelect'); $this->select("task", "label=Add Contacts to Group"); // Because it tends to cause problems, all uses of sleep() must be justified in comments // Sleep should never be used for wait for anything to load from the server // Justification for this instance: FIXME sleep(1); $this->click("Go"); $this->waitForPageToLoad($this->getTimeoutMsec()); // Select the new group and click to add $this->click("group_id"); $this->select("group_id", "label=" . $newGroupName); $this->click("_qf_AddToGroup_next-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); // Check status messages are as expected $this->waitForText('crm-notification-container', "Added Contacts to {$newGroupName}"); $this->waitForText('crm-notification-container', "2 contacts added to group"); // Search by group membership in newly created group $this->openCiviPage('contact/search/advanced', 'reset=1'); $this->select("group", "label=" . $newGroupName); $this->click("_qf_Advanced_refresh"); $this->waitForPageToLoad($this->getTimeoutMsec()); // Verify those two contacts (and only those two) are in the group if (!$this->isTextPresent("2 Contacts")) { die("nothing found for group $newGroupName"); } $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results belonging to group: ' . $newGroupName); foreach ($cids as $cid) { $this->assertTrue($this->isElementPresent('rowid' . $cid)); } } function testMultiplePageContactSearchAddContactsToGroup() { $this->webtestLogin(); $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7); $this->WebtestAddGroup($newGroupName); $this->openCiviPage('contact/search', 'reset=1'); $this->click("_qf_Basic_refresh"); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->type("xpath=//*[@id='Basic-rows-per-page-select']", '25'); $this->waitForElementPresent("toggleSelect"); $this->click("toggleSelect"); $this->click("xpath=//div[@class='crm-content-block']/div/div[2]/div/span[2]/a"); $this->waitForText("xpath=//div[@class='crm-content-block']/div/div[2]/div/span[2]/a", "First"); $this->click("toggleSelect"); $this->select("task", "label=Add Contacts to Group"); $this->click("Go"); $this->waitForPageToLoad($this->getTimeoutMsec()); // Select the new group and click to add $this->click("group_id"); $this->select("group_id", "label=" . $newGroupName); $this->click("_qf_AddToGroup_next-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); // Check status messages are as expected $this->waitForText('crm-notification-container', "Added Contacts to {$newGroupName}"); $this->waitForText('crm-notification-container', "50 contacts added to group"); $this->openCiviPage('contact/search/advanced', 'reset=1'); $this->select("group", "label=" . $newGroupName); $this->click("_qf_Advanced_refresh"); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->assertTrue($this->isTextPresent("50 Contacts"), 'Looking for 50 results belonging to group: ' . $newGroupName); } }