Merge pull request #3749 from civicrm/4.4
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / MembershipTest.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_Campaign_MembershipTest
31 */
32 class WebTest_Campaign_MembershipTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testCreateCampaign() {
39 $this->webtestLogin('admin');
40
41 // Create new group
42 $title = substr(sha1(rand()), 0, 7);
43 $groupName = $this->WebtestAddGroup();
44
45 // Adding contact
46 // We're using Quick Add block on the main page for this.
47 $firstName1 = substr(sha1(rand()), 0, 7);
48 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
49
50 // add contact to group
51 // visit group tab
52 $this->click("css=li#tab_group a");
53 $this->waitForElementPresent("group_id");
54
55 // add to group
56 $this->select("group_id", "label=$groupName");
57 $this->click("_qf_GroupContact_next");
58 $this->waitForElementPresent('link=Remove');
59
60 $firstName2 = substr(sha1(rand()), 0, 7);
61 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
62
63 // add contact to group
64 // visit group tab
65 $this->click("css=li#tab_group a");
66 $this->waitForElementPresent("group_id");
67
68 // add to group
69 $this->select("group_id", "label=$groupName");
70 $this->click("_qf_GroupContact_next");
71 $this->waitForElementPresent('link=Remove');
72
73 // Enable CiviCampaign module if necessary
74 $this->enableComponents(array('CiviCampaign'));
75
76 // add the required Drupal permission
77 $this->changePermissions('edit-2-administer-civicampaign');
78
79 // Log in as normal user
80 $this->webtestLogin();
81 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
82
83 $campaignTitle = "Campaign $title";
84 $this->type("title", $campaignTitle);
85
86 // select the campaign type
87 $this->select("campaign_type_id", "value=2");
88
89 // fill in the description
90 $this->type("description", "This is a test campaign");
91
92 // include groups for the campaign
93 $this->addSelection("includeGroups-f", "label=$groupName");
94 $this->click("//option[@value=4]");
95 $this->click("add");
96
97 // fill the end date for campaign
98 $this->webtestFillDate("end_date", "+1 year");
99
100 // select campaign status
101 $this->select("status_id", "value=2");
102
103 // click save
104 $this->click("_qf_Campaign_upload-bottom");
105 $this->waitForPageToLoad($this->getTimeoutMsec());
106
107 $this->waitForText('crm-notification-container', "Campaign $title");
108
109 $this->waitForElementPresent("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
110 $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
111 $this->memberAddTest($campaignTitle, $id);
112 }
113
114 /**
115 * @param $campaignTitle
116 * @param $id
117 */
118 function memberAddTest($campaignTitle, $id) {
119 //Add new memebershipType
120 $memTypeParams = $this->webtestAddMembershipType();
121
122 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
123 // We're using Quick Add block on the main page for this.
124 $firstName = substr(sha1(rand()), 0, 7);
125 $this->webtestAddContact($firstName, "John", $firstName . "john@gmail.com");
126 $this->assertTrue($this->isTextPresent("{$firstName} John has been created."));
127
128 // click through to the membership view screen
129 $this->click("css=li#tab_member a");
130
131 $this->waitForElementPresent("link=Add Membership");
132 $this->click("link=Add Membership");
133
134 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
135
136 // fill in Membership Organization and Type
137 $this->select("membership_type_id_0", "label={$memTypeParams['member_of_contact']}");
138
139 // Wait for membership type select to reload
140 $this->waitForTextPresent($memTypeParams['membership_type']);
141 $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}");
142
143 $sourceText = "Membership ContactAddTest Webtest";
144 // fill in Source
145 $this->type("source", $sourceText);
146
147 // select campaign
148 $this->click("campaign_id");
149 $this->select("campaign_id", "value=$id");
150
151 // Let Join Date stay default
152 // fill in Start Date
153 $this->webtestFillDate('start_date');
154
155 // Clicking save.
156 $this->click("_qf_Membership_upload");
157 $this->waitForElementPresent('link=View');
158
159 // page was loaded
160 $this->waitForTextPresent($sourceText);
161
162 // Is status message correct?
163 $this->assertTrue($this->isTextPresent("membership for $firstName John has been added."),
164 "Status message didn't show up after saving!"
165 );
166
167 // click through to the membership view screen
168 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
169 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
170
171 $this->webtestVerifyTabularData(array('Campaign' => $campaignTitle));
172 }
173 }
174