summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/farmer/_test
diff options
context:
space:
mode:
Diffstat (limited to 'platform/www/lib/plugins/farmer/_test')
-rw-r--r--platform/www/lib/plugins/farmer/_test/core.test.php40
-rw-r--r--platform/www/lib/plugins/farmer/_test/general.test.php36
-rw-r--r--platform/www/lib/plugins/farmer/_test/getUserLine.test.php86
-rw-r--r--platform/www/lib/plugins/farmer/_test/helper.test.php64
4 files changed, 226 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/farmer/_test/core.test.php b/platform/www/lib/plugins/farmer/_test/core.test.php
new file mode 100644
index 0000000..d6a1dab
--- /dev/null
+++ b/platform/www/lib/plugins/farmer/_test/core.test.php
@@ -0,0 +1,40 @@
+<?php
+namespace plugin\struct\test;
+
+require_once(__DIR__ . '/../DokuWikiFarmCore.php');
+
+class DokuWikiFarmCore extends \DokuWikiFarmCore {
+ public function getAnimalNamesForHost($host) {
+ return parent::getAnimalNamesForHost($host);
+ }
+}
+
+
+/**
+ * @group plugin_farmer
+ * @group plugins
+ */
+class core_plugin_farmer_test extends \DokuWikiTest {
+
+ protected $pluginsEnabled = array('farmer');
+
+
+ public function test_hostsAnimals() {
+ $core = new DokuWikiFarmCore();
+
+ $input = 'www.foobar.example.com:8000';
+ $expect = array(
+ 'www.foobar.example.com.8000',
+ 'foobar.example.com.8000',
+ 'www.foobar.example.com',
+ 'foobar.example.com',
+ 'www.foobar.example',
+ 'foobar.example',
+ 'www.foobar',
+ 'foobar',
+ 'www',
+ );
+
+ $this->assertEquals($expect, $core->getAnimalNamesForHost($input));
+ }
+}
diff --git a/platform/www/lib/plugins/farmer/_test/general.test.php b/platform/www/lib/plugins/farmer/_test/general.test.php
new file mode 100644
index 0000000..af45139
--- /dev/null
+++ b/platform/www/lib/plugins/farmer/_test/general.test.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * General tests for the farmer plugin
+ *
+ * @group plugin_farmer
+ * @group plugins
+ */
+class general_plugin_farmer_test extends DokuWikiTest {
+
+ protected $pluginsEnabled = array('farmer');
+
+ /**
+ * Simple test to make sure the plugin.info.txt is in correct format
+ */
+ public function test_plugininfo() {
+ $file = __DIR__ . '/../plugin.info.txt';
+ $this->assertFileExists($file);
+
+ $info = confToHash($file);
+
+ $this->assertArrayHasKey('base', $info);
+ $this->assertArrayHasKey('author', $info);
+ $this->assertArrayHasKey('email', $info);
+ $this->assertArrayHasKey('date', $info);
+ $this->assertArrayHasKey('name', $info);
+ $this->assertArrayHasKey('desc', $info);
+ $this->assertArrayHasKey('url', $info);
+
+ $this->assertEquals('farmer', $info['base']);
+ $this->assertRegExp('/^https?:\/\//', $info['url']);
+ $this->assertTrue(mail_isvalid($info['email']));
+ $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
+ $this->assertTrue(false !== strtotime($info['date']));
+ }
+}
diff --git a/platform/www/lib/plugins/farmer/_test/getUserLine.test.php b/platform/www/lib/plugins/farmer/_test/getUserLine.test.php
new file mode 100644
index 0000000..8f228cb
--- /dev/null
+++ b/platform/www/lib/plugins/farmer/_test/getUserLine.test.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace plugin\struct\test;
+
+class admin_plugin_farmer_new extends \admin_plugin_farmer_new {
+ public function getAdminLine() {
+ return parent::getAdminLine();
+ }
+
+}
+
+
+/**
+ * Tests for the validation functionality of the farmer plugin
+ *
+ * @group plugin_farmer
+ * @group plugins
+ */
+class getUserLine_plugin_farmer_test extends \DokuWikiTest {
+
+ protected $pluginsEnabled = array('farmer',);
+ private $usersfile;
+
+ public function setUp() {
+ parent::setUp();
+ $this->usersfile = DOKU_CONF . 'users.auth.php';
+ copy($this->usersfile, $this->usersfile . "org");
+ unlink($this->usersfile);
+ }
+
+ public function tearDown() {
+ parent::tearDown();
+ unlink($this->usersfile);
+ copy($this->usersfile . "org", $this->usersfile);
+ unlink($this->usersfile . "org");
+ }
+
+
+ public function test_getUserLine_oneUser () {
+ $helper = new admin_plugin_farmer_new();
+ $usersfileData = "# users.auth.php
+# <?php exit()?>
+# Don't modify the lines above
+#
+# Userfile
+#
+# Format:
+#
+# user:MD5password:Real Name:email:groups,comma,seperated
+#
+# testuser : testpass
+testuser:179ad45c6ce2cb97cf1029e212046e81:Arthur Dent:arthur@example.com:\n";
+ file_put_contents($this->usersfile,$usersfileData);
+
+ $_SERVER['REMOTE_USER'] = 'testuser';
+ $expected_result = 'testuser:179ad45c6ce2cb97cf1029e212046e81:Arthur Dent:arthur@example.com:' . "\n";
+ $actual_result = $helper->getAdminLine();
+
+ $this->assertSame($expected_result, $actual_result);
+ }
+
+ public function test_getUserLine_manyUser () {
+ $helper = new admin_plugin_farmer_new();
+ $usersfileData = "# users.auth.php
+# <?php exit()?>
+# Don't modify the lines above
+#
+# Userfile
+#
+# Format:
+#
+# user:MD5password:Real Name:email:groups,comma,seperated
+#
+# testuser : testpass
+1testuser:179ad45c6ce43897cf1029e212046e81:Arthur Dent:brthur@example.com:admin
+testuser:179ad45c6ce2cb97cf1029e212046e81:Arthur Dent:arthur@example.com:
+2testuser:179ad45c6ce2cb97cf10214712046e81:Arthur inDent:crthur@example.com:admin\n";
+ file_put_contents($this->usersfile,$usersfileData);
+
+ $_SERVER['REMOTE_USER'] = 'testuser';
+ $expected_result = 'testuser:179ad45c6ce2cb97cf1029e212046e81:Arthur Dent:arthur@example.com:' . "\n";
+ $actual_result = $helper->getAdminLine();
+
+ $this->assertSame($expected_result, $actual_result);
+ }
+}
diff --git a/platform/www/lib/plugins/farmer/_test/helper.test.php b/platform/www/lib/plugins/farmer/_test/helper.test.php
new file mode 100644
index 0000000..3fc689b
--- /dev/null
+++ b/platform/www/lib/plugins/farmer/_test/helper.test.php
@@ -0,0 +1,64 @@
+<?php
+
+/**
+ * Tests for the validation functionality of the farmer plugin
+ *
+ * @group plugin_farmer
+ * @group plugins
+ */
+class helper_plugin_farmer_test extends DokuWikiTest {
+
+ protected $pluginsEnabled = array('farmer',);
+
+ public function validationProvider() {
+ return array(
+ array('ant', true),
+ array('ant.lion', true),
+ array('ant.lion.cow', true),
+ array('ant-lion', true),
+ array('ant-lion.cow', true),
+ array('4ant', true),
+ array('ant4', true),
+ array('ant44lion', true),
+ array('44', true),
+
+ array('ant.', false),
+ array('.ant', false),
+ array('ant-', false),
+ array('-ant', false),
+ array('ant--lion', false),
+ array('ant..lion', false),
+ array('ant.-lion', false),
+ array('ant/lion', false),
+ array('!ant', false),
+ array('ant lion', false),
+ );
+ }
+
+ /**
+ * @dataProvider validationProvider
+ * @param $input
+ * @param $expect
+ */
+ public function test_validateAnimalName($input, $expect) {
+ /** @var helper_plugin_farmer $helper */
+ $helper = plugin_load('helper', 'farmer');
+ $this->assertEquals($expect, $helper->validateAnimalName($input));
+ }
+
+ public function test_isInPath() {
+ /** @var helper_plugin_farmer $helper */
+ $helper = plugin_load('helper', 'farmer');
+
+ $this->assertTrue($helper->isInPath('/var/www/foo', '/var/www'));
+ $this->assertFalse($helper->isInPath('/var/www/../foo', '/var/www'));
+
+ // same dir should return false, too
+ $this->assertFalse($helper->isInPath('/var/www/foo', '/var/www/foo'));
+ $this->assertFalse($helper->isInPath('/var/www/foo/', '/var/www/foo'));
+ $this->assertFalse($helper->isInPath('/var/www/foo/bar/../', '/var/www/foo'));
+
+ // https://github.com/cosmocode/dokuwiki-plugin-farmer/issues/30
+ $this->assertFalse($helper->isInPath('/var/lib/dokuwiki.animals', '/var/lib/dokuwiki'));
+ }
+}