Merge pull request #4796 from jitendrapurohit/webtest4.6
[civicrm-core.git] / tests / phpunit / WebTest / Report / AddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
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 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Report_AddTest
31 */
6a488035
TO
32class WebTest_Report_AddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testAddReport() {
6a488035
TO
39 $this->webtestLogin();
40
41 // create contact
42daf119 42 $firstName = 'reportuser_' . substr(sha1(rand()), 0, 7);
6a488035 43 $displayName = "Anderson, $firstName";
42daf119 44 $emailId = "$firstName.anderson@example.org";
6a488035
TO
45 $this->webtestAddContact($firstName, "Anderson", $emailId);
46
305515fb 47 $this->openCiviPage('report/contact/summary', 'reset=1', '_qf_Summary_submit' );
6a488035
TO
48
49 // enable email field
50 $this->click("fields[email]");
51
52 // enable phone field
53 $this->click("fields[phone]");
54
55 // apply Contact Name filter
56 $this->select("sort_name_op", "value=has");
57 $this->type("sort_name_value", $firstName);
58
59 // preview result
60 $this->click("_qf_Summary_submit");
61 $this->waitForPageToLoad($this->getTimeoutMsec());
62
63 // Is filter statistics present?
305515fb 64 $this->assertElementContainsText("xpath=//tr/th[@class='statistics'][text()='Contact Name']/../td", "Contains $firstName", "Statistics did not found!");
76e86fd8 65
6a488035 66 // Is Contact Name present in result?
305515fb 67 $this->assertElementContainsText('css=td.crm-report-civicrm_contact_sort_name', $displayName, "Contact Name did not found!");
6a488035
TO
68
69 // Is email Id present on result?
305515fb 70 $this->assertElementContainsText('css=td.crm-report-civicrm_email_email', $emailId, "Email did not found!");
76e86fd8 71
6a488035
TO
72 // check criteria
73 $this->click("css=div.crm-report_criteria-accordion div.crm-accordion-header");
74 $this->waitForElementPresent("sort_name_value");
75
76 // Is Contact Name filter?
77 $this->assertContains($firstName, $this->getValue("sort_name_value"), "Filter Contact Name expected $firstName");
78
79 // Is Email Field?
80 $this->assertEquals("on", $this->getValue("fields[email]"));
81
82 // Is Phone Field?
83 $this->assertEquals("on", $this->getValue("fields[phone]"));
84
85 // Create report
86 $this->click("css=div.crm-report_setting-accordion div.crm-accordion-header");
87 $this->waitForElementPresent("title");
88
42daf119 89 $reportName = 'ContactSummary_' . substr(sha1(rand()), 0, 7);
6a488035 90 $reportDescription = "New Contact Summary Report";
42daf119
CW
91 $emaiSubject = "Contact Summary Report";
92 $emailCC = "tesmail@example.org";
6a488035
TO
93
94 // Fill Report Title
95 $this->type("title", $reportName);
96
97 // Fill Report Description
98 $this->type("description", $reportDescription);
99
100 // Fill Email Subject
101 $this->type("email_subject", $emaiSubject);
102
103 // Fill Email To
104 $this->type("email_to", $emailId);
105
106 // Fill Email CC
107 $this->type("email_cc", $emailCC);
108
109 // We want navigation menu
110 $this->click("is_navigation");
111 $this->waitForElementPresent("parent_id");
112
113 // Navigation menu under Reports section
114 $this->select("parent_id", "label=Reports");
115
116 // Set permission as access CiviCRM
117 $this->select("permission", "value=access CiviCRM");
118
119 // click to create report
120 $this->click("_qf_Summary_submit_save");
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122
123 // Open report list
305515fb 124 $this->openCiviPage('report/list', 'reset=1');
76e86fd8 125
6a488035 126 // Is report is resent in list?
305515fb 127 $this->assertElementContainsText('css=table.report-layout', $reportName);
6a488035
TO
128
129 // Visit report
8cc4f1ab 130 $this->click("xpath=//div[@id='Contact']//table/tbody//tr/td/a/strong[text() = '$reportName']");
6a488035
TO
131 $this->waitForPageToLoad($this->getTimeoutMsec());
132
305515fb
PJ
133 // Is filter statistics present?
134 $this->assertElementContainsText("xpath=//tr/th[@class='statistics'][text()='Contact Name']/../td", "Contains $firstName", "Statistics did not found!");
76e86fd8 135
6a488035 136 // Is Contact Name present in result?
305515fb 137 $this->assertElementContainsText('css=td.crm-report-civicrm_contact_sort_name', $displayName, "Contact Name did not found!");
6a488035
TO
138
139 // Is email Id present on result?
305515fb 140 $this->assertElementContainsText('css=td.crm-report-civicrm_email_email', $emailId, "Email did not found!");
6a488035
TO
141
142 // check report criteria
143 $this->click("css=div.crm-report_criteria-accordion div.crm-accordion-header");
144 $this->waitForElementPresent("sort_name_value");
145
146 // Is Contact Name filter?
147 $this->assertContains($firstName, $this->getValue("sort_name_value"), "Filter Contact Name expected $firstName");
148
149 // Is Email Field?
150 $this->assertEquals("on", $this->getValue("fields[email]"));
151
152 // Is Phone Field?
153 $this->assertEquals("on", $this->getValue("fields[phone]"));
154
155 // Check Report settings
156 $this->click("css=div.crm-report_setting-accordion div.crm-accordion-header");
157 $this->waitForElementPresent("title");
158
159 // Is correct Report Title?
160 $this->assertContains($reportName, $this->getValue("title"), "Report Title expected $reportName");
161
162 // Is correct Report Description?
163 $this->assertContains($reportDescription, $this->getValue("description"), "Report Description expected $reportDescription");
164
165 // Is correct email Subject?
166 $this->assertContains($emaiSubject, $this->getValue("email_subject"), "Email Subject expected $emaiSubject");
167
168 // Is correct email to?
169 $this->assertContains($emailId, $this->getValue("email_to"), "Email To expected $emailId");
170
171 // Is correct email cc?
172 $this->assertContains($emailCC, $this->getValue("email_cc"), "Email CC expected $emailCC");
173
174 // Is Navigation?
175 $this->assertEquals("on", $this->getValue("is_navigation"));
176
177 // Is correct Navigation Parent?
178 $this->assertSelectedLabel("parent_id", "Reports");
179
180 // Is correct access permission?
181 $this->assertSelectedLabel("permission", "access CiviCRM");
182 }
183}
184