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