| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License along with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | */ |
| 26 | |
| 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
| 28 | |
| 29 | /** |
| 30 | * Class WebTest_Profile_ProfileCountryState |
| 31 | */ |
| 32 | class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testStateCountry() { |
| 39 | $this->webtestLogin(); |
| 40 | $config = CRM_Core_Config::singleton(); |
| 41 | // Add new profile. |
| 42 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
| 43 | $this->click('newCiviCRMProfile-top'); |
| 44 | $this->waitForElementPresent('_qf_Group_next-bottom'); |
| 45 | |
| 46 | //Name of profile |
| 47 | $profileTitle = 'Country state province web test temp'; |
| 48 | $this->type('title', $profileTitle); |
| 49 | |
| 50 | // Standalone form or directory |
| 51 | $this->click('uf_group_type_Profile'); |
| 52 | |
| 53 | //click on save |
| 54 | $this->click('_qf_Group_next'); |
| 55 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 56 | |
| 57 | //check for profile create |
| 58 | $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been added. You can add fields to this profile now."); |
| 59 | $gid = $this->urlArg('gid'); |
| 60 | |
| 61 | //Add Country field to profile |
| 62 | $this->openCiviPage('admin/uf/group/field/add', array( |
| 63 | 'action' => 'add', |
| 64 | 'reset' => 1, |
| 65 | 'gid' => $gid, |
| 66 | ), 'field_name[0]'); |
| 67 | $this->click('field_name[0]'); |
| 68 | $this->select('field_name[0]', 'value=Contact'); |
| 69 | $this->click("//option[@value='Contact']"); |
| 70 | $this->click('field_name[1]'); |
| 71 | $this->select('field_name[1]', 'value=country'); |
| 72 | $this->click("//option[@value='country']"); |
| 73 | $this->click('is_required'); |
| 74 | |
| 75 | $this->click('_qf_Field_next_new'); |
| 76 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 77 | |
| 78 | //Add State field to profile |
| 79 | $this->click('field_name[0]'); |
| 80 | $this->select('field_name[0]', 'value=Contact'); |
| 81 | $this->click("//option[@value='Contact']"); |
| 82 | $this->click('field_name[1]'); |
| 83 | $this->select('field_name[1]', 'value=state_province'); |
| 84 | $this->click("xpath=//select[@id='field_name_1']/option[@value='state_province']"); |
| 85 | $this->click('is_required'); |
| 86 | //click on save |
| 87 | $this->click('_qf_Field_next'); |
| 88 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 89 | |
| 90 | if ($gid) { |
| 91 | $this->openCiviPage('admin/setting/localization', 'reset=1', '_qf_Localization_next-bottom'); |
| 92 | $country = array(1001 => 'Afghanistan', 1013 => 'Australia', 1039 => 'Canada', 1101 => 'India'); |
| 93 | $enabledCountries = $this->getSelectOptions("countryLimit-t"); |
| 94 | $enabledStates = $this->getSelectOptions("provinceLimit-t"); |
| 95 | $newCountry = array(); |
| 96 | foreach ($country as $countryID => $countryName) { |
| 97 | if (!in_array($countryName, $enabledCountries)) { |
| 98 | $newCountry[$countryID] = $countryName; |
| 99 | $this->addSelection("countryLimit-f", "label=$countryName"); |
| 100 | $this->click("xpath=//select[@id='countryLimit-f']/option[@value='$countryID']"); |
| 101 | $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']"); |
| 102 | } |
| 103 | if (!in_array($countryName, $enabledStates)) { |
| 104 | $this->addSelection("provinceLimit-f", "label=$countryName"); |
| 105 | $this->click("//option[@value='$countryID']"); |
| 106 | $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']"); |
| 107 | } |
| 108 | $added = TRUE; |
| 109 | } |
| 110 | if ($added) { |
| 111 | $this->click("_qf_Localization_next-bottom"); |
| 112 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 113 | $this->waitForText('crm-notification-container', "Saved"); |
| 114 | } |
| 115 | $this->openCiviPage("profile/create", "gid=$gid&reset=1", NULL); |
| 116 | |
| 117 | $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select"); |
| 118 | $this->click("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select"); |
| 119 | $countryID = array_rand($country); |
| 120 | $states = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID, 'id'); |
| 121 | $stateID = array_rand($states); |
| 122 | $this->select("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select", "value=$countryID"); |
| 123 | $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select/option[@value=$stateID]"); |
| 124 | $this->click("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select"); |
| 125 | $this->select("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select", "value=$stateID"); |
| 126 | $this->clickLink('_qf_Edit_next', NULL); |
| 127 | |
| 128 | // Delete profile |
| 129 | $this->openCiviPage('admin/uf/group', 'action=delete&id=' . $gid, '_qf_Group_next-bottom'); |
| 130 | $this->clickLink('_qf_Group_next-bottom', 'newCiviCRMProfile-bottom'); |
| 131 | $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been deleted."); |
| 132 | |
| 133 | $this->openCiviPage("admin/setting/localization", "reset=1", "_qf_Localization_next-bottom"); |
| 134 | $enabledCountries = $this->getSelectOptions("countryLimit-t"); |
| 135 | $enabledStates = $this->getSelectOptions("provinceLimit-t"); |
| 136 | $removed = FALSE; |
| 137 | foreach ($newCountry as $countryID => $countryName) { |
| 138 | $this->addSelection("countryLimit-t", "label=$countryName"); |
| 139 | $this->click("xpath=//select[@id='countryLimit-t']/option[@value='$countryID']"); |
| 140 | $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']"); |
| 141 | |
| 142 | $this->addSelection("provinceLimit-t", "label=$countryName"); |
| 143 | $this->click("//option[@value='$countryID']"); |
| 144 | $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']"); |
| 145 | $removed = TRUE; |
| 146 | } |
| 147 | if ($removed) { |
| 148 | $this->click("_qf_Localization_next-bottom"); |
| 149 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 150 | $this->waitForText('crm-notification-container', "Saved"); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | } |