6f22496e88991fd286610e0651240665ec756d0b
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileGroupSubscriptionTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Profile_ProfileGroupSubscriptionTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testProfileGroupSubscription() {
36 $this->webtestLogin();
37
38 // Add new profile.
39 $this->openCiviPage('admin/uf/group', 'reset=1');
40
41 $this->click('newCiviCRMProfile-top');
42
43 $this->waitForElementPresent('_qf_Group_next-bottom');
44
45 //Name of profile
46 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
47 $this->type('title', $profileTitle);
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 maping 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->assertElementContainsText('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 $radomEmail = substr(sha1(rand()), 0, 7) . "@example.com";
109
110 $this->type("email-Primary", $radomEmail);
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 $this->waitForPageToLoad($this->getTimeoutMsec());
118
119 // assert for subscription message
120 $this->assertElementContainsText('messages', "Your subscription request has been submitted for group ", "Subscription message is not shown");
121
122 //check if profile is saved
123 $this->assertElementContainsText('css=span.msg-text', 'Your information has been saved.', 'Profile is not saved');
124
125 // delete the profile
126 $this->openCiviPage('admin/uf/group', 'reset=1');
127 $this->_testdeleteProfile($profileTitle);
128 }
129
130 function _testdeleteProfile($profileTitle) {
131 //$this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text() = '$profileTitle']/../following-sibling::td[4]/span[2][text()='more']");
132 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text() = '$profileTitle']/../following-sibling::td[4]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
133 $this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text() = '$profileTitle']/../following-sibling::td[4]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
134 $this->waitForElementPresent('_qf_Group_next-bottom');
135 $this->click('_qf_Group_next-bottom');
136 $this->waitForElementPresent('newCiviCRMProfile-bottom');
137 $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
138 }
139 }
140
141