From 4eb5e17453694b80e84a83a6960d02ac63cfa320 Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 13:27:38 +0100 Subject: add test getlastrevisionat --- .../tests/inc/changelog_getlastrevisionat.test.php | 127 +++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 _test/tests/inc/changelog_getlastrevisionat.test.php (limited to '_test/tests') diff --git a/_test/tests/inc/changelog_getlastrevisionat.test.php b/_test/tests/inc/changelog_getlastrevisionat.test.php new file mode 100644 index 000000000..b4d0466b3 --- /dev/null +++ b/_test/tests/inc/changelog_getlastrevisionat.test.php @@ -0,0 +1,127 @@ +getLastRevisionAt($rev); + $this->assertEquals($revsexpected, $revs); + } + + /** + * start at exact current revision of mailinglist page + * + */ + function test_startatexactcurrentrev() { + $rev = 1385051947; + $revsexpected = ''; + + //set a known timestamp + touch(wikiFN($this->pageid), $rev); + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revs = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revsexpected, $revs); + + } + + /** + * test a future revision + * + */ + function test_futurerev() { + $rev = 1385051947; + $revsexpected = ''; + + //set a known timestamp + touch(wikiFN($this->pageid), $rev); + + $rev +=1; + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revs = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revsexpected, $revs); + + } + + /** + * start at exact last revision of mailinglist page + * + */ + function test_exactlastrev() { + $rev = 1360110636; + $revsexpected = 1360110636; + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revs = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revsexpected, $revs); + } + + + /** + * Request not existing revision + * + */ + function test_olderrev() { + $rev = 1; + $revexpected = false; + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revfound = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revexpected, $revfound); + } + + /** + * Start at non existing revision somewhere between existing revisions + */ + function test_notexistingrev() { + $rev = 1362525890; + $revexpected = 1362525359; + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revfound = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revexpected, $revfound); + } + + /** + * request nonexisting page + * + */ + function test_notexistingpage() { + $rev = 1385051947; + $currentexpected = false; + + $pagelog = new PageChangeLog('nonexistingpage', $chunk_size = 8192); + $current = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($currentexpected, $current); + } +} \ No newline at end of file -- cgit v1.2.3 From 07a7d227f78d5956f62a4164def7c68ca03019ee Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 14:56:42 +0100 Subject: add test for empty rev in ml() and wl() --- _test/tests/inc/common_ml.test.php | 11 +++++++++++ _test/tests/inc/common_wl.test.php | 11 +++++++++++ 2 files changed, 22 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/common_ml.test.php b/_test/tests/inc/common_ml.test.php index 415c0a88d..027dcaef2 100644 --- a/_test/tests/inc/common_ml.test.php +++ b/_test/tests/inc/common_ml.test.php @@ -146,4 +146,15 @@ class common_ml_test extends DokuWikiTest { $this->assertEquals($expect, ml($id, $args)); } + + function test_ml_empty_rev() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $args = array('a' => 'b', 'c' => 'd', 'rev' => ''); + + $expect = DOKU_BASE . $this->script . '?a=b&c=d&media=some:img.jpg'; + $this->assertEquals($expect, ml('some:img.jpg', $args)); + } } diff --git a/_test/tests/inc/common_wl.test.php b/_test/tests/inc/common_wl.test.php index 2e34dcae3..4bfde3f39 100644 --- a/_test/tests/inc/common_wl.test.php +++ b/_test/tests/inc/common_wl.test.php @@ -142,6 +142,17 @@ class common_wl_test extends DokuWikiTest { $expect = DOKU_BASE . DOKU_SCRIPT . '/some/one?a=b&c=d'; $this->assertEquals($expect, wl('some:one', 'a=b,c=d', false, '&')); } + + function test_wl_empty_rev() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $args = array('a' => 'b', 'c' => 'd', 'rev' => ''); + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:&a=b&c=d'; + $this->assertEquals($expect, wl('some:', $args)); + } -- cgit v1.2.3 From 81e7bffefad6e652e45320e87d966712e5711efd Mon Sep 17 00:00:00 2001 From: lisps Date: Mon, 17 Feb 2014 23:48:05 +0100 Subject: rename classname --- _test/tests/inc/changelog_getlastrevisionat.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/inc/changelog_getlastrevisionat.test.php b/_test/tests/inc/changelog_getlastrevisionat.test.php index b4d0466b3..84b185ce8 100644 --- a/_test/tests/inc/changelog_getlastrevisionat.test.php +++ b/_test/tests/inc/changelog_getlastrevisionat.test.php @@ -7,7 +7,7 @@ * - data/pages/mailinglist.txt * - data/meta/mailinglist.changes */ -class changelog_getrelativerevision_test extends DokuWikiTest { +class changelog_getlastrevisionat_test extends DokuWikiTest { private $pageid = 'mailinglist'; -- cgit v1.2.3 From 496e3a6f34d97e44e44340c1fbd2d3cbc262c05c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 17 Mar 2014 23:03:53 +0100 Subject: completely new base for CLI scripts This introduces an abstract base class that command line tools need to inherit from. It provides a simple framework for registering accepted command line options and provides commonly needed things like help output and colored text. Existing CLI scripts still need to be converted. --- _test/tests/inc/cli_options.test.php | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 _test/tests/inc/cli_options.test.php (limited to '_test/tests') diff --git a/_test/tests/inc/cli_options.test.php b/_test/tests/inc/cli_options.test.php new file mode 100644 index 000000000..1d121d7ce --- /dev/null +++ b/_test/tests/inc/cli_options.test.php @@ -0,0 +1,56 @@ +registerOption('exclude', 'exclude files', 'x', true); + + $args = array('-x', 'foo', 'bang'); + $options->parseOptions($args); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $args); + $this->assertFalse($options->getOpt('nothing')); + } + + function test_simplelong1() { + $options = new DokuCLI_Options(); + $options->registerOption('exclude', 'exclude files', 'x', true); + + $args = array('--exclude', 'foo', 'bang'); + $options->parseOptions($args); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $args); + $this->assertFalse($options->getOpt('nothing')); + } + + function test_simplelong2() { + $options = new DokuCLI_Options(); + $options->registerOption('exclude', 'exclude files', 'x', true); + + $args = array('--exclude=foo', 'bang'); + $options->parseOptions($args); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $args); + $this->assertFalse($options->getOpt('nothing')); + } + + function test_complex() { + $options = new DokuCLI_Options(); + + $options->registerOption('plugins', 'run on plugins only', 'p'); + $options->registerCommand('status', 'display status info'); + $options->registerOption('long', 'display long lines', 'l', false, 'status'); + + $args = array('-p', 'status', '--long', 'foo'); + $options->parseOptions($args); + + $this->assertEquals('status', $options->getCmd()); + $this->assertTrue($options->getOpt('plugins')); + $this->assertTrue($options->getOpt('long')); + $this->assertEquals(array('foo'), $args); + } +} \ No newline at end of file -- cgit v1.2.3 From d48bcdb42c1e80fa258ebbd70d9fe6f649237a78 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 20 Mar 2014 21:01:06 +0100 Subject: fixed tests --- _test/tests/inc/cli_options.test.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to '_test/tests') diff --git a/_test/tests/inc/cli_options.test.php b/_test/tests/inc/cli_options.test.php index 1d121d7ce..ab03ee29b 100644 --- a/_test/tests/inc/cli_options.test.php +++ b/_test/tests/inc/cli_options.test.php @@ -4,37 +4,37 @@ class cli_options extends DokuWikiTest { function test_simpleshort() { $options = new DokuCLI_Options(); - $options->registerOption('exclude', 'exclude files', 'x', true); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); - $args = array('-x', 'foo', 'bang'); - $options->parseOptions($args); + $options->args = array('-x', 'foo', 'bang'); + $options->parseOptions(); $this->assertEquals('foo', $options->getOpt('exclude')); - $this->assertEquals(array('bang'), $args); + $this->assertEquals(array('bang'), $options->args); $this->assertFalse($options->getOpt('nothing')); } function test_simplelong1() { $options = new DokuCLI_Options(); - $options->registerOption('exclude', 'exclude files', 'x', true); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); - $args = array('--exclude', 'foo', 'bang'); - $options->parseOptions($args); + $options->args = array('--exclude', 'foo', 'bang'); + $options->parseOptions(); $this->assertEquals('foo', $options->getOpt('exclude')); - $this->assertEquals(array('bang'), $args); + $this->assertEquals(array('bang'), $options->args); $this->assertFalse($options->getOpt('nothing')); } function test_simplelong2() { $options = new DokuCLI_Options(); - $options->registerOption('exclude', 'exclude files', 'x', true); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); - $args = array('--exclude=foo', 'bang'); - $options->parseOptions($args); + $options->args = array('--exclude=foo', 'bang'); + $options->parseOptions(); $this->assertEquals('foo', $options->getOpt('exclude')); - $this->assertEquals(array('bang'), $args); + $this->assertEquals(array('bang'), $options->args); $this->assertFalse($options->getOpt('nothing')); } @@ -45,12 +45,12 @@ class cli_options extends DokuWikiTest { $options->registerCommand('status', 'display status info'); $options->registerOption('long', 'display long lines', 'l', false, 'status'); - $args = array('-p', 'status', '--long', 'foo'); - $options->parseOptions($args); + $options->args = array('-p', 'status', '--long', 'foo'); + $options->parseOptions(); $this->assertEquals('status', $options->getCmd()); $this->assertTrue($options->getOpt('plugins')); $this->assertTrue($options->getOpt('long')); - $this->assertEquals(array('foo'), $args); + $this->assertEquals(array('foo'), $options->args); } } \ No newline at end of file -- cgit v1.2.3 From 9d60a747702d8da1436fda4de3126116a7db002b Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 13 May 2014 16:14:44 +0100 Subject: Issue 694: fix failing test - set filemtimes explicitly in test setup --- _test/tests/inc/cache_use.test.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to '_test/tests') diff --git a/_test/tests/inc/cache_use.test.php b/_test/tests/inc/cache_use.test.php index c54a472a3..02fe329de 100644 --- a/_test/tests/inc/cache_use.test.php +++ b/_test/tests/inc/cache_use.test.php @@ -18,11 +18,14 @@ class cache_use_test extends DokuWikiTest { $conf['cachetime'] = 0; // ensure the value is not -1, which disables caching 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); $this->cache = new cache_renderer($ID, $file, 'xhtml'); $this->cache->storeCache('Test'); + + // set the modification times explicitly (overcome Issue #694) + $time = time(); + touch($file, $time-1); + touch($this->cache->cache, $time); } function test_use() { -- cgit v1.2.3 From e80146ebf289d9243a864b9c8db1d97ba9516724 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 13 May 2014 20:01:51 +0200 Subject: added another test for fe5a50 That commit did not test what it actually made for. Handling protocol relative URLs in CSS. --- _test/tests/lib/exe/css_css_compress.test.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/lib/exe/css_css_compress.test.php b/_test/tests/lib/exe/css_css_compress.test.php index f0eb17968..4769684a8 100644 --- a/_test/tests/lib/exe/css_css_compress.test.php +++ b/_test/tests/lib/exe/css_css_compress.test.php @@ -53,6 +53,13 @@ class css_css_compress_test extends DokuWikiTest { $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text)); } + function test_slcom6(){ + $text = '#foo { + background-image: url(//foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is all commented + }'; + $this->assertEquals('#foo{background-image:url(//foo.bar/baz.jpg);}', css_compress($text)); + } + function test_hack(){ $text = '/* Mac IE will not see this and continue with inline-block */ /* \\*/ -- cgit v1.2.3 From 918a4468877109c2ba2f82fa4e1a225a4738ed9a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 14 May 2014 19:24:01 +0200 Subject: don't treat double slashes as comments when used in string This avoids treating double slashes as single line comments in CSS when they are used in a filter or content string. closes #638 --- _test/tests/lib/exe/css_css_compress.test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/lib/exe/css_css_compress.test.php b/_test/tests/lib/exe/css_css_compress.test.php index 4769684a8..807317ca6 100644 --- a/_test/tests/lib/exe/css_css_compress.test.php +++ b/_test/tests/lib/exe/css_css_compress.test.php @@ -60,6 +60,14 @@ class css_css_compress_test extends DokuWikiTest { $this->assertEquals('#foo{background-image:url(//foo.bar/baz.jpg);}', css_compress($text)); } + function test_slcom7(){ + $text = '#foo a[href ^="https://"], #foo a[href ^=\'https://\'] { + background-image: url(//foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is \'all\' "commented" + }'; + $this->assertEquals('#foo a[href ^="https://"],#foo a[href ^=\'https://\']{background-image:url(//foo.bar/baz.jpg);}', css_compress($text)); + } + + function test_hack(){ $text = '/* Mac IE will not see this and continue with inline-block */ /* \\*/ -- cgit v1.2.3 From c42f789c87b115a747a7436d81e7aee886d0ac88 Mon Sep 17 00:00:00 2001 From: Enrico Tagliavini Date: Thu, 30 Jan 2014 15:42:09 +0000 Subject: Adding unit test for is_ssl() this should test the correctness of the return value of is_ssl() function based on various combinations of PHP environment variables --- _test/tests/inc/init_checkssl.test.php | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 _test/tests/inc/init_checkssl.test.php (limited to '_test/tests') diff --git a/_test/tests/inc/init_checkssl.test.php b/_test/tests/inc/init_checkssl.test.php new file mode 100644 index 000000000..c57d3c37e --- /dev/null +++ b/_test/tests/inc/init_checkssl.test.php @@ -0,0 +1,81 @@ +assertEquals(is_ssl(), true); + } + + /** + * Running behind a plain HTTP proxy, HTTP between server and proxy + * HTTPS not set + * HTTP_X_FORWARDED_PROTO set to http + */ + function test2() { + $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'http'; + + $this->assertEquals(is_ssl(), false); + } + + /** + * Running behind an SSL proxy, HTTP between server and proxy + * HTTPS set to off, + * HTTP_X_FORWARDED_PROTO set to https + */ + function test3() { + $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https'; + $_SERVER['HTTPS'] = 'off'; + + $this->assertEquals(is_ssl(), true); + } + + /** + * Not running behind a proxy, HTTPS server + * HTTPS set to on, + * HTTP_X_FORWARDED_PROTO not set + */ + function test4() { + $_SERVER['HTTPS'] = 'on'; + + $this->assertEquals(is_ssl(), true); + } + + /** + * Not running behind a proxy, plain HTTP server + * HTTPS not set + * HTTP_X_FORWARDED_PROTO not set + */ + function test5() { + $this->assertEquals(is_ssl(), false); + } + + /** + * Not running behind a proxy, plain HTTP server + * HTTPS set to off + * HTTP_X_FORWARDED_PROTO not set + */ + function test6() { + $_SERVER['HTTPS'] = 'off'; + $this->assertEquals(is_ssl(), false); + } + + /** + * Running behind an SSL proxy, SSL between proxy and HTTP server + * HTTPS set to on, + * HTTP_X_FORWARDED_PROTO set to https + */ + function test7() { + $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https'; + $_SERVER['HTTPS'] = 'on'; + + $this->assertEquals(is_ssl(), true); + } +} -- cgit v1.2.3 From a5ac1d91deb9f263c360e34096a469b3beb681f9 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jul 2014 12:19:31 +0200 Subject: skip cache test until #694 has been fixed --- _test/tests/inc/cache_use.test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/cache_use.test.php b/_test/tests/inc/cache_use.test.php index 02fe329de..3ea212d50 100644 --- a/_test/tests/inc/cache_use.test.php +++ b/_test/tests/inc/cache_use.test.php @@ -29,6 +29,9 @@ class cache_use_test extends DokuWikiTest { } function test_use() { + $this->markTestSkipped('Disabled until Ticket #694 has been fixed'); + return; + $this->assertTrue($this->cache->useCache()); } -- cgit v1.2.3 From 37abef5f8744159697aa2dc18cc468477f2ca965 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 23 Sep 2014 20:08:09 +0200 Subject: added filter method to INPUT class the filter() function can be chained between the accessor and the value function to get a filtered value. When no filter allable is given in the filter() function, stripctl() is used to strip all control chars (ASCII<32) Examples: $INPUT->post->filter()->str('foobar'); $INPUT->get->filter('myfilter')->int('baz'); --- _test/tests/inc/input.test.php | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/input.test.php b/_test/tests/inc/input.test.php index cec0b80f6..4a8fb8d71 100644 --- a/_test/tests/inc/input.test.php +++ b/_test/tests/inc/input.test.php @@ -14,8 +14,58 @@ class input_test extends DokuWikiTest { 'empty' => '', 'emptya' => array(), 'do' => array('save' => 'Speichern'), + ); + /** + * custom filter function + * + * @param $string + * @return mixed + */ + public function myfilter($string) { + $string = str_replace('foo', 'bar', $string); + $string = str_replace('baz', '', $string); + return $string; + } + + public function test_filter() { + $_GET = array( + 'foo' => 'foo', + 'zstring'=> "foo\0bar", + 'znull' => "\0", + 'zint' => '42'."\0".'42', + 'zintbaz'=> "baz42", + ); + $_POST = $_GET; + $_REQUEST = $_GET; + $INPUT = new Input(); + + $filter = array($this,'myfilter'); + + $this->assertNotSame('foobar', $INPUT->str('zstring')); + $this->assertSame('foobar', $INPUT->filter()->str('zstring')); + $this->assertSame('bar', $INPUT->filter($filter)->str('foo')); + $this->assertSame('bar', $INPUT->filter()->str('znull', 'bar', true)); + $this->assertNotSame('foobar', $INPUT->str('zstring')); // make sure original input is unmodified + + $this->assertNotSame('foobar', $INPUT->get->str('zstring')); + $this->assertSame('foobar', $INPUT->get->filter()->str('zstring')); + $this->assertSame('bar', $INPUT->get->filter($filter)->str('foo')); + $this->assertSame('bar', $INPUT->get->filter()->str('znull', 'bar', true)); + $this->assertNotSame('foobar', $INPUT->get->str('zstring')); // make sure original input is unmodified + + $this->assertNotSame(4242, $INPUT->int('zint')); + $this->assertSame(4242, $INPUT->filter()->int('zint')); + $this->assertSame(42, $INPUT->filter($filter)->int('zintbaz')); + $this->assertSame(42, $INPUT->filter()->str('znull', 42, true)); + + $this->assertSame(true, $INPUT->bool('znull')); + $this->assertSame(false, $INPUT->filter()->bool('znull')); + + $this->assertSame('foobar', $INPUT->filter()->valid('zstring', array('foobar', 'bang'))); + } + public function test_str() { $_REQUEST = $this->data; $_POST = $this->data; -- cgit v1.2.3