Permalink
Browse files

Merge pull request MrBertie#5 from micgro42/pageNameStrategy

Page name strategy
  • Loading branch information...
MrBertie committed Sep 9, 2018
2 parents 9ea9095 + 9728bb6 commit 3b1cc98957df8f8fbae195ca530a80933bfc684f
View
@@ -0,0 +1,19 @@
# Config file for travis-ci.org
language: php
php:
- "nightly"
- "7.2"
- "7.1"
- "7.0"
- "5.6"
env:
matrix:
- DOKUWIKI=master
- DOKUWIKI=stable
matrix:
allow_failures:
- php: "nightly"
before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh
install: sh travis.sh
script: cd _test && phpunit --stderr --group plugin_yearbox
View
@@ -0,0 +1,80 @@
<?php
namespace dokuwiki\plugin\yearbox\test;
/**
* General tests for the yearbox plugin
*
* @group plugin_yearbox
* @group plugins
*/
class general_plugin_yearbox_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('yearbox', $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->assertNotFalse(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 . 'sentry/conf/default.php and ' . DOKU_PLUGIN . 'sentry/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 . 'sentry/conf/metadata.php'
);
}
foreach ($meta as $key => $value) {
$this->assertArrayHasKey(
$key,
$conf,
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'sentry/conf/default.php'
);
}
}
}
}
@@ -0,0 +1,72 @@
<?php
namespace dokuwiki\plugin\yearbox\test;
use dokuwiki\plugin\yearbox\services\pageNameStrategies\PageNameStrategy;
/**
* Tests from syntax to html for the yearbox plugin
*
* @group plugin_yearbox
* @group plugins
*/
class pagenameStrategy_plugin_yearbox_test extends \DokuWikiTest {
public function dataProvider()
{
return [
[
'',
'',
'day',
':2018-03:day-2018-03-08',
'Test default configutation',
],
[
'separatedCompletely',
'bar',
null,
'bar:2018:03:08',
'test completely separated namespaces'
],
[
'YearMonthSeperatedNS',
'',
'',
':2018:03:2018-03-08',
'have year and month as separate ns, but keep the pageid the iso-date',
],
[
'YearNS',
'appreciation',
'',
'appreciation:2018:2018-03-08',
'have a year namespace and the iso-date as pade id'
],
];
}
/**
* @dataProvider dataProvider
*
* @param string $strategyName
* @param string $baseNS
* @param string $name
* @param string $expectedPageId
* @param $msg
*/
public function test_pagenameStrategy($strategyName, $baseNS, $name, $expectedPageId, $msg)
{
$year = 2018;
$month = '03';
$day = '08';
$strategy = PageNameStrategy::getPagenameStategy($strategyName);
$actual_id = $strategy->getPageId($baseNS, $year, $month, $day, $name);
$this->assertSame($expectedPageId, $actual_id, $msg);
}
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,3 @@
<?php
$conf['namestructure'] = 'default';
View
@@ -0,0 +1,11 @@
<?php
$meta['namestructure'] = [
'multichoice',
'_choices' => [
'default',
'separatedCompletely',
'YearMonthSeperatedNS',
'YearNS',
],
];
View
@@ -0,0 +1,7 @@
<?php
$lang['namestructure'] = 'The naming scheme used for creating new entries and finding the entries to display.';
$lang['namestructure_o_default'] = '<root> : year-month : <name>-year-month-day';
$lang['namestructure_o_YearMonthSeperatedNS'] = '<root> : year : month : <name>-year-month-day';
$lang['namestructure_o_separatedCompletely'] = '<root> : year : month : day';
$lang['namestructure_o_YearNS'] = '<root> : year : <name>-year-month-day';
@@ -0,0 +1,14 @@
<?php
namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;
class CompletelySeparated extends PageNameStrategy
{
public function getPageId($baseNS, $year, $month, $day, $name)
{
return "$baseNS:$year:$month:$day";
}
}
@@ -0,0 +1,25 @@
<?php
namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;
abstract class PageNameStrategy
{
public static function getPagenameStategy($namingStructure)
{
switch ($namingStructure) {
case 'separatedCompletely':
case 2:
return new CompletelySeparated();
case 'YearMonthSeperatedNS':
case 1:
return new YearMonthSeperatedNS();
case 'YearNS':
return new YearNS();
default:
return new YearMonthCombinedNS();
}
}
abstract public function getPageId($baseNS, $year, $month, $day, $name);
}
@@ -0,0 +1,15 @@
<?php
namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;
class YearMonthCombinedNS extends PageNameStrategy
{
public function getPageId($baseNS, $year, $month, $day, $name)
{
$pagename = ($name ? "$name-" : '') . "$year-$month-$day";
return "$baseNS:$year-$month:$pagename";
}
}
@@ -0,0 +1,15 @@
<?php
namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;
class YearMonthSeperatedNS extends PageNameStrategy
{
public function getPageId($baseNS, $year, $month, $day, $name)
{
$pagename = ($name ? "$name-" : '') . "$year-$month-$day";
return "$baseNS:$year:$month:$pagename";
}
}
@@ -0,0 +1,15 @@
<?php
namespace dokuwiki\plugin\yearbox\services\pageNameStrategies;
class YearNS extends PageNameStrategy
{
public function getPageId($baseNS, $year, $month, $day, $name)
{
$pagename = ($name ? "$name-" : '') . "$year-$month-$day";
return "$baseNS:$year:$pagename";
}
}
Oops, something went wrong.

0 comments on commit 3b1cc98

Please sign in to comment.