xref: /plugin/dw2pdf/_test/ConfigTest.php (revision 92200750cd9cfc4a9489fe7c04c6e41b5a3de6ee)
1<?php
2
3namespace dokuwiki\plugin\dw2pdf\test;
4
5use dokuwiki\plugin\dw2pdf\src\Config;
6use DokuWikiTest;
7
8/**
9 * @group plugin_dw2pdf
10 * @group plugins
11 */
12class ConfigTest extends DokuWikiTest
13{
14    public function setUp(): void
15    {
16        parent::setUp();
17        $_REQUEST = [];
18    }
19
20    /**
21     * Ensure plugin.conf overrides and transformations are honored before reading user input.
22     */
23    public function testPluginConfigurationOverridesDefaults(): void
24    {
25        $config = new Config([
26            'pagesize' => 'Letter',
27            'orientation' => 'landscape',
28            'font-size' => 14,
29            'doublesided' => 0,
30            'toc' => 1,
31            'toclevels' => '2-4',
32            'maxbookmarks' => 3,
33            'headernumber' => 1,
34            'template' => 'default',
35            'usestyles' => 'wrap,foo ',
36            'watermark' => 'CONFIDENTIAL',
37            'qrcodescale' => '2.5',
38        ]);
39
40        $this->assertSame('Letter-L', $config->getFormat());
41        $this->assertTrue($config->hasToc());
42        $this->assertSame(3, $config->getMaxBookmarks());
43        $this->assertTrue($config->useNumberedHeaders());
44        $this->assertSame(['wrap', 'foo'], $config->getStyledExtensions());
45        $this->assertSame('CONFIDENTIAL', $config->getWatermarkText());
46        $this->assertSame(2.5, $config->getQRScale());
47
48        $mpdfConfig = $config->getMPdfConfig();
49        $this->assertSame('Letter-L', $mpdfConfig['format']);
50        $this->assertSame(14, $mpdfConfig['default_font_size']);
51        $this->assertTrue($mpdfConfig['showWatermarkText']);
52        $this->assertNotEmpty($config->getCacheKey());
53    }
54
55    /**
56     * Ensure request parameters take precedence over plugin defaults for book export context.
57     */
58    public function testInputOverridesBookParameters(): void
59    {
60        global $INPUT;
61        $INPUT->set('pagesize', 'Legal');
62        $INPUT->set('orientation', 'landscape');
63        $INPUT->set('font-size', '9');
64        $INPUT->set('doublesided', '0');
65        $INPUT->set('toclevels', '3-3');
66        $INPUT->set('watermark', 'TOPSECRET');
67        $INPUT->set('debug', '1');
68        $INPUT->set('book_title', 'My Book');
69        $INPUT->set('book_ns', 'playground:sub');
70        $INPUT->set('book_order', 'date');
71        $INPUT->set('book_nsdepth', 2);
72        $INPUT->set('excludes', ['playground:sub:skip']);
73        $INPUT->set('excludesns', ['playground:private']);
74        $INPUT->set('selection', '["playground:start","playground:Sub:Child"]');
75        $INPUT->set('savedselection', 'fav:123');
76        $INPUT->set('id', 'Playground:Start ');
77
78        $config = new Config();
79
80        $this->assertSame('Legal-L', $config->getFormat());
81        $this->assertTrue($config->isDebugEnabled());
82        $this->assertSame('My Book', $config->getBookTitle());
83        $this->assertSame('playground:sub', $config->getBookNamespace());
84        $this->assertSame('date', $config->getBookSortOrder());
85        $this->assertSame(2, $config->getBookNamespaceDepth());
86        $this->assertSame(['playground:sub:skip'], $config->getBookExcludedPages());
87        $this->assertSame(['playground:private'], $config->getBookExcludedNamespaces());
88        $this->assertTrue($config->hasLiveSelection());
89        $this->assertSame('["playground:start","playground:Sub:Child"]', $config->getLiveSelection());
90        $this->assertTrue($config->hasSavedSelection());
91        $this->assertSame('fav:123', $config->getSavedSelection());
92        $this->assertSame('playground:start', $config->getExportId());
93    }
94}
95