diff options
author | lisps <stummp@loewen.de> | 2014-03-19 08:07:16 +0100 |
---|---|---|
committer | lisps <stummp@loewen.de> | 2014-03-19 08:07:16 +0100 |
commit | e310313d794a3336d279ee09973508e794dbf08e (patch) | |
tree | 7f90b51d344f7163c6fbb109f04ff22dea5ae129 /_test | |
parent | cdb5e9613f7c4b1be4515715652aca451493d5d5 (diff) | |
parent | 177ef92c4ddd38cb906dd7d5f0208c698048cd57 (diff) | |
download | rpg-e310313d794a3336d279ee09973508e794dbf08e.tar.gz rpg-e310313d794a3336d279ee09973508e794dbf08e.tar.bz2 |
Merge remote-tracking branch 'remotes/origin/master' into revisions_local
Diffstat (limited to '_test')
-rw-r--r-- | _test/core/DokuWikiTest.php | 3 | ||||
-rw-r--r-- | _test/tests/inc/cache_use.test.php | 36 | ||||
-rw-r--r-- | _test/tests/inc/common_pageinfo.test.php | 8 | ||||
-rw-r--r-- | _test/tests/inc/common_stripsourcemaps.test.php | 29 | ||||
-rw-r--r-- | _test/tests/inc/parser/renderer_resolveinterwiki.test.php | 53 | ||||
-rw-r--r-- | _test/tests/inc/parserutils_get_renderer.test.php | 83 | ||||
-rw-r--r-- | _test/tests/inc/utf8_strtolower.test.php | 23 | ||||
-rw-r--r-- | _test/tests/lib/exe/css_css_compress.test.php | 39 |
8 files changed, 265 insertions, 9 deletions
diff --git a/_test/core/DokuWikiTest.php b/_test/core/DokuWikiTest.php index 91eb5293b..f4521256a 100644 --- a/_test/core/DokuWikiTest.php +++ b/_test/core/DokuWikiTest.php @@ -115,5 +115,8 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { // reload language $local = $conf['lang']; trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); + + global $INPUT; + $INPUT = new Input(); } } diff --git a/_test/tests/inc/cache_use.test.php b/_test/tests/inc/cache_use.test.php new file mode 100644 index 000000000..f5349df13 --- /dev/null +++ b/_test/tests/inc/cache_use.test.php @@ -0,0 +1,36 @@ +<?php + +/** + * Class cache_use_test + * + * Tests if caching can actually be used + */ +class cache_use_test extends DokuWikiTest { + /** @var cache_renderer $cache */ + private $cache; + + function setUp() { + global $ID; + parent::setUp(); + + $ID = 'cached'; + $file = wikiFN($ID); + + saveWikiText($ID, 'Content', 'Created'); + // set the modification time a second in the past in order to ensure that the cache is newer than the page + touch($file, time()-1); + + # Create cache. Note that the metadata cache is used as the xhtml cache triggers metadata rendering + $this->cache = new cache_renderer($ID, $file, 'metadata'); + $this->cache->storeCache('Test'); + } + + function test_use() { + $this->assertTrue($this->cache->useCache()); + } + + + function test_purge() { + $this->assertFalse($this->cache->useCache(array('purge' => true))); + } +}
\ No newline at end of file diff --git a/_test/tests/inc/common_pageinfo.test.php b/_test/tests/inc/common_pageinfo.test.php index 0a1ea0a8f..2b230d9ce 100644 --- a/_test/tests/inc/common_pageinfo.test.php +++ b/_test/tests/inc/common_pageinfo.test.php @@ -38,6 +38,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['writable'] = true; $info['editable'] = true; $info['lastmod'] = false; + $info['currentrev'] = false; $info['meta'] = array(); $info['ip'] = null; $info['user'] = null; @@ -77,6 +78,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); $this->assertEquals($info, pageinfo()); @@ -101,6 +103,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); $info['rev'] = ''; @@ -131,6 +134,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['namespace'] = 'wiki'; $info['meta'] = p_get_metadata($ID); $info['rev'] = $REV; + $info['currentrev'] = $rev; $info['filepath'] = str_replace('pages','attic',substr($filename,0,-3).$REV.'.txt.gz'); $this->assertEquals($info, pageinfo()); @@ -153,6 +157,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['namespace'] = 'wiki'; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); $info['filepath'] = $filename; @@ -197,6 +202,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); // need $INFO set correctly for addLogEntry() global $INFO; @@ -226,6 +232,7 @@ class common_pageinfo_test extends DokuWikiTest { touch($filename,$now); $info['lastmod'] = $now; + $info['currentrev'] = $now; $info['meta']['last_change'] = false; $info['ip'] = null; $info['user'] = null; @@ -251,6 +258,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); // setup a draft, make it more recent than the current page diff --git a/_test/tests/inc/common_stripsourcemaps.test.php b/_test/tests/inc/common_stripsourcemaps.test.php new file mode 100644 index 000000000..c6a915dcf --- /dev/null +++ b/_test/tests/inc/common_stripsourcemaps.test.php @@ -0,0 +1,29 @@ +<?php + +class common_stripsourcemaps_test extends DokuWikiTest { + + function test_all() { + + $text = <<<EOL +//@ sourceMappingURL=/foo/bar/xxx.map +//# sourceMappingURL=/foo/bar/xxx.map +/*@ sourceMappingURL=/foo/bar/xxx.map */ +/*# sourceMappingURL=/foo/bar/xxx.map */ +bang +EOL; + + $expect = <<<EOL +// +// +/**/ +/**/ +bang +EOL; + + stripsourcemaps($text); + + + $this->assertEquals($expect, $text); + } + +}
\ No newline at end of file diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php new file mode 100644 index 000000000..7b43b6d62 --- /dev/null +++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php @@ -0,0 +1,53 @@ +<?php + +require_once DOKU_INC . 'inc/parser/renderer.php'; + +/** + * Tests for Doku_Renderer::_resolveInterWiki() + */ +class Test_resolveInterwiki extends PHPUnit_Framework_TestCase { + + function testDefaults() { + $Renderer = new Doku_Renderer(); + $Renderer->interwiki = getInterwiki(); + $Renderer->interwiki['scheme'] = '{SCHEME}://example.com'; + $Renderer->interwiki['withslash'] = '/test'; + $Renderer->interwiki['onlytext'] = ':onlytext{NAME}'; //with {URL} double urlencoded + $Renderer->interwiki['withquery'] = ':anyns:{NAME}?do=edit'; + + $tests = array( + // shortcut, reference and expected + array('wp', 'foo @+%/#txt', 'http://en.wikipedia.org/wiki/foo @+%/#txt'), + array('amazon', 'foo @+%/#txt', 'http://www.amazon.com/exec/obidos/ASIN/foo%20%40%2B%25%2F/splitbrain-20/#txt'), + array('doku', 'foo @+%/#txt', 'http://www.dokuwiki.org/foo%20%40%2B%25%2F#txt'), + array('coral', 'http://example.com:83/path/naar/?query=foo%20%40%2B%25%2F', 'http://example.com.83.nyud.net:8090/path/naar/?query=foo%20%40%2B%25%2F'), + array('scheme', 'ftp://foo @+%/#txt', 'ftp://example.com#txt'), + //relative url + array('withslash', 'foo @+%/#txt', '/testfoo%20%40%2B%25%2F#txt'), + array('skype', 'foo @+%/#txt', 'skype:foo @+%/#txt'), + //dokuwiki id's + array('onlytext', 'foo @+%#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'), + array('user', 'foo @+%#txt', DOKU_BASE.'doku.php?id=user:foo#txt'), + array('withquery', 'foo @+%#txt', DOKU_BASE.'doku.php?id=anyns:foo&do=edit#txt') + ); + + foreach($tests as $test) { + $url = $Renderer->_resolveInterWiki($test[0], $test[1]); + + $this->assertEquals($test[2], $url); + } + } + + function testNonexisting() { + $Renderer = new Doku_Renderer(); + $Renderer->interwiki = getInterwiki(); + + $shortcut = 'nonexisting'; + $reference = 'foo @+%/'; + $url = $Renderer->_resolveInterWiki($shortcut, $reference); + $expected = 'http://www.google.com/search?q=foo%20%40%2B%25%2F&btnI=lucky'; + + $this->assertEquals($expected, $url); + } + +}
\ No newline at end of file diff --git a/_test/tests/inc/parserutils_get_renderer.test.php b/_test/tests/inc/parserutils_get_renderer.test.php new file mode 100644 index 000000000..69aeb3b19 --- /dev/null +++ b/_test/tests/inc/parserutils_get_renderer.test.php @@ -0,0 +1,83 @@ +<?php + +class parserutils_get_renderer_test extends DokuWikiTest { + + private $plugin_controller; + + // test default behaviour / usual settings + function test_p_get_renderer_normal() { + global $conf; + + $old_conf = $conf; + $conf['renderer_xhtml'] = 'xhtml'; + + $this->assertInstanceOf('Doku_Renderer_xhtml', p_get_renderer('xhtml')); + + $conf = $old_conf; + } + + // test get a renderer plugin + function test_p_get_renderer_plugin() { + global $conf; + global $plugin_controller; + + $old_conf = $conf; + $conf['renderer_xhtml'] = 'get_renderer_test'; + $this->plugin_controller = $plugin_controller; + $plugin_controller = $this; + + $this->assertInstanceOf('renderer_plugin_test', p_get_renderer('xhtml')); + + $conf = $old_conf; + $plugin_controller = $this->plugin_controller; + } + + // test fallback succeeds + function test_p_get_renderer_fallback() { + global $conf; + + $old_conf = $conf; + $conf['renderer_xhtml'] = 'badvalue'; + + $this->assertInstanceOf('Doku_Renderer_xhtml', p_get_renderer('xhtml')); + + $conf = $old_conf; + } + + // test fallback fails + /** + * @expectedException PHPUnit_Framework_Error + * @expectedExceptionCode E_USER_WARNING + */ + function test_p_get_renderer_fallback_fail() { + global $conf; + + $old_conf = $conf; + $conf['renderer_junk'] = 'badvalue'; + + $this->assertNull(p_get_renderer('junk')); + + $conf = $old_conf; + } + + // wrapper function for the fake plugin controller, return $this for the fake syntax of this test + function load($type,$name,$new=false,$disabled=false){ + if ($name == 'get_renderer_test') { + return new renderer_plugin_test(); + } else { + return $this->plugin_controller->load($type, $name, $new, $disabled); + } + } + } + +require_once DOKU_INC . 'inc/parser/xhtml.php'; + +class renderer_plugin_test extends Doku_Renderer_xhtml { + + function canRender($format) { + return ($format=='xhtml'); + } + +} + +// vim:ts=4:sw=4:et: diff --git a/_test/tests/inc/utf8_strtolower.test.php b/_test/tests/inc/utf8_strtolower.test.php new file mode 100644 index 000000000..85f5b270b --- /dev/null +++ b/_test/tests/inc/utf8_strtolower.test.php @@ -0,0 +1,23 @@ +<?php +// use no mbstring help here +if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1); + +class utf8_strtolower_test extends DokuWikiTest { + + function test_givens(){ + $data = array( + 'Αρχιτεκτονική Μελέτη' => 'αρχιτεκτονική μελέτη', // FS#2173 + ); + + foreach($data as $input => $expected) { + $this->assertEquals($expected, utf8_strtolower($input)); + } + + // just make sure our data was correct + if(function_exists('mb_strtolower')) { + foreach($data as $input => $expected) { + $this->assertEquals($expected, mb_strtolower($input, 'utf-8')); + } + } + } +}
\ No newline at end of file diff --git a/_test/tests/lib/exe/css_css_compress.test.php b/_test/tests/lib/exe/css_css_compress.test.php index a614ea2fd..f0eb17968 100644 --- a/_test/tests/lib/exe/css_css_compress.test.php +++ b/_test/tests/lib/exe/css_css_compress.test.php @@ -10,33 +10,47 @@ class css_css_compress_test extends DokuWikiTest { * line *test* * check */'; - $this->assertEquals(css_compress($text), ''); + $this->assertEquals('', css_compress($text)); } function test_mlcom2(){ $text = '#comment/* */ { color: lime; }'; - $this->assertEquals(css_compress($text), '#comment/* */{color:lime;}'); + $this->assertEquals('#comment/* */{color:lime;}', css_compress($text)); } function test_slcom1(){ $text = '// this is a comment'; - $this->assertEquals(css_compress($text), ''); + $this->assertEquals('', css_compress($text)); } function test_slcom2(){ $text = '#foo { color: lime; // another comment }'; - $this->assertEquals(css_compress($text), '#foo{color:lime;}'); + $this->assertEquals('#foo{color:lime;}', css_compress($text)); } function test_slcom3(){ $text = '#foo { - background-image: url(http://foo.bar/baz.jpg); + background-image: url(http://foo.bar/baz.jpg); // this is a comment }'; - $this->assertEquals(css_compress($text), '#foo{background-image:url(http://foo.bar/baz.jpg);}'); + $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text)); + } + + function test_slcom4(){ + $text = '#foo { + background-image: url(http://foo.bar/baz.jpg); background-image: url(http://foo.bar/baz.jpg); // this is a comment + }'; + $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);background-image:url(http://foo.bar/baz.jpg);}', css_compress($text)); + } + + function test_slcom5(){ + $text = '#foo { + background-image: url(http://foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is all commented + }'; + $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text)); } function test_hack(){ @@ -44,7 +58,7 @@ class css_css_compress_test extends DokuWikiTest { /* \\*/ display: inline; /* */'; - $this->assertEquals(css_compress($text), '/* \\*/display:inline;/* */'); + $this->assertEquals('/* \\*/display:inline;/* */', css_compress($text)); } function test_hack2(){ @@ -54,12 +68,12 @@ class css_css_compress_test extends DokuWikiTest { height: 450px; } /**/'; - $this->assertEquals(css_compress($text), '/*\\*/* html .page{height:450px;}/**/'); + $this->assertEquals('/*\\*/* html .page{height:450px;}/**/', css_compress($text)); } function test_nl1(){ $text = "a{left:20px;\ntop:20px}"; - $this->assertEquals(css_compress($text), 'a{left:20px;top:20px}'); + $this->assertEquals('a{left:20px;top:20px}', css_compress($text)); } function test_shortening() { @@ -102,6 +116,13 @@ class css_css_compress_test extends DokuWikiTest { $this->assertEquals($expected, $input); } + function test_data() { + $input = 'list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);'; + $expect = 'list-style-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);'; + + $this->assertEquals($expect, css_compress($input)); + } + } //Setup VIM: ex: et ts=4 : |