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