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