add autogenerated comment blocks to tests dir
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileCountryState.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 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 //click on save
51 $this->click('_qf_Group_next');
52 $this->waitForPageToLoad($this->getTimeoutMsec());
53
54
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');
66
67 $this->click('_qf_Field_next_new');
68 $this->waitForPageToLoad($this->getTimeoutMsec());
69
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');
78 //click on save
79 $this->click('_qf_Field_next');
80 $this->waitForPageToLoad($this->getTimeoutMsec());
81
82 if($gid) {
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']");
94 }
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']");
99 }
100 $added = true;
101 }
102 if ($added) {
103 $this->click("_qf_Localization_next-bottom");
104 $this->waitForPageToLoad($this->getTimeoutMsec());
105 $this->waitForText('crm-notification-container', "Saved");
106 }
107 $this->openCiviPage("profile/create", "gid=$gid&reset=1", NULL);
108
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");
115 sleep(2);
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']");
123
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.");
128
129 $this->openCiviPage("admin/setting/localization", "reset=1", "_qf_Localization_next-bottom");
130 $enabledCountries = $this->getSelectOptions("countryLimit-t");
131 $enabledStates = $this->getSelectOptions("provinceLimit-t");
132 $removed = false;
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']");
137
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']");
141 $removed = true;
142 }
143 if ($removed) {
144 $this->click("_qf_Localization_next-bottom");
145 $this->waitForPageToLoad($this->getTimeoutMsec());
146 $this->waitForText('crm-notification-container', "Saved");
147 }
148 }
149 }
150 }