Commit | Line | Data |
---|---|---|
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Campaign_MembershipTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Campaign_MembershipTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testCreateCampaign() { | |
42daf119 | 39 | $this->webtestLogin('admin'); |
6a488035 TO |
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"); | |
2af8120a | 58 | $this->waitForElementPresent('link=Remove'); |
6a488035 TO |
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"); | |
2af8120a | 71 | $this->waitForElementPresent('link=Remove'); |
6a488035 TO |
72 | |
73 | // Enable CiviCampaign module if necessary | |
8f737a72 | 74 | $this->enableComponents(array('CiviCampaign')); |
6a488035 TO |
75 | |
76 | // add the required Drupal permission | |
42daf119 | 77 | $this->changePermissions('edit-2-administer-civicampaign'); |
6a488035 | 78 | |
42daf119 CW |
79 | // Log in as normal user |
80 | $this->webtestLogin(); | |
8f737a72 | 81 | $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom'); |
6a488035 | 82 | |
6a488035 TO |
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 | |
ba6f320f | 93 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
6a488035 TO |
94 | |
95 | // fill the end date for campaign | |
96 | $this->webtestFillDate("end_date", "+1 year"); | |
97 | ||
98 | // select campaign status | |
99 | $this->select("status_id", "value=2"); | |
100 | ||
101 | // click save | |
102 | $this->click("_qf_Campaign_upload-bottom"); | |
103 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
104 | ||
6c5f7368 | 105 | $this->waitForText('crm-notification-container', "Campaign $title"); |
6a488035 | 106 | |
ba6f320f JP |
107 | $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]"); |
108 | $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]"); | |
6a488035 TO |
109 | $this->memberAddTest($campaignTitle, $id); |
110 | } | |
111 | ||
4cbe18b8 EM |
112 | /** |
113 | * @param $campaignTitle | |
114 | * @param $id | |
115 | */ | |
6a488035 TO |
116 | function memberAddTest($campaignTitle, $id) { |
117 | //Add new memebershipType | |
118 | $memTypeParams = $this->webtestAddMembershipType(); | |
76e86fd8 | 119 | |
6a488035 TO |
120 | // Adding Adding contact with randomized first name for test testContactContextActivityAdd |
121 | // We're using Quick Add block on the main page for this. | |
122 | $firstName = substr(sha1(rand()), 0, 7); | |
123 | $this->webtestAddContact($firstName, "John", $firstName . "john@gmail.com"); | |
124 | $this->assertTrue($this->isTextPresent("{$firstName} John has been created.")); | |
125 | ||
126 | // click through to the membership view screen | |
127 | $this->click("css=li#tab_member a"); | |
128 | ||
129 | $this->waitForElementPresent("link=Add Membership"); | |
130 | $this->click("link=Add Membership"); | |
131 | ||
132 | $this->waitForElementPresent("_qf_Membership_cancel-bottom"); | |
133 | ||
134 | // fill in Membership Organization and Type | |
135 | $this->select("membership_type_id_0", "label={$memTypeParams['member_of_contact']}"); | |
136 | ||
137 | // Wait for membership type select to reload | |
138 | $this->waitForTextPresent($memTypeParams['membership_type']); | |
139 | $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}"); | |
140 | ||
141 | $sourceText = "Membership ContactAddTest Webtest"; | |
142 | // fill in Source | |
143 | $this->type("source", $sourceText); | |
144 | ||
145 | // select campaign | |
146 | $this->click("campaign_id"); | |
147 | $this->select("campaign_id", "value=$id"); | |
148 | ||
6a488035 TO |
149 | // Let Join Date stay default |
150 | // fill in Start Date | |
151 | $this->webtestFillDate('start_date'); | |
152 | ||
153 | // Clicking save. | |
154 | $this->click("_qf_Membership_upload"); | |
2af8120a | 155 | $this->waitForElementPresent('link=View'); |
6a488035 TO |
156 | |
157 | // page was loaded | |
158 | $this->waitForTextPresent($sourceText); | |
159 | ||
160 | // Is status message correct? | |
161 | $this->assertTrue($this->isTextPresent("membership for $firstName John has been added."), | |
162 | "Status message didn't show up after saving!" | |
163 | ); | |
164 | ||
165 | // click through to the membership view screen | |
166 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); | |
167 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
168 | ||
169 | $this->webtestVerifyTabularData(array('Campaign' => $campaignTitle)); | |
170 | } | |
171 | } | |
172 |