diff options
author | Guy Brand <gb@unistra.fr> | 2015-08-10 10:03:27 +0200 |
---|---|---|
committer | Guy Brand <gb@unistra.fr> | 2015-08-10 10:03:27 +0200 |
commit | 53a57d16b9c741bb44099fd93bf79efa06796341 (patch) | |
tree | 24a90a50afe9325926c8ebaa2ed90f9fa093e5b9 /_test/tests | |
parent | cf6e6645c31a9f185cef3fb9452fb188882ede47 (diff) | |
parent | a060d9973e7c1d5051f2cc426937881826e4972e (diff) | |
download | rpg-53a57d16b9c741bb44099fd93bf79efa06796341.tar.gz rpg-53a57d16b9c741bb44099fd93bf79efa06796341.tar.bz2 |
Merge branch master into stable
Diffstat (limited to '_test/tests')
39 files changed, 734 insertions, 527 deletions
diff --git a/_test/tests/inc/auth_password.test.php b/_test/tests/inc/auth_password.test.php index 07b9f5bb2..5067e2ca1 100644 --- a/_test/tests/inc/auth_password.test.php +++ b/_test/tests/inc/auth_password.test.php @@ -16,9 +16,16 @@ class auth_password_test extends DokuWikiTest { 'kmd5' => 'a579299436d7969791189acadd86fcb716', 'djangomd5' => 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158', 'djangosha1' => 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678', - 'sha512' => '$6$abcdefgh12345678$J9.zOcgx0lotwZdcz0uulA3IVQMinZvFZVjA5vapRLVAAqtay23XD4xeeUxQ3B4JvDWYFBIxVWW1tOYlHX13k1' + ); + function __construct() { + if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) { + // Check SHA512 only if available in this PHP + $this->passes['sha512'] = '$6$abcdefgh12345678$J9.zOcgx0lotwZdcz0uulA3IVQMinZvFZVjA5vapRLVAAqtay23XD4xeeUxQ3B4JvDWYFBIxVWW1tOYlHX13k1'; + } + } + function test_cryptPassword(){ foreach($this->passes as $method => $hash){ diff --git a/_test/tests/inc/cache_use.test.php b/_test/tests/inc/cache_use.test.php index 3ea212d50..c0c12580a 100644 --- a/_test/tests/inc/cache_use.test.php +++ b/_test/tests/inc/cache_use.test.php @@ -4,6 +4,8 @@ * Class cache_use_test * * Tests if caching can actually be used + * + * @todo tests marked as flaky until Ticket #694 has been fixed */ class cache_use_test extends DokuWikiTest { /** @var cache_renderer $cache */ @@ -28,18 +30,11 @@ class cache_use_test extends DokuWikiTest { touch($this->cache->cache, $time); } - function test_use() { - $this->markTestSkipped('Disabled until Ticket #694 has been fixed'); - return; - - $this->assertTrue($this->cache->useCache()); - } - /** * In all the following tests the cache should not be usable * as such, they are meaningless if test_use didn't pass. * - * @depends test_use + * @group flaky */ function test_purge() { /* @var Input $INPUT */ @@ -51,7 +46,7 @@ class cache_use_test extends DokuWikiTest { } /** - * @depends test_use + * @group flaky */ function test_filedependency() { // give the dependent src file the same mtime as the cache @@ -60,7 +55,7 @@ class cache_use_test extends DokuWikiTest { } /** - * @depends test_use + * @group flaky */ function test_age() { // need to age both our source file & the cache @@ -74,7 +69,7 @@ class cache_use_test extends DokuWikiTest { } /** - * @depends test_use + * @group flaky */ function test_confnocaching() { global $conf; @@ -83,4 +78,4 @@ class cache_use_test extends DokuWikiTest { $this->assertFalse($this->cache->useCache()); $this->assertNotEmpty($this->cache->_nocache); } -}
\ No newline at end of file +} diff --git a/_test/tests/inc/form/checkableelement.test.php b/_test/tests/inc/form/checkableelement.test.php new file mode 100644 index 000000000..a0e4173e8 --- /dev/null +++ b/_test/tests/inc/form/checkableelement.test.php @@ -0,0 +1,49 @@ +<?php + +use dokuwiki\Form; + +class form_checkableelement_test extends DokuWikiTest { + + function test_defaults() { + $form = new Form\Form(); + $form->addRadioButton('foo', 'label text first')->val('first')->attr('checked', 'checked'); + $form->addRadioButton('foo', 'label text second')->val('second'); + + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $input = $pq->find('input[name=foo]'); + $this->assertTrue($input->length == 2); + + $label = $pq->find('label'); + $this->assertTrue($label->length == 2); + + $inputs = $pq->find('input[name=foo]'); + $this->assertEquals('first', pq($inputs->elements[0])->val()); + $this->assertEquals('second', pq($inputs->elements[1])->val()); + $this->assertEquals('checked', pq($inputs->elements[0])->attr('checked')); + $this->assertEquals('', pq($inputs->elements[1])->attr('checked')); + } + + /** + * check that posted values overwrite preset default + */ + function test_prefill() { + global $INPUT; + $INPUT->post->set('foo', 'second'); + + + $form = new Form\Form(); + $form->addRadioButton('foo', 'label text first')->val('first')->attr('checked', 'checked'); + $form->addRadioButton('foo', 'label text second')->val('second'); + + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $inputs = $pq->find('input[name=foo]'); + $this->assertEquals('first', pq($inputs->elements[0])->val()); + $this->assertEquals('second', pq($inputs->elements[1])->val()); + $this->assertEquals('', pq($inputs->elements[0])->attr('checked')); + $this->assertEquals('checked', pq($inputs->elements[1])->attr('checked')); + } +} diff --git a/_test/tests/inc/form/form.test.php b/_test/tests/inc/form/form.test.php new file mode 100644 index 000000000..3ae832b2c --- /dev/null +++ b/_test/tests/inc/form/form.test.php @@ -0,0 +1,115 @@ +<?php + +use dokuwiki\Form; + +/** + * makes form internals accessible for testing + */ +class TestForm extends Form\Form { + /** + * @return array list of element types + */ + function getElementTypeList() { + $list = array(); + foreach($this->elements as $element) $list[] = $element->getType(); + return $list; + } + + public function balanceFieldsets() { + parent::balanceFieldsets(); + } + +} + +class form_form_test extends DokuWikiTest { + + /** + * checks that an empty form is initialized correctly + */ + function test_defaults() { + global $INPUT; + global $ID; + $ID = 'some:test'; + $INPUT->get->set('id', $ID); + $INPUT->get->set('foo', 'bar'); + + $form = new Form\Form(); + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $this->assertTrue($pq->find('form')->hasClass('doku_form')); + $this->assertEquals(wl($ID, array('foo' => 'bar'), false, '&'), $pq->find('form')->attr('action')); + $this->assertEquals('post', $pq->find('form')->attr('method')); + + $this->assertTrue($pq->find('input[name=sectok]')->length == 1); + } + + + function test_fieldsetbalance() { + $form = new TestForm(); + $form->addFieldsetOpen(); + $form->addHTML('ignored'); + $form->addFieldsetClose(); + $form->balanceFieldsets(); + + $this->assertEquals( + array( + 'fieldsetopen', + 'html', + 'fieldsetclose' + ), + $form->getElementTypeList() + ); + + $form = new TestForm(); + $form->addHTML('ignored'); + $form->addFieldsetClose(); + $form->balanceFieldsets(); + + $this->assertEquals( + array( + 'fieldsetopen', + 'html', + 'fieldsetclose' + ), + $form->getElementTypeList() + ); + + + $form = new TestForm(); + $form->addFieldsetOpen(); + $form->addHTML('ignored'); + $form->balanceFieldsets(); + + $this->assertEquals( + array( + 'fieldsetopen', + 'html', + 'fieldsetclose' + ), + $form->getElementTypeList() + ); + + $form = new TestForm(); + $form->addHTML('ignored'); + $form->addFieldsetClose(); + $form->addHTML('ignored'); + $form->addFieldsetOpen(); + $form->addHTML('ignored'); + $form->balanceFieldsets(); + + $this->assertEquals( + array( + 'fieldsetopen', + 'html', + 'fieldsetclose', + 'html', + 'fieldsetopen', + 'html', + 'fieldsetclose' + ), + $form->getElementTypeList() + ); + } + +} diff --git a/_test/tests/inc/form/inputelement.test.php b/_test/tests/inc/form/inputelement.test.php new file mode 100644 index 000000000..7a5e6d2ea --- /dev/null +++ b/_test/tests/inc/form/inputelement.test.php @@ -0,0 +1,41 @@ +<?php + +use dokuwiki\Form; + +class form_inputelement_test extends DokuWikiTest { + + function test_defaults() { + $form = new Form\Form(); + $form->addTextInput('foo', 'label text')->val('this is text'); + + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $input = $pq->find('input[name=foo]'); + $this->assertTrue($input->length == 1); + $this->assertEquals('this is text', $input->val()); + + $label = $pq->find('label'); + $this->assertTrue($label->length == 1); + $this->assertEquals('label text', $label->find('span')->text()); + } + + /** + * check that posted values overwrite preset default + */ + function test_prefill() { + global $INPUT; + $INPUT->post->set('foo', 'a new text'); + + $form = new Form\Form(); + $form->addTextInput('foo', 'label text')->val('this is text'); + + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $input = $pq->find('input[name=foo]'); + $this->assertTrue($input->length == 1); + $this->assertEquals('a new text', $input->val()); + } + +} diff --git a/_test/tests/inc/form_form.test.php b/_test/tests/inc/form_form.test.php index 02242a807..7f168b895 100644 --- a/_test/tests/inc/form_form.test.php +++ b/_test/tests/inc/form_form.test.php @@ -30,9 +30,9 @@ class form_test extends DokuWikiTest { $realoutput .= '<input type="checkbox" id="check__id" name="r" value="1" /> '; $realoutput .= '<span>Check</span></label>'; $realoutput .= "\n"; - $realoutput .= '<input name="do[save]" type="submit" value="Save" class="button" accesskey="s" title="Save [S]" />'; + $realoutput .= '<button name="do[save]" type="submit" accesskey="s" title="Save [S]">Save</button>'; $realoutput .= "\n"; - $realoutput .= '<input name="do[cancel]" type="submit" value="Cancel" class="button" />'; + $realoutput .= '<button name="do[cancel]" type="submit">Cancel</button>'; $realoutput .= "\n"; $realoutput .= "</fieldset>\n</div></form>\n"; return $realoutput; diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index 3446e1184..94b8e1bc1 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -289,6 +289,7 @@ class httpclient_http_test extends DokuWikiTest { * This address caused trouble with stream_select() * * @group internet + * @group flaky */ function test_wikimatrix(){ $http = new HTTPMockClient(); diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index c44dc7ed7..dae801dbd 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -3,7 +3,7 @@ require_once (__DIR__ . '/httpclient_mock.php'); class httpclient_http_proxy_test extends DokuWikiTest { - protected $url = 'http://test.dokuwiki.org/README'; + protected $url = 'http://httpbin.org/user-agent'; /** * @group internet @@ -15,7 +15,7 @@ class httpclient_http_proxy_test extends DokuWikiTest { $http->proxy_port = 8080; $data = $http->get($this->url); - $this->assertFalse($data === false, 'HTTP response '.$http->error); + $this->assertFalse($data === false, 'HTTP response: '.$http->error.' ['.$this->url.']'); $this->assertTrue(strpos($data,'DokuWiki') !== false, 'response content'); } }
\ No newline at end of file diff --git a/_test/tests/inc/httpclient_https_proxy.test.php b/_test/tests/inc/httpclient_https_proxy.test.php index 9402e91af..cf5b9a8b9 100644 --- a/_test/tests/inc/httpclient_https_proxy.test.php +++ b/_test/tests/inc/httpclient_https_proxy.test.php @@ -2,7 +2,7 @@ require_once dirname(__FILE__).'/httpclient_http_proxy.test.php'; class httpclient_https_proxy_test extends httpclient_http_proxy_test { - protected $url = 'https://www.dokuwiki.org/README'; + protected $url = 'https://httpbin.org/user-agent'; public function setUp(){ // skip tests when this PHP has no SSL support @@ -27,4 +27,4 @@ class httpclient_https_proxy_test extends httpclient_http_proxy_test { $this->assertFalse($data); $this->assertEquals(-150, $http->status); } -}
\ No newline at end of file +} diff --git a/_test/tests/inc/io_deletefromfile.test.php b/_test/tests/inc/io_deletefromfile.test.php new file mode 100644 index 000000000..e86150aac --- /dev/null +++ b/_test/tests/inc/io_deletefromfile.test.php @@ -0,0 +1,15 @@ +<?php + +class io_deletefromfile_test extends DokuWikiTest { + + function test_delete(){ + $file = TMP_DIR.'/test.txt'; + $contents = "The\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012"; + io_saveFile($file, $contents); + $this->assertTrue(io_deleteFromFile($file, "Delete\012")); + $this->assertEquals("The\012Delete01\012Delete02\012DeleteX\012Test\012", io_readFile($file)); + $this->assertTrue(io_deleteFromFile($file, "#Delete\\d+\012#", true)); + $this->assertEquals("The\012DeleteX\012Test\012", io_readFile($file)); + } + +} diff --git a/_test/tests/inc/io_readfile.test.php b/_test/tests/inc/io_readfile.test.php new file mode 100644 index 000000000..700c1902b --- /dev/null +++ b/_test/tests/inc/io_readfile.test.php @@ -0,0 +1,58 @@ +<?php + +class io_readfile_test extends DokuWikiTest { + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_zlib() { + if (!extension_loaded('zlib')) { + $this->markTestSkipped('skipping all zlib tests. Need zlib extension'); + } + } + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_bz2() { + if (!extension_loaded('bz2')) { + $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); + } + } + + function test_plain(){ + // since git converts line endings, we can't check in this test file but have to create it ourselves + $plain = TMP_DIR.'/test.txt'; + file_put_contents($plain, "The\015\012Test\015\012"); + + $this->assertEquals("The\012Test\012", io_readFile($plain)); + $this->assertEquals("The\015\012Test\015\012", io_readFile($plain, false)); + $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt')); + } + + /** + * @depends test_ext_zlib + */ + function test_gzfiles(){ + $this->assertEquals("The\012Test\012", io_readFile(__DIR__.'/io_readfile/test.txt.gz')); + $this->assertEquals("The\015\012Test\015\012", io_readFile(__DIR__.'/io_readfile/test.txt.gz', false)); + $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt.gz')); + $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.gz')); + } + + /** + * @depends test_ext_bz2 + */ + function test_bzfiles(){ + $this->assertEquals("The\012Test\012", io_readFile(__DIR__.'/io_readfile/test.txt.bz2')); + $this->assertEquals("The\015\012Test\015\012", io_readFile(__DIR__.'/io_readfile/test.txt.bz2', false)); + $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt.bz2')); + $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.bz2')); + // internal bzfile function + $this->assertEquals(array("The\015\012","Test\015\012"), bzfile(__DIR__.'/io_readfile/test.txt.bz2', true)); + $this->assertEquals(array_fill(0, 120, str_repeat('a', 80)."\012"), bzfile(__DIR__.'/io_readfile/large.txt.bz2', true)); + $line = str_repeat('a', 8888)."\012"; + $this->assertEquals(array($line,"\012",$line,"!"), bzfile(__DIR__.'/io_readfile/long.txt.bz2', true)); + } + +} diff --git a/_test/tests/inc/io_readfile/corrupt.txt.bz2 b/_test/tests/inc/io_readfile/corrupt.txt.bz2 new file mode 100644 index 000000000..97f742919 --- /dev/null +++ b/_test/tests/inc/io_readfile/corrupt.txt.bz2 @@ -0,0 +1 @@ +BZh91AY&SYXHd¬
\ No newline at end of file diff --git a/_test/tests/inc/io_readfile/corrupt.txt.gz b/_test/tests/inc/io_readfile/corrupt.txt.gz Binary files differnew file mode 100644 index 000000000..9d7666f47 --- /dev/null +++ b/_test/tests/inc/io_readfile/corrupt.txt.gz diff --git a/_test/tests/inc/io_readfile/large.txt.bz2 b/_test/tests/inc/io_readfile/large.txt.bz2 Binary files differnew file mode 100644 index 000000000..3135435f8 --- /dev/null +++ b/_test/tests/inc/io_readfile/large.txt.bz2 diff --git a/_test/tests/inc/io_readfile/long.txt.bz2 b/_test/tests/inc/io_readfile/long.txt.bz2 Binary files differnew file mode 100644 index 000000000..fb40759e6 --- /dev/null +++ b/_test/tests/inc/io_readfile/long.txt.bz2 diff --git a/_test/tests/inc/io_readfile/test.txt.bz2 b/_test/tests/inc/io_readfile/test.txt.bz2 Binary files differnew file mode 100644 index 000000000..3d4e1b226 --- /dev/null +++ b/_test/tests/inc/io_readfile/test.txt.bz2 diff --git a/_test/tests/inc/io_readfile/test.txt.gz b/_test/tests/inc/io_readfile/test.txt.gz Binary files differnew file mode 100644 index 000000000..8ac8f7d40 --- /dev/null +++ b/_test/tests/inc/io_readfile/test.txt.gz diff --git a/_test/tests/inc/io_replaceinfile.test.php b/_test/tests/inc/io_replaceinfile.test.php new file mode 100644 index 000000000..452ed7401 --- /dev/null +++ b/_test/tests/inc/io_replaceinfile.test.php @@ -0,0 +1,108 @@ +<?php + +class io_replaceinfile_test extends DokuWikiTest { + + protected $contents = "The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012"; + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_zlib() { + if (!extension_loaded('zlib')) { + $this->markTestSkipped('skipping all zlib tests. Need zlib extension'); + } + } + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_bz2() { + if (!extension_loaded('bz2')) { + $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); + } + } + + function _write($file){ + + io_saveFile($file, $this->contents); + // Replace one, no regex + $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete00\012", false, 1)); + $this->assertEquals("The\012Delete00\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012", io_readFile($file)); + // Replace all, no regex + $this->assertTrue(io_replaceInFile($file, "Delete\012", "DeleteX\012", false, -1)); + $this->assertEquals("The\012Delete00\012DeleteX\012Delete01\012Delete02\012DeleteX\012DeleteX\012Test\012", io_readFile($file)); + // Replace two, regex and backreference + $this->assertTrue(io_replaceInFile($file, "#Delete(\\d+)\012#", "\\1\012", true, 2)); + $this->assertEquals("The\01200\012DeleteX\01201\012Delete02\012DeleteX\012DeleteX\012Test\012", io_readFile($file)); + // Delete and insert, no regex + $this->assertTrue(io_replaceInFile($file, "DeleteX\012", "Replace\012", false, 0)); + $this->assertEquals("The\01200\01201\012Delete02\012Test\012Replace\012", io_readFile($file)); + } + + function test_replace(){ + $this->_write(TMP_DIR.'/test.txt'); + } + + + /** + * @depends test_ext_zlib + */ + function test_gzwrite(){ + $this->_write(TMP_DIR.'/test.txt.gz'); + } + + /** + * @depends test_ext_bz2 + */ + function test_bzwrite(){ + $this->_write(TMP_DIR.'/test.txt.bz2'); + } + + /** + * Test for a non-regex replacement where $newline contains a backreference like construct - it shouldn't affect the replacement + */ + function test_edgecase1() + { + $file = TMP_DIR . '/test.txt'; + + io_saveFile($file, $this->contents); + $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete\\00\012", false, -1)); + $this->assertEquals("The\012Delete\\00\012Delete\\00\012Delete01\012Delete02\012Delete\\00\012DeleteX\012Test\012", io_readFile($file), "Edge case: backreference like construct in replacement line"); + } + /** + * Test with replace all where replacement line == search line - must not timeout + * + * @small + */ + function test_edgecase2() { + $file = TMP_DIR.'/test.txt'; + + io_saveFile($file, $this->contents); + $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete\012", false, -1)); + $this->assertEquals("The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012", io_readFile($file), "Edge case: new line the same as old line"); + } + + /** + * Test where $oldline exactly matches one line and also matches part of other lines - only the exact match should be replaced + */ + function test_edgecase3() + { + $file = TMP_DIR . '/test.txt'; + $contents = "The\012Delete\01201Delete\01202Delete\012Test\012"; + + io_saveFile($file, $contents); + $this->assertTrue(io_replaceInFile($file, "Delete\012", "Replace\012", false, -1)); + $this->assertEquals("The\012Replace\01201Delete\01202Delete\012Test\012", io_readFile($file), "Edge case: old line is a match for parts of other lines"); + } + + /** + * Test passing an invalid parameter. + * + * @expectedException PHPUnit_Framework_Error_Warning + */ + function test_badparam() + { + /* The empty $oldline parameter should be caught before the file doesn't exist test. */ + $this->assertFalse(io_replaceInFile(TMP_DIR.'/not_existing_file.txt', '', '', false, 0)); + } +} diff --git a/_test/tests/inc/io_savefile.test.php b/_test/tests/inc/io_savefile.test.php new file mode 100644 index 000000000..4a4d4671d --- /dev/null +++ b/_test/tests/inc/io_savefile.test.php @@ -0,0 +1,49 @@ +<?php + +class io_savefile_test extends DokuWikiTest { + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_zlib() { + if (!extension_loaded('zlib')) { + $this->markTestSkipped('skipping all zlib tests. Need zlib extension'); + } + } + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_bz2() { + if (!extension_loaded('bz2')) { + $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); + } + } + + function _write($file){ + $contents = "The\012Write\012Test\012"; + $this->assertTrue(io_saveFile($file, $contents)); + $this->assertEquals($contents, io_readFile($file)); + $this->assertTrue(io_saveFile($file, $contents, true)); + $this->assertEquals($contents.$contents, io_readFile($file)); + } + + function test_write(){ + $this->_write(TMP_DIR.'/test.txt'); + } + + /** + * @depends test_ext_zlib + */ + function test_gzwrite(){ + $this->_write(TMP_DIR.'/test.txt.gz'); + } + + /** + * @depends test_ext_bz2 + */ + function test_bzwrite(){ + $this->_write(TMP_DIR.'/test.txt.bz2'); + } + +} diff --git a/_test/tests/inc/ixr_library_date.test.php b/_test/tests/inc/ixr_library_date.test.php index f38486925..0c81e6741 100644 --- a/_test/tests/inc/ixr_library_date.test.php +++ b/_test/tests/inc/ixr_library_date.test.php @@ -2,6 +2,9 @@ require_once DOKU_INC.'inc/IXR_Library.php'; +/** + * Class ixr_library_date_test + */ class ixr_library_date_test extends DokuWikiTest { @@ -16,18 +19,24 @@ class ixr_library_date_test extends DokuWikiTest { array('2010-08-17T09:23:14Z', 1282036994), array('20100817T09:23:14Z', 1282036994), + // with timezone + array('2010-08-17 09:23:14+0000', 1282036994), + array('2010-08-17 09:23:14+00:00', 1282036994), + array('2010-08-17 12:23:14+03:00', 1282036994), + // no seconds array('2010-08-17T09:23', 1282036980), array('20100817T09:23', 1282036980), // no time array('2010-08-17', 1282003200), - //array('20100817', 1282003200), #this will NOT be parsed, but is assumed to be timestamp + array(1282036980, 1282036980), +// array('20100817', 1282003200), #this will NOT be parsed, but is assumed to be timestamp ); foreach($tests as $test){ $dt = new IXR_Date($test[0]); - $this->assertEquals($dt->getTimeStamp(),$test[1]); + $this->assertEquals($test[1], $dt->getTimeStamp()); } } diff --git a/_test/tests/inc/parser/lexer.test.php b/_test/tests/inc/parser/lexer.test.php index d0965a13e..c50665928 100644 --- a/_test/tests/inc/parser/lexer.test.php +++ b/_test/tests/inc/parser/lexer.test.php @@ -146,7 +146,7 @@ class TestOfLexerStateStack extends DokuWikiTest { } class TestParser { - function TestParser() { + function __construct() { } function accept() { } @@ -364,7 +364,7 @@ class TestOfLexerHandlers extends DokuWikiTest { class TestParserByteIndex { - function TestParserByteIndex() {} + function __construct() {} function ignore() {} diff --git a/_test/tests/inc/parser/parser_footnote.test.php b/_test/tests/inc/parser/parser_footnote.test.php index b47a575de..2457fb031 100644 --- a/_test/tests/inc/parser/parser_footnote.test.php +++ b/_test/tests/inc/parser/parser_footnote.test.php @@ -303,7 +303,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { array('nest', array ( array ( array('footnote_open',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), diff --git a/_test/tests/inc/parser/parser_lists.test.php b/_test/tests/inc/parser/parser_lists.test.php index e4ef1f83e..6acaff637 100644 --- a/_test/tests/inc/parser/parser_lists.test.php +++ b/_test/tests/inc/parser/parser_lists.test.php @@ -13,7 +13,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -46,7 +46,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listo_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -80,7 +80,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listo_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -109,7 +109,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -138,7 +138,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listo_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -188,7 +188,7 @@ Bar'); array('cdata',array("Foo")), array('p_close',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -227,7 +227,7 @@ Bar'); $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('strong_open',array()), array('cdata',array("A")), @@ -262,7 +262,7 @@ Bar'); $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('unformatted',array("A")), array('listcontent_close',array()), @@ -291,7 +291,7 @@ Bar'); $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('linebreak',array()), @@ -355,7 +355,7 @@ Bar'); $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('nest', array( array( array('footnote_open',array()), diff --git a/_test/tests/inc/parser/parser_media.test.php b/_test/tests/inc/parser/parser_media.test.php new file mode 100644 index 000000000..d9a0626f5 --- /dev/null +++ b/_test/tests/inc/parser/parser_media.test.php @@ -0,0 +1,103 @@ +<?php +require_once 'parser.inc.php'; + +/** + * Tests for the implementation of audio and video files + * + * @author Michael Große <grosse@cosmocode.de> +*/ +class TestOfDoku_Parser_Media extends TestOfDoku_Parser { + + function testVideoOGVExternal() { + $file = 'http://some.where.far/away.ogv'; + $parser_response = p_get_instructions('{{' . $file . '}}'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('externalmedia',array($file,null,null,null,null,'cache','details')), + array('cdata',array(null)), + array('p_close',array()), + array('document_end',array()), + ); + $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls); + + $Renderer = new Doku_Renderer_xhtml(); + $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true); + //print_r("url: " . $url); + $video = '<video class="media" width="320" height="240" controls="controls">'; + $this->assertEquals(substr($url,0,66),$video); + $source = '<source src="http://some.where.far/away.ogv" type="video/ogg" />'; + $this->assertEquals(substr($url,67,64),$source); + // work around random token + $a_first_part = '<a href="/./lib/exe/fetch.php?cache=&tok='; + $a_second_part = '&media=http%3A%2F%2Fsome.where.far%2Faway.ogv" class="media mediafile mf_ogv" title="http://some.where.far/away.ogv">'; + $this->assertEquals(substr($url,132,45),$a_first_part); + $this->assertEquals(substr($url,183,121),$a_second_part); + $rest = 'away.ogv</a></video>'."\n"; + $this->assertEquals(substr($url,304),$rest); + } + + /** + * unknown extension of external media file + */ + function testVideoVIDExternal() { + $file = 'http://some.where.far/away.vid'; + $parser_response = p_get_instructions('{{' . $file . '}}'); + + $calls = array( + array('document_start', array()), + array('p_open', array()), + array('externalmedia', array($file, null, null, null, null, 'cache', 'details')), + array('cdata', array(null)), + array('p_close', array()), + array('document_end', array()), + ); + $this->assertEquals(array_map('stripbyteindex', $parser_response), $calls); + + $Renderer = new Doku_Renderer_xhtml(); + $url = $Renderer->externalmedia($file, null, null, null, null, 'cache', 'details', true); + // work around random token + $a_first_part = '<a href="/./lib/exe/fetch.php?tok='; + $a_second_part = '&media=http%3A%2F%2Fsome.where.far%2Faway.vid" class="media mediafile mf_vid" title="http://some.where.far/away.vid">'; + $this->assertEquals(substr($url,0,34),$a_first_part); + $this->assertEquals(substr($url,40,121),$a_second_part); + $rest = 'away.vid</a>'; + $this->assertEquals(substr($url,161),$rest); + } + + + function testVideoOGVInternal() { + $file = 'wiki:kind_zu_katze.ogv'; + $parser_response = p_get_instructions('{{' . $file . '}}'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('internalmedia',array($file,null,null,null,null,'cache','details')), + array('cdata',array(null)), + array('p_close',array()), + array('document_end',array()), + ); + $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls); + + $Renderer = new Doku_Renderer_xhtml(); + $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true); + + $video = '<video class="media" width="320" height="240" controls="controls" poster="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.png">'; + $this->assertEquals(substr($url,0,125),$video); + + $source_webm = '<source src="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.webm" type="video/webm" />'; + $this->assertEquals(substr($url,126,85),$source_webm); + $source_ogv = '<source src="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.ogv" type="video/ogg" />'; + $this->assertEquals(substr($url,212,83),$source_ogv); + + $a_webm = '<a href="/./lib/exe/fetch.php?id=&cache=&media=wiki:kind_zu_katze.webm" class="media mediafile mf_webm" title="wiki:kind_zu_katze.webm (99.1 KB)">kind_zu_katze.webm</a>'; + $a_ogv = '<a href="/./lib/exe/fetch.php?id=&cache=&media=wiki:kind_zu_katze.ogv" class="media mediafile mf_ogv" title="wiki:kind_zu_katze.ogv (44.8 KB)">kind_zu_katze.ogv</a>'; + $this->assertEquals(substr($url,296,176),$a_webm); + $this->assertEquals(substr($url,472,172),$a_ogv); + + $rest = '</video>'."\n"; + $this->assertEquals(substr($url,644),$rest); + } +} diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php index dd1ed1d3f..772001b99 100644 --- a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php +++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php @@ -14,21 +14,23 @@ class Test_resolveInterwiki extends DokuWikiTest { $Renderer->interwiki['withslash'] = '/test'; $Renderer->interwiki['onlytext'] = ':onlytext{NAME}'; //with {URL} double urlencoded $Renderer->interwiki['withquery'] = ':anyns:{NAME}?do=edit'; + //this was the only link with host/port/path/query. Keep it here for regression + $Renderer->interwiki['coral'] = 'http://{HOST}.{PORT}.nyud.net:8090{PATH}?{QUERY}'; $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('wp', 'foo [\\]^`{|}~@+#%?/#txt', 'https://en.wikipedia.org/wiki/foo %5B%5C%5D%5E%60%7B%7C%7D~@+%23%25?/#txt'), + array('amazon', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.amazon.com/exec/obidos/ASIN/foo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F/splitbrain-20/#txt'), + array('doku', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.dokuwiki.org/foo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F#txt'), + array('coral', 'http://example.com:83/path/naar/?query=foo%20%40%2B%25%3F%2F', 'http://example.com.83.nyud.net:8090/path/naar/?query=foo%20%40%2B%25%3F%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'), + array('withslash', 'foo [\\]^`{|}~@+#%?/#txt', '/testfoo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F#txt'), + array('skype', 'foo [\\]^`{|}~@+#%?/#txt', 'skype:foo %5B%5C%5D%5E%60%7B%7C%7D~@+%23%25?/#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') + 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) { @@ -45,7 +47,7 @@ class Test_resolveInterwiki extends DokuWikiTest { $shortcut = 'nonexisting'; $reference = 'foo @+%/'; $url = $Renderer->_resolveInterWiki($shortcut, $reference); - $expected = 'http://www.google.com/search?q=foo%20%40%2B%25%2F&btnI=lucky'; + $expected = 'https://www.google.com/search?q=foo%20%40%2B%25%2F&btnI=lucky'; $this->assertEquals($expected, $url); } diff --git a/_test/tests/inc/remote.test.php b/_test/tests/inc/remote.test.php index d0d4eb7ce..037b1dc0b 100644 --- a/_test/tests/inc/remote.test.php +++ b/_test/tests/inc/remote.test.php @@ -160,10 +160,16 @@ class remote_test extends DokuWikiTest { $this->assertTrue($this->remote->hasAccess()); } + /** + * @expectedException RemoteAccessDeniedException + */ function test_hasAccessFail() { global $conf; $conf['remote'] = 0; - $this->assertFalse($this->remote->hasAccess()); + // the hasAccess() should throw a Exception to keep the same semantics with xmlrpc.php. + // because the user(xmlrpc) check remote before .--> (!$conf['remote']) die('XML-RPC server not enabled.'); + // so it must be a Exception when get here. + $this->remote->hasAccess(); } function test_hasAccessFailAcl() { diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php deleted file mode 100644 index 15453b16d..000000000 --- a/_test/tests/inc/tar.test.php +++ /dev/null @@ -1,454 +0,0 @@ -<?php - -class Tar_TestCase extends DokuWikiTest { - /** - * file extensions that several tests use - */ - protected $extensions = array('tar'); - - public function setUp() { - parent::setUp(); - if (extension_loaded('zlib')) { - $this->extensions[] = 'tgz'; - } - if (extension_loaded('bz2')) { - $this->extensions[] = 'tbz'; - } - } - - /* - * dependency for tests needing zlib extension to pass - */ - public function test_ext_zlib() { - if (!extension_loaded('zlib')) { - $this->markTestSkipped('skipping all zlib tests. Need zlib extension'); - } - } - - /* - * dependency for tests needing zlib extension to pass - */ - public function test_ext_bz2() { - if (!extension_loaded('bz2')) { - $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); - } - } - - /** - * simple test that checks that the given filenames and contents can be grepped from - * the uncompressed tar stream - * - * No check for format correctness - */ - public function test_createdynamic() { - $tar = new Tar(); - - $dir = dirname(__FILE__).'/tar'; - $tdir = ltrim($dir,'/'); - - $tar->create(); - $tar->AddFile("$dir/testdata1.txt"); - $tar->AddFile("$dir/foobar/testdata2.txt", 'noway/testdata2.txt'); - $tar->addData('another/testdata3.txt', 'testcontent3'); - - $data = $tar->getArchive(); - - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'Content in TAR'); - $this->assertTrue(strpos($data, 'testcontent2') !== false, 'Content in TAR'); - $this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in TAR'); - - // fullpath might be too long to be stored as full path FS#2802 - $this->assertTrue(strpos($data, "$tdir") !== false, 'Path in TAR'); - $this->assertTrue(strpos($data, "testdata1.txt") !== false, 'File in TAR'); - - $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR'); - $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR'); - - // fullpath might be too long to be stored as full path FS#2802 - $this->assertTrue(strpos($data, "$tdir/foobar") === false, 'Path not in TAR'); - $this->assertTrue(strpos($data, "foobar.txt") === false, 'File not in TAR'); - - $this->assertTrue(strpos($data, "foobar") === false, 'Path not in TAR'); - } - - /** - * simple test that checks that the given filenames and contents can be grepped from the - * uncompressed tar file - * - * No check for format correctness - */ - public function test_createfile() { - $tar = new Tar(); - - $dir = dirname(__FILE__).'/tar'; - $tdir = ltrim($dir,'/'); - $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); - - $tar->create($tmp, Tar::COMPRESS_NONE); - $tar->AddFile("$dir/testdata1.txt"); - $tar->AddFile("$dir/foobar/testdata2.txt", 'noway/testdata2.txt'); - $tar->addData('another/testdata3.txt', 'testcontent3'); - $tar->close(); - - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number - $data = file_get_contents($tmp); - - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'Content in TAR'); - $this->assertTrue(strpos($data, 'testcontent2') !== false, 'Content in TAR'); - $this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in TAR'); - - // fullpath might be too long to be stored as full path FS#2802 - $this->assertTrue(strpos($data, "$tdir") !== false, "Path in TAR '$tdir'"); - $this->assertTrue(strpos($data, "testdata1.txt") !== false, 'File in TAR'); - - $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR'); - $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR'); - - // fullpath might be too long to be stored as full path FS#2802 - $this->assertTrue(strpos($data, "$tdir/foobar") === false, 'Path not in TAR'); - $this->assertTrue(strpos($data, "foobar.txt") === false, 'File not in TAR'); - - $this->assertTrue(strpos($data, "foobar") === false, 'Path not in TAR'); - - @unlink($tmp); - } - - /** - * List the contents of the prebuilt TAR files - */ - public function test_tarcontent() { - $dir = dirname(__FILE__).'/tar'; - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $content = $tar->contents(); - - $this->assertCount(4, $content, "Contents of $file"); - $this->assertEquals('tar/testdata1.txt', $content[1]['filename'], "Contents of $file"); - $this->assertEquals(13, $content[1]['size'], "Contents of $file"); - - $this->assertEquals('tar/foobar/testdata2.txt', $content[3]['filename'], "Contents of $file"); - $this->assertEquals(13, $content[1]['size'], "Contents of $file"); - } - } - - /** - * Extract the prebuilt tar files - */ - public function test_tarextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out); - - clearstatcache(); - - $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file"); - - $this->assertFileExists($out.'/tar/foobar/testdata2.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/foobar/testdata2.txt'), "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Extract the prebuilt tar files with component stripping - */ - public function test_compstripextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out, 1); - - clearstatcache(); - - $this->assertFileExists($out.'/testdata1.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/testdata1.txt'), "Extracted $file"); - - $this->assertFileExists($out.'/foobar/testdata2.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/foobar/testdata2.txt'), "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Extract the prebuilt tar files with prefix stripping - */ - public function test_prefixstripextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out, 'tar/foobar/'); - - clearstatcache(); - - $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file"); - - $this->assertFileExists($out.'/testdata2.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/testdata2.txt'), "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Extract the prebuilt tar files with include regex - */ - public function test_includeextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out, '', '', '/\/foobar\//'); - - clearstatcache(); - - $this->assertFileNotExists($out.'/tar/testdata1.txt', "Extracted $file"); - - $this->assertFileExists($out.'/tar/foobar/testdata2.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/foobar/testdata2.txt'), "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Extract the prebuilt tar files with exclude regex - */ - public function test_excludeextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out, '', '/\/foobar\//'); - - clearstatcache(); - - $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file"); - - $this->assertFileNotExists($out.'/tar/foobar/testdata2.txt', "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Check the extension to compression guesser - */ - public function test_filetype() { - $tar = new Tar(); - $this->assertEquals(Tar::COMPRESS_NONE, $tar->filetype('foo')); - $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tgz')); - $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tGZ')); - $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tar.GZ')); - $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tar.gz')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tbz')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tBZ')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ2')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2')); - } - - /** - * @depends test_ext_zlib - */ - public function test_longpathextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach(array('ustar', 'gnu') as $format) { - $tar = new Tar(); - $tar->open("$dir/longpath-$format.tgz"); - $tar->extract($out); - - $this->assertFileExists($out.'/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/test.txt'); - - TestUtils::rdelete($out); - } - } - - // FS#1442 - public function test_createlongfile() { - $tar = new Tar(); - $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); - - $path = '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.txt'; - - $tar->create($tmp, Tar::COMPRESS_NONE); - $tar->addData($path, 'testcontent1'); - $tar->close(); - - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number - $data = file_get_contents($tmp); - - // We should find the complete path and a longlink entry - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR'); - $this->assertTrue(strpos($data, $path) !== false, 'path in TAR'); - $this->assertTrue(strpos($data, '@LongLink') !== false, '@LongLink in TAR'); - - @unlink($tmp); - } - - public function test_createlongpathustar() { - $tar = new Tar(); - $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); - - $path = ''; - for($i=0; $i<11; $i++) $path .= '1234567890/'; - $path = rtrim($path,'/'); - - $tar->create($tmp, Tar::COMPRESS_NONE); - $tar->addData("$path/test.txt", 'testcontent1'); - $tar->close(); - - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number - $data = file_get_contents($tmp); - - // We should find the path and filename separated, no longlink entry - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR'); - $this->assertTrue(strpos($data, 'test.txt') !== false, 'filename in TAR'); - $this->assertTrue(strpos($data, $path) !== false, 'path in TAR'); - $this->assertFalse(strpos($data, "$path/test.txt") !== false, 'full filename in TAR'); - $this->assertFalse(strpos($data, '@LongLink') !== false, '@LongLink in TAR'); - - @unlink($tmp); - } - - public function test_createlongpathgnu() { - $tar = new Tar(); - $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); - - $path = ''; - for($i=0; $i<20; $i++) $path .= '1234567890/'; - $path = rtrim($path,'/'); - - $tar->create($tmp, Tar::COMPRESS_NONE); - $tar->addData("$path/test.txt", 'testcontent1'); - $tar->close(); - - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number - $data = file_get_contents($tmp); - - // We should find the complete path/filename and a longlink entry - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR'); - $this->assertTrue(strpos($data, 'test.txt') !== false, 'filename in TAR'); - $this->assertTrue(strpos($data, $path) !== false, 'path in TAR'); - $this->assertTrue(strpos($data, "$path/test.txt") !== false, 'full filename in TAR'); - $this->assertTrue(strpos($data, '@LongLink') !== false, '@LongLink in TAR'); - - @unlink($tmp); - } - - /** - * Extract a tarbomomb - * @depends test_ext_zlib - */ - public function test_tarbomb() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - $tar = new Tar(); - - $tar->open("$dir/tarbomb.tgz"); - $tar->extract($out); - - clearstatcache(); - - $this->assertFileExists($out.'/AAAAAAAAAAAAAAAAA/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB.txt'); - - TestUtils::rdelete($out); - } - - /** - * A single zero file should be just a header block + the footer - */ - public function test_zerofile(){ - $dir = dirname(__FILE__).'/tar'; - $tar = new Tar(); - $tar->create(); - $tar->addFile("$dir/zero.txt", 'zero.txt'); - $file = $tar->getArchive(Tar::COMPRESS_NONE); - - $this->assertEquals(512*3, strlen($file)); // 1 header block + 2 footer blocks - } - - public function test_zerodata(){ - $tar = new Tar(); - $tar->create(); - $tar->addData('zero.txt',''); - $file = $tar->getArchive(Tar::COMPRESS_NONE); - - $this->assertEquals(512*3, strlen($file)); // 1 header block + 2 footer blocks - } - - /** - * A file of exactly one block should be just a header block + data block + the footer - */ - public function test_blockfile(){ - $dir = dirname(__FILE__).'/tar'; - $tar = new Tar(); - $tar->create(); - $tar->addFile("$dir/block.txt", 'block.txt'); - $file = $tar->getArchive(Tar::COMPRESS_NONE); - - $this->assertEquals(512*4, strlen($file)); // 1 header block + data block + 2 footer blocks - } - - public function test_blockdata(){ - $tar = new Tar(); - $tar->create(); - $tar->addData('block.txt', str_pad('', 512, 'x')); - $file = $tar->getArchive(Tar::COMPRESS_NONE); - - $this->assertEquals(512*4, strlen($file)); // 1 header block + data block + 2 footer blocks - } - - - public function test_cleanPath(){ - $tar = new Tar(); - $tests = array ( - '/foo/bar' => 'foo/bar', - '/foo/bar/' => 'foo/bar', - 'foo//bar' => 'foo/bar', - 'foo/0/bar' => 'foo/0/bar', - 'foo/../bar' => 'bar', - 'foo/bang/bang/../../bar' => 'foo/bar', - 'foo/../../bar' => 'bar', - 'foo/.././../bar' => 'bar', - ); - - foreach($tests as $in => $out){ - $this->assertEquals($out, $tar->cleanPath($in), "Input: $in"); - } - } -} diff --git a/_test/tests/inc/tar/block.txt b/_test/tests/inc/tar/block.txt deleted file mode 100644 index 9b2f53080..000000000 --- a/_test/tests/inc/tar/block.txt +++ /dev/null @@ -1 +0,0 @@ -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\ No newline at end of file diff --git a/_test/tests/inc/tar/foobar/testdata2.txt b/_test/tests/inc/tar/foobar/testdata2.txt deleted file mode 100644 index a7db15771..000000000 --- a/_test/tests/inc/tar/foobar/testdata2.txt +++ /dev/null @@ -1 +0,0 @@ -testcontent2 diff --git a/_test/tests/inc/tar/longpath-gnu.tgz b/_test/tests/inc/tar/longpath-gnu.tgz Binary files differdeleted file mode 100644 index 6c937c8fe..000000000 --- a/_test/tests/inc/tar/longpath-gnu.tgz +++ /dev/null diff --git a/_test/tests/inc/tar/longpath-ustar.tgz b/_test/tests/inc/tar/longpath-ustar.tgz Binary files differdeleted file mode 100644 index 59efbff66..000000000 --- a/_test/tests/inc/tar/longpath-ustar.tgz +++ /dev/null diff --git a/_test/tests/inc/tar/tarbomb.tgz b/_test/tests/inc/tar/tarbomb.tgz Binary files differdeleted file mode 100644 index 8418d4073..000000000 --- a/_test/tests/inc/tar/tarbomb.tgz +++ /dev/null diff --git a/_test/tests/inc/tar/test.tar b/_test/tests/inc/tar/test.tar Binary files differdeleted file mode 100644 index 931866b0b..000000000 --- a/_test/tests/inc/tar/test.tar +++ /dev/null diff --git a/_test/tests/inc/tar/test.tbz b/_test/tests/inc/tar/test.tbz Binary files differdeleted file mode 100644 index 5a7374019..000000000 --- a/_test/tests/inc/tar/test.tbz +++ /dev/null diff --git a/_test/tests/inc/tar/test.tgz b/_test/tests/inc/tar/test.tgz Binary files differdeleted file mode 100644 index b00319649..000000000 --- a/_test/tests/inc/tar/test.tgz +++ /dev/null diff --git a/_test/tests/inc/tar/testdata1.txt b/_test/tests/inc/tar/testdata1.txt deleted file mode 100644 index ac65bb32e..000000000 --- a/_test/tests/inc/tar/testdata1.txt +++ /dev/null @@ -1 +0,0 @@ -testcontent1 diff --git a/_test/tests/inc/tar/zero.txt b/_test/tests/inc/tar/zero.txt deleted file mode 100644 index e69de29bb..000000000 --- a/_test/tests/inc/tar/zero.txt +++ /dev/null diff --git a/_test/tests/inc/template_include_page.test.php b/_test/tests/inc/template_include_page.test.php index 47d4d46f1..7dd13ba23 100644 --- a/_test/tests/inc/template_include_page.test.php +++ b/_test/tests/inc/template_include_page.test.php @@ -1,40 +1,67 @@ <?php -class template_include_page_test extends DokuWikiTest { - function testNoSidebar() { - global $ID; +class template_pagetitle_test extends DokuWikiTest { - $ID = 'foo:bar:baz:test'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertEquals('', $sidebar); + function test_localID() { + global $ID,$ACT; + + + $id = 'foo:bar'; + + $ACT = 'show'; + $this->assertEquals('foo:bar', tpl_pagetitle($id, true)); } - function testExistingSidebars() { - global $ID; + function test_globalID() { + global $ID,$ACT; + - saveWikiText('sidebar', 'topsidebar-test', ''); + $ID = 'foo:bar'; - $ID = 'foo:bar:baz:test'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + $ACT = 'show'; + $this->assertEquals('foo:bar', tpl_pagetitle(null, true)); + } + + function test_adminTitle() { + global $ID,$ACT; - $ID = 'foo'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + $ID = 'foo:bar'; + + $ACT = 'admin'; + $this->assertEquals('Admin', tpl_pagetitle(null, true)); + } - saveWikiText('foo:bar:sidebar', 'bottomsidebar-test', ''); + function test_adminPluginTitle() { + global $ID,$ACT,$INPUT,$conf; - $ID = 'foo:bar:baz:test'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'bottomsidebar-test') > 0); + if (!plugin_load('admin','revert')) { + $this->markTestSkipped('Revert plugin not found, unable to test admin plugin titles'); + return; + } - $ID = 'foo:bar:test'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'bottomsidebar-test') > 0); + $ID = 'foo:bar'; + $ACT = 'admin'; + $conf['lang'] = 'en'; + $INPUT->set('page','revert'); - $ID = 'foo'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + $this->assertEquals('Revert Manager', tpl_pagetitle(null, true)); } + function test_nonPageFunctionTitle() { + global $ID,$ACT; + + $ID = 'foo:bar'; + + $ACT = 'index'; + $this->assertEquals('Sitemap', tpl_pagetitle(null, true)); + } + + function test_pageFunctionTitle() { + global $ID,$ACT; + + $ID = 'foo:bar'; + + $ACT = 'revisions'; + $this->assertEquals('foo:bar - Old revisions', tpl_pagetitle(null, true)); + } } diff --git a/_test/tests/lib/exe/js_js_compress.test.php b/_test/tests/lib/exe/js_js_compress.test.php index b1ae2a84f..648ede07e 100644 --- a/_test/tests/lib/exe/js_js_compress.test.php +++ b/_test/tests/lib/exe/js_js_compress.test.php @@ -58,6 +58,18 @@ class js_js_compress_test extends DokuWikiTest { $this->assertEquals(js_compress($text), 'text.replace(/"/,"//")'); } + function test_regex_after_and_with_slashes_outside_string(){ + $text = 'if ( peng == bla && /pattern\//.test(url)) request = new Something();'; + $this->assertEquals(js_compress($text), + 'if(peng==bla&&/pattern\//.test(url))request=new Something();'); + } + + function test_regex_after_or_with_slashes_outside_string(){ + $text = 'if ( peng == bla || /pattern\//.test(url)) request = new Something();'; + $this->assertEquals(js_compress($text), + 'if(peng==bla||/pattern\//.test(url))request=new Something();'); + } + function test_dquot1(){ $text = 'var foo="Now what \\" \'do we//get /*here*/ ?";'; $this->assertEquals(js_compress($text), $text); @@ -145,6 +157,72 @@ EOF; $this->assertEquals($out, js_compress($text)); } + function test_plusplus1(){ + $text = 'a = 5 + ++b;'; + $this->assertEquals('a=5+ ++b;',js_compress($text)); + } + + function test_plusplus2(){ + $text = 'a = 5+ ++b;'; + $this->assertEquals('a=5+ ++b;',js_compress($text)); + } + + function test_plusplus3(){ + $text = 'a = 5++ + b;'; + $this->assertEquals('a=5++ +b;',js_compress($text)); + } + + function test_plusplus4(){ + $text = 'a = 5++ +b;'; + $this->assertEquals('a=5++ +b;',js_compress($text)); + } + + function test_minusminus1(){ + $text = 'a = 5 - --b;'; + $this->assertEquals('a=5- --b;',js_compress($text)); + } + + function test_minusminus2(){ + $text = 'a = 5- --b;'; + $this->assertEquals('a=5- --b;',js_compress($text)); + } + + function test_minusminus3(){ + $text = 'a = 5-- - b;'; + $this->assertEquals('a=5-- -b;',js_compress($text)); + } + + function test_minusminus4(){ + $text = 'a = 5-- -b;'; + $this->assertEquals('a=5-- -b;',js_compress($text)); + } + + function test_minusplus1(){ + $text = 'a = 5-- +b;'; + $this->assertEquals('a=5--+b;',js_compress($text)); + } + + function test_minusplus2(){ + $text = 'a = 5-- + b;'; + $this->assertEquals('a=5--+b;',js_compress($text)); + } + + function test_plusminus1(){ + $text = 'a = 5++ - b;'; + $this->assertEquals('a=5++-b;',js_compress($text)); + } + + function test_plusminus2(){ + $text = 'a = 5++ -b;'; + $this->assertEquals('a=5++-b;',js_compress($text)); + } + + function test_unusual_signs(){ + $text='var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, radians = π / 180, degrees = 180 / π;'; + $this->assertEquals(js_compress($text), + 'var π=Math.PI,τ=2*π,halfπ=π/2,ε=1e-6,ε2=ε*ε,radians=π/180,degrees=180/π;'); + } + /** * Test the files provided with the original JsStrip */ |