summaryrefslogtreecommitdiff
path: root/_test/tests/inc
diff options
context:
space:
mode:
Diffstat (limited to '_test/tests/inc')
-rw-r--r--_test/tests/inc/auth_aclcheck.test.php27
-rw-r--r--_test/tests/inc/common_cleanText.test.php6
-rw-r--r--_test/tests/inc/events_nested.test.php36
-rw-r--r--_test/tests/inc/httpclient_http.test.php15
-rw-r--r--_test/tests/inc/input.test.php216
-rw-r--r--_test/tests/inc/pageutils_findnearest.test.php40
-rw-r--r--_test/tests/inc/template_sidebar.test.php40
7 files changed, 375 insertions, 5 deletions
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);
+ }
+
+}