diff options
Diffstat (limited to 'platform/www/lib/plugins/translation/_test')
-rw-r--r-- | platform/www/lib/plugins/translation/_test/basic.test.php | 113 | ||||
-rw-r--r-- | platform/www/lib/plugins/translation/_test/general.test.php | 61 |
2 files changed, 174 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/translation/_test/basic.test.php b/platform/www/lib/plugins/translation/_test/basic.test.php new file mode 100644 index 0000000..870c7a7 --- /dev/null +++ b/platform/www/lib/plugins/translation/_test/basic.test.php @@ -0,0 +1,113 @@ +<?php + +/** + * General tests for the translation plugin + * + * @group plugin_translation + * @group plugins + */ +class basic_plugin_translation_test extends DokuWikiTest { + + protected $pluginsEnabled = array('translation'); + + public static function buildTransID_testdata() { + return array( + array( + 'en', + 'ns:page', + 'de es', + array(':ns:page', 'en'), + ), + array( + '', + 'ns:page', + 'de es', + array(':ns:page', 'en'), + ), + array( + 'de', + 'ns:page', + 'de es', + array(':de:ns:page', 'de'), + ), + ); + } + + /** + * @dataProvider buildTransID_testdata + * + * @param $inputLang + * @param $inputID + * @param $translationsOption + * @param $expected + */ + public function test_buildTransID($inputLang, $inputID, $translationsOption, $expected) { + global $conf; + $conf['plugin']['translation']['translations'] = $translationsOption; + /** @var helper_plugin_translation $helper */ + $helper = plugin_load('helper', 'translation', true); + + $actual_result = $helper->buildTransID($inputLang, $inputID); + + $this->assertEquals($expected, $actual_result); + } + + + public static function redirectStart_testdata() { + return array( + array( + 'start', + 'de es', + 'de,en-US;q=0.8,en;q=0.5,fr;q=0.3', + ':de:start', + 'redirect to translated page', + ), + array( + 'start', + 'de es', + 'en-US,de;q=0.8,en;q=0.5,fr;q=0.3', + array(), + 'do not redirect if basic namespace is correct lang', + ), + array( + 'de:start', + 'en de es', + 'en-US,en;q=0.8,fr;q=0.5', + array(), + 'do not redirect anything other than exactly $conf[\'start\']', + ), + ); + } + + + /** + * @dataProvider redirectStart_testdata + * + * @param $input + * @param $translationsOption + * @param $httpAcceptHeader + * @param $expected + */ + public function test_redirectStart($input, $translationsOption, $httpAcceptHeader, $expected, $msg) { + global $conf; + $conf['plugin']['translation']['translations'] = $translationsOption; + $conf['plugin']['translation']['redirectstart'] = 1; + + /** @var helper_plugin_translation $helper */ + $helper = plugin_load('helper', 'translation'); + $helper->loadTranslationNamespaces(); + + $request = new TestRequest(); + $request->setServer('HTTP_ACCEPT_LANGUAGE', $httpAcceptHeader); + + $response = $request->get(array('id' => $input)); + $actual = $response->getHeader('Location'); + + if (is_string($actual)) { + list(, $actual) = explode('doku.php?id=', $actual); + } + + $this->assertEquals($expected, $actual, $msg); + } + +} diff --git a/platform/www/lib/plugins/translation/_test/general.test.php b/platform/www/lib/plugins/translation/_test/general.test.php new file mode 100644 index 0000000..ec1675c --- /dev/null +++ b/platform/www/lib/plugins/translation/_test/general.test.php @@ -0,0 +1,61 @@ +<?php +/** + * General tests for the translation plugin + * + * @group plugin_translation + * @group plugins + */ +class general_plugin_translation_test extends DokuWikiTest { + + /** + * 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('translation', $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'])); + } + + /** + * Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in + * conf/metadata.php. + */ + public function test_plugin_conf() { + $conf_file = __DIR__.'/../conf/default.php'; + if (file_exists($conf_file)){ + include($conf_file); + } + $meta_file = __DIR__.'/../conf/metadata.php'; + if (file_exists($meta_file)) { + include($meta_file); + } + + $this->assertEquals(gettype($conf), gettype($meta),'Both ' . DOKU_PLUGIN . 'translation/conf/default.php and ' . DOKU_PLUGIN . 'translation/conf/metadata.php have to exist and contain the same keys.'); + + if (gettype($conf) != 'NULL' && gettype($meta) != 'NULL') { + foreach($conf as $key => $value) { + $this->assertArrayHasKey($key, $meta, 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'translation/conf/metadata.php'); + } + + foreach($meta as $key => $value) { + $this->assertArrayHasKey($key, $conf, 'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'translation/conf/default.php'); + } + } + + } +} |