From bd4e67d289bd025f1285f39c1a3d29277c4f7102 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Mon, 18 Feb 2013 21:27:13 +0000 Subject: some unit test, more required --- _test/tests/inc/common_infofunctions.test.php | 112 ++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 _test/tests/inc/common_infofunctions.test.php (limited to '_test') diff --git a/_test/tests/inc/common_infofunctions.test.php b/_test/tests/inc/common_infofunctions.test.php new file mode 100644 index 000000000..b66e6f687 --- /dev/null +++ b/_test/tests/inc/common_infofunctions.test.php @@ -0,0 +1,112 @@ + '179ad45c6ce2cb97cf1029e212046e81', + 'name' => 'Arthur Dent', + 'mail' => 'arthur@example.com', + 'grps' => array ('admin','user'), + ); + $_SERVER['REMOTE_USER'] = 'testuser'; + $_SERVER['REMOTE_ADDR'] = '1.2.3.4'; + } + + function _get_info() { + global $USERINFO; + $info = array ( + 'isadmin' => true, + 'ismanager' => true, + 'userinfo' => $USERINFO, + 'perm' => 255, + 'namespace' => false, + 'ismobile' => false, + 'client' => 'testuser', + ); + + return $info; + } + + /** + * Its important to have the correct set of keys. + * Other functions provide the values + */ + function test_basicinfo(){ + // test with REMOTE_USER set and the user an admin user + $info = $this->_get_info(); + $this->assertEquals(basicinfo($ID,true),$info); + + // with $httpclient parameter set to false + unset($info['ismobile']); + $this->assertEquals(basicinfo($ID,false),$info); + + // with anonymous user + unset($_SERVER['REMOTE_USER']); + global $USERINFO; $USERINFO = array(); + + $info = array( + 'isadmin' => false, + 'ismanager' => false, + 'perm' => 8, + 'namespace' => false, + 'ismobile' => false, + 'client' => '1.2.3.4', + ); + $this->assertEquals(basicinfo($ID,true),$info); + } + + /** + * We're interested in the extra keys required for $INFO when its a page request + * and that $REV, $RANGE globals are set/cleared correctly + */ + function test_pageinfo(){ + global $ID,$conf; + $ID = 'wiki:start'; + + $info = $this->_get_info(); + $info['id'] = 'wiki:start'; + $info['namespace'] = 'wiki'; + $info['rev'] = null; + $info['subscribed'] = false; + $info['locked'] = false; + $info['filepath'] = $conf['datadir'].'/wiki/start.txt'; + $info['exists'] = false; + $info['writable'] = true; + $info['editable'] = true; + $info['lastmod'] = false; + $info['meta'] = array(); + $info['ip'] = null; + $info['user'] = null; + $info['sum'] = null; + $info['editor'] = null; + + // basic test, no revision + $this->assertEquals(pageinfo(),$info); + + // TODO: test with revision = current page + + // TODO: test with true revision + + // TODO: test with revision & range + } + + /** + * We're interested in the extra keys for $INFO when its a media request + */ + function test_mediainfo(){ + global $NS, $IMG; + $NS = ''; + $IMG = 'testimage.png'; + + $info = $this->_get_info(); + $info['image'] = 'testimage.png'; + + $this->assertEquals(mediainfo(),$info); + } +} + +//Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 177daee5492e8c3cdfdb950cdf61a6798f7a9586 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 21 Feb 2013 17:22:50 +0000 Subject: another test todo --- _test/tests/inc/common_infofunctions.test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/common_infofunctions.test.php b/_test/tests/inc/common_infofunctions.test.php index b66e6f687..2e383ef8b 100644 --- a/_test/tests/inc/common_infofunctions.test.php +++ b/_test/tests/inc/common_infofunctions.test.php @@ -92,6 +92,8 @@ class common_infofunctions_test extends DokuWikiTest { // TODO: test with true revision // TODO: test with revision & range + + // TODO: validate against the same test run on master branch pre this change } /** -- cgit v1.2.3 From 7ae29fa453970036576e8b18fe228c24a25e94ff Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Mon, 25 Feb 2013 15:00:16 +0000 Subject: refactor info functions test pageinfo() test no longer required, unit test committed elsewhere and verified against both previous and updated versions of pageinfo() fn. basicinfo() and mediainfo() tests separated each into their own test file. --- _test/tests/inc/common_basicinfo.test.php | 114 ++++++++++++++++++++++++++ _test/tests/inc/common_infofunctions.test.php | 114 -------------------------- _test/tests/inc/common_mediainfo.test.php | 49 +++++++++++ 3 files changed, 163 insertions(+), 114 deletions(-) create mode 100644 _test/tests/inc/common_basicinfo.test.php delete mode 100644 _test/tests/inc/common_infofunctions.test.php create mode 100644 _test/tests/inc/common_mediainfo.test.php (limited to '_test') diff --git a/_test/tests/inc/common_basicinfo.test.php b/_test/tests/inc/common_basicinfo.test.php new file mode 100644 index 000000000..2e383ef8b --- /dev/null +++ b/_test/tests/inc/common_basicinfo.test.php @@ -0,0 +1,114 @@ + '179ad45c6ce2cb97cf1029e212046e81', + 'name' => 'Arthur Dent', + 'mail' => 'arthur@example.com', + 'grps' => array ('admin','user'), + ); + $_SERVER['REMOTE_USER'] = 'testuser'; + $_SERVER['REMOTE_ADDR'] = '1.2.3.4'; + } + + function _get_info() { + global $USERINFO; + $info = array ( + 'isadmin' => true, + 'ismanager' => true, + 'userinfo' => $USERINFO, + 'perm' => 255, + 'namespace' => false, + 'ismobile' => false, + 'client' => 'testuser', + ); + + return $info; + } + + /** + * Its important to have the correct set of keys. + * Other functions provide the values + */ + function test_basicinfo(){ + // test with REMOTE_USER set and the user an admin user + $info = $this->_get_info(); + $this->assertEquals(basicinfo($ID,true),$info); + + // with $httpclient parameter set to false + unset($info['ismobile']); + $this->assertEquals(basicinfo($ID,false),$info); + + // with anonymous user + unset($_SERVER['REMOTE_USER']); + global $USERINFO; $USERINFO = array(); + + $info = array( + 'isadmin' => false, + 'ismanager' => false, + 'perm' => 8, + 'namespace' => false, + 'ismobile' => false, + 'client' => '1.2.3.4', + ); + $this->assertEquals(basicinfo($ID,true),$info); + } + + /** + * We're interested in the extra keys required for $INFO when its a page request + * and that $REV, $RANGE globals are set/cleared correctly + */ + function test_pageinfo(){ + global $ID,$conf; + $ID = 'wiki:start'; + + $info = $this->_get_info(); + $info['id'] = 'wiki:start'; + $info['namespace'] = 'wiki'; + $info['rev'] = null; + $info['subscribed'] = false; + $info['locked'] = false; + $info['filepath'] = $conf['datadir'].'/wiki/start.txt'; + $info['exists'] = false; + $info['writable'] = true; + $info['editable'] = true; + $info['lastmod'] = false; + $info['meta'] = array(); + $info['ip'] = null; + $info['user'] = null; + $info['sum'] = null; + $info['editor'] = null; + + // basic test, no revision + $this->assertEquals(pageinfo(),$info); + + // TODO: test with revision = current page + + // TODO: test with true revision + + // TODO: test with revision & range + + // TODO: validate against the same test run on master branch pre this change + } + + /** + * We're interested in the extra keys for $INFO when its a media request + */ + function test_mediainfo(){ + global $NS, $IMG; + $NS = ''; + $IMG = 'testimage.png'; + + $info = $this->_get_info(); + $info['image'] = 'testimage.png'; + + $this->assertEquals(mediainfo(),$info); + } +} + +//Setup VIM: ex: et ts=4 : diff --git a/_test/tests/inc/common_infofunctions.test.php b/_test/tests/inc/common_infofunctions.test.php deleted file mode 100644 index 2e383ef8b..000000000 --- a/_test/tests/inc/common_infofunctions.test.php +++ /dev/null @@ -1,114 +0,0 @@ - '179ad45c6ce2cb97cf1029e212046e81', - 'name' => 'Arthur Dent', - 'mail' => 'arthur@example.com', - 'grps' => array ('admin','user'), - ); - $_SERVER['REMOTE_USER'] = 'testuser'; - $_SERVER['REMOTE_ADDR'] = '1.2.3.4'; - } - - function _get_info() { - global $USERINFO; - $info = array ( - 'isadmin' => true, - 'ismanager' => true, - 'userinfo' => $USERINFO, - 'perm' => 255, - 'namespace' => false, - 'ismobile' => false, - 'client' => 'testuser', - ); - - return $info; - } - - /** - * Its important to have the correct set of keys. - * Other functions provide the values - */ - function test_basicinfo(){ - // test with REMOTE_USER set and the user an admin user - $info = $this->_get_info(); - $this->assertEquals(basicinfo($ID,true),$info); - - // with $httpclient parameter set to false - unset($info['ismobile']); - $this->assertEquals(basicinfo($ID,false),$info); - - // with anonymous user - unset($_SERVER['REMOTE_USER']); - global $USERINFO; $USERINFO = array(); - - $info = array( - 'isadmin' => false, - 'ismanager' => false, - 'perm' => 8, - 'namespace' => false, - 'ismobile' => false, - 'client' => '1.2.3.4', - ); - $this->assertEquals(basicinfo($ID,true),$info); - } - - /** - * We're interested in the extra keys required for $INFO when its a page request - * and that $REV, $RANGE globals are set/cleared correctly - */ - function test_pageinfo(){ - global $ID,$conf; - $ID = 'wiki:start'; - - $info = $this->_get_info(); - $info['id'] = 'wiki:start'; - $info['namespace'] = 'wiki'; - $info['rev'] = null; - $info['subscribed'] = false; - $info['locked'] = false; - $info['filepath'] = $conf['datadir'].'/wiki/start.txt'; - $info['exists'] = false; - $info['writable'] = true; - $info['editable'] = true; - $info['lastmod'] = false; - $info['meta'] = array(); - $info['ip'] = null; - $info['user'] = null; - $info['sum'] = null; - $info['editor'] = null; - - // basic test, no revision - $this->assertEquals(pageinfo(),$info); - - // TODO: test with revision = current page - - // TODO: test with true revision - - // TODO: test with revision & range - - // TODO: validate against the same test run on master branch pre this change - } - - /** - * We're interested in the extra keys for $INFO when its a media request - */ - function test_mediainfo(){ - global $NS, $IMG; - $NS = ''; - $IMG = 'testimage.png'; - - $info = $this->_get_info(); - $info['image'] = 'testimage.png'; - - $this->assertEquals(mediainfo(),$info); - } -} - -//Setup VIM: ex: et ts=4 : diff --git a/_test/tests/inc/common_mediainfo.test.php b/_test/tests/inc/common_mediainfo.test.php new file mode 100644 index 000000000..0e67fbcd9 --- /dev/null +++ b/_test/tests/inc/common_mediainfo.test.php @@ -0,0 +1,49 @@ + '179ad45c6ce2cb97cf1029e212046e81', + 'name' => 'Arthur Dent', + 'mail' => 'arthur@example.com', + 'grps' => array ('admin','user'), + ); + $_SERVER['REMOTE_USER'] = 'testuser'; + $_SERVER['REMOTE_ADDR'] = '1.2.3.4'; + } + + function _get_info() { + global $USERINFO; + $info = array ( + 'isadmin' => true, + 'ismanager' => true, + 'userinfo' => $USERINFO, + 'perm' => 255, + 'namespace' => false, + 'ismobile' => false, + 'client' => 'testuser', + ); + + return $info; + } + + /** + * We're interested in the extra keys for $INFO when its a media request + */ + function test_mediainfo(){ + global $NS, $IMG; + $NS = ''; + $IMG = 'testimage.png'; + + $info = $this->_get_info(); + $info['image'] = 'testimage.png'; + + $this->assertEquals(mediainfo(),$info); + } +} + +//Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 5ba389b2134d71e9b0a8b78a465bb4e8849ab664 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Mon, 25 Feb 2013 15:10:39 +0000 Subject: (incl. the refactored file) --- _test/tests/inc/common_basicinfo.test.php | 50 ------------------------------- 1 file changed, 50 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/common_basicinfo.test.php b/_test/tests/inc/common_basicinfo.test.php index 2e383ef8b..0369474c9 100644 --- a/_test/tests/inc/common_basicinfo.test.php +++ b/_test/tests/inc/common_basicinfo.test.php @@ -59,56 +59,6 @@ class common_infofunctions_test extends DokuWikiTest { $this->assertEquals(basicinfo($ID,true),$info); } - /** - * We're interested in the extra keys required for $INFO when its a page request - * and that $REV, $RANGE globals are set/cleared correctly - */ - function test_pageinfo(){ - global $ID,$conf; - $ID = 'wiki:start'; - - $info = $this->_get_info(); - $info['id'] = 'wiki:start'; - $info['namespace'] = 'wiki'; - $info['rev'] = null; - $info['subscribed'] = false; - $info['locked'] = false; - $info['filepath'] = $conf['datadir'].'/wiki/start.txt'; - $info['exists'] = false; - $info['writable'] = true; - $info['editable'] = true; - $info['lastmod'] = false; - $info['meta'] = array(); - $info['ip'] = null; - $info['user'] = null; - $info['sum'] = null; - $info['editor'] = null; - - // basic test, no revision - $this->assertEquals(pageinfo(),$info); - - // TODO: test with revision = current page - - // TODO: test with true revision - - // TODO: test with revision & range - - // TODO: validate against the same test run on master branch pre this change - } - - /** - * We're interested in the extra keys for $INFO when its a media request - */ - function test_mediainfo(){ - global $NS, $IMG; - $NS = ''; - $IMG = 'testimage.png'; - - $info = $this->_get_info(); - $info['image'] = 'testimage.png'; - - $this->assertEquals(mediainfo(),$info); - } } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 826d276602b191ee09d3450f7a8f9476c0e787b1 Mon Sep 17 00:00:00 2001 From: Klap-in Date: Tue, 21 May 2013 12:06:16 +0200 Subject: Clean internal ids in ml(), that it matches with fetch.php The resize token was broken because fetch.php cleans the id before the token calculation, while ml() uses the raw id --- _test/tests/inc/common_ml.test.php | 52 ++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 8 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/common_ml.test.php b/_test/tests/inc/common_ml.test.php index 0abfde37a..9f3d87598 100644 --- a/_test/tests/inc/common_ml.test.php +++ b/_test/tests/inc/common_ml.test.php @@ -20,8 +20,8 @@ class common_ml_test extends DokuWikiTest { $args = array('a' => 'b', 'c' => 'd', 'q' => '&รค'); - $expect = DOKU_BASE . $this->script . '?a=b&c=d&q=%26%C3%A4&media=some:'; - $this->assertEquals($expect, ml('some:', $args)); + $expect = DOKU_BASE . $this->script . '?a=b&c=d&q=%26%C3%A4&media=some:img.jpg'; + $this->assertEquals($expect, ml('some:img.jpg', $args)); } function test_ml_args_string() { @@ -31,8 +31,8 @@ class common_ml_test extends DokuWikiTest { $args = 'a=b&c=d'; - $expect = DOKU_BASE . $this->script . '?a=b&c=d&media=some:'; - $this->assertEquals($expect, ml('some:', $args)); + $expect = DOKU_BASE . $this->script . '?a=b&c=d&media=some:img.png'; + $this->assertEquals($expect, ml('some:img.png', $args)); } function test_ml_args_comma_string() { @@ -42,8 +42,8 @@ class common_ml_test extends DokuWikiTest { $args = 'a=b,c=d'; - $expect = DOKU_BASE . $this->script . '?a=b&c=d&media=some:'; - $this->assertEquals($expect, ml('some:', $args)); + $expect = DOKU_BASE . $this->script . '?a=b&c=d&media=some:img.gif'; + $this->assertEquals($expect, ml('some:img.gif', $args)); } @@ -52,7 +52,7 @@ class common_ml_test extends DokuWikiTest { $conf['useslash'] = 0; $conf['userewrite'] = 0; - $id = 'some:'; + $id = 'some:img.png'; $w = 80; $args = array('w' => $w); $tok = media_get_token($id,$w,0); @@ -66,7 +66,7 @@ class common_ml_test extends DokuWikiTest { $conf['useslash'] = 0; $conf['userewrite'] = 0; - $id = 'some:'; + $id = 'some:img.png'; $w = 80; $args = 'w='.$w; $tok = media_get_token($id,$w,0); @@ -74,4 +74,40 @@ class common_ml_test extends DokuWikiTest { $expect = DOKU_BASE . $this->script . '?w='.$w.'&tok='.$tok.'&media='.$id; $this->assertEquals($expect, ml($id, $args)); } + + function test_ml_imgresize_array_rootid() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $id = ':wiki:dokuwiki-128.png'; + $cleanid = 'wiki:dokuwiki-128.png'; + $w = 80; + $args = array('w' => $w); + $tok = media_get_token($cleanid, $w, 0); + + $expect = DOKU_BASE.$this->script.'?w='.$w.'&tok='.$tok.'&media='.$cleanid; + $this->assertEquals($expect, ml($id, $args)); + } + + function test_ml_imgresize_array_external() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $ids = array( + 'https://example.com/lib/tpl/dokuwiki/images/logo.png', + 'http://example.com/lib/tpl/dokuwiki/images/logo.png', + 'ftp://example.com/lib/tpl/dokuwiki/images/logo.png' + ); + $w = 80; + $args = array('w' => $w); + + foreach($ids as $id) { + $tok = media_get_token($id, $w, 0); + + $expect = DOKU_BASE.$this->script.'?hash='.substr(md5(auth_cookiesalt().$id), 0, 6).'&w='.$w.'&tok='.$tok.'&media='.rawurlencode($id); + $this->assertEquals($expect, ml($id, $args)); + } + } } -- cgit v1.2.3 From dcb2204bf0a8e3e25bf4ff8352a71160e846266b Mon Sep 17 00:00:00 2001 From: Klap-in Date: Tue, 21 May 2013 12:24:40 +0200 Subject: Add some tests about handling of semicolons Informative as sample implementation too --- _test/tests/inc/pageutils_clean_id.test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/pageutils_clean_id.test.php b/_test/tests/inc/pageutils_clean_id.test.php index 9c5781b24..478fd2bc4 100644 --- a/_test/tests/inc/pageutils_clean_id.test.php +++ b/_test/tests/inc/pageutils_clean_id.test.php @@ -43,6 +43,10 @@ class init_clean_id_test extends DokuWikiTest { $tests[] = array('ns._#!ns:page','false','ns._ns:page'); $tests[] = array('ns_:page',false,'ns:page'); $tests[] = array('page...page','false','page...page'); + $tests[] = array(':page',false,'page'); + $tests[] = array(':ns:page',false,'ns:page'); + $tests[] = array('page:',false,'page'); + $tests[] = array('ns:page:',false,'ns:page'); $conf['useslash'] = 0; $tests[] = array('page/page',false,'page_page'); -- cgit v1.2.3 From 5287f99cf079142a71032cbbfaffbd32a5bd6f3d Mon Sep 17 00:00:00 2001 From: Klap-in Date: Tue, 21 May 2013 22:51:07 +0200 Subject: tests for media_isexternal --- _test/tests/inc/media_isexternal.test.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 _test/tests/inc/media_isexternal.test.php (limited to '_test') diff --git a/_test/tests/inc/media_isexternal.test.php b/_test/tests/inc/media_isexternal.test.php new file mode 100644 index 000000000..cf5f793e4 --- /dev/null +++ b/_test/tests/inc/media_isexternal.test.php @@ -0,0 +1,22 @@ +assertTrue(media_isexternal('http://www.example.com/foo.png')); + $this->assertTrue(media_isexternal('https://www.example.com/foo.png')); + $this->assertTrue(media_isexternal('ftp://www.example.com/foo.png')); + $this->assertTrue(media_isexternal('hTTp://www.example.com/foo.png')); + $this->assertTrue(media_isexternal('hTTps://www.example.com/foo.png')); + $this->assertTrue(media_isexternal('Ftp://www.example.com/foo.png')); + } + + public function test_internal(){ + $this->assertFalse(media_isexternal('wiki:logo.png')); + $this->assertFalse(media_isexternal('private:logo.png')); + $this->assertFalse(media_isexternal('ftp:private:logo.png')); + + } + +} \ No newline at end of file -- cgit v1.2.3 From 62765857f84626449d6c53b1a46c462a37e5083a Mon Sep 17 00:00:00 2001 From: Klap-in Date: Sun, 9 Jun 2013 21:17:20 +0200 Subject: update common_ml test for hash change --- _test/tests/inc/common_ml.test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to '_test') diff --git a/_test/tests/inc/common_ml.test.php b/_test/tests/inc/common_ml.test.php index 9f3d87598..6f3b71db4 100644 --- a/_test/tests/inc/common_ml.test.php +++ b/_test/tests/inc/common_ml.test.php @@ -105,8 +105,9 @@ class common_ml_test extends DokuWikiTest { foreach($ids as $id) { $tok = media_get_token($id, $w, 0); + $hash = substr(PassHash::hmac('md5', $id, auth_cookiesalt()), 0, 6); - $expect = DOKU_BASE.$this->script.'?hash='.substr(md5(auth_cookiesalt().$id), 0, 6).'&w='.$w.'&tok='.$tok.'&media='.rawurlencode($id); + $expect = DOKU_BASE.$this->script.'?hash='.$hash.'&w='.$w.'&tok='.$tok.'&media='.rawurlencode($id); $this->assertEquals($expect, ml($id, $args)); } } -- cgit v1.2.3