From d37a395509092f21060e2a042a2be0ea759f6d0b Mon Sep 17 00:00:00 2001 From: Tom N Harris Date: Tue, 19 Jun 2012 03:17:21 -0400 Subject: Unit test for HTTPClient chunked encoding --- _test/tests/inc/httpclient_http.test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index 9cae3736a..cf8137152 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -176,5 +176,15 @@ class httpclient_http_test extends DokuWikiTest { $this->assertArrayHasKey('foo',$http->resp_headers); $this->assertEquals('bar',$http->resp_headers['foo']); } + + /** + * @group internet + */ + function test_chunked(){ + $http = new HTTPClient(); + $data = $http->get('http://whoopdedo.org/cgi-bin/chunked/2550'); + $this->assertFalse($data === false, 'HTTP response'); + $this->assertEquals(2550,strlen($data)); + } } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 769b429a77368df14e3753f624466f658e971df6 Mon Sep 17 00:00:00 2001 From: Tom N Harris Date: Wed, 20 Jun 2012 03:00:18 -0400 Subject: HTTPClient will read up to max_bodysize if it can --- _test/tests/inc/httpclient_http.test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index cf8137152..c3ee182dc 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -124,6 +124,12 @@ class httpclient_http_test extends DokuWikiTest { $http->max_bodysize = 250; $data = $http->get($this->server.'/stream/30'); $this->assertTrue($data === false, 'HTTP response'); + $http->max_bodysize_abort = false; + $data = $http->get($this->server.'/stream/30'); + $this->assertFalse($data === false, 'HTTP response'); + /* the current implementation will read in max_bodysize blocks, + and aborts if the response is larger, thus a limit of 2*max_bodysize */ + $this->assertLessThanOrEqual(500,strlen($data)); } /** -- cgit v1.2.3 From 591acd873d64abb271864b581c48ca419aa5d329 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 25 Jun 2012 00:37:21 +0200 Subject: some Input class fixes and unit tests --- _test/tests/inc/input.test.php | 206 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 _test/tests/inc/input.test.php (limited to '_test/tests/inc') diff --git a/_test/tests/inc/input.test.php b/_test/tests/inc/input.test.php new file mode 100644 index 000000000..627af3a2b --- /dev/null +++ b/_test/tests/inc/input.test.php @@ -0,0 +1,206 @@ + array('foo', 'bar'), + 'string' => 'foo', + 'int' => '17', + 'zero' => '0', + 'one' => '1', + 'empty' => '', + 'emptya' => array() + ); + + public function test_str() { + $_REQUEST = $this->data; + $_POST = $this->data; + $_GET = $this->data; + $_GET['get'] = 1; + $_POST['post'] = 1; + $INPUT = new Input(); + + $this->assertSame('foo', $INPUT->str('string')); + $this->assertSame('', $INPUT->str('none')); + $this->assertSame('', $INPUT->str('empty')); + $this->assertSame('foo', $INPUT->str('none', 'foo')); + $this->assertSame('', $INPUT->str('empty', 'foo')); + $this->assertSame('foo', $INPUT->str('empty', 'foo', true)); + + $this->assertSame(false, $INPUT->str('get', false)); + $this->assertSame(false, $INPUT->str('post', false)); + + $this->assertSame('foo', $INPUT->post->str('string')); + $this->assertSame('', $INPUT->post->str('none')); + $this->assertSame('', $INPUT->post->str('empty')); + $this->assertSame('foo', $INPUT->post->str('none', 'foo')); + $this->assertSame('', $INPUT->post->str('empty', 'foo')); + $this->assertSame('foo', $INPUT->post->str('empty', 'foo', true)); + + $this->assertSame(false, $INPUT->post->str('get', false)); + $this->assertSame('1', $INPUT->post->str('post', false)); + + $this->assertSame('foo', $INPUT->get->str('string')); + $this->assertSame('', $INPUT->get->str('none')); + $this->assertSame('', $INPUT->get->str('empty')); + $this->assertSame('foo', $INPUT->get->str('none', 'foo')); + $this->assertSame('', $INPUT->get->str('empty', 'foo')); + $this->assertSame('foo', $INPUT->get->str('empty', 'foo', true)); + + $this->assertSame(false, $INPUT->get->str('post', false)); + $this->assertSame('1', $INPUT->get->str('get', false)); + + $this->assertSame('', $INPUT->str('array')); + } + + public function test_int() { + $_REQUEST = $this->data; + $_POST = $this->data; + $_GET = $this->data; + $_GET['get'] = 1; + $_POST['post'] = 1; + $INPUT = new Input(); + + $this->assertSame(17, $INPUT->int('int')); + $this->assertSame(0, $INPUT->int('none')); + $this->assertSame(0, $INPUT->int('empty')); + $this->assertSame(42, $INPUT->int('none', 42)); + $this->assertSame(0, $INPUT->int('zero', 42)); + $this->assertSame(42, $INPUT->int('zero', 42, true)); + + $this->assertSame(false, $INPUT->int('get', false)); + $this->assertSame(false, $INPUT->int('post', false)); + + $this->assertSame(17, $INPUT->post->int('int')); + $this->assertSame(0, $INPUT->post->int('none')); + $this->assertSame(0, $INPUT->post->int('empty')); + $this->assertSame(42, $INPUT->post->int('none', 42)); + $this->assertSame(0, $INPUT->post->int('zero', 42)); + $this->assertSame(42, $INPUT->post->int('zero', 42, true)); + + $this->assertSame(false, $INPUT->post->int('get', false)); + $this->assertSame(1, $INPUT->post->int('post', false)); + + $this->assertSame(17, $INPUT->post->int('int')); + $this->assertSame(0, $INPUT->post->int('none')); + $this->assertSame(0, $INPUT->post->int('empty')); + $this->assertSame(42, $INPUT->post->int('none', 42)); + $this->assertSame(0, $INPUT->post->int('zero', 42)); + $this->assertSame(42, $INPUT->post->int('zero', 42, true)); + + $this->assertSame(false, $INPUT->get->int('post', false)); + $this->assertSame(1, $INPUT->get->int('get', false)); + + $this->assertSame(0, $INPUT->int('array')); + } + + public function test_arr() { + $_REQUEST = $this->data; + $_POST = $this->data; + $_GET = $this->data; + $_GET['get'] = array(1, 2); + $_POST['post'] = array(1, 2); + $INPUT = new Input(); + + $this->assertSame(array('foo', 'bar'), $INPUT->arr('array')); + $this->assertSame(array(), $INPUT->arr('none')); + $this->assertSame(array(), $INPUT->arr('empty')); + $this->assertSame(array(1, 2), $INPUT->arr('none', array(1, 2))); + $this->assertSame(array(), $INPUT->arr('emptya', array(1, 2))); + $this->assertSame(array(1, 2), $INPUT->arr('emptya', array(1, 2), true)); + + $this->assertSame(false, $INPUT->arr('get', false)); + $this->assertSame(false, $INPUT->arr('post', false)); + + $this->assertSame(array('foo', 'bar'), $INPUT->post->arr('array')); + $this->assertSame(array(), $INPUT->post->arr('none')); + $this->assertSame(array(), $INPUT->post->arr('empty')); + $this->assertSame(array(1, 2), $INPUT->post->arr('none', array(1, 2))); + $this->assertSame(array(), $INPUT->post->arr('emptya', array(1, 2))); + $this->assertSame(array(1, 2), $INPUT->post->arr('emptya', array(1, 2), true)); + + $this->assertSame(false, $INPUT->post->arr('get', false)); + $this->assertSame(array(1, 2), $INPUT->post->arr('post', false)); + + $this->assertSame(array('foo', 'bar'), $INPUT->get->arr('array')); + $this->assertSame(array(), $INPUT->get->arr('none')); + $this->assertSame(array(), $INPUT->get->arr('empty')); + $this->assertSame(array(1, 2), $INPUT->get->arr('none', array(1, 2))); + $this->assertSame(array(), $INPUT->get->arr('emptya', array(1, 2))); + $this->assertSame(array(1, 2), $INPUT->get->arr('emptya', array(1, 2), true)); + + $this->assertSame(array(1, 2), $INPUT->get->arr('get', false)); + $this->assertSame(false, $INPUT->get->arr('post', false)); + } + + public function test_bool() { + $_REQUEST = $this->data; + $_POST = $this->data; + $_GET = $this->data; + $_GET['get'] = '1'; + $_POST['post'] = '1'; + $INPUT = new Input(); + + $this->assertSame(true, $INPUT->bool('one')); + $this->assertSame(false, $INPUT->bool('zero')); + + $this->assertSame(false, $INPUT->bool('get')); + $this->assertSame(false, $INPUT->bool('post')); + + $this->assertSame(true, $INPUT->post->bool('one')); + $this->assertSame(false, $INPUT->post->bool('zero')); + + $this->assertSame(false, $INPUT->post->bool('get')); + $this->assertSame(true, $INPUT->post->bool('post')); + } + + public function test_remove() { + $_REQUEST = $this->data; + $_POST = $this->data; + $_GET = $this->data; + $INPUT = new Input(); + + $INPUT->remove('string'); + $this->assertNull($_REQUEST['string']); + $this->assertNull($_POST['string']); + $this->assertNull($_GET['string']); + + $INPUT->post->remove('int'); + $this->assertNull($_POST['int']); + $this->assertEquals(17, $_GET['int']); + $this->assertEquals(17, $_REQUEST['int']); + } + + public function test_set(){ + $_REQUEST = $this->data; + $_POST = $this->data; + $_GET = $this->data; + $INPUT = new Input(); + + $INPUT->set('test','foo'); + $this->assertEquals('foo',$_REQUEST['test']); + $this->assertNull($_POST['test']); + $this->assertNull($_GET['test']); + + $INPUT->get->set('test2','foo'); + $this->assertEquals('foo',$_GET['test2']); + $this->assertEquals('foo',$_REQUEST['test2']); + $this->assertNull($_POST['test']); + } + + public function test_ref(){ + $_REQUEST = $this->data; + $_POST = $this->data; + $_GET = $this->data; + $INPUT = new Input(); + + $test = &$INPUT->ref('string'); + $this->assertEquals('foo',$test); + $_REQUEST['string'] = 'bla'; + $this->assertEquals('bla',$test); + } + +} \ No newline at end of file -- cgit v1.2.3 From 5d0aaf958325f500ce69cfb79e69eb0d8f83fdeb Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 28 Jun 2012 17:17:24 +0200 Subject: treat empty string inputs as unset for int and bool --- _test/tests/inc/input.test.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/input.test.php b/_test/tests/inc/input.test.php index 627af3a2b..761b7ddbc 100644 --- a/_test/tests/inc/input.test.php +++ b/_test/tests/inc/input.test.php @@ -95,6 +95,11 @@ class input_test extends DokuWikiTest { $this->assertSame(1, $INPUT->get->int('get', false)); $this->assertSame(0, $INPUT->int('array')); + + $this->assertSame(0, $INPUT->int('zero', -1)); + $this->assertSame(-1, $INPUT->int('empty', -1)); + $this->assertSame(-1, $INPUT->int('zero', -1, true)); + $this->assertSame(-1, $INPUT->int('empty', -1, true)); } public function test_arr() { @@ -155,6 +160,11 @@ class input_test extends DokuWikiTest { $this->assertSame(false, $INPUT->post->bool('get')); $this->assertSame(true, $INPUT->post->bool('post')); + + $this->assertSame(false, $INPUT->bool('zero', -1)); + $this->assertSame(-1, $INPUT->bool('empty', -1)); + $this->assertSame(-1, $INPUT->bool('zero', -1, true)); + $this->assertSame(-1, $INPUT->bool('empty', -1, true)); } public function test_remove() { @@ -203,4 +213,4 @@ class input_test extends DokuWikiTest { $this->assertEquals('bla',$test); } -} \ No newline at end of file +} -- cgit v1.2.3 From 772c924913365ea9be90e667f6d06cdcef3ab4ec Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 30 Jun 2012 13:37:23 +0200 Subject: Add a test case for nested events, this tests 8cb3706df5ad54c654bffb76a69ac0ca1006521e --- _test/tests/inc/events_nested.test.php | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 _test/tests/inc/events_nested.test.php (limited to '_test/tests/inc') diff --git a/_test/tests/inc/events_nested.test.php b/_test/tests/inc/events_nested.test.php new file mode 100644 index 000000000..fe5e395bb --- /dev/null +++ b/_test/tests/inc/events_nested.test.php @@ -0,0 +1,36 @@ +register_hook('NESTED_EVENT', 'BEFORE', null, + function() use (&$firstcount) { + $firstcount++; + if ($firstcount == 1) { + $param = array(); + trigger_event('NESTED_EVENT', $param); + } + } + ); + + $EVENT_HANDLER->register_hook('NESTED_EVENT', 'BEFORE', null, + function() use (&$secondcount) { + $secondcount++; + } + ); + + $param = array(); + trigger_event('NESTED_EVENT', $param); + + $this->assertEquals(2, $firstcount); + $this->assertEquals(2, $secondcount); + } +} -- cgit v1.2.3 From 32e82180a785b09b1886cf44ecca5ed22ce37b9d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 30 Jun 2012 14:19:51 +0200 Subject: fixed group wildcards and added tests --- _test/tests/inc/auth_aclcheck.test.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/auth_aclcheck.test.php b/_test/tests/inc/auth_aclcheck.test.php index ea48ec6a5..991f82da7 100644 --- a/_test/tests/inc/auth_aclcheck.test.php +++ b/_test/tests/inc/auth_aclcheck.test.php @@ -235,6 +235,33 @@ class auth_acl_test extends DokuWikiTest { $this->assertEquals(auth_aclcheck('namespace:*', 'jill',array('foo','roots')), AUTH_ADMIN); } + function test_wildcards(){ + global $conf; + global $AUTH_ACL; + global $USERINFO; + $conf['useacl'] = 1; + + $_SERVER['REMOTE_USER'] = 'john'; + $USERINFO['grps'] = array('test','töst','foo bar'); + $AUTH_ACL = auth_loadACL(); // default test file + + // default setting + $this->assertEquals(AUTH_UPLOAD, auth_aclcheck('page', $_SERVER['REMOTE_USER'], $USERINFO['grps'])); + + // user namespace + $this->assertEquals(AUTH_DELETE, auth_aclcheck('users:john:foo', $_SERVER['REMOTE_USER'], $USERINFO['grps'])); + $this->assertEquals(AUTH_READ, auth_aclcheck('users:john:foo', 'schmock', array())); + + // group namespace + $this->assertEquals(AUTH_DELETE, auth_aclcheck('groups:test:foo', $_SERVER['REMOTE_USER'], $USERINFO['grps'])); + $this->assertEquals(AUTH_READ, auth_aclcheck('groups:test:foo', 'schmock', array())); + $this->assertEquals(AUTH_DELETE, auth_aclcheck('groups:toest:foo', $_SERVER['REMOTE_USER'], $USERINFO['grps'])); + $this->assertEquals(AUTH_READ, auth_aclcheck('groups:toest:foo', 'schmock', array())); + $this->assertEquals(AUTH_DELETE, auth_aclcheck('groups:foo_bar:foo', $_SERVER['REMOTE_USER'], $USERINFO['grps'])); + $this->assertEquals(AUTH_READ, auth_aclcheck('groups:foo_bar:foo', 'schmock', array())); + + } + } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 65ee48a57f42826189844ad1039c37a8a675dbab Mon Sep 17 00:00:00 2001 From: Hakan Sandell Date: Sun, 1 Jul 2012 11:38:02 +0200 Subject: Made multiline test cases work on windows too --- _test/tests/inc/common_cleanText.test.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/common_cleanText.test.php b/_test/tests/inc/common_cleanText.test.php index 00e70d4c7..9d4494332 100644 --- a/_test/tests/inc/common_cleanText.test.php +++ b/_test/tests/inc/common_cleanText.test.php @@ -3,11 +3,7 @@ class common_cleanText_test extends DokuWikiTest { function test_unix(){ - $unix = 'one - two - - three'; - + $unix = "one\n two\n\n three"; $this->assertEquals($unix,cleanText($unix)); } -- cgit v1.2.3 From e66d3e6dfa7ba6f0cf55b58f0b00b66b52c98321 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 1 Jul 2012 11:41:22 +0200 Subject: Improved sidebar inclusion Template authors now can use tpl_sidebar() to include the sidebar. Sidebars can be defined in subnamespaces as well --- _test/tests/inc/pageutils_findnearest.test.php | 40 ++++++++++++++++++++++++++ _test/tests/inc/template_sidebar.test.php | 40 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 _test/tests/inc/pageutils_findnearest.test.php create mode 100644 _test/tests/inc/template_sidebar.test.php (limited to '_test/tests/inc') diff --git a/_test/tests/inc/pageutils_findnearest.test.php b/_test/tests/inc/pageutils_findnearest.test.php new file mode 100644 index 000000000..e129b5e58 --- /dev/null +++ b/_test/tests/inc/pageutils_findnearest.test.php @@ -0,0 +1,40 @@ +assertEquals(false, $sidebar); + } + + function testExistingSidebars() { + global $ID; + + saveWikiText('sidebar', 'topsidebar-test', ''); + + $ID = 'foo:bar:baz:test'; + $sidebar = page_findnearest('sidebar'); + $this->assertEquals('sidebar', $sidebar); + + $ID = 'foo'; + $sidebar = page_findnearest('sidebar'); + $this->assertEquals('sidebar', $sidebar); + + saveWikiText('foo:bar:sidebar', 'bottomsidebar-test', ''); + + $ID = 'foo:bar:baz:test'; + $sidebar = page_findnearest('sidebar'); + $this->assertEquals('foo:bar:sidebar', $sidebar); + + $ID = 'foo:bar:test'; + $sidebar = page_findnearest('sidebar'); + $this->assertEquals('foo:bar:sidebar', $sidebar); + + $ID = 'foo'; + $sidebar = page_findnearest('sidebar'); + $this->assertEquals('sidebar', $sidebar); + } + +} diff --git a/_test/tests/inc/template_sidebar.test.php b/_test/tests/inc/template_sidebar.test.php new file mode 100644 index 000000000..56153894a --- /dev/null +++ b/_test/tests/inc/template_sidebar.test.php @@ -0,0 +1,40 @@ +assertEquals('',$sidebar); + } + + function testExistingSidebars() { + global $ID; + + saveWikiText('sidebar', 'topsidebar-test', ''); + + $ID = 'foo:bar:baz:test'; + $sidebar = tpl_sidebar(false); + $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + + $ID = 'foo'; + $sidebar = tpl_sidebar(false); + $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + + saveWikiText('foo:bar:sidebar', 'bottomsidebar-test', ''); + + $ID = 'foo:bar:baz:test'; + $sidebar = tpl_sidebar(false); + $this->assertTrue(strpos($sidebar, 'bottomsidebar-test') > 0); + + $ID = 'foo:bar:test'; + $sidebar = tpl_sidebar(false); + $this->assertTrue(strpos($sidebar, 'bottomsidebar-test') > 0); + + $ID = 'foo'; + $sidebar = tpl_sidebar(false); + $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + } + +} -- cgit v1.2.3 From 08118f511f456cc119c08a966a83704af88e6182 Mon Sep 17 00:00:00 2001 From: Tom N Harris Date: Sun, 1 Jul 2012 15:25:33 -0400 Subject: Adjust unit test to reflect desired behavior of max_bodysize --- _test/tests/inc/httpclient_http.test.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index c3ee182dc..9959a1f06 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -127,9 +127,8 @@ class httpclient_http_test extends DokuWikiTest { $http->max_bodysize_abort = false; $data = $http->get($this->server.'/stream/30'); $this->assertFalse($data === false, 'HTTP response'); - /* the current implementation will read in max_bodysize blocks, - and aborts if the response is larger, thus a limit of 2*max_bodysize */ - $this->assertLessThanOrEqual(500,strlen($data)); + /* should read no more than max_bodysize+1 */ + $this->assertLessThanOrEqual(251,strlen($data)); } /** -- cgit v1.2.3