summaryrefslogtreecommitdiff
path: root/lib/plugins/extension/_test/extension.test.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2013-08-09 20:04:17 +0200
committerAndreas Gohr <andi@splitbrain.org>2013-08-09 20:04:17 +0200
commit519895b5625277197a88748c515919515f1113b8 (patch)
tree8fbc02ed6efb617d2ba7045232ed795fd7dfee05 /lib/plugins/extension/_test/extension.test.php
parent61746d5540723d7463a0c1d666decb9c164c6678 (diff)
downloadrpg-519895b5625277197a88748c515919515f1113b8.tar.gz
rpg-519895b5625277197a88748c515919515f1113b8.tar.bz2
added tests for the find_folders method
Diffstat (limited to 'lib/plugins/extension/_test/extension.test.php')
-rw-r--r--lib/plugins/extension/_test/extension.test.php234
1 files changed, 232 insertions, 2 deletions
diff --git a/lib/plugins/extension/_test/extension.test.php b/lib/plugins/extension/_test/extension.test.php
index 6dfa49a46..97726d212 100644
--- a/lib/plugins/extension/_test/extension.test.php
+++ b/lib/plugins/extension/_test/extension.test.php
@@ -1,10 +1,23 @@
<?php
+
+/**
+ * Class mock_helper_plugin_extension_extension
+ *
+ * makes protected methods accessible
+ */
+class mock_helper_plugin_extension_extension extends helper_plugin_extension_extension {
+ public function find_folders(&$result, $base, $default_type = 'plugin', $dir = '') {
+ return parent::find_folders($result, $base, $default_type, $dir);
+ }
+
+}
+
/**
* @group plugin_extension
*/
class helper_plugin_extension_extension_test extends DokuWikiTest {
- protected $pluginsEnabled = array('extension');
+ protected $pluginsEnabled = array('extension');
/**
* FIXME should we test this without internet first?
@@ -12,7 +25,6 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
* @group internet
*/
public function testExtensionParameters() {
-
$extension = new helper_plugin_extension_extension();
$extension->setExtension('extension');
@@ -56,7 +68,225 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
$this->assertTrue($extension->isEnabled());
$this->assertTrue($extension->isInstalled());
$this->assertTrue($extension->isBundled());
+ }
+
+ public function testFindFoldersPlugins() {
+ $extension = new mock_helper_plugin_extension_extension();
+ $tdir = dirname(__FILE__).'/testdata';
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/plugin1", 'plugin');
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('plugin', $result['old'][0]['type']);
+ $this->assertEquals('plugin1', $this->extdir($result['old'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/plugin2", 'plugin');
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('plugin', $result['new'][0]['type']);
+ $this->assertEquals('plugin2', $result['new'][0]['base']);
+ $this->assertEquals('plugin2', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/plgsub3", 'plugin');
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('plugin', $result['old'][0]['type']);
+ $this->assertEquals('plgsub3/plugin3', $this->extdir($result['old'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/plgsub4", 'plugin');
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('plugin', $result['new'][0]['type']);
+ $this->assertEquals('plugin4', $result['new'][0]['base']);
+ $this->assertEquals('plgsub4/plugin4', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/plgfoo5", 'plugin');
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('plugin', $result['new'][0]['type']);
+ $this->assertEquals('plugin5', $result['new'][0]['base']);
+ $this->assertEquals('plgfoo5', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/plgsub6/plgfoo6", 'plugin');
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('plugin', $result['new'][0]['type']);
+ $this->assertEquals('plugin6', $result['new'][0]['base']);
+ $this->assertEquals('plgsub6/plgfoo6', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/either1", 'plugin');
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('plugin', $result['old'][0]['type']);
+ $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/eithersub2/either2", 'plugin');
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('plugin', $result['old'][0]['type']);
+ $this->assertEquals('eithersub2/either2', $this->extdir($result['old'][0]['tmp']));
+ }
+
+ public function testFindFoldersTemplates() {
+ $extension = new mock_helper_plugin_extension_extension();
+ $tdir = dirname(__FILE__).'/testdata';
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/template1", 'template');
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('template', $result['old'][0]['type']);
+ $this->assertEquals('template1', $this->extdir($result['old'][0]['tmp']));
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/template2", 'template');
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('template', $result['new'][0]['type']);
+ $this->assertEquals('template2', $result['new'][0]['base']);
+ $this->assertEquals('template2', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/tplsub3", 'template');
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('template', $result['old'][0]['type']);
+ $this->assertEquals('tplsub3/template3', $this->extdir($result['old'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/tplsub4", 'template');
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('template', $result['new'][0]['type']);
+ $this->assertEquals('template4', $result['new'][0]['base']);
+ $this->assertEquals('tplsub4/template4', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/tplfoo5", 'template');
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('template', $result['new'][0]['type']);
+ $this->assertEquals('template5', $result['new'][0]['base']);
+ $this->assertEquals('tplfoo5', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/tplsub6/tplfoo6", 'template');
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('template', $result['new'][0]['type']);
+ $this->assertEquals('template6', $result['new'][0]['base']);
+ $this->assertEquals('tplsub6/tplfoo6', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/either1", 'template');
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('template', $result['old'][0]['type']);
+ $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/eithersub2/either2", 'template');
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('template', $result['old'][0]['type']);
+ $this->assertEquals('eithersub2/either2', $this->extdir($result['old'][0]['tmp']));
+ }
+
+ public function testFindFoldersTemplatesAutodetect() {
+ $extension = new mock_helper_plugin_extension_extension();
+ $tdir = dirname(__FILE__).'/testdata';
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/template1");
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('template', $result['old'][0]['type']);
+ $this->assertEquals('template1', $this->extdir($result['old'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/template2");
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('template', $result['new'][0]['type']);
+ $this->assertEquals('template2', $result['new'][0]['base']);
+ $this->assertEquals('template2', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/tplsub3");
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('template', $result['old'][0]['type']);
+ $this->assertEquals('tplsub3/template3', $this->extdir($result['old'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/tplsub4");
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('template', $result['new'][0]['type']);
+ $this->assertEquals('template4', $result['new'][0]['base']);
+ $this->assertEquals('tplsub4/template4', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/tplfoo5");
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('template', $result['new'][0]['type']);
+ $this->assertEquals('template5', $result['new'][0]['base']);
+ $this->assertEquals('tplfoo5', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/tplsub6/tplfoo6");
+ $this->assertTrue($ok);
+ $this->assertEquals(1, count($result['new']));
+ $this->assertEquals('template', $result['new'][0]['type']);
+ $this->assertEquals('template6', $result['new'][0]['base']);
+ $this->assertEquals('tplsub6/tplfoo6', $this->extdir($result['new'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/either1");
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('plugin', $result['old'][0]['type']);
+ $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
+
+ $result = array('old' => array(), 'new' => array());
+ $ok = $extension->find_folders($result, "$tdir/eithersub2/either2");
+ $this->assertTrue($ok);
+ $this->assertEquals(0, count($result['new']));
+ $this->assertEquals(1, count($result['old']));
+ $this->assertEquals('plugin', $result['old'][0]['type']);
+ $this->assertEquals('eithersub2/either2', $this->extdir($result['old'][0]['tmp']));
}
+ /**
+ * remove the test data directory from a dir name for cross install comparison
+ *
+ * @param string $dir
+ * @return string
+ */
+ protected function extdir($dir) {
+ $tdir = dirname(__FILE__).'/testdata';
+ $len = strlen($tdir);
+ $dir = trim(substr($dir, $len), '/');
+ return $dir;
+ }
} \ No newline at end of file