remove duplicate assignments
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / PledgeTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Campaign_PledgeTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testCreateCampaign() {
6a488035 35 // Log in as admin first to verify permissions for CiviGrant
42daf119 36 $this->webtestLogin('admin');
6a488035
TO
37
38 // Enable CiviCampaign module and CiviPledge module if necessary
b9715b8a 39 $this->enableComponents(array("CiviCampaign", "CiviPledge"));
6a488035
TO
40
41 // add the required Drupal permission
42 $permissions = array(
43 'edit-2-access-civipledge',
44 'edit-2-edit-pledges',
45 );
46 $this->changePermissions($permissions);
47
6a488035 48 // Log in as demo user
6a488035
TO
49 $this->webtestLogin();
50
51 // Create new group
52 $title = substr(sha1(rand()), 0, 7);
53 $groupName = $this->WebtestAddGroup();
54
55 // Adding contact
56 // We're using Quick Add block on the main page for this.
57 $firstName1 = substr(sha1(rand()), 0, 7);
58 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
59
60 // add contact to group
61 // visit group tab
62 $this->click("css=li#tab_group a");
63 $this->waitForElementPresent("group_id");
64
65 // add to group
66 $this->select("group_id", "label=$groupName");
67 $this->click("_qf_GroupContact_next");
701f18c0 68 $this->waitForElementPresent('link=Remove');
6a488035
TO
69
70 $firstName2 = substr(sha1(rand()), 0, 7);
71 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
72
73 // add contact to group
74 // visit group tab
75 $this->click("css=li#tab_group a");
76 $this->waitForElementPresent("group_id");
77
78 // add to group
79 $this->select("group_id", "label=$groupName");
80 $this->click("_qf_GroupContact_next");
701f18c0 81 $this->waitForElementPresent('link=Remove');
6a488035 82
42daf119 83 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
6a488035 84
6a488035
TO
85 $campaignTitle = "Campaign $title";
86 $this->type("title", $campaignTitle);
87
88 // select the campaign type
89 $this->select("campaign_type_id", "value=2");
90
91 // fill in the description
92 $this->type("description", "This is a test campaign");
93
94 // include groups for the campaign
95 $this->addSelection("includeGroups-f", "label=$groupName");
96 $this->click("//option[@value=4]");
97 $this->click("add");
98
99 // fill the end date for campaign
100 $this->webtestFillDate("end_date", "+1 year");
101
102 // select campaign status
103 $this->select("status_id", "value=2");
104
105 // click save
106 $this->click("_qf_Campaign_upload-bottom");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
108
109 $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."),
110 "Status message didn't show up after saving campaign!"
111 );
112
1d4d99e9 113 $this->waitForElementPresent("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
114 $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
6a488035
TO
115 $this->pledgeAddTest($campaignTitle, $id);
116 }
117
118 function pledgeAddTest($campaignTitle, $id) {
119 // create unique name
42daf119 120 $name = substr(sha1(rand()), 0, 7);
6a488035 121 $firstName = 'Adam' . $name;
42daf119 122 $lastName = 'Jones' . $name;
6a488035
TO
123
124 // create new contact
125 $this->webtestAddContact($firstName, $lastName, $firstName . "@example.com");
126
127 // wait for action element
128 $this->waitForElementPresent('crm-contact-actions-link');
129
130 // now add pledge from contact summary
131 $this->click("//a[@id='crm-contact-actions-link']/span/div");
132
133 // wait for add plegde link
134 $this->waitForElementPresent('link=Add Pledge');
135
136 $this->click('link=Add Pledge');
137
138 // wait for pledge form to load completely
139 $this->waitForElementPresent('_qf_Pledge_upload-bottom');
140
141 // check contact name on pledge form
142 $this->assertTrue($this->isTextPresent("$firstName $lastName"));
143
6a488035
TO
144 $this->type("amount", "100");
145 $this->type("installments", "10");
146 $this->select("frequency_unit", "value=week");
147 $this->type("frequency_day", "2");
148
149 $this->webtestFillDate('acknowledge_date', 'now');
150
151 // select campaign
152 $this->click("campaign_id");
153 $this->select("campaign_id", "value=$id");
154
155 $this->select("contribution_page_id", "value=3");
156
6a488035
TO
157 //PaymentReminders
158 $this->click("PaymentReminders");
159 $this->waitForElementPresent("additional_reminder_day");
160 $this->type("initial_reminder_day", "4");
161 $this->type("max_reminders", "2");
162 $this->type("additional_reminder_day", "4");
163
164 $this->click("_qf_Pledge_upload-bottom");
701f18c0 165 $this->waitForElementPresent('link=Add Pledge');
6a488035 166
701f18c0 167 $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created.");
6a488035 168
701f18c0 169 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span[1]/a[text()='View']");
6a488035 170 //click through to the Pledge view screen
701f18c0 171 $this->click("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span[1]/a[text()='View']");
6a488035
TO
172 $this->waitForElementPresent("_qf_PledgeView_next-bottom");
173 $pledgeDate = date('F jS, Y', strtotime('now'));
174
175 // verify Activity created
176 $this->verifyText("xpath=//form[@id='PledgeView']//table/tbody/tr[8]/td[2]", preg_quote($campaignTitle));
177 }
178}
179