3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Profile_ProfileCountryState
32 class WebTest_Profile_ProfileCountryState
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testStateCountry() {
39 $this->webtestLogin();
40 $config = CRM_Core_Config
::singleton();
42 $this->openCiviPage('admin/uf/group', 'reset=1');
43 $this->click('newCiviCRMProfile-top');
44 $this->waitForElementPresent('_qf_Group_next-bottom');
47 $profileTitle = 'Country state province web test temp';
48 $this->type('title', $profileTitle);
51 $this->click('_qf_Group_next');
52 $this->waitForPageToLoad($this->getTimeoutMsec());
55 //check for profile create
56 $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
57 $gid = $this->urlArg('gid');
58 //Add Country field to profile
59 $this->click('field_name[0]');
60 $this->select('field_name[0]', 'value=Contact');
61 $this->click("//option[@value='Contact']");
62 $this->click('field_name[1]');
63 $this->select('field_name[1]', 'value=country');
64 $this->click("//option[@value='country']");
65 $this->click('is_required');
67 $this->click('_qf_Field_next_new');
68 $this->waitForPageToLoad($this->getTimeoutMsec());
70 //Add State field to profile
71 $this->click('field_name[0]');
72 $this->select('field_name[0]', 'value=Contact');
73 $this->click("//option[@value='Contact']");
74 $this->click('field_name[1]');
75 $this->select('field_name[1]', 'value=state_province');
76 $this->click("xpath=//select[@id='field_name_1']/option[@value='state_province']");
77 $this->click('is_required');
79 $this->click('_qf_Field_next');
80 $this->waitForPageToLoad($this->getTimeoutMsec());
83 $this->openCiviPage('admin/setting/localization', 'reset=1', '_qf_Localization_next-bottom');
84 $country = array(1001 => 'Afghanistan', 1013 => 'Australia', 1039 => 'Canada', 1101 => 'India');
85 $enabledCountries = $this->getSelectOptions("countryLimit-t");
86 $enabledStates = $this->getSelectOptions("provinceLimit-t");
87 $newCountry = array();
88 foreach($country as $countryID => $countryName) {
89 if(!in_array($countryName, $enabledCountries)) {
90 $newCountry[$countryID] = $countryName;
91 $this->addSelection("countryLimit-f", "label=$countryName");
92 $this->click("xpath=//select[@id='countryLimit-f']/option[@value='$countryID']");
93 $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']");
95 if(!in_array($countryName, $enabledStates)) {
96 $this->addSelection("provinceLimit-f", "label=$countryName");
97 $this->click("//option[@value='$countryID']");
98 $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']");
103 $this->click("_qf_Localization_next-bottom");
104 $this->waitForPageToLoad($this->getTimeoutMsec());
105 $this->waitForText('crm-notification-container', "Saved");
107 $this->openCiviPage("profile/create", "gid=$gid&reset=1", NULL);
109 $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select");
110 $this->click("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select");
111 $countryID = array_rand($country);
112 $states = CRM_Core_PseudoConstant
::stateProvinceForCountry($countryID, 'id');
113 $stateID = array_rand($states);
114 $this->select("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select", "value=$countryID");
116 $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select");
117 $this->click("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select");
118 $this->select("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select", "value=$stateID");
119 $this->clickLink('_qf_Edit_next', NULL);
120 $this->openCiviPage('admin/uf/group', 'reset=1');
121 $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']");
122 $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']");
124 $this->waitForElementPresent('_qf_Group_next-bottom');
125 $this->click('_qf_Group_next-bottom');
126 $this->waitForElementPresent('newCiviCRMProfile-bottom');
127 $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been deleted.");
129 $this->openCiviPage("admin/setting/localization", "reset=1", "_qf_Localization_next-bottom");
130 $enabledCountries = $this->getSelectOptions("countryLimit-t");
131 $enabledStates = $this->getSelectOptions("provinceLimit-t");
133 foreach($newCountry as $countryID => $countryName) {
134 $this->addSelection("countryLimit-t", "label=$countryName");
135 $this->click("xpath=//select[@id='countryLimit-t']/option[@value='$countryID']");
136 $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
138 $this->addSelection("provinceLimit-t", "label=$countryName");
139 $this->click("//option[@value='$countryID']");
140 $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
144 $this->click("_qf_Localization_next-bottom");
145 $this->waitForPageToLoad($this->getTimeoutMsec());
146 $this->waitForText('crm-notification-container', "Saved");