Update Copywrite year to be 2019
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileCountryState.php
CommitLineData
69932a56
N
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
69932a56 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
69932a56
N
26
27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Profile_ProfileCountryState
31 */
69932a56
N
32class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testStateCountry() {
e9479dcf 39 $this->webtestLogin();
69932a56 40 $config = CRM_Core_Config::singleton();
a55077dc
N
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
39a2888d
CW
50 // Standalone form or directory
51 $this->click('uf_group_type_Profile');
52
a55077dc
N
53 //click on save
54 $this->click('_qf_Group_next');
55 $this->waitForPageToLoad($this->getTimeoutMsec());
e9479dcf 56
a55077dc
N
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');
39a2888d 60
a55077dc 61 //Add Country field to profile
92915c55
TO
62 $this->openCiviPage('admin/uf/group/field/add', array(
63 'action' => 'add',
64 'reset' => 1,
8d7a9d07 65 'gid' => $gid,
92915c55 66 ), 'field_name[0]');
a55077dc
N
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
22e263ad 90 if ($gid) {
a55077dc 91 $this->openCiviPage('admin/setting/localization', 'reset=1', '_qf_Localization_next-bottom');
69932a56
N
92 $country = array(1001 => 'Afghanistan', 1013 => 'Australia', 1039 => 'Canada', 1101 => 'India');
93 $enabledCountries = $this->getSelectOptions("countryLimit-t");
94 $enabledStates = $this->getSelectOptions("provinceLimit-t");
a55077dc 95 $newCountry = array();
22e263ad
TO
96 foreach ($country as $countryID => $countryName) {
97 if (!in_array($countryName, $enabledCountries)) {
a55077dc 98 $newCountry[$countryID] = $countryName;
69932a56
N
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 }
22e263ad 103 if (!in_array($countryName, $enabledStates)) {
69932a56
N
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 }
6c6e6187 108 $added = TRUE;
69932a56
N
109 }
110 if ($added) {
111 $this->click("_qf_Localization_next-bottom");
112 $this->waitForPageToLoad($this->getTimeoutMsec());
113 $this->waitForText('crm-notification-container', "Saved");
e9479dcf 114 }
a55077dc 115 $this->openCiviPage("profile/create", "gid=$gid&reset=1", NULL);
69932a56 116
69932a56 117 $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select");
69932a56
N
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");
39a2888d 123 $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select/option[@value=$stateID]");
69932a56
N
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);
a55077dc 127
39a2888d
CW
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');
a55077dc
N
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");
6c6e6187 136 $removed = FALSE;
22e263ad 137 foreach ($newCountry as $countryID => $countryName) {
6c6e6187
TO
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;
a55077dc
N
146 }
147 if ($removed) {
148 $this->click("_qf_Localization_next-bottom");
149 $this->waitForPageToLoad($this->getTimeoutMsec());
150 $this->waitForText('crm-notification-container', "Saved");
151 }
69932a56
N
152 }
153 }
96025800 154
e9479dcf 155}