Webtest fixes for profile/custom-field/price-set
[civicrm-core.git] / tests / phpunit / WebTest / Profile / SearchTest.php
index d5f0c3316ad07670e8aa33bf2f7e60326d52b6b1..d674e965a8614d12fe14a4493be7a7cda7004587 100644 (file)
 */
 
 require_once 'CiviTest/CiviSeleniumTestCase.php';
+
+/**
+ * Class WebTest_Profile_SearchTest
+ */
 class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
 
   protected function setUp() {
@@ -54,6 +58,7 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     //click on save
     $this->click('_qf_Group_next-bottom');
     $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("xpath=//a/span[text()='Add Field']");
 
     //check for  profile create
     $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
@@ -62,6 +67,7 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $profileId = $this->urlArg('gid');
 
     // Add Last Name field.
+    $this->waitForElementPresent("field_name[0]");
     $this->click('field_name[0]');
     $this->select('field_name[0]', 'value=Individual');
     $this->click('field_name[1]');
@@ -73,7 +79,6 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->click('in_selector');
     // click on save
     $this->click('_qf_Field_next_new-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
     //check for field add
     $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Last Name' has been saved to '$profileTitle'.");
     $this->waitForText('crm-notification-container', 'You can add another profile field.');
@@ -90,7 +95,6 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->click('in_selector');
     // click on save
     $this->click('_qf_Field_next_new-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
     //check for field add
     $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Email' has been saved to '$profileTitle'.");
     $this->waitForText('crm-notification-container', 'You can add another profile field.');
@@ -105,7 +109,8 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->select('visibility', 'value=Public Pages');
     $this->click('is_searchable');
     $this->click('in_selector');
-    $this->clickLink('_qf_Field_next_new-bottom');
+    $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
+    $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
 
     // Add state, country and county field
     $this->click('field_name[0]');
@@ -118,7 +123,8 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->click('is_searchable');
     $this->click('in_selector');
     // click on save and new
-    $this->clickLink('_qf_Field_next_new-bottom');
+    $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
+    $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
 
     $this->click('field_name[0]');
     $this->select('field_name[0]', 'value=Contact');
@@ -130,7 +136,8 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->click('is_searchable');
     $this->click('in_selector');
     // click on save and new
-    $this->clickLink('_qf_Field_next_new-bottom');
+    $this->clickLink('_qf_Field_next_new-bottom', 'field_name[0]', FALSE);
+    $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
 
     $this->click('field_name[0]');
     $this->select('field_name[0]', 'value=Contact');
@@ -143,11 +150,10 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->click('in_selector');
 
     // click on save
-    $this->clickLink('_qf_Field_next-bottom', "xpath=//div[@id='field_page']/div[1]/a[4]/span[text()='Use (create mode)']");
+    $this->clickLink('_qf_Field_next-bottom', "xpath=//div[@id='field_page']/div[1]/a[4]/span[text()='Use (create mode)']", FALSE);
 
     $uselink = explode('?', $this->getAttribute("xpath=//*[@id='field_page']/div[1]/a[4]@href"));
-    $this->openCiviPage('profile/create', "$uselink[1]", '_qf_Edit_cancel');
-    $this->waitForElementPresent('_qf_Edit_next');
+    $this->openCiviPage('profile/create', "$uselink[1]", '_qf_Edit_next');
     $lastName = substr(sha1(rand()), 0, 7);
 
     // Fill Last Name
@@ -159,16 +165,16 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
 
     // fill country, state, county
     $this->select('country-Primary', "United States");
-    // adding sleep gives time for state data
-    // to get populated in state combo box
-    sleep(1);
+
+    // wait for state data to be populated
+    $this->waitForElementPresent("xpath=//select[@id='state_province-Primary']/option[text()='California']");
     $this->select('state_province-Primary', "California");
-    // adding sleep gives time for county data
-    // to get populated in county combo box
-    sleep(1);
+
+    // wait for county data to be populated
+    $this->waitForElementPresent("xpath=//select[@id='county-Primary']/option[text()='Alameda']");
     $this->select('county-Primary', "Alameda");
-    $this->click('_qf_Edit_next');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+
+    $this->clickLink('_qf_Edit_next', NULL);
 
     $this->assertElementContainsText("css=span.msg-text", 'Your information has been saved.');
 
@@ -184,19 +190,18 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
 
     // Fill state, county, country
     $this->select('country-Primary', "United States");
-    // adding sleep gives time for state data
-    // to get populated in state combo box
-    sleep(1);
+
+    // wait for state data to be populated
+    $this->waitForElementPresent("xpath=//select[@id='state_province-Primary']/option[text()='California']");
     $this->select('state_province-Primary', "California");
-    // adding sleep gives time for county data
-    // to get populated in county combo box
-    sleep(1);
+
+    // wait for county data to be populated
+    $this->waitForElementPresent("xpath=//select[@id='county-Primary']/option[text()='Alameda']");
     $this->select('county-Primary', "Alameda");
 
     // Select Custom option
-    $this->click('CIVICRM_QFID_Edu_2');
-    $this->click('_qf_Search_refresh');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->select('custom_1', 'Education');
+    $this->clickLink('_qf_Search_refresh', NULL);
 
     // Verify Data.
     $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[2][text()='$lastName']"));
@@ -208,18 +213,12 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[8][text()='Alameda']"));
 
     // Go back to Profile fields admin
-    $this->openCiviPage('admin/uf/group/field', "reset=1&action=browse&gid=$profileId");
+    $this->openCiviPage('admin/uf/group/field', "reset=1&action=browse&gid=$profileId", "xpath=//table/tbody/tr[1]/td[9]");
 
     // Edit first profile field
-    $this->waitForElementPresent("xpath=//table/tbody/tr[1]/td[9]");
     $this->clickLink("xpath=//table/tbody/tr[1]/td[9]/span[1]/a[1]", '_qf_Field_next-bottom', FALSE);
 
-    // sleep 5 to make sure jQuery is not hiding field after page load
-    // 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(5);
-    $this->assertTrue($this->isElementPresent("visibility"), 'Visibility field not present when editing existing profile field.');
+    $this->waitForElementPresent("visibility");
     $this->click("xpath=//tr[@id='profile_visibility']/td[1]/a");
     $this->waitForElementPresent("xpath=//div[@id='crm-notification-container']/div/div[2]/p[2]");
     $this->waitForText('crm-notification-container', 'Is this field hidden from other users');