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        global $INFO;
39
40        $syntaxPrefix = ['---- struct table ----'];
41        $syntaxConfig = ['schema: wikilookup', 'cols: *'];
42        $syntaxPostFix = ['----'];
43        $syntax = implode("\n", array_merge($syntaxPrefix, $syntaxConfig, $syntaxPostFix));
44        $expectedCSV = '"FirstFieldText","SecondFieldLongText","ThirdFieldWiki"
45"abc def","abc
46def","  * hi
47  * ho"';
48
49        $configParser = new ConfigParser($syntaxConfig);
50        $INPUT->set('hash', md5(var_export($configParser->getConfig(), true)));
51
52        $INFO['id'] = 'unit_test';
53        $ins = p_get_instructions($syntax);
54        $renderedCSV = p_render('struct_csv', $ins, $info);
55        $actualCSV = str_replace("\r", '', $renderedCSV);
56
57        $this->assertEquals(trim($expectedCSV), trim($actualCSV));
58    }
59}
60