diff options
author | Andreas Gohr <andi@splitbrain.org> | 2013-08-09 20:04:17 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2013-08-09 20:04:17 +0200 |
commit | 519895b5625277197a88748c515919515f1113b8 (patch) | |
tree | 8fbc02ed6efb617d2ba7045232ed795fd7dfee05 /lib/plugins/extension/_test | |
parent | 61746d5540723d7463a0c1d666decb9c164c6678 (diff) | |
download | rpg-519895b5625277197a88748c515919515f1113b8.tar.gz rpg-519895b5625277197a88748c515919515f1113b8.tar.bz2 |
added tests for the find_folders method
Diffstat (limited to 'lib/plugins/extension/_test')
17 files changed, 288 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 diff --git a/lib/plugins/extension/_test/testdata/either1/script.js b/lib/plugins/extension/_test/testdata/either1/script.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/plugins/extension/_test/testdata/either1/script.js diff --git a/lib/plugins/extension/_test/testdata/eithersub2/either2/script.js b/lib/plugins/extension/_test/testdata/eithersub2/either2/script.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/plugins/extension/_test/testdata/eithersub2/either2/script.js diff --git a/lib/plugins/extension/_test/testdata/plgfoo5/plugin.info.txt b/lib/plugins/extension/_test/testdata/plgfoo5/plugin.info.txt new file mode 100644 index 000000000..cc4532d29 --- /dev/null +++ b/lib/plugins/extension/_test/testdata/plgfoo5/plugin.info.txt @@ -0,0 +1,7 @@ +base plugin5 +author Andreas Gohr +email andi@splitbrain.org +date 2013-05-02 +name Dummy Plugin +desc Dummy plugin data +url http://example.com/plugin:plugin5 diff --git a/lib/plugins/extension/_test/testdata/plgsub3/plugin3/syntax.php b/lib/plugins/extension/_test/testdata/plgsub3/plugin3/syntax.php new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/plugins/extension/_test/testdata/plgsub3/plugin3/syntax.php diff --git a/lib/plugins/extension/_test/testdata/plgsub4/plugin4/plugin.info.txt b/lib/plugins/extension/_test/testdata/plgsub4/plugin4/plugin.info.txt new file mode 100644 index 000000000..374b6bf24 --- /dev/null +++ b/lib/plugins/extension/_test/testdata/plgsub4/plugin4/plugin.info.txt @@ -0,0 +1,7 @@ +base plugin4 +author Andreas Gohr +email andi@splitbrain.org +date 2013-05-02 +name Dummy Plugin +desc Dummy plugin data +url http://example.com/plugin:plugin4 diff --git a/lib/plugins/extension/_test/testdata/plgsub6/plgfoo6/plugin.info.txt b/lib/plugins/extension/_test/testdata/plgsub6/plgfoo6/plugin.info.txt new file mode 100644 index 000000000..461ff8735 --- /dev/null +++ b/lib/plugins/extension/_test/testdata/plgsub6/plgfoo6/plugin.info.txt @@ -0,0 +1,7 @@ +base plugin6 +author Andreas Gohr +email andi@splitbrain.org +date 2013-05-02 +name Dummy Plugin +desc Dummy plugin data +url http://example.com/plugin:plugin6 diff --git a/lib/plugins/extension/_test/testdata/plugin1/syntax.php b/lib/plugins/extension/_test/testdata/plugin1/syntax.php new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/plugins/extension/_test/testdata/plugin1/syntax.php diff --git a/lib/plugins/extension/_test/testdata/plugin2/plugin.info.txt b/lib/plugins/extension/_test/testdata/plugin2/plugin.info.txt new file mode 100644 index 000000000..d56758fe9 --- /dev/null +++ b/lib/plugins/extension/_test/testdata/plugin2/plugin.info.txt @@ -0,0 +1,7 @@ +base plugin2 +author Andreas Gohr +email andi@splitbrain.org +date 2013-05-02 +name Dummy Plugin +desc Dummy Plugin data +url http://example.com/plugin:plugin2 diff --git a/lib/plugins/extension/_test/testdata/template1/main.php b/lib/plugins/extension/_test/testdata/template1/main.php new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/plugins/extension/_test/testdata/template1/main.php diff --git a/lib/plugins/extension/_test/testdata/template1/style.ini b/lib/plugins/extension/_test/testdata/template1/style.ini new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/plugins/extension/_test/testdata/template1/style.ini diff --git a/lib/plugins/extension/_test/testdata/template2/template.info.txt b/lib/plugins/extension/_test/testdata/template2/template.info.txt new file mode 100644 index 000000000..882a7b914 --- /dev/null +++ b/lib/plugins/extension/_test/testdata/template2/template.info.txt @@ -0,0 +1,7 @@ +base template2 +author Andreas Gohr +email andi@splitbrain.org +date 2013-05-02 +name Dummy Template +desc Dummy template data +url http://example.com/template:template2 diff --git a/lib/plugins/extension/_test/testdata/tplfoo5/template.info.txt b/lib/plugins/extension/_test/testdata/tplfoo5/template.info.txt new file mode 100644 index 000000000..4d7ecb8ef --- /dev/null +++ b/lib/plugins/extension/_test/testdata/tplfoo5/template.info.txt @@ -0,0 +1,7 @@ +base template5 +author Andreas Gohr +email andi@splitbrain.org +date 2013-05-02 +name Dummy Template +desc Dummy template data +url http://example.com/template:template5 diff --git a/lib/plugins/extension/_test/testdata/tplsub3/template3/main.php b/lib/plugins/extension/_test/testdata/tplsub3/template3/main.php new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/plugins/extension/_test/testdata/tplsub3/template3/main.php diff --git a/lib/plugins/extension/_test/testdata/tplsub3/template3/style.ini b/lib/plugins/extension/_test/testdata/tplsub3/template3/style.ini new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/plugins/extension/_test/testdata/tplsub3/template3/style.ini diff --git a/lib/plugins/extension/_test/testdata/tplsub4/template4/template.info.txt b/lib/plugins/extension/_test/testdata/tplsub4/template4/template.info.txt new file mode 100644 index 000000000..f050555e5 --- /dev/null +++ b/lib/plugins/extension/_test/testdata/tplsub4/template4/template.info.txt @@ -0,0 +1,7 @@ +base template4 +author Andreas Gohr +email andi@splitbrain.org +date 2013-05-02 +name Dummy Template +desc Dummy template data +url http://example.com/template:template4 diff --git a/lib/plugins/extension/_test/testdata/tplsub6/tplfoo6/template.info.txt b/lib/plugins/extension/_test/testdata/tplsub6/tplfoo6/template.info.txt new file mode 100644 index 000000000..ea4dc230d --- /dev/null +++ b/lib/plugins/extension/_test/testdata/tplsub6/tplfoo6/template.info.txt @@ -0,0 +1,7 @@ +base template6 +author Andreas Gohr +email andi@splitbrain.org +date 2013-05-02 +name Dummy Template +desc Dummy template data +url http://example.com/template:template6 |