Webtest fixes
[civicrm-core.git] / tests / phpunit / WebTest / Contact / GroupAddTest.php
index 695f7fcc04d4b9ac93c3ca737fc79a814227ebc4..9160f210c49442423b7d265ad458004f3b409477 100644 (file)
 */
 
 require_once 'CiviTest/CiviSeleniumTestCase.php';
+
+/**
+ * Class WebTest_Contact_GroupAddTest
+ */
 class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
 
   protected function setUp() {
@@ -70,34 +74,29 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
     $this->openCiviPage('group', 'reset=1');
     $this->type('title', $params['name']);
     $this->click('_qf_Search_refresh');
-    $this->waitForVisible('crm-group-selector_processing');
-    $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td[contains(., '{$params['name']}')]");
-    $createdBy = $this->getText("xpath=//table[@id='crm-group-selector']/tbody/tr/td[3]/a");
-    $this->click("xpath=//table[@id='crm-group-selector']/tbody/tr/td[7]/span/a[2]");
-    $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/table[2]/tbody/tr/td[2]/select");
-
-    //assert created by in the edit page
-    $this->assertTrue($this->isElementPresent(
-      "xpath=//form[@id='Edit']/div[2]/div/table/tbody/tr[2]/td[contains(text(), '{$createdBy}')]"));
+    $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]");
+    $createdBy = $this->getText("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td[3]/a");
+    $this->click("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td[7]/span/a[2]");
+    $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/table/tbody/tr[2]/td[contains(text(), '{$createdBy}')]");
     $this->openCiviPage('group', 'reset=1');
 
     //search groups using created by
     $this->type('created_by', $createdBy);
-    $this->click('_qf_Search_refresh');
+    $this->clickLink('_qf_Search_refresh');
 
     //show maximum no. of groups on first result set page
     //as many groups can be created by same creator
     //and checking is done on first result set page
-    $this->waitForVisible('crm-group-selector_processing');
-    $this->select("xpath=//select[@name='crm-group-selector_length']", '100');
-    $this->waitForVisible('crm-group-selector_processing');
+    $this->waitForVisible("xpath=//table[@class='crm-group-selector no-footer dataTable']");
+    $this->select("xpath=//div[@class='dataTables_length']/label/select", '100');
+    $this->waitForVisible("xpath=//table[@class='crm-group-selector no-footer dataTable']");
 
-    $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td[contains(., '{$params['name']}')]");
-    $this->assertTrue($this->isElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td[contains(., '{$params['name']}')]/following-sibling::td[2]/a[text()='{$createdBy}']"));
+    $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]");
+    $this->click("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']");
+    $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']");
 
     //check link of the contact who created the group
-    $this->click("xpath=//table[@id='crm-group-selector']/tbody//tr/td[1][contains(.,'{$params['name']}')]/following-sibling::td[2]/a");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody//tr/td[1]/span[contains(text(),'{$params['name']}')]/../following-sibling::td[2]/a", "css=div.crm-summary-display_name");
     $name = explode(',', $createdBy);
     $name1 = isset($name[1]) ? trim($name[1]) : NULL;
     $name0 = trim($name[0]);
@@ -140,11 +139,10 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
     $this->click("is_reserved");
 
     // Clicking save.
-    $this->click("_qf_Edit_upload");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Edit_upload");
 
     // Is status message correct?
-    $this->assertTrue($this->isTextPresent("The Group '{$params['name']}' has been saved."));
+    $this->waitForText('crm-notification-container', "The Group '{$params['name']}' has been saved.");
 
     // Create a new role w/o reserved group permissions
     $role = 'role' . substr(sha1(rand()), 0, 7);
@@ -152,8 +150,7 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
 
     $this->waitForElementPresent("edit-add");
     $this->type("edit-name", $role);
-    $this->click("edit-add");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("edit-add", NULL);
 
     $this->open($this->sboxPath . "admin/people/permissions/roles");
     $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']");
@@ -184,6 +181,11 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
     $this->_roleDelete($role);
   }
 
+  /**
+   * @param $roleid
+   *
+   * @return string
+   */
   function _testCreateUser($roleid) {
     $this->open($this->sboxPath . "admin/people/create");
 
@@ -217,6 +219,9 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
     return $name;
   }
 
+  /**
+   * @param $role
+   */
   function _roleDelete($role) {
     $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
     $this->click("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
@@ -226,4 +231,51 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
     $this->click("edit-submit");
     $this->waitForTextPresent("The role has been deleted.");
   }
+
+   /**
+   * Webtest for add contact to group (CRM-15108)
+   */
+  function testAddContactToGroup() {
+    $this->webtestLogin();
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
+    $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
+
+    //Create contact.
+    $group = "Advisory Board";
+    $firstName = "Adams".substr(sha1(rand()), 0, 4);
+    $lastName = substr(sha1(rand()), 0, 4);
+    $email = "{$lastName}.{$firstName}@example.org";
+    $this->type('first_name', $firstName);
+    $this->type('last_name', $lastName);
+    $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
+    $this->click('_qf_Contact_upload_view-bottom');
+    $this->waitForText('crm-notification-container', "Contact Saved");
+
+    $this->openCiviPage('group', 'reset=1');
+    $this->waitForElementPresent("xpath=//a/span[text()='Add Group']");
+    $this->waitForElementPresent("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/span[contains(text(), '{$group}')]");
+    $this->click("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/span[text()='{$group}']/../../td[7]/span[1]/a[1]");
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("xpath=//form[@id='Basic']/div[2]/a/span");
+    $this->waitForElementPresent("_qf_Basic_refresh");
+    $this->type('sort_name', $firstName);
+    $this->click('_qf_Basic_refresh');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("_qf_Basic_next_action");
+
+    $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']"));
+    $this->click("xpath=//table/tbody//tr/td[1]/input[@type='checkbox']");
+    $this->click('_qf_Basic_next_action');
+    $this->waitForElementPresent("_qf_AddToGroup_back-bottom");
+    $this->click('_qf_AddToGroup_next-bottom');
+    $this->waitForText('crm-notification-container', "1 contact added to group");
+
+    $this->openCiviPage('contact/search', 'reset=1');
+    $this->waitForElementPresent("_qf_Basic_refresh");
+    $this->type('sort_name', $firstName);
+    $this->select('group',"Advisory Board");
+    $this->click('_qf_Basic_refresh');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']"));
+  }
 }