diff options
Diffstat (limited to '_test/tests')
-rw-r--r-- | _test/tests/conf/title.test.php | 19 | ||||
-rw-r--r-- | _test/tests/inc/auth_aclcheck.test.php | 27 | ||||
-rw-r--r-- | _test/tests/inc/common_cleanText.test.php | 6 | ||||
-rw-r--r-- | _test/tests/inc/events_nested.test.php | 36 | ||||
-rw-r--r-- | _test/tests/inc/httpclient_http.test.php | 15 | ||||
-rw-r--r-- | _test/tests/inc/input.test.php | 216 | ||||
-rw-r--r-- | _test/tests/inc/pageutils_findnearest.test.php | 40 | ||||
-rw-r--r-- | _test/tests/inc/template_sidebar.test.php | 40 | ||||
-rw-r--r-- | _test/tests/lib/exe/js_js_compress.test.php | 6 | ||||
-rw-r--r-- | _test/tests/test/basic.test.php | 83 |
10 files changed, 479 insertions, 9 deletions
diff --git a/_test/tests/conf/title.test.php b/_test/tests/conf/title.test.php new file mode 100644 index 000000000..7cae040e7 --- /dev/null +++ b/_test/tests/conf/title.test.php @@ -0,0 +1,19 @@ +<?php + +class conf_title_test extends DokuWikiTest { + + function testTitle() { + global $conf; + + $request = new TestRequest(); + $response = $request->get(); + $content = $response->queryHTML('title'); + $this->assertTrue(strpos($content,$conf['title']) > 0); + + $conf['title'] = 'Foo'; + $request = new TestRequest(); + $response = $request->get(); + $content = $response->queryHTML('title'); + $this->assertTrue(strpos($content,'Foo') > 0); + } +} 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 : 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)); } 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 @@ +<?php + +/** + * This tests if event handlers can trigger the same event again. + * This is used by plugins that modify cache handling and use metadata + * for checking cache validity which triggers another cache use event. + */ +class events_nested_test extends DokuWikiTest { + function test_nested_events() { + global $EVENT_HANDLER; + $firstcount = 0; + $secondcount = 0; + + $EVENT_HANDLER->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); + } +} diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index 9cae3736a..9959a1f06 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -124,6 +124,11 @@ 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'); + /* should read no more than max_bodysize+1 */ + $this->assertLessThanOrEqual(251,strlen($data)); } /** @@ -176,5 +181,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 : diff --git a/_test/tests/inc/input.test.php b/_test/tests/inc/input.test.php new file mode 100644 index 000000000..761b7ddbc --- /dev/null +++ b/_test/tests/inc/input.test.php @@ -0,0 +1,216 @@ +<?php + +/** + * Tests for the Input class + */ +class input_test extends DokuWikiTest { + + private $data = array( + 'array' => 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')); + + $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() { + $_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')); + + $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() { + $_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); + } + +} 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 @@ +<?php + +class pageutils_findnearest_test extends DokuWikiTest { + function testNoSidebar() { + global $ID; + + $ID = 'foo:bar:baz:test'; + $sidebar = page_findnearest('sidebar'); + $this->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 @@ +<?php + +class template_sidebar_test extends DokuWikiTest { + function testNoSidebar() { + global $ID; + + $ID = 'foo:bar:baz:test'; + $sidebar = tpl_sidebar(false); + $this->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); + } + +} diff --git a/_test/tests/lib/exe/js_js_compress.test.php b/_test/tests/lib/exe/js_js_compress.test.php index aa8d82933..49f93cc54 100644 --- a/_test/tests/lib/exe/js_js_compress.test.php +++ b/_test/tests/lib/exe/js_js_compress.test.php @@ -111,12 +111,10 @@ class js_js_compress_test extends DokuWikiTest { } function test_multilinestring(){ - $text = 'var foo = "this is a \\ -multiline string";'; + $text = 'var foo = "this is a \\'."\n".'multiline string";'; $this->assertEquals('var foo="this is a multiline string";',js_compress($text)); - $text = "var foo = 'this is a \\ -multiline string';"; + $text = "var foo = 'this is a \\\nmultiline string';"; $this->assertEquals("var foo='this is a multiline string';",js_compress($text)); } diff --git a/_test/tests/test/basic.test.php b/_test/tests/test/basic.test.php index b4926d2ba..a0ea48a3a 100644 --- a/_test/tests/test/basic.test.php +++ b/_test/tests/test/basic.test.php @@ -19,4 +19,87 @@ class InttestsBasicTest extends DokuWikiTest { 'DokuWiki was not a word in the output' ); } + + function testPost() { + $request = new TestRequest(); + + $input = array( + 'string' => 'A string', + 'array' => array(1, 2, 3), + 'id' => 'wiki:dokuwiki' + ); + + $response = $request->post($input); + + // server var check + $this->assertEquals('POST',$request->getServer('REQUEST_METHOD')); + $this->assertEquals('',$request->getServer('QUERY_STRING')); + $this->assertEquals('/doku.php',$request->getServer('REQUEST_URI')); + + // variable setup check + $this->assertEquals('A string', $request->getPost('string')); + $this->assertEquals(array(1, 2, 3), $request->getPost('array')); + $this->assertEquals('wiki:dokuwiki', $request->getPost('id')); + + // output check + $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); + } + + function testPostGet() { + $request = new TestRequest(); + + $input = array( + 'string' => 'A string', + 'array' => array(1, 2, 3), + ); + + $response = $request->post($input,'/doku.php?id=wiki:dokuwiki'); + + // server var check + $this->assertEquals('POST',$request->getServer('REQUEST_METHOD')); + $this->assertEquals('?id=wiki:dokuwiki',$request->getServer('QUERY_STRING')); + $this->assertEquals('/doku.php?id=wiki:dokuwiki',$request->getServer('REQUEST_URI')); + + // variable setup check + $this->assertEquals('A string', $request->getPost('string')); + $this->assertEquals(array(1, 2, 3), $request->getPost('array')); + $this->assertEquals('wiki:dokuwiki', $request->getGet('id')); + + // output check + $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); + } + + function testGet() { + $request = new TestRequest(); + + $input = array( + 'string' => 'A string', + 'array' => array(1, 2, 3), + 'test' => 'bar' + ); + + $response = $request->get($input,'/doku.php?id=wiki:dokuwiki&test=foo'); + + // server var check + $this->assertEquals('GET',$request->getServer('REQUEST_METHOD')); + $this->assertEquals( + '?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3', + $request->getServer('QUERY_STRING') + ); + $this->assertEquals( + '/doku.php?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3', + $request->getServer('REQUEST_URI') + ); + + // variable setup check + $this->assertEquals('A string', $request->getGet('string')); + $this->assertEquals(array(1, 2, 3), $request->getGet('array')); + $this->assertEquals('wiki:dokuwiki', $request->getGet('id')); + $this->assertEquals('bar', $request->getGet('test')); + + // output check + $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); + } + + } |