Merge pull request #4979 from xurizaemon/codingstandards-12
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileCountryState.php
index 80c0d44b7a22dd4054b93e51ef4dc4357f360bc6..ee35c8e0c4d2080a0dbd173fb1802300a28d653e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 */
 
 require_once 'CiviTest/CiviSeleniumTestCase.php';
+
+/**
+ * Class WebTest_Profile_ProfileCountryState
+ */
 class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase {
 
   protected function setUp() {
     parent::setUp();
   }
 
-  function testStateCountry() {
-    $this->webtestLogin();    
+  public function testStateCountry() {
+    $this->webtestLogin();
     $config = CRM_Core_Config::singleton();
     // Add new profile.
     $this->openCiviPage('admin/uf/group', 'reset=1');
@@ -43,15 +47,23 @@ class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase {
     $profileTitle = 'Country state province web test temp';
     $this->type('title', $profileTitle);
 
+    // Standalone form or directory
+    $this->click('uf_group_type_Profile');
+
     //click on save
     $this->click('_qf_Group_next');
     $this->waitForPageToLoad($this->getTimeoutMsec());
-    
 
     //check for  profile create
     $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
     $gid = $this->urlArg('gid');
+
     //Add Country field to profile
+    $this->openCiviPage('admin/uf/group/field/add', array(
+        'action' => 'add',
+        'reset' => 1,
+        'gid' => $gid,
+      ), 'field_name[0]');
     $this->click('field_name[0]');
     $this->select('field_name[0]', 'value=Contact');
     $this->click("//option[@value='Contact']");
@@ -75,31 +87,31 @@ class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase {
     $this->click('_qf_Field_next');
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
-    if($gid) {
+    if ($gid) {
       $this->openCiviPage('admin/setting/localization', 'reset=1', '_qf_Localization_next-bottom');
       $country = array(1001 => 'Afghanistan', 1013 => 'Australia', 1039 => 'Canada', 1101 => 'India');
       $enabledCountries = $this->getSelectOptions("countryLimit-t");
       $enabledStates = $this->getSelectOptions("provinceLimit-t");
       $newCountry = array();
-      foreach($country as $countryID => $countryName) {
-        if(!in_array($countryName, $enabledCountries)) {
+      foreach ($country as $countryID => $countryName) {
+        if (!in_array($countryName, $enabledCountries)) {
           $newCountry[$countryID] = $countryName;
           $this->addSelection("countryLimit-f", "label=$countryName");
           $this->click("xpath=//select[@id='countryLimit-f']/option[@value='$countryID']");
           $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']");
         }
-        if(!in_array($countryName, $enabledStates)) {
+        if (!in_array($countryName, $enabledStates)) {
           $this->addSelection("provinceLimit-f", "label=$countryName");
           $this->click("//option[@value='$countryID']");
           $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']");
         }
-        $added = true;
+        $added = TRUE;
       }
       if ($added) {
         $this->click("_qf_Localization_next-bottom");
         $this->waitForPageToLoad($this->getTimeoutMsec());
         $this->waitForText('crm-notification-container', "Saved");
-      } 
+      }
       $this->openCiviPage("profile/create", "gid=$gid&reset=1", NULL);
 
       $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select");
@@ -108,33 +120,29 @@ class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase {
       $states = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID, 'id');
       $stateID = array_rand($states);
       $this->select("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select", "value=$countryID");
-      sleep(2);
-      $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select");
+      $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select/option[@value=$stateID]");
       $this->click("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select");
       $this->select("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select", "value=$stateID");
       $this->clickLink('_qf_Edit_next', NULL);
-      $this->openCiviPage('admin/uf/group', 'reset=1');
-      $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
-      $this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
 
-      $this->waitForElementPresent('_qf_Group_next-bottom');
-      $this->click('_qf_Group_next-bottom');
-      $this->waitForElementPresent('newCiviCRMProfile-bottom');
+      // Delete profile
+      $this->openCiviPage('admin/uf/group', 'action=delete&id=' . $gid, '_qf_Group_next-bottom');
+      $this->clickLink('_qf_Group_next-bottom', 'newCiviCRMProfile-bottom');
       $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been deleted.");
 
       $this->openCiviPage("admin/setting/localization", "reset=1", "_qf_Localization_next-bottom");
       $enabledCountries = $this->getSelectOptions("countryLimit-t");
       $enabledStates = $this->getSelectOptions("provinceLimit-t");
-      $removed = false;
-      foreach($newCountry as $countryID => $countryName) {
-          $this->addSelection("countryLimit-t", "label=$countryName");
-          $this->click("xpath=//select[@id='countryLimit-t']/option[@value='$countryID']");
-          $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
+      $removed = FALSE;
+      foreach ($newCountry as $countryID => $countryName) {
+        $this->addSelection("countryLimit-t", "label=$countryName");
+        $this->click("xpath=//select[@id='countryLimit-t']/option[@value='$countryID']");
+        $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
 
-          $this->addSelection("provinceLimit-t", "label=$countryName");
-          $this->click("//option[@value='$countryID']");
-          $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
-          $removed = true;
+        $this->addSelection("provinceLimit-t", "label=$countryName");
+        $this->click("//option[@value='$countryID']");
+        $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
+        $removed = TRUE;
       }
       if ($removed) {
         $this->click("_qf_Localization_next-bottom");
@@ -143,4 +151,4 @@ class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase {
       }
     }
   }
-}
\ No newline at end of file
+}