Webtest fixes for profile/custom-field/price-set
[civicrm-core.git] / tests / phpunit / WebTest / Profile / SearchTest.php
index 8b89ac570b159d8d6434d09de1495869f1f00bcf..d674e965a8614d12fe14a4493be7a7cda7004587 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 */
 
 require_once 'CiviTest/CiviSeleniumTestCase.php';
+
+/**
+ * Class WebTest_Profile_SearchTest
+ */
 class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
 
   protected function setUp() {
@@ -34,6 +38,11 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
   function testSearchProfile() {
     $this->webtestLogin();
 
+    // enable county field
+    $this->openCiviPage('admin/setting/preferences/address', 'reset=1');
+    $this->check('address_options[7]');
+    $this->clickLink('_qf_Address_next-bottom');
+
     // Add new profile.
     $this->openCiviPage('admin/uf/group', 'reset=1');
 
@@ -45,9 +54,11 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
     $this->type('title', $profileTitle);
 
+    $this->click('uf_group_type_Profile');
     //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.");
@@ -56,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]');
@@ -67,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.');
@@ -84,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.');
@@ -99,11 +109,51 @@ 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', '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]');
+    $this->select('field_name[0]', 'value=Contact');
+    $this->click('field_name[1]');
+    $this->select('field_name[1]', 'value=country');
+    $this->select('field_name[2]', 'Primary');
+    $this->click('visibility');
+    $this->select('visibility', 'value=Public Pages and Listings');
+    $this->click('is_searchable');
+    $this->click('in_selector');
+    // click on save and new
+    $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');
+    $this->click('field_name[1]');
+    $this->select('field_name[1]', 'value=state_province');
+    $this->select('field_name[2]', 'Primary');
+    $this->click('visibility');
+    $this->select('visibility', 'value=Public Pages and Listings');
+    $this->click('is_searchable');
+    $this->click('in_selector');
+    // click on save and new
+    $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');
+    $this->click('field_name[1]');
+    $this->select('field_name[1]', 'value=county');
+    $this->select('field_name[2]', 'Primary');
+    $this->click('visibility');
+    $this->select('visibility', 'value=Public Pages and Listings');
+    $this->click('is_searchable');
+    $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->click("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);
 
-    $this->waitForElementPresent('_qf_Edit_next');
+    $uselink = explode('?', $this->getAttribute("xpath=//*[@id='field_page']/div[1]/a[4]@href"));
+    $this->openCiviPage('profile/create', "$uselink[1]", '_qf_Edit_next');
     $lastName = substr(sha1(rand()), 0, 7);
 
     // Fill Last Name
@@ -112,10 +162,21 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->type('email-Primary', "jhon@$lastName.com");
     // Select Custom option
     $this->click('CIVICRM_QFID_Edu_2');
-    $this->click('_qf_Edit_next');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
 
-    $this->assertElementContainsText('css=span.msg-text', 'Your information has been saved.');
+    // fill country, state, county
+    $this->select('country-Primary', "United States");
+
+    // wait for state data to be populated
+    $this->waitForElementPresent("xpath=//select[@id='state_province-Primary']/option[text()='California']");
+    $this->select('state_province-Primary', "California");
+
+    // wait for county data to be populated
+    $this->waitForElementPresent("xpath=//select[@id='county-Primary']/option[text()='Alameda']");
+    $this->select('county-Primary', "Alameda");
+
+    $this->clickLink('_qf_Edit_next', NULL);
+
+    $this->assertElementContainsText("css=span.msg-text", 'Your information has been saved.');
 
     // Search Contact via profile.
     $this->waitForElementPresent("xpath=//div[@id='crm-container']//div/a[text()='ยป Back to Listings']");
@@ -126,30 +187,38 @@ class WebTest_Profile_SearchTest extends CiviSeleniumTestCase {
     $this->type('last_name', $lastName);
     // Fill Email
     $this->type('email-Primary', "jhon@$lastName.com");
+
+    // Fill state, county, country
+    $this->select('country-Primary', "United States");
+
+    // wait for state data to be populated
+    $this->waitForElementPresent("xpath=//select[@id='state_province-Primary']/option[text()='California']");
+    $this->select('state_province-Primary', "California");
+
+    // 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']"));
     $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[3][text()='$lastName']"));
     $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[4][text()='jhon@$lastName.com']"));
     $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[5][text()='Education']"));
+    $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[6][text()='United States']"));
+    $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[7][text()='CA']"));
+    $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');
-
-    // 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->clickLink("xpath=//table/tbody/tr[1]/td[9]/span[1]/a[1]", '_qf_Field_next-bottom', FALSE);
+
+    $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');