summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2012-11-30 12:30:40 +0100
committerAndreas Gohr <andi@splitbrain.org>2012-11-30 12:30:40 +0100
commitd14415e37072dbe16077efd700aee5bd33707b54 (patch)
tree062c3c190039ac9490f56598b0ee116de18c2480 /_test
parent2ed38036a53a489d2fcadc46ce601f8c876fca31 (diff)
parent38479cbba628ee76a92ff5f3c974cfa8e6ce9e61 (diff)
downloadrpg-d14415e37072dbe16077efd700aee5bd33707b54.tar.gz
rpg-d14415e37072dbe16077efd700aee5bd33707b54.tar.bz2
Merge branch 'master' into subscription
* master: (175 commits) some coding style improvements added .idea project folder to gitignore use correct setUp method and parent calls. Correct German plugin manager translation (download != install) correct return in sendDigest() Fix case-insensitive match in ACL checking GeSHi update to 1.0.8.11 ignore empty header on mail sending remove empty BCC/CC mail headers Galician language update some welcome page changes Combine subsequent calls to strtr into a single transformation changed semicolon to colon in link to welcome page to make it less confusing fixed wrong sidebar showing in namespaces when sidebar is disabled Typo fix for TL;DR removed a bunch of outdated and irrelevant networking acronyms added another place to look for logo to make it more consistent (FS#2656) French language update Czech language update compat js findPosX/y more closely mimic historical function ... Conflicts: inc/auth.php inc/common.php inc/subscription.php lib/exe/indexer.php
Diffstat (limited to '_test')
-rw-r--r--_test/bootstrap.php4
-rw-r--r--_test/core/phpQuery-onefile.php2
-rw-r--r--_test/tests/inc/PageUtilsIsHiddenPage.test.php95
-rw-r--r--_test/tests/inc/auth_aclcheck.test.php10
-rw-r--r--_test/tests/inc/auth_aclcheck_caseinsensitive.test.php128
-rw-r--r--_test/tests/inc/auth_admincheck.test.php5
-rw-r--r--_test/tests/inc/auth_nameencode.test.php2
-rw-r--r--_test/tests/inc/mailer.test.php20
-rw-r--r--_test/tests/inc/parser/parser.inc.php3
-rw-r--r--_test/tests/inc/parser/parser_footnote.test.php4
-rw-r--r--_test/tests/inc/parser/parser_quotes.test.php4
-rw-r--r--_test/tests/inc/parserutils_set_metadata_during_rendering.test.php3
-rw-r--r--_test/tests/inc/remote.test.php5
-rw-r--r--_test/tests/inc/subscription_set.test.php20
-rw-r--r--_test/tests/inc/tar.test.php319
-rw-r--r--_test/tests/inc/tar/foobar/testdata2.txt1
-rw-r--r--_test/tests/inc/tar/longpath-gnu.tgzbin0 -> 413 bytes
-rw-r--r--_test/tests/inc/tar/longpath-ustar.tgzbin0 -> 311 bytes
-rw-r--r--_test/tests/inc/tar/tarbomb.tgzbin0 -> 183 bytes
-rw-r--r--_test/tests/inc/tar/test.tarbin0 -> 10240 bytes
-rw-r--r--_test/tests/inc/tar/test.tbzbin0 -> 217 bytes
-rw-r--r--_test/tests/inc/tar/test.tgzbin0 -> 220 bytes
-rw-r--r--_test/tests/inc/tar/testdata1.txt1
-rw-r--r--_test/tests/inc/template_include_page.test.php (renamed from _test/tests/inc/template_sidebar.test.php)16
24 files changed, 612 insertions, 30 deletions
diff --git a/_test/bootstrap.php b/_test/bootstrap.php
index 58ad6a0d7..310b3627a 100644
--- a/_test/bootstrap.php
+++ b/_test/bootstrap.php
@@ -110,3 +110,7 @@ $dh->close();
// load dw
require_once(DOKU_INC.'inc/init.php');
+// load the parser so $PARSER_MODES is defined before the tests start
+// otherwise PHPUnit unsets $PARSER_MODES in some cases which breaks p_get_parsermodes()
+require_once(DOKU_INC.'inc/parser/parser.php');
+
diff --git a/_test/core/phpQuery-onefile.php b/_test/core/phpQuery-onefile.php
index 4c1dfa3da..402cf8e49 100644
--- a/_test/core/phpQuery-onefile.php
+++ b/_test/core/phpQuery-onefile.php
@@ -4206,7 +4206,7 @@ class phpQueryObject
.($node->getAttribute('id')
? '#'.$node->getAttribute('id'):'')
.($node->getAttribute('class')
- ? '.'.join('.', split(' ', $node->getAttribute('class'))):'')
+ ? '.'.join('.', explode(' ', $node->getAttribute('class'))):'')
.($node->getAttribute('name')
? '[name="'.$node->getAttribute('name').'"]':'')
.($node->getAttribute('value') && strpos($node->getAttribute('value'), '<'.'?php') === false
diff --git a/_test/tests/inc/PageUtilsIsHiddenPage.test.php b/_test/tests/inc/PageUtilsIsHiddenPage.test.php
new file mode 100644
index 000000000..a7077862e
--- /dev/null
+++ b/_test/tests/inc/PageUtilsIsHiddenPage.test.php
@@ -0,0 +1,95 @@
+<?php
+
+class PageUtilsIsHiddenPageTest extends DokuWikiTest {
+
+ function prepare($hidePages = '^:test$', $act = 'show') {
+ global $conf;
+ global $ACT;
+ $conf['hidepages'] = $hidePages;
+ $ACT = $act;
+ }
+
+ function testHiddenOff(){
+ $this->prepare('');
+
+ $this->assertFalse(isHiddenPage('test'));
+ }
+
+ function testHiddenOffAdmin(){
+ $this->prepare('^:test$', 'admin');
+
+ $this->assertFalse(isHiddenPage('test'));
+ }
+
+ function testHiddenOnMatch(){
+ $this->prepare();
+
+ $this->assertTrue(isHiddenPage('test'));
+ }
+
+ function testHiddenOnNoMatch(){
+ $this->prepare();
+
+ $this->assertFalse(isHiddenPage('another'));
+ }
+
+ function testEventHandlerBefore() {
+ global $EVENT_HANDLER;
+ $this->prepare();
+ $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'alwaysHide');
+
+ $this->assertTrue(isHiddenPage('another'));
+ }
+
+ function alwaysHide(Doku_Event &$event, $params) {
+ $event->data['hidden'] = true;
+ }
+
+ function testEventHandlerBeforeAndPrevent() {
+ global $EVENT_HANDLER;
+ $this->prepare();
+ $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'showBefore');
+
+ $this->assertFalse(isHiddenPage('test'));
+ }
+
+ function showBefore(Doku_Event &$event, $params) {
+ $event->data['hidden'] = false;
+ $event->preventDefault();
+ $event->stopPropagation();
+ }
+
+ function testEventHandlerAfter() {
+ global $EVENT_HANDLER;
+ $this->prepare();
+ $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'alwaysHide');
+
+ $this->assertTrue(isHiddenPage('another'));
+ }
+
+ function testEventHandlerAfterHide() {
+ global $EVENT_HANDLER;
+ $this->prepare();
+ $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'hideBeforeWithoutPrevent');
+
+ $this->assertTrue(isHiddenPage('another'));
+ }
+
+ function hideBeforeWithoutPrevent(Doku_Event &$event, $params) {
+ $event->data['hidden'] = true;
+ }
+
+ function testEventHandlerAfterShow() {
+ global $EVENT_HANDLER;
+ $this->prepare();
+ $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'showAfter');
+
+ $this->assertFalse(isHiddenPage('test'));
+ }
+
+ function showAfter(Doku_Event &$event, $params) {
+ $event->data['hidden'] = false;
+ }
+
+}
+//Setup VIM: ex: et ts=4 :
diff --git a/_test/tests/inc/auth_aclcheck.test.php b/_test/tests/inc/auth_aclcheck.test.php
index 991f82da7..8e5a04ff5 100644
--- a/_test/tests/inc/auth_aclcheck.test.php
+++ b/_test/tests/inc/auth_aclcheck.test.php
@@ -2,22 +2,18 @@
class auth_acl_test extends DokuWikiTest {
- var $oldConf;
var $oldAuthAcl;
- function setup() {
- global $conf;
+ function setUp() {
+ parent::setUp();
global $AUTH_ACL;
global $auth;
- $this->oldConf = $conf;
$this->oldAuthAcl = $AUTH_ACL;
$auth = new auth_basic();
}
- function teardown() {
- global $conf;
+ function tearDown() {
global $AUTH_ACL;
- $conf = $this->oldConf;
$AUTH_ACL = $this->oldAuthAcl;
}
diff --git a/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php b/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php
new file mode 100644
index 000000000..2f4821c2d
--- /dev/null
+++ b/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php
@@ -0,0 +1,128 @@
+<?php
+
+class auth_acl_caseinsensitive_auth extends auth_basic {
+ function isCaseSensitive() {
+ return false;
+ }
+}
+
+class auth_acl_caseinsensitive_test extends DokuWikiTest {
+ protected $oldAuth;
+ protected $oldAuthAcl;
+
+ function setUp() {
+ parent::setUp();
+ global $auth;
+ global $AUTH_ACL;
+
+ $this->oldAuth = $auth;
+ $this->oldAuthAcl = $AUTH_ACL;
+
+ $auth = new auth_acl_caseinsensitive_auth();
+ }
+
+ function tearDown() {
+ global $conf;
+ global $AUTH_ACL;
+ global $auth;
+
+ $auth = $this->oldAuth;
+ $AUTH_ACL = $this->oldAuthAcl;
+ }
+
+ function test_multiadmin_restricted_ropage() {
+ global $conf;
+ global $AUTH_ACL;
+
+ $conf['superuser'] = 'John,doe,@Admin1,@admin2';
+ $conf['useacl'] = 1;
+
+ $AUTH_ACL = array(
+ '* @ALL 0',
+ '* @Group1 8',
+ '* @group2 8',
+ 'namespace:page @Group1 1',
+ 'namespace:page @group2 1',
+ );
+
+ // anonymous user
+ $this->assertEquals(auth_aclcheck('page', '', array()), AUTH_NONE);
+ $this->assertEquals(auth_aclcheck('namespace:page', '', array()), AUTH_NONE);
+ $this->assertEquals(auth_aclcheck('namespace:*', '', array()), AUTH_NONE);
+
+ // user with no matching group
+ $this->assertEquals(auth_aclcheck('page', 'jill', array('foo')), AUTH_NONE);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo')), AUTH_NONE);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo')), AUTH_NONE);
+
+ // user with matching group 1
+ $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'group1')), AUTH_UPLOAD);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'group1')), AUTH_READ);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'group1')), AUTH_UPLOAD);
+
+ // user with matching group 2
+ $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'Group2')), AUTH_UPLOAD);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'Group2')), AUTH_READ);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'Group2')), AUTH_UPLOAD);
+
+ // super user John
+ $this->assertEquals(auth_aclcheck('page', 'john', array('foo')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'john', array('foo')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'john', array('foo')), AUTH_ADMIN);
+
+ // super user doe
+ $this->assertEquals(auth_aclcheck('page', 'Doe', array('foo')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'Doe', array('foo')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'Doe', array('foo')), AUTH_ADMIN);
+
+ // user with matching admin group 1
+ $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'admin1')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'admin1')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'admin1')), AUTH_ADMIN);
+
+ // user with matching admin group 2
+ $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'Admin2')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'Admin2')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'Admin2')), AUTH_ADMIN);
+ }
+
+ /*
+ * Test aclcheck on @ALL group
+ *
+ * The default permission for @ALL group is AUTH_NONE. So we use an
+ * ACL entry which grants @ALL group an AUTH_READ permission to see
+ * whether ACL matching is properly done or not.
+ */
+ function test_restricted_allread() {
+ global $conf;
+ global $AUTH_ACL;
+
+ $conf['superuser'] = 'john';
+ $conf['useacl'] = 1;
+
+ $AUTH_ACL = array(
+ '* @ALL 1',
+ '* @group1 8',
+ );
+
+ // anonymous user
+ $this->assertEquals(auth_aclcheck('page', '', array()), AUTH_READ);
+ $this->assertEquals(auth_aclcheck('namespace:page', '', array()), AUTH_READ);
+ $this->assertEquals(auth_aclcheck('namespace:*', '', array()), AUTH_READ);
+
+ // user with no matching group
+ $this->assertEquals(auth_aclcheck('page', 'jill', array('foo')), AUTH_READ);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo')), AUTH_READ);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo')), AUTH_READ);
+
+ // user with matching group
+ $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'Group1')), AUTH_UPLOAD);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'Group1')), AUTH_UPLOAD);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'Group1')), AUTH_UPLOAD);
+
+ // super user
+ $this->assertEquals(auth_aclcheck('page', 'John', array('foo')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:page', 'John', array('foo')), AUTH_ADMIN);
+ $this->assertEquals(auth_aclcheck('namespace:*', 'John', array('foo')), AUTH_ADMIN);
+ }
+}
diff --git a/_test/tests/inc/auth_admincheck.test.php b/_test/tests/inc/auth_admincheck.test.php
index d88399cbe..17424a08e 100644
--- a/_test/tests/inc/auth_admincheck.test.php
+++ b/_test/tests/inc/auth_admincheck.test.php
@@ -10,7 +10,8 @@ class auth_admin_test extends DokuWikiTest {
private $oldauth;
- function setup() {
+ function setUp() {
+ parent::setUp();
global $auth;
$this->oldauth = $auth;
}
@@ -27,9 +28,7 @@ class auth_admin_test extends DokuWikiTest {
function teardown() {
global $auth;
- global $conf;
global $AUTH_ACL;
- unset($conf);
unset($AUTH_ACL);
$auth = $this->oldauth;
}
diff --git a/_test/tests/inc/auth_nameencode.test.php b/_test/tests/inc/auth_nameencode.test.php
index 21db304e0..da9f31f90 100644
--- a/_test/tests/inc/auth_nameencode.test.php
+++ b/_test/tests/inc/auth_nameencode.test.php
@@ -2,7 +2,7 @@
class auth_nameencode_test extends DokuWikiTest {
- function teardown() {
+ function tearDown() {
global $cache_authname;
$cache_authname = array();
}
diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php
index b2c74a257..053e216b8 100644
--- a/_test/tests/inc/mailer.test.php
+++ b/_test/tests/inc/mailer.test.php
@@ -7,6 +7,14 @@ class TestMailer extends Mailer {
public function prop($name){
return $this->$name;
}
+
+ public function &propRef($name) {
+ return $this->$name;
+ }
+
+ public function prepareHeaders() {
+ return parent::prepareHeaders();
+ }
}
class mailer_test extends DokuWikiTest {
@@ -90,5 +98,17 @@ class mailer_test extends DokuWikiTest {
}
}
+ /**
+ * @see https://forum.dokuwiki.org/post/35822
+ */
+ function test_emptyBCCorCC() {
+ $mail = new TestMailer();
+ $headers = &$mail->propRef('headers');
+ $headers['Bcc'] = '';
+ $headers['Cc'] = '';
+ $header = $mail->prepareHeaders();
+ $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.');
+ $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Bcc found in headers.');
+ }
}
//Setup VIM: ex: et ts=4 :
diff --git a/_test/tests/inc/parser/parser.inc.php b/_test/tests/inc/parser/parser.inc.php
index e9efef0d3..61f15678b 100644
--- a/_test/tests/inc/parser/parser.inc.php
+++ b/_test/tests/inc/parser/parser.inc.php
@@ -8,7 +8,8 @@ abstract class TestOfDoku_Parser extends PHPUnit_Framework_TestCase {
var $P;
var $H;
- function setup() {
+ function setUp() {
+ parent::setUp();
$this->P = new Doku_Parser();
$this->H = new Doku_Handler();
$this->P->Handler = & $this->H;
diff --git a/_test/tests/inc/parser/parser_footnote.test.php b/_test/tests/inc/parser/parser_footnote.test.php
index f3b5ddf56..b47a575de 100644
--- a/_test/tests/inc/parser/parser_footnote.test.php
+++ b/_test/tests/inc/parser/parser_footnote.test.php
@@ -3,8 +3,8 @@ require_once 'parser.inc.php';
class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser {
- function setup() {
- parent::setup();
+ function setUp() {
+ parent::setUp();
$this->P->addMode('footnote',new Doku_Parser_Mode_Footnote());
}
diff --git a/_test/tests/inc/parser/parser_quotes.test.php b/_test/tests/inc/parser/parser_quotes.test.php
index b2dae1039..b82328212 100644
--- a/_test/tests/inc/parser/parser_quotes.test.php
+++ b/_test/tests/inc/parser/parser_quotes.test.php
@@ -3,8 +3,8 @@ require_once 'parser.inc.php';
class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser {
- function setup() {
- parent::setup();
+ function setUp() {
+ parent::setUp();
global $conf;
$conf['typography'] = 2;
}
diff --git a/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php b/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php
index 0683848f1..f08785ca2 100644
--- a/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php
+++ b/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php
@@ -50,7 +50,8 @@ class parserutils_set_metadata_during_rendering_test extends DokuWikiTest {
function helper_set_metadata($event, $meta) {
if ($this->active) {
p_set_metadata($this->id, $meta, false, true);
- $key = array_pop(array_keys($meta));
+ $keys = array_keys($meta);
+ $key = array_pop($keys);
$this->assertTrue(is_string($meta[$key])); // ensure we really have a key
// ensure that the metadata property hasn't been set previously
$this->assertNotEquals($meta[$key], p_get_metadata($this->id, $key));
diff --git a/_test/tests/inc/remote.test.php b/_test/tests/inc/remote.test.php
index 49152d8db..611e1ab0f 100644
--- a/_test/tests/inc/remote.test.php
+++ b/_test/tests/inc/remote.test.php
@@ -112,12 +112,12 @@ class remote_plugin_testplugin extends DokuWiki_Remote_Plugin {
class remote_test extends DokuWikiTest {
- var $originalConf;
var $userinfo;
var $remote;
function setUp() {
+ parent::setUp();
global $plugin_controller;
global $conf;
global $USERINFO;
@@ -131,7 +131,6 @@ class remote_test extends DokuWikiTest {
$plugin_controller = $pluginManager;
- $this->originalConf = $conf;
$conf['remote'] = 1;
$conf['remoteuser'] = '!!not set!!';
$conf['useacl'] = 0;
@@ -143,9 +142,7 @@ class remote_test extends DokuWikiTest {
}
function tearDown() {
- global $conf;
global $USERINFO;
- $conf = $this->originalConf;
$USERINFO = $this->userinfo;
}
diff --git a/_test/tests/inc/subscription_set.test.php b/_test/tests/inc/subscription_set.test.php
new file mode 100644
index 000000000..5c0a6c816
--- /dev/null
+++ b/_test/tests/inc/subscription_set.test.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Tests the subscription set function
+ */
+class subscription_set_test extends DokuWikiTest {
+ /**
+ * Tests, if overwriting subscriptions works even when subscriptions for the same
+ * user exist for two nested namespaces, this is a test for the bug described in FS#2580
+ */
+ function test_overwrite() {
+ subscription_set('admin', ':', 'digest', '123456789');
+ subscription_set('admin', ':wiki:', 'digest', '123456789');
+ subscription_set('admin', ':', 'digest', '1234', true);
+ subscription_set('admin', ':wiki:', 'digest', '1234', true);
+ $subscriptions = subscription_find(':wiki:', array('user' => 'admin'));
+ $this->assertCount(1, $subscriptions[':'], 'More than one subscription saved for the root namespace even though the old one should have been overwritten.');
+ $this->assertCount(1, $subscriptions[':wiki:'], 'More than one subscription saved for the wiki namespace even though the old one should have been overwritten.');
+ $this->assertCount(2, $subscriptions, 'Didn\'t find the expected two subscriptions');
+ }
+}
diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php
new file mode 100644
index 000000000..e8805a75d
--- /dev/null
+++ b/_test/tests/inc/tar.test.php
@@ -0,0 +1,319 @@
+<?php
+
+class Tar_TestCase extends DokuWikiTest {
+
+ /**
+ * simple test that checks that the given filenames and contents can be grepped from
+ * the uncompressed tar stream
+ *
+ * No check for format correctness
+ */
+ public function test_createdynamic() {
+ $tar = new Tar();
+
+ $dir = dirname(__FILE__).'/tar';
+
+ $tar->create();
+ $tar->AddFile("$dir/testdata1.txt");
+ $tar->AddFile("$dir/foobar/testdata2.txt", 'noway/testdata2.txt');
+ $tar->addData('another/testdata3.txt', 'testcontent3');
+
+ $data = $tar->getArchive();
+
+ $this->assertTrue(strpos($data, 'testcontent1') !== false, 'Content in TAR');
+ $this->assertTrue(strpos($data, 'testcontent2') !== false, 'Content in TAR');
+ $this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in TAR');
+
+ $this->assertTrue(strpos($data, "$dir/testdata1.txt") !== false, 'Path in TAR');
+ $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR');
+ $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR');
+
+ $this->assertTrue(strpos($data, "$dir/foobar/testdata2.txt") === false, 'Path not in TAR');
+ $this->assertTrue(strpos($data, "foobar") === false, 'Path not in TAR');
+ }
+
+ /**
+ * simple test that checks that the given filenames and contents can be grepped from the
+ * uncompressed tar file
+ *
+ * No check for format correctness
+ */
+ public function test_createfile() {
+ $tar = new Tar();
+
+ $dir = dirname(__FILE__).'/tar';
+ $tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
+
+ $tar->create($tmp, Tar::COMPRESS_NONE);
+ $tar->AddFile("$dir/testdata1.txt");
+ $tar->AddFile("$dir/foobar/testdata2.txt", 'noway/testdata2.txt');
+ $tar->addData('another/testdata3.txt', 'testcontent3');
+ $tar->close();
+
+ $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number
+ $data = file_get_contents($tmp);
+
+ $this->assertTrue(strpos($data, 'testcontent1') !== false, 'Content in TAR');
+ $this->assertTrue(strpos($data, 'testcontent2') !== false, 'Content in TAR');
+ $this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in TAR');
+
+ $this->assertTrue(strpos($data, "$dir/testdata1.txt") !== false, 'Path in TAR');
+ $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR');
+ $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR');
+
+ $this->assertTrue(strpos($data, "$dir/foobar/testdata2.txt") === false, 'Path not in TAR');
+ $this->assertTrue(strpos($data, "foobar") === false, 'Path not in TAR');
+
+ @unlink($tmp);
+ }
+
+ /**
+ * List the contents of the prebuilt TAR files
+ */
+ public function test_tarcontent() {
+ $dir = dirname(__FILE__).'/tar';
+
+ foreach(array('tar', 'tgz', 'tbz') as $ext) {
+ $tar = new Tar();
+ $file = "$dir/test.$ext";
+
+ $tar->open($file);
+ $content = $tar->contents();
+
+ $this->assertCount(4, $content, "Contents of $file");
+ $this->assertEquals('tar/testdata1.txt', $content[1]['filename'], "Contents of $file");
+ $this->assertEquals(13, $content[1]['size'], "Contents of $file");
+
+ $this->assertEquals('tar/foobar/testdata2.txt', $content[3]['filename'], "Contents of $file");
+ $this->assertEquals(13, $content[1]['size'], "Contents of $file");
+ }
+ }
+
+ /**
+ * Extract the prebuilt tar files
+ */
+ public function test_tarextract() {
+ $dir = dirname(__FILE__).'/tar';
+ $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+ foreach(array('tar', 'tgz', 'tbz') as $ext) {
+ $tar = new Tar();
+ $file = "$dir/test.$ext";
+
+ $tar->open($file);
+ $tar->extract($out);
+
+ clearstatcache();
+
+ $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file");
+ $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file");
+
+ $this->assertFileExists($out.'/tar/foobar/testdata2.txt', "Extracted $file");
+ $this->assertEquals(13, filesize($out.'/tar/foobar/testdata2.txt'), "Extracted $file");
+
+ TestUtils::rdelete($out);
+ }
+ }
+
+ /**
+ * Extract the prebuilt tar files with component stripping
+ */
+ public function test_compstripextract() {
+ $dir = dirname(__FILE__).'/tar';
+ $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+ foreach(array('tar', 'tgz', 'tbz') as $ext) {
+ $tar = new Tar();
+ $file = "$dir/test.$ext";
+
+ $tar->open($file);
+ $tar->extract($out, 1);
+
+ clearstatcache();
+
+ $this->assertFileExists($out.'/testdata1.txt', "Extracted $file");
+ $this->assertEquals(13, filesize($out.'/testdata1.txt'), "Extracted $file");
+
+ $this->assertFileExists($out.'/foobar/testdata2.txt', "Extracted $file");
+ $this->assertEquals(13, filesize($out.'/foobar/testdata2.txt'), "Extracted $file");
+
+ TestUtils::rdelete($out);
+ }
+ }
+
+ /**
+ * Extract the prebuilt tar files with prefix stripping
+ */
+ public function test_prefixstripextract() {
+ $dir = dirname(__FILE__).'/tar';
+ $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+ foreach(array('tar', 'tgz', 'tbz') as $ext) {
+ $tar = new Tar();
+ $file = "$dir/test.$ext";
+
+ $tar->open($file);
+ $tar->extract($out, 'tar/foobar/');
+
+ clearstatcache();
+
+ $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file");
+ $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file");
+
+ $this->assertFileExists($out.'/testdata2.txt', "Extracted $file");
+ $this->assertEquals(13, filesize($out.'/testdata2.txt'), "Extracted $file");
+
+ TestUtils::rdelete($out);
+ }
+ }
+
+ /**
+ * Extract the prebuilt tar files with include regex
+ */
+ public function test_includeextract() {
+ $dir = dirname(__FILE__).'/tar';
+ $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+ foreach(array('tar', 'tgz', 'tbz') as $ext) {
+ $tar = new Tar();
+ $file = "$dir/test.$ext";
+
+ $tar->open($file);
+ $tar->extract($out, '', '', '/\/foobar\//');
+
+ clearstatcache();
+
+ $this->assertFileNotExists($out.'/tar/testdata1.txt', "Extracted $file");
+
+ $this->assertFileExists($out.'/tar/foobar/testdata2.txt', "Extracted $file");
+ $this->assertEquals(13, filesize($out.'/tar/foobar/testdata2.txt'), "Extracted $file");
+
+ TestUtils::rdelete($out);
+ }
+ }
+
+ /**
+ * Extract the prebuilt tar files with exclude regex
+ */
+ public function test_excludeextract() {
+ $dir = dirname(__FILE__).'/tar';
+ $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+ foreach(array('tar', 'tgz', 'tbz') as $ext) {
+ $tar = new Tar();
+ $file = "$dir/test.$ext";
+
+ $tar->open($file);
+ $tar->extract($out, '', '/\/foobar\//');
+
+ clearstatcache();
+
+ $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file");
+ $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file");
+
+ $this->assertFileNotExists($out.'/tar/foobar/testdata2.txt', "Extracted $file");
+
+ TestUtils::rdelete($out);
+ }
+ }
+
+ /**
+ * Check the extension to compression guesser
+ */
+ public function test_filetype() {
+ $tar = new Tar();
+ $this->assertEquals(Tar::COMPRESS_NONE, $tar->filetype('foo'));
+ $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tgz'));
+ $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tGZ'));
+ $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tar.GZ'));
+ $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tar.gz'));
+ $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tbz'));
+ $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tBZ'));
+ $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ2'));
+ $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2'));
+ }
+
+ public function test_longpathextract() {
+ $dir = dirname(__FILE__).'/tar';
+ $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+ foreach(array('ustar', 'gnu') as $format) {
+ $tar = new Tar();
+ $tar->open("$dir/longpath-$format.tgz");
+ $tar->extract($out);
+
+ $this->assertFileExists($out.'/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/test.txt');
+
+ TestUtils::rdelete($out);
+ }
+ }
+
+ public function test_createlongpathustar() {
+ $tar = new Tar();
+ $tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
+
+ $path = '';
+ for($i=0; $i<11; $i++) $path .= '1234567890/';
+ $path = rtrim($path,'/');
+
+ $tar->create($tmp, Tar::COMPRESS_NONE);
+ $tar->addData("$path/test.txt", 'testcontent1');
+ $tar->close();
+
+ $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number
+ $data = file_get_contents($tmp);
+
+ // We should find the path and filename separated, no longlink entry
+ $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR');
+ $this->assertTrue(strpos($data, 'test.txt') !== false, 'filename in TAR');
+ $this->assertTrue(strpos($data, $path) !== false, 'path in TAR');
+ $this->assertFalse(strpos($data, "$path/test.txt") !== false, 'full filename in TAR');
+ $this->assertFalse(strpos($data, '@LongLink') !== false, '@LongLink in TAR');
+
+ @unlink($tmp);
+ }
+
+ public function test_createlongpathgnu() {
+ $tar = new Tar();
+ $tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
+
+ $path = '';
+ for($i=0; $i<20; $i++) $path .= '1234567890/';
+ $path = rtrim($path,'/');
+
+ $tar->create($tmp, Tar::COMPRESS_NONE);
+ $tar->addData("$path/test.txt", 'testcontent1');
+ $tar->close();
+
+ $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number
+ $data = file_get_contents($tmp);
+
+ // We should find the complete path/filename and a longlink entry
+ $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR');
+ $this->assertTrue(strpos($data, 'test.txt') !== false, 'filename in TAR');
+ $this->assertTrue(strpos($data, $path) !== false, 'path in TAR');
+ $this->assertTrue(strpos($data, "$path/test.txt") !== false, 'full filename in TAR');
+ $this->assertTrue(strpos($data, '@LongLink') !== false, '@LongLink in TAR');
+
+ @unlink($tmp);
+ }
+
+ /**
+ * Extract a tarbomomb
+ */
+ public function test_tarbomb() {
+ $dir = dirname(__FILE__).'/tar';
+ $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+ $tar = new Tar();
+
+ $tar->open("$dir/tarbomb.tgz");
+ $tar->extract($out);
+
+ clearstatcache();
+
+ $this->assertFileExists($out.'/AAAAAAAAAAAAAAAAA/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB.txt');
+
+ TestUtils::rdelete($out);
+ }
+} \ No newline at end of file
diff --git a/_test/tests/inc/tar/foobar/testdata2.txt b/_test/tests/inc/tar/foobar/testdata2.txt
new file mode 100644
index 000000000..a7db15771
--- /dev/null
+++ b/_test/tests/inc/tar/foobar/testdata2.txt
@@ -0,0 +1 @@
+testcontent2
diff --git a/_test/tests/inc/tar/longpath-gnu.tgz b/_test/tests/inc/tar/longpath-gnu.tgz
new file mode 100644
index 000000000..6c937c8fe
--- /dev/null
+++ b/_test/tests/inc/tar/longpath-gnu.tgz
Binary files differ
diff --git a/_test/tests/inc/tar/longpath-ustar.tgz b/_test/tests/inc/tar/longpath-ustar.tgz
new file mode 100644
index 000000000..59efbff66
--- /dev/null
+++ b/_test/tests/inc/tar/longpath-ustar.tgz
Binary files differ
diff --git a/_test/tests/inc/tar/tarbomb.tgz b/_test/tests/inc/tar/tarbomb.tgz
new file mode 100644
index 000000000..8418d4073
--- /dev/null
+++ b/_test/tests/inc/tar/tarbomb.tgz
Binary files differ
diff --git a/_test/tests/inc/tar/test.tar b/_test/tests/inc/tar/test.tar
new file mode 100644
index 000000000..931866b0b
--- /dev/null
+++ b/_test/tests/inc/tar/test.tar
Binary files differ
diff --git a/_test/tests/inc/tar/test.tbz b/_test/tests/inc/tar/test.tbz
new file mode 100644
index 000000000..5a7374019
--- /dev/null
+++ b/_test/tests/inc/tar/test.tbz
Binary files differ
diff --git a/_test/tests/inc/tar/test.tgz b/_test/tests/inc/tar/test.tgz
new file mode 100644
index 000000000..b00319649
--- /dev/null
+++ b/_test/tests/inc/tar/test.tgz
Binary files differ
diff --git a/_test/tests/inc/tar/testdata1.txt b/_test/tests/inc/tar/testdata1.txt
new file mode 100644
index 000000000..ac65bb32e
--- /dev/null
+++ b/_test/tests/inc/tar/testdata1.txt
@@ -0,0 +1 @@
+testcontent1
diff --git a/_test/tests/inc/template_sidebar.test.php b/_test/tests/inc/template_include_page.test.php
index 56153894a..47d4d46f1 100644
--- a/_test/tests/inc/template_sidebar.test.php
+++ b/_test/tests/inc/template_include_page.test.php
@@ -1,12 +1,12 @@
<?php
-class template_sidebar_test extends DokuWikiTest {
+class template_include_page_test extends DokuWikiTest {
function testNoSidebar() {
global $ID;
$ID = 'foo:bar:baz:test';
- $sidebar = tpl_sidebar(false);
- $this->assertEquals('',$sidebar);
+ $sidebar = tpl_include_page('sidebar', false, true);
+ $this->assertEquals('', $sidebar);
}
function testExistingSidebars() {
@@ -15,25 +15,25 @@ class template_sidebar_test extends DokuWikiTest {
saveWikiText('sidebar', 'topsidebar-test', '');
$ID = 'foo:bar:baz:test';
- $sidebar = tpl_sidebar(false);
+ $sidebar = tpl_include_page('sidebar', false, true);
$this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0);
$ID = 'foo';
- $sidebar = tpl_sidebar(false);
+ $sidebar = tpl_include_page('sidebar', false, true);
$this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0);
saveWikiText('foo:bar:sidebar', 'bottomsidebar-test', '');
$ID = 'foo:bar:baz:test';
- $sidebar = tpl_sidebar(false);
+ $sidebar = tpl_include_page('sidebar', false, true);
$this->assertTrue(strpos($sidebar, 'bottomsidebar-test') > 0);
$ID = 'foo:bar:test';
- $sidebar = tpl_sidebar(false);
+ $sidebar = tpl_include_page('sidebar', false, true);
$this->assertTrue(strpos($sidebar, 'bottomsidebar-test') > 0);
$ID = 'foo';
- $sidebar = tpl_sidebar(false);
+ $sidebar = tpl_include_page('sidebar', false, true);
$this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0);
}