Commit | Line | Data |
---|---|---|
69932a56 N |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
69932a56 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
69932a56 N |
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 | class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | function testStateCountry() { | |
a55077dc | 35 | $this->webtestLogin(); |
69932a56 | 36 | $config = CRM_Core_Config::singleton(); |
a55077dc N |
37 | // Add new profile. |
38 | $this->openCiviPage('admin/uf/group', 'reset=1'); | |
39 | $this->click('newCiviCRMProfile-top'); | |
40 | $this->waitForElementPresent('_qf_Group_next-bottom'); | |
41 | ||
42 | //Name of profile | |
43 | $profileTitle = 'Country state province web test temp'; | |
44 | $this->type('title', $profileTitle); | |
45 | ||
46 | //click on save | |
47 | $this->click('_qf_Group_next'); | |
48 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
49 | ||
50 | ||
51 | //check for profile create | |
52 | $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been added. You can add fields to this profile now."); | |
53 | $gid = $this->urlArg('gid'); | |
54 | //Add Country field to profile | |
55 | $this->click('field_name[0]'); | |
56 | $this->select('field_name[0]', 'value=Contact'); | |
57 | $this->click("//option[@value='Contact']"); | |
58 | $this->click('field_name[1]'); | |
59 | $this->select('field_name[1]', 'value=country'); | |
60 | $this->click("//option[@value='country']"); | |
61 | $this->click('is_required'); | |
62 | ||
63 | $this->click('_qf_Field_next_new'); | |
64 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
65 | ||
66 | //Add State field to profile | |
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=state_province'); | |
72 | $this->click("xpath=//select[@id='field_name_1']/option[@value='state_province']"); | |
73 | $this->click('is_required'); | |
74 | //click on save | |
75 | $this->click('_qf_Field_next'); | |
76 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
77 | ||
78 | if($gid) { | |
79 | $this->openCiviPage('admin/setting/localization', 'reset=1', '_qf_Localization_next-bottom'); | |
69932a56 N |
80 | $country = array(1001 => 'Afghanistan', 1013 => 'Australia', 1039 => 'Canada', 1101 => 'India'); |
81 | $enabledCountries = $this->getSelectOptions("countryLimit-t"); | |
82 | $enabledStates = $this->getSelectOptions("provinceLimit-t"); | |
a55077dc | 83 | $newCountry = array(); |
69932a56 N |
84 | foreach($country as $countryID => $countryName) { |
85 | if(!in_array($countryName, $enabledCountries)) { | |
a55077dc | 86 | $newCountry[$countryID] = $countryName; |
69932a56 N |
87 | $this->addSelection("countryLimit-f", "label=$countryName"); |
88 | $this->click("xpath=//select[@id='countryLimit-f']/option[@value='$countryID']"); | |
89 | $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']"); | |
90 | } | |
91 | if(!in_array($countryName, $enabledStates)) { | |
92 | $this->addSelection("provinceLimit-f", "label=$countryName"); | |
93 | $this->click("//option[@value='$countryID']"); | |
94 | $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']"); | |
95 | } | |
96 | $added = true; | |
97 | } | |
98 | if ($added) { | |
99 | $this->click("_qf_Localization_next-bottom"); | |
100 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
101 | $this->waitForText('crm-notification-container', "Saved"); | |
a55077dc N |
102 | } |
103 | $this->openCiviPage("profile/create", "gid=$gid&reset=1", NULL); | |
69932a56 | 104 | |
69932a56 | 105 | $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select"); |
69932a56 N |
106 | $this->click("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select"); |
107 | $countryID = array_rand($country); | |
108 | $states = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID, 'id'); | |
109 | $stateID = array_rand($states); | |
110 | $this->select("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select", "value=$countryID"); | |
a55077dc | 111 | sleep(2); |
69932a56 N |
112 | $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select"); |
113 | $this->click("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select"); | |
114 | $this->select("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select", "value=$stateID"); | |
115 | $this->clickLink('_qf_Edit_next', NULL); | |
a55077dc N |
116 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
117 | $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']"); | |
118 | $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']"); | |
119 | ||
120 | $this->waitForElementPresent('_qf_Group_next-bottom'); | |
121 | $this->click('_qf_Group_next-bottom'); | |
122 | $this->waitForElementPresent('newCiviCRMProfile-bottom'); | |
123 | $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been deleted."); | |
124 | ||
125 | $this->openCiviPage("admin/setting/localization", "reset=1", "_qf_Localization_next-bottom"); | |
126 | $enabledCountries = $this->getSelectOptions("countryLimit-t"); | |
127 | $enabledStates = $this->getSelectOptions("provinceLimit-t"); | |
128 | $removed = false; | |
129 | foreach($newCountry as $countryID => $countryName) { | |
130 | $this->addSelection("countryLimit-t", "label=$countryName"); | |
131 | $this->click("xpath=//select[@id='countryLimit-t']/option[@value='$countryID']"); | |
132 | $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']"); | |
133 | ||
134 | $this->addSelection("provinceLimit-t", "label=$countryName"); | |
135 | $this->click("//option[@value='$countryID']"); | |
136 | $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']"); | |
137 | $removed = true; | |
138 | } | |
139 | if ($removed) { | |
140 | $this->click("_qf_Localization_next-bottom"); | |
141 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
142 | $this->waitForText('crm-notification-container', "Saved"); | |
143 | } | |
69932a56 N |
144 | } |
145 | } | |
146 | } |