1
0
Fork 0

Adding dw2pdf version 2023-11-25 (48253f1).

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2024-12-01 20:29:19 +01:00
parent d4820b660a
commit 8e32b01eb0
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
999 changed files with 144285 additions and 0 deletions

View file

@ -0,0 +1,104 @@
<?php
namespace dokuwiki\plugin\dw2pdf\test;
use DokuWikiTest;
/**
* @group plugin_dw2pdf
* @group plugins
*/
class ActionPagenameSortTest extends DokuWikiTest
{
protected $pluginsEnabled = array('dw2pdf');
public function testDirectPagenameSort()
{
$action = new \action_plugin_dw2pdf();
$this->assertLessThan(0, $action->cbPagenameSort(['id' => 'bar'], ['id' => 'bar:start']));
$this->assertGreaterThan(0, $action->cbPagenameSort(['id' => 'bar:bar'], ['id' => 'bar:start']));
}
/**
* @return array
* @see testPageNameSort
*/
public function providerPageNameSort()
{
return [
[
'start pages sorted',
[
'bar',
'bar:start',
'bar:alpha',
'bar:bar',
],
],
[
'pages and subspaces mixed',
[
'alpha',
'beta:foo',
'gamma',
],
],
[
'full test',
[
'start',
'01_page',
'10_page',
'bar',
'bar:start',
'bar:1_page',
'bar:2_page',
'bar:10_page',
'bar:22_page',
'bar:aa_page',
'bar:aa_page:detail1',
'bar:zz_page',
'foo',
'foo:start',
'foo:01_page',
'foo:10_page',
'foo:foo',
'foo:zz_page',
'ns',
'ns:01_page',
'ns:10_page',
'ns:ns',
'ns:zz_page',
'zz_page',
],
],
];
}
/**
* @dataProvider providerPageNameSort
* @param string $comment
* @param array $expected
*/
public function testPagenameSort($comment, $expected)
{
// prepare the array as expected in the sort function
$prepared = [];
foreach ($expected as $line) {
$prepared[] = ['id' => $line];
}
// the input is random
$input = $prepared;
shuffle($input);
// run sort
$action = new \action_plugin_dw2pdf();
usort($input, [$action, 'cbPagenameSort']);
$this->assertSame($prepared, $input);
}
}

View file

@ -0,0 +1,73 @@
<?php
namespace dokuwiki\plugin\dw2pdf\test;
use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator;
use DokuWikiTest;
/**
* General tests for the imagemap plugin
*
* @group plugin_dw2pdf
* @group plugins
*/
class DokuImageProcessorTest extends DokuWikiTest
{
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
require_once __DIR__ . '/../vendor/autoload.php';
}
/**
* @return array the Testdata
*/
public function provideGetImageTestdata() {
global $conf;
return [
[
DOKU_URL . 'lib/exe/fetch.php?tok=b0b7a3&media=http%3A%2F%2Fphp.net%2Fimages%2Fphp.gif',
DOKU_REL . 'lib/exe/fetch.php?tok=b0b7a3&media=http%3A%2F%2Fphp.net%2Fimages%2Fphp.gif',
'http://php.net/images/php.gif',
'http://php.net/images/php.gif',
'external image',
],
[
DOKU_URL . 'lib/images/throbber.gif',
DOKU_REL . 'lib/images/throbber.gif',
DOKU_INC . 'lib/images/throbber.gif',
DOKU_INC . 'lib/images/throbber.gif',
'fixed standard image',
],
[
DOKU_URL . 'lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
DOKU_REL . 'lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
$conf['mediadir'] . '/wiki/dokuwiki-128.png',
$conf['mediadir'] . '/wiki/dokuwiki-128.png',
'Internal image',
],
];
}
/**
* @dataProvider provideGetImageTestdata
*
* @param $input_file
* @param $input_orig_srcpath
* @param $expected_file
* @param $expected_orig_srcpath
* @param $msg
*/
public function testGetImage($input_file, $input_orig_srcpath, $expected_file, $expected_orig_srcpath, $msg)
{
list($actual_file, $actual_orig_srcpath) = DokuImageProcessorDecorator::adjustGetImageLinks($input_file,
$input_orig_srcpath);
$this->assertEquals($expected_file, $actual_file, '$file ' . $msg);
$this->assertEquals($expected_orig_srcpath, $actual_orig_srcpath, '$orig_srcpath ' . $msg);
}
}

View file

@ -0,0 +1,86 @@
<?php
namespace dokuwiki\plugin\dw2pdf\test;
use DokuWikiTest;
/**
* General tests for the dw2pdf plugin
*
* @group plugin_dw2pdf
* @group plugins
*/
class GeneralTest extends DokuWikiTest
{
/**
* Simple test to make sure the plugin.info.txt is in correct format
*/
public function testPluginInfo(): void
{
$file = __DIR__ . '/../plugin.info.txt';
$this->assertFileExists($file);
$info = confToHash($file);
$this->assertArrayHasKey('base', $info);
$this->assertArrayHasKey('author', $info);
$this->assertArrayHasKey('email', $info);
$this->assertArrayHasKey('date', $info);
$this->assertArrayHasKey('name', $info);
$this->assertArrayHasKey('desc', $info);
$this->assertArrayHasKey('url', $info);
$this->assertEquals('dw2pdf', $info['base']);
$this->assertRegExp('/^https?:\/\//', $info['url']);
$this->assertTrue(mail_isvalid($info['email']));
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
$this->assertTrue(false !== strtotime($info['date']));
}
/**
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
* conf/metadata.php.
*/
public function testPluginConf(): void
{
$conf_file = __DIR__ . '/../conf/default.php';
$meta_file = __DIR__ . '/../conf/metadata.php';
if (!file_exists($conf_file) && !file_exists($meta_file)) {
self::markTestSkipped('No config files exist -> skipping test');
}
if (file_exists($conf_file)) {
include($conf_file);
}
if (file_exists($meta_file)) {
include($meta_file);
}
$this->assertEquals(
gettype($conf),
gettype($meta),
'Both ' . DOKU_PLUGIN . 'dw2pdf/conf/default.php and ' . DOKU_PLUGIN . 'dw2pdf/conf/metadata.php have to exist and contain the same keys.'
);
if ($conf !== null && $meta !== null) {
foreach ($conf as $key => $value) {
$this->assertArrayHasKey(
$key,
$meta,
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'dw2pdf/conf/metadata.php'
);
}
foreach ($meta as $key => $value) {
$this->assertArrayHasKey(
$key,
$conf,
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'dw2pdf/conf/default.php'
);
}
}
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace dokuwiki\plugin\dw2pdf\test;
use DokuWikiTest;
/**
* Class dw2pdf_renderer_dw2pdf_test
*
* @group plugin_dw2pdf
* @group plugins
*/
class RendererTest extends DokuWikiTest {
public function test() {
$Renderer = new \renderer_plugin_dw2pdf();
$levels = [
1,2,2,2,3,4,5,6,5,4,3,2,1, // index:0-12
3,4,3,1, // 13-16
2,3,4,2,3,4,1, // 17-23
3,4,3,2,1, // 24-28
3,4,2,1, // 29-32
3,5,6,5,6,4,6,3,1, // 33-41
3,6,4,5,6,4,3,6,2,1, // 42-51
2,3,2,3,3 // 52-56
];
$expectedbookmarklevels = [
0,1,1,1,2,3,4,5,4,3,2,1,0,
1,2,1,0,
1,2,3,1,2,3,0,
1,2,1,1,0,
1,2,1,0,
1,2,3,2,3,2,3,2,0,
1,2,2,3,4,2,2,3,1,0,
1,2,1,2,2
];
foreach ($levels as $i => $level) {
$actualbookmarklevel = $this->callInaccessibleMethod($Renderer, 'calculateBookmarklevel', [$level]);
$this->assertEquals($expectedbookmarklevels[$i], $actualbookmarklevel, "index:$i, lvl:$level");
}
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace dokuwiki\plugin\dw2pdf\test;
use DokuWikiTest;
/**
* Export link tests for the dw2pdf plugin
*
* @group plugin_dw2pdf
* @group plugins
*/
class SyntaxExportLinkTest extends DokuWikiTest
{
protected $pluginsEnabled = array('dw2pdf');
function testParser()
{
global $ID;
$ID = 'foo:bar:start';
$parser_response = p_get_instructions('~~PDFNS>.:|Foo~~');
$expected_parser_response = array(
'plugin',
array(
'dw2pdf_exportlink',
array(
'link' => '?do=export_pdfns&book_ns=foo:bar&book_title=Foo',
'title' => 'Export namespace "foo:bar:" to file Foo.pdf',
5,
1,
),
5,
'~~PDFNS>.:|Foo~~',
),
1,
);
$this->assertEquals($expected_parser_response, $parser_response[2]);
$renderer_response = p_render('xhtml', $parser_response, $info);
$expected_renderer_response = 'doku.php?id=foo:bar:start&amp;do=export_pdfns&amp;book_ns=foo:bar&amp;book_title=Foo" class="wikilink2" title="foo:bar:start" rel="nofollow" data-wiki-id="foo:bar:start">Export namespace &quot;foo:bar:&quot; to file Foo.pdf</a>';
$trimmed_renderer_response = substr($renderer_response, strpos($renderer_response, 'doku.php'), -5);
$trimmed_renderer_response = trim($trimmed_renderer_response);
$this->assertEquals($expected_renderer_response, $trimmed_renderer_response);
}
}