include BOM in attachment when sending csv civireport via mail_report job
[civicrm-core.git] / tests / phpunit / CRM / Report / Utils / ReportTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 * Test CRM_Report_Utils_Report functions.
15 *
16 * @group headless
17 */
18 class CRM_Report_Utils_ReportTest extends CiviUnitTestCase {
19
20 /**
21 * Test makeCsv
22 */
23 public function testMakeCsv() {
24 $form = new CRM_Report_Form();
25 $form->_columnHeaders = [
26 'civicrm_activity_activity_type_id' => [
27 'title' => 'Activity Type',
28 'type' => 2,
29 ],
30 'civicrm_activity_activity_subject' => [
31 'title' => 'Subject',
32 'type' => 2,
33 ],
34 'civicrm_activity_details' => [
35 'title' => 'Activity Details',
36 'type' => NULL,
37 ],
38 ];
39
40 $details = <<<ENDDETAILS
41 <p>Here&#39;s some typical data from an activity details field.
42 </p>
43 <p>дè some non-ascii and <strong>html</strong> styling and these ̋“weird” quotes’s.
44 </p>
45 <p>Also some named entities &quot;hello&quot;. And &amp; &eacute;. Also some math like 2 &lt; 4.
46 </p>
47 ENDDETAILS;
48
49 $expectedOutput = <<<ENDOUTPUT
50 \xEF\xBB\xBF"Activity Type","Subject","Activity Details"\r
51 "Meeting","Meeting with the apostrophe's and that person who does ""air quotes"". Some non-ascii characters: дè","Here's some typical data from an activity details field.
52
53 дè some non-ascii and html styling and these ̋“weird” quotes’s.
54
55 Also some named entities ""hello"". And & é. Also some math like 2 < 4.
56 "\r
57
58 ENDOUTPUT;
59
60 $rows = [
61 [
62 'civicrm_activity_activity_type_id' => 'Meeting',
63 'civicrm_activity_activity_subject' => 'Meeting with the apostrophe\'s and that person who does "air quotes". Some non-ascii characters: дè',
64 'civicrm_activity_details' => $details,
65 ],
66 ];
67
68 $csvString = CRM_Report_Utils_Report::makeCsv($form, $rows);
69 $this->assertEquals($expectedOutput, $csvString);
70 }
71
72 }