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