Files
edittable/_test/renderer_plugin_edittable_inverse.test.php
Andreas Gohr 99bd0733da more tests for the inverse renderer
This adds a test to the inverse renderer to reproduce the whole syntax
page. It's not a perfect test but should cover a lot of common cases.

The inverse renderer was adjusted to make the test pass. This might
actually have broken things because:

a) the test squashes whitespaces. but whitespaces are significant in
   a lot of DokuWiki's syntax
b) because some whitespace handling was changed it might not give
   desired results for the use in the table editor where line breaks
   need to be avoided
2014-01-14 19:01:55 +01:00

55 lines
1.5 KiB
PHP

<?php
require_once dirname(__FILE__).'/../renderer/inverse.php';
/**
* @group plugin_edittable
* @group plugins
*/
class renderer_plugin_edittable_inverse_test extends DokuWikiTest {
function test_externallink() {
$input = '[[file:///x:\folder\file.zip]]';
$output = $this->render($input);
$this->assertEquals($input, $output);
}
function test_fullsyntax() {
$input = io_readFile(dirname(__FILE__).'/'.basename(__FILE__, '.php').'.txt');
$this->assertTrue(strlen($input) > 1000); // make sure we got what we want
$output = $this->render($input);
$input = $this->noWS($input);
$output = $this->noWS($output);
$this->assertEquals($input, $output);
}
/**
* reduce spaces and newlines to single occurances
*
* @param $text
* @return mixed
*/
protected function noWS($text) {
$text = preg_replace('/\n+/s', "\n", $text);
$text = preg_replace('/ +/', ' ', $text);
return $text;
}
/**
* render the given text with the inverse renderer
*
* @param $text
* @return string
*/
protected function render($text) {
$instructions = p_get_instructions($text);
$Renderer = new renderer_plugin_edittable_inverse();
foreach($instructions as $instruction) {
// Execute the callback against the Renderer
call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]);
}
return $Renderer->doc;
}
}