summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorChristopher Smith <chris@jalakai.co.uk>2013-02-25 14:50:59 +0000
committerChristopher Smith <chris@jalakai.co.uk>2013-02-25 14:50:59 +0000
commit1fe0882c56ea31e738540e942b743966927415fd (patch)
treec3324566ada64f09775b35bc989592c7701c32d4 /_test
parent177daee5492e8c3cdfdb950cdf61a6798f7a9586 (diff)
parent058fd09655df42c72f3c447e3b9561e4909e978d (diff)
downloadrpg-1fe0882c56ea31e738540e942b743966927415fd.tar.gz
rpg-1fe0882c56ea31e738540e942b743966927415fd.tar.bz2
Merge branch 'master' into FS#2415
Diffstat (limited to '_test')
-rw-r--r--_test/tests/inc/auth_browseruid.test.php30
-rw-r--r--_test/tests/inc/common_pageinfo.test.php299
-rw-r--r--_test/tests/inc/search/search.test.php4
3 files changed, 331 insertions, 2 deletions
diff --git a/_test/tests/inc/auth_browseruid.test.php b/_test/tests/inc/auth_browseruid.test.php
new file mode 100644
index 000000000..d33552582
--- /dev/null
+++ b/_test/tests/inc/auth_browseruid.test.php
@@ -0,0 +1,30 @@
+<?php
+
+class auth_browseruid_test extends DokuWikiTest {
+
+
+ /**
+ * regression test to ensure correct browser id on IE9.
+ *
+ * IE9 send different HTTP_ACCEPT_LANGUAGE header on ajax request.
+ */
+ function testIE9JsVsDefault() {
+
+ // javascript request
+ $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
+ $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate';
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de';
+ unset($_SERVER['HTTP_ACCEPT_CHARSET']);
+ $javascriptId = auth_browseruid();
+
+ // default request
+ $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
+ $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate';
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-DE';
+ $normalId = auth_browseruid();
+
+ $this->assertEquals($normalId, $javascriptId);
+
+ }
+
+} \ No newline at end of file
diff --git a/_test/tests/inc/common_pageinfo.test.php b/_test/tests/inc/common_pageinfo.test.php
new file mode 100644
index 000000000..c54fbce26
--- /dev/null
+++ b/_test/tests/inc/common_pageinfo.test.php
@@ -0,0 +1,299 @@
+<?php
+/**
+ * Unit Test for inc/common.php - pageinfo()
+ *
+ * @author Christopher Smith <chris@jalakai.co.uk>
+ */
+class common_pageinfo_test extends DokuWikiTest {
+
+ function setup(){
+ parent::setup();
+
+ global $USERINFO;
+ $USERINFO = array(
+ 'pass' => '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_expected_pageinfo() {
+ global $USERINFO;
+ $info = array (
+ 'isadmin' => true,
+ 'ismanager' => true,
+ 'userinfo' => $USERINFO,
+ 'perm' => 255,
+ 'namespace' => false,
+ 'ismobile' => false,
+ 'client' => 'testuser',
+ );
+ $info['rev'] = null;
+ $info['subscribed'] = false;
+ $info['locked'] = false;
+ $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;
+
+ return $info;
+ }
+
+ /**
+ * check info keys and values for a non-existent page & admin user
+ */
+ function test_basic_nonexistentpage(){
+ global $ID,$conf;
+ $ID = 'wiki:start';
+
+ $info = $this->_get_expected_pageinfo();
+ $info['id'] = 'wiki:start';
+ $info['namespace'] = 'wiki';
+ $info['filepath'] = $conf['datadir'].'/wiki/start.txt';
+
+ $this->assertEquals($info, pageinfo());
+ }
+
+ /**
+ * check info keys and values for a existing page & admin user
+ */
+ function test_basic_existingpage(){
+ global $ID,$conf;
+ $ID = 'wiki:syntax';
+ $filename = $conf['datadir'].'/wiki/syntax.txt';
+ $rev = filemtime($filename);
+
+ $info = $this->_get_expected_pageinfo();
+ $info['id'] = 'wiki:syntax';
+ $info['namespace'] = 'wiki';
+ $info['filepath'] = $filename;
+ $info['exists'] = true;
+ $info['lastmod'] = $rev;
+ $info['meta'] = p_get_metadata($ID);
+
+ $this->assertEquals($info, pageinfo());
+ }
+
+ /**
+ * check info keys and values for anonymous user
+ */
+ function test_anonymoususer(){
+ global $ID,$conf,$REV;
+
+ unset($_SERVER['REMOTE_USER']);
+ global $USERINFO; $USERINFO = array();
+
+ $ID = 'wiki:syntax';
+ $filename = $conf['datadir'].'/wiki/syntax.txt';
+ $rev = filemtime($filename);
+
+ $info = $this->_get_expected_pageinfo();
+ $info['id'] = 'wiki:syntax';
+ $info['namespace'] = 'wiki';
+ $info['filepath'] = $filename;
+ $info['exists'] = true;
+ $info['lastmod'] = $rev;
+ $info['meta'] = p_get_metadata($ID);
+ $info['rev'] = '';
+
+ $info = array_merge($info, array(
+ 'isadmin' => false,
+ 'ismanager' => false,
+ 'perm' => 8,
+ 'client' => '1.2.3.4',
+ ));
+ unset($info['userinfo']);
+ $this->assertEquals($info, pageinfo());
+ }
+
+ /**
+ * check info keys and values with $REV
+ * (also see $RANGE tests)
+ */
+ function test_rev(){
+ global $ID,$conf,$REV;
+
+ $ID = 'wiki:syntax';
+ $filename = $conf['datadir'].'/wiki/syntax.txt';
+ $rev = filemtime($filename);
+ $REV = $rev - 100;
+
+ $info = $this->_get_expected_pageinfo();
+ $info['id'] = 'wiki:syntax';
+ $info['namespace'] = 'wiki';
+ $info['meta'] = p_get_metadata($ID);
+ $info['rev'] = $REV;
+ $info['filepath'] = str_replace('pages','attic',substr($filename,0,-3).$REV.'.txt.gz');
+
+ $this->assertEquals($info, pageinfo());
+ $this->assertEquals($rev-100, $REV);
+ }
+
+ /**
+ * check info keys and values with $RANGE
+ */
+ function test_range(){
+ global $ID,$conf,$REV,$RANGE;
+
+ $ID = 'wiki:syntax';
+ $filename = $conf['datadir'].'/wiki/syntax.txt';
+ $rev = filemtime($filename);
+ $range = '1000-2000';
+
+ $info = $this->_get_expected_pageinfo();
+ $info['id'] = 'wiki:syntax';
+ $info['namespace'] = 'wiki';
+ $info['exists'] = true;
+ $info['lastmod'] = $rev;
+ $info['meta'] = p_get_metadata($ID);
+ $info['filepath'] = $filename;
+
+ // check $RANGE without $REV
+ // expected result $RANGE unchanged
+ $RANGE = $range;
+
+ $this->assertEquals($info, pageinfo());
+ $this->assertFalse(isset($REV));
+ $this->assertEquals($range,$RANGE);
+
+ // check $RANGE with $REV = current
+ // expected result: $RANGE unchanged, $REV cleared
+ $REV = $rev;
+ $info['rev'] = '';
+
+ $this->assertEquals($info, pageinfo());
+ $this->assertEquals('',$REV);
+ $this->assertEquals($range,$RANGE);
+
+ // check with a real $REV
+ // expected result: $REV and $RANGE are cleared
+ $REV = $rev - 100;
+
+ $this->assertEquals($info, pageinfo());
+ $this->assertEquals('',$REV);
+ $this->assertEquals('',$RANGE);
+ }
+
+ /**
+ * test editor entry and external edit
+ */
+ function test_editor_and_externaledits(){
+ global $ID,$conf;
+ $ID = 'wiki:syntax';
+ $filename = $conf['datadir'].'/wiki/syntax.txt';
+ $rev = filemtime($filename);
+
+ $info = $this->_get_expected_pageinfo();
+ $info['id'] = 'wiki:syntax';
+ $info['namespace'] = 'wiki';
+ $info['filepath'] = $filename;
+ $info['exists'] = true;
+ $info['lastmod'] = $rev;
+ $info['meta'] = p_get_metadata($ID); // need $INFO set correctly for addLogEntry()
+
+ global $INFO;
+ $INFO = $info;
+
+ // add an editor for the current version of $ID
+ addLogEntry($rev, $ID);
+
+ $info['meta'] = p_get_metadata($ID);
+ $info['editor'] = $_SERVER['REMOTE_USER'];
+ $info['user'] = $_SERVER['REMOTE_USER'];
+ $info['ip'] = $_SERVER['REMOTE_ADDR'];
+ $info['sum'] = '';
+
+ // with an editor ...
+ $this->assertEquals($info, pageinfo());
+
+ // clear the meta['last_change'] value, pageinfo should restore it
+ p_set_metadata($ID,array('last_change' => false));
+
+ $this->assertEquals($info, pageinfo());
+ $this->assertEquals($info['meta']['last_change'], p_get_metadata($ID,'last_change'));
+
+ // fake an external edit, pageinfo should clear the last change from meta data
+ // and not return any editor data
+ $now = time()+10;
+ touch($filename,$now);
+
+ $info['lastmod'] = $now;
+ $info['meta']['last_change'] = false;
+ $info['ip'] = null;
+ $info['user'] = null;
+ $info['sum'] = null;
+ $info['editor'] = null;
+
+ $this->assertEquals($info, pageinfo());
+ $this->assertEquals($info['meta'], p_get_metadata($ID)); // check metadata has been updated correctly
+ }
+
+ /**
+ * check draft
+ */
+ function test_draft(){
+ global $ID,$conf;
+ $ID = 'wiki:syntax';
+ $filename = $conf['datadir'].'/wiki/syntax.txt';
+ $rev = filemtime($filename);
+
+ $info = $this->_get_expected_pageinfo();
+ $info['id'] = 'wiki:syntax';
+ $info['namespace'] = 'wiki';
+ $info['filepath'] = $filename;
+ $info['exists'] = true;
+ $info['lastmod'] = $rev;
+ $info['meta'] = p_get_metadata($ID);
+
+ // setup a draft, make it more recent than the current page
+ // - pageinfo should recognise it and keep it
+ $draft = getCacheName($info['client'].$ID,'.draft');
+ touch($draft,$rev + 10);
+
+ $info['draft'] = $draft;
+
+ $this->assertEquals($info, pageinfo());
+ $this->assertFileExists($draft);
+
+ // make the draft older than the current page
+ // - pageinfo should remove it and not return the 'draft' key
+ touch($draft,$rev - 10);
+ unset($info['draft']);
+
+ $this->assertEquals($info, pageinfo());
+ $this->assertFalse(file_exists($draft));
+ }
+
+ /**
+ * check ismobile
+ */
+ function test_ismobile(){
+ global $ID,$conf;
+ $ID = 'wiki:start';
+
+ $info = $this->_get_expected_pageinfo();
+ $info['id'] = 'wiki:start';
+ $info['namespace'] = 'wiki';
+ $info['filepath'] = $conf['datadir'].'/wiki/start.txt';
+
+ // overkill, ripped from clientismobile() as we aren't testing detection - but forcing it
+ $_SERVER['HTTP_X_WAP_PROFILE'] = 'a fake url';
+ $_SERVER['HTTP_ACCEPT'] .= ';wap';
+ $_SERVER['HTTP_USER_AGENT'] = 'blackberry,symbian,hand,mobi,phone';
+
+ $info['ismobile'] = clientismobile();
+
+ $this->assertTrue(clientismobile()); // ensure THIS test fails if clientismobile() returns false
+ $this->assertEquals($info, pageinfo()); // it would be a test failure not a pageinfo failure.
+ }
+}
+
+//Setup VIM: ex: et ts=4 :
diff --git a/_test/tests/inc/search/search.test.php b/_test/tests/inc/search/search.test.php
index 9c854a661..33d4e9d8d 100644
--- a/_test/tests/inc/search/search.test.php
+++ b/_test/tests/inc/search/search.test.php
@@ -22,9 +22,9 @@ class search_test extends DokuWikiTest {
search($data, dirname(__FILE__) . '/data', 'search_allpages', array('depth' => 1), 'ns1/ns3');
$this->assertEquals(0, count($data));
- //depth is 1 so I should get only pages from ns1
+ //depth is 2 so I should get only pages from ns1
$data = array();
- search($data, dirname(__FILE__) . '/data', 'search_allpages', array('depth' => 1), 'ns1');
+ search($data, dirname(__FILE__) . '/data', 'search_allpages', array('depth' => 2), 'ns1');
$this->assertEquals(2, count($data));
}