1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta\AccessTable;
6use dokuwiki\plugin\struct\meta\ConfigParser;
7
8/**
9 * Testing the CSV exports of aggregations
10 *
11 * @group plugin_struct
12 * @group plugins
13 */
14class AggregationExportCSV extends StructTest
15{
16
17    public function setUp(): void
18    {
19        parent::setUp();
20
21        $this->loadSchemaJSON('wikilookup', '');
22
23        /** @var \helper_plugin_struct $helper */
24        $helper = plugin_load('helper', 'struct');
25
26        $saveDate = [
27            'FirstFieldText' => 'abc def',
28            'SecondFieldLongText' => "abc\ndef\n",
29            'ThirdFieldWiki' => "  * hi\n  * ho",
30        ];
31        $access = AccessTable::getGlobalAccess('wikilookup');
32        $helper->saveLookupData($access, $saveDate);
33    }
34
35    public function test_wikiColumn()
36    {
37        global $INPUT;
38
39        $syntaxPrefix = ['---- struct table ----'];
40        $syntaxConfig = ['schema: wikilookup', 'cols: *'];
41        $syntaxPostFix = ['----'];
42        $syntax = implode("\n", array_merge($syntaxPrefix, $syntaxConfig, $syntaxPostFix));
43        $expectedCSV = '"FirstFieldText","SecondFieldLongText","ThirdFieldWiki"
44"abc def","abc
45def","  * hi
46  * ho"';
47
48        $configParser = new ConfigParser($syntaxConfig);
49        $INPUT->set('hash', md5(var_export($configParser->getConfig(), true)));
50
51        $ins = p_get_instructions($syntax);
52        $renderedCSV = p_render('struct_csv', $ins, $info);
53        $actualCSV = str_replace("\r", '', $renderedCSV);
54
55        $this->assertEquals(trim($expectedCSV), trim($actualCSV));
56    }
57}
58