3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Campaign_PledgeTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testCreateCampaign() {
35 // Log in as admin first to verify permissions for CiviGrant
36 $this->webtestLogin('admin');
38 // Enable CiviCampaign module and CiviPledge module if necessary
39 $this->enableComponents(array("CiviCampaign", "CiviPledge"));
41 // add the required Drupal permission
43 'edit-2-access-civipledge',
44 'edit-2-edit-pledges',
46 $this->changePermissions($permissions);
48 // Log in as demo user
49 $this->webtestLogin();
52 $title = substr(sha1(rand()), 0, 7);
53 $groupName = $this->WebtestAddGroup();
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");
60 // add contact to group
62 $this->click("css=li#tab_group a");
63 $this->waitForElementPresent("group_id");
66 $this->select("group_id", "label=$groupName");
67 $this->click("_qf_GroupContact_next");
68 $this->waitForElementPresent('link=Remove');
70 $firstName2 = substr(sha1(rand()), 0, 7);
71 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
73 // add contact to group
75 $this->click("css=li#tab_group a");
76 $this->waitForElementPresent("group_id");
79 $this->select("group_id", "label=$groupName");
80 $this->click("_qf_GroupContact_next");
81 $this->waitForElementPresent('link=Remove');
83 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
85 $campaignTitle = "Campaign $title";
86 $this->type("title", $campaignTitle);
88 // select the campaign type
89 $this->select("campaign_type_id", "value=2");
91 // fill in the description
92 $this->type("description", "This is a test campaign");
94 // include groups for the campaign
95 $this->addSelection("includeGroups-f", "label=$groupName");
96 $this->click("//option[@value=4]");
99 // fill the end date for campaign
100 $this->webtestFillDate("end_date", "+1 year");
102 // select campaign status
103 $this->select("status_id", "value=2");
106 $this->click("_qf_Campaign_upload-bottom");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
109 $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."),
110 "Status message didn't show up after saving campaign!"
113 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
114 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
115 $this->pledgeAddTest($campaignTitle, $id);
118 function pledgeAddTest($campaignTitle, $id) {
119 // create unique name
120 $name = substr(sha1(rand()), 0, 7);
121 $firstName = 'Adam' . $name;
122 $lastName = 'Jones' . $name;
124 // create new contact
125 $this->webtestAddContact($firstName, $lastName, $firstName . "@example.com");
127 // wait for action element
128 $this->waitForElementPresent('crm-contact-actions-link');
130 // now add pledge from contact summary
131 $this->click("//a[@id='crm-contact-actions-link']/span/div");
133 // wait for add plegde link
134 $this->waitForElementPresent('link=Add Pledge');
136 $this->click('link=Add Pledge');
138 // wait for pledge form to load completely
139 $this->waitForElementPresent('_qf_Pledge_upload-bottom');
141 // check contact name on pledge form
142 $this->assertTrue($this->isTextPresent("$firstName $lastName"));
144 $this->type("amount", "100");
145 $this->type("installments", "10");
146 $this->select("frequency_unit", "value=week");
147 $this->type("frequency_day", "2");
149 $this->webtestFillDate('acknowledge_date', 'now');
152 $this->click("campaign_id");
153 $this->select("campaign_id", "value=$id");
155 $this->select("contribution_page_id", "value=3");
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");
164 $this->click("_qf_Pledge_upload-bottom");
165 $this->waitForElementPresent('link=Add Pledge');
167 $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created.");
169 $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span[1]/a[text()='View']");
170 //click through to the Pledge view screen
171 $this->click("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span[1]/a[text()='View']");
172 $this->waitForElementPresent("_qf_PledgeView_next-bottom");
173 $pledgeDate = date('F jS, Y', strtotime('now'));
175 // verify Activity created
176 $this->verifyText("xpath=//form[@id='PledgeView']//table/tbody/tr[8]/td[2]", preg_quote($campaignTitle));