xref: /plugin/dw2pdf/_test/PageCollectorTest.php (revision 4c5691130dbf9035b960f10f5b3cb4b319a026d8)
1<?php
2
3namespace dokuwiki\plugin\dw2pdf\test;
4
5use dokuwiki\plugin\dw2pdf\src\Config;
6use dokuwiki\plugin\dw2pdf\src\ExportException;
7use dokuwiki\plugin\dw2pdf\src\PageCollector;
8use DokuWikiTest;
9
10/**
11 * @group plugin_dw2pdf
12 * @group plugins
13 */
14class PageCollectorTest extends DokuWikiTest
15{
16    public function setUp(): void
17    {
18        parent::setUp();
19        $_REQUEST = [];
20    }
21
22    /**
23     * Exporting a single page should return the current page ID when it exists.
24     */
25    public function testCollectsExistingPage(): void
26    {
27        global $ID, $INPUT;
28        $ID = 'playground:dw2pdfpage';
29        $INPUT->set('id', $ID);
30        saveWikiText($ID, 'DW2PDF page content', 'create test page');
31
32        $collector = new PageCollector(new Config());
33        $this->assertSame([$ID], $collector->getPages());
34    }
35
36    /**
37     * Missing pages should fail with a message for the user.
38     */
39    public function testThrowsForMissingPage(): void
40    {
41        global $ID, $INPUT;
42        $ID = 'playground:missingdw2pdf';
43        $INPUT->set('id', $ID);
44
45        @unlink(wikiFN($ID));
46
47        $this->expectException(ExportException::class);
48        $this->expectExceptionMessage('notexist');
49        new PageCollector(new Config());
50    }
51}
52