Merge pull request #2744 from pratik-joshi/CRM-13992_temp_fix
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileGroupSubscriptionTest.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 class WebTest_Profile_ProfileGroupSubscriptionTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testProfileGroupSubscription() {
35 $this->webtestLogin();
36
37 // Add new profile.
38 $this->openCiviPage('admin/uf/group', 'reset=1');
39
40 $this->click('newCiviCRMProfile-top');
41
42 $this->waitForElementPresent('_qf_Group_next-bottom');
43
44 //Name of profile
45 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
46 $this->type('title', $profileTitle);
47 $this->click('uf_group_type_Profile');
48
49 //Drupal user account registration option
50 $this->click('CIVICRM_QFID_0_8');
51
52 //What to do upon duplicate match
53 $this->click('CIVICRM_QFID_0_2');
54
55 //Proximity search options
56 $this->click('CIVICRM_QFID_0_14');
57
58 // enable mapping for contact
59 $this->click('is_map');
60
61 // include a link in the listings to Edit profile fields
62 $this->click('is_edit_link');
63
64 //to view contacts' Drupal user account information
65 $this->click('is_uf_link');
66
67 //click on save
68 $this->click('_qf_Group_next');
69 $this->waitForPageToLoad($this->getTimeoutMsec());
70
71 //check for profile create
72 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
73
74 //Add email field to profile
75 $this->click('field_name[0]');
76 $this->select('field_name[0]', 'value=Contact');
77 $this->click("//option[@value='Contact']");
78
79 $this->select('field_name[1]', 'value=email');
80 $this->click("//option[@value='email']");
81
82 //click on save
83 $this->click('_qf_Field_next_new-top');
84 $this->waitForPageToLoad($this->getTimeoutMsec());
85
86 //Add email field to profile
87 $this->click('field_name[0]');
88 $this->select('field_name[0]', 'value=Contact');
89 $this->click("//option[@value='Contact']");
90
91 $this->select('field_name[1]', 'value=group');
92 $this->click("//option[@value='group']");
93
94 //click on save
95 $this->click('_qf_Field_next');
96
97 $this->waitForPageToLoad($this->getTimeoutMsec());
98
99 //now use profile create mode for group subscription
100 $this->click("xpath=//div[@id='field_page']/div/a[4]/span");
101
102 $this->waitForElementPresent('email-Primary');
103
104 //check for group field
105 $this->assertElementContainsText('crm-profile-block', 'Group(s)', "Groups field was not found.");
106
107 //fill the subscription form
108 $randomEmail = substr(sha1(rand()), 0, 7) . "@example.com";
109
110 $this->type("email-Primary", $randomEmail);
111
112 // check advisory group ( may be we should create a separate group to test this)
113 $this->click("group_3");
114
115 $this->click('_qf_Edit_next');
116
117
118 // assert for subscription message
119
120 $this->isTextPresent("Your subscription request has been submitted for");
121 //check if profile is saved
122 $this->waitForText('crm-notification-container','Your information has been saved.');
123
124 // delete the profile
125 $this->openCiviPage('admin/uf/group', 'reset=1');
126 $this->_testdeleteProfile($profileTitle);
127 }
128
129 function _testdeleteProfile($profileTitle) {
130 $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']");
131 $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']");
132 $this->waitForElementPresent('_qf_Group_next-bottom');
133 $this->click('_qf_Group_next-bottom');
134 $this->waitForElementPresent('newCiviCRMProfile-bottom');
135 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
136 }
137 }
138