xref: /plugin/totext/_test/HelperTest.php (revision ca76a2e67052f7370ed3571784ecdc865c0c30b4)
1<?php
2
3namespace dokuwiki\plugin\totext\test;
4
5use dokuwiki\plugin\totext\Exception\UnsupportedFormatException;
6use DokuWikiTest;
7
8/**
9 * Tests for the helper component end-to-end.
10 *
11 * @group plugin_totext
12 */
13class HelperTest extends DokuWikiTest
14{
15    /** @var string[] */
16    protected $pluginsEnabled = ['totext'];
17
18    /** @var string temp working directory */
19    private $tmp = '';
20
21    /** @inheritDoc */
22    public function setUp(): void
23    {
24        parent::setUp();
25        $this->tmp = FixtureBuilder::tempDir();
26    }
27
28    /** @inheritDoc */
29    public function tearDown(): void
30    {
31        FixtureBuilder::cleanup($this->tmp);
32        parent::tearDown();
33    }
34
35    public function testHelperLoads()
36    {
37        $helper = plugin_load('helper', 'totext');
38        $this->assertInstanceOf(\helper_plugin_totext::class, $helper);
39    }
40
41    public function testExtractTextHappyPath()
42    {
43        $path = $this->tmp . '/sample.docx';
44        FixtureBuilder::buildDocx($path);
45
46        /** @var \helper_plugin_totext $helper */
47        $helper = plugin_load('helper', 'totext');
48        $text = $helper->extractText($path);
49        $this->assertStringContainsString('Hello world from DOCX', $text);
50    }
51
52    public function testExtractTextThrowsOnUnsupported()
53    {
54        /** @var \helper_plugin_totext $helper */
55        $helper = plugin_load('helper', 'totext');
56        $this->expectException(UnsupportedFormatException::class);
57        $helper->extractText($this->tmp . '/file.unknownext');
58    }
59
60    public function testIsSupported()
61    {
62        /** @var \helper_plugin_totext $helper */
63        $helper = plugin_load('helper', 'totext');
64        $this->assertTrue($helper->isSupported('foo.docx'));
65        $this->assertTrue($helper->isSupported('foo.PDF'));
66        $this->assertFalse($helper->isSupported('foo.unknownext'));
67    }
68
69    public function testSupportedExtensions()
70    {
71        /** @var \helper_plugin_totext $helper */
72        $helper = plugin_load('helper', 'totext');
73        $this->assertContains('odt', $helper->supportedExtensions());
74    }
75}
76