Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Eckelmann committed Jan 23, 2013
1 parent 7b842d2 commit 7c5209b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
16 changes: 8 additions & 8 deletions _test/helper.test.php
Expand Up @@ -85,8 +85,8 @@ function testResolveData() {
$this->assertEquals('tom', $helper->_resolveData('tom', 'name'));
$this->assertEquals('jerry', $helper->_resolveData('jerry', 'name'));

$this->assertEquals('Formatting Syntax', $helper->_resolveData('wiki:syntax', 'name_title'));
$this->assertEquals(null, $helper->_resolveData('none:existing', 'name_title'));
$this->assertEquals('wiki:syntax Formatting Syntax', $helper->_resolveData('wiki:syntax', 'name_title'));
$this->assertEquals('none:existing ', $helper->_resolveData('none:existing', 'name_title'));
}

function testFormatData() {
Expand All @@ -98,13 +98,13 @@ function testFormatData() {
$this->assertEquals('value1, value2, val',
$helper->_formatData(array('type' => ''), "value1\n value2\n val", $renderer));

$this->assertEquals('link: :page ',
$this->assertEquals('link: page ',
$helper->_formatData(array('type' => 'page'), "page", $renderer));

$this->assertEquals('link: :page title',
$this->assertEquals('link: page title',
$helper->_formatData(array('type' => 'title'), "page|title", $renderer));

$this->assertEquals('link: :page title',
$this->assertEquals('link: page title',
$helper->_formatData(array('type' => 'pageid'), "page|title", $renderer));

$this->assertEquals('link: :key:page ',
Expand All @@ -124,10 +124,10 @@ function testFormatData() {
$this->assertEquals('<a href="mailto:pa%3Age" class="mail" title="pa%3Age">some user</a>',
$helper->_formatData(array('type' => 'mail'), "pa:ge some user", $renderer));

$this->assertEquals('<a href="url" class="urlextern" title="url">url</a>',
$this->assertEquals('<a href=\'url\' class=\'urlextern\' rel="nofollow">url</a>',
$helper->_formatData(array('type' => 'url'), "url", $renderer));

$this->assertEquals('<a href="/./doku.php?id=start&amp;dataflt=%3Dvalue" title="Show pages matching \'value\'" class="wikilink1">value</a>',
$this->assertEquals('<a href="' . wl('start', array('dataflt[0]'=>'_=value')) . '" title="Show pages matching \'value\'" class="wikilink1">value</a>',
$helper->_formatData(array('type' => 'tag'), "value", $renderer));

$this->assertEquals('1970/01/15 07:56',
Expand All @@ -137,7 +137,7 @@ function testFormatData() {
$helper->_formatData(array('type' => 'wiki'), '|**bla**', $renderer));


$this->assertEquals('<a href="/./lib/exe/fetch.php?media=wiki:dokuwiki-128.png" class="media" rel="lightbox"><img src="/./lib/exe/fetch.php?w=300&amp;media=wiki:dokuwiki-128.png" alt=": dokuwiki-128.png" title=": dokuwiki-128.png" width="300" /></a>',
$this->assertEquals('<a href="'.ml('wiki:dokuwiki-128.png').'" class="media" rel="lightbox"><img src="'.ml('wiki:dokuwiki-128.png', array('w'=>300)).'" alt=": dokuwiki-128.png" title=": dokuwiki-128.png" width="300" /></a>',
$helper->_formatData(array('type' => 'img300'), 'wiki:dokuwiki-128.png', $renderer));
}

Expand Down
6 changes: 3 additions & 3 deletions _test/syntax_plugin_data_entry.test.php
Expand Up @@ -113,17 +113,17 @@ function testShowData() {
$this->assertEquals(1, pq('dl dt.volume')->length);
$this->assertEquals(1, pq('dl dd.volume')->length);
$this->assertEquals(1, pq('dl dt.employee')->length);
$this->assertEquals(3, pq('dl dd.employee')->length);
$this->assertEquals(1, pq('dl dd.employee')->length);
$this->assertEquals(1, pq('dl dt.customer')->length);
$this->assertEquals(1, pq('dl dd.customer')->length);
$this->assertEquals(1, pq('dl dt.deadline')->length);
$this->assertEquals(1, pq('dl dd.deadline')->length);
$this->assertEquals(1, pq('dl dt.server')->length);
$this->assertEquals(2, pq('dl dd.server')->length);
$this->assertEquals(1, pq('dl dd.server')->length);
$this->assertEquals(1, pq('dl dt.website')->length);
$this->assertEquals(1, pq('dl dd.website')->length);
$this->assertEquals(1, pq('dl dt.task')->length);
$this->assertEquals(4, pq('dl dd.task')->length);
$this->assertEquals(1, pq('dl dd.task')->length);
}
}

Expand Down
39 changes: 20 additions & 19 deletions helper.php
Expand Up @@ -16,29 +16,31 @@
*/
class helper_plugin_data extends DokuWiki_Plugin {

/**
* initialized via _getDb()
* @var $db helper_plugin_sqlite
*/
protected $db = null;

protected $aliases = null;

/**
* @return helper_plugin_sqlite load the sqlite helper
*/
function _getDB(){

/**
* static variable: only first time initialised
* @var $db helper_plugin_sqlite
*/
static $db = null;
if ($db === null) {
$db =& plugin_load('helper', 'sqlite');
if ($db === null) {
if ($this->db === null) {
$this->db =& plugin_load('helper', 'sqlite');
if ($this->db === null) {
msg('The data plugin needs the sqlite plugin', -1);
return false;
}
if(!$db->init('data',dirname(__FILE__).'/db/')){
if(!$this->db->init('data',dirname(__FILE__).'/db/')){
$db = null;
return false;
}
$db->create_function('DATARESOLVE',array($this,'_resolveData'),2);
$this->db->create_function('DATARESOLVE',array($this,'_resolveData'),2);
}
return $db;
return $this->db;
}

/**
Expand Down Expand Up @@ -116,7 +118,7 @@ function _resolveData($value, $colname){
list($id,) = explode('|',$value,2);
}
//DATARESOLVE is only used with the 'LIKE' comparator, so concatenate the different strings is fine.
$value .= p_get_first_heading($id);
$value .= ' ' . p_get_first_heading($id);
}
return $value;
}
Expand Down Expand Up @@ -252,22 +254,21 @@ function _column($col){
* Load defined type aliases
*/
function _aliases(){
static $aliases = null;
if(!is_null($aliases)) return $aliases;
if(!is_null($this->aliases)) return $this->aliases;

$sqlite = $this->_getDB();
if(!$sqlite) return array();

$aliases = array();
$this->aliases = array();
$res = $sqlite->query("SELECT * FROM aliases");
$rows = $sqlite->res2arr($res);
foreach($rows as $row){
$name = $row['name'];
unset($row['name']);
$aliases[$name] = array_filter(array_map('trim', $row));
if (!isset($aliases[$name]['type'])) $aliases[$name]['type'] = '';
$this->aliases[$name] = array_filter(array_map('trim', $row));
if (!isset($this->aliases[$name]['type'])) $this->aliases[$name]['type'] = '';
}
return $aliases;
return $this->aliases;
}

/**
Expand Down

0 comments on commit 7c5209b

Please sign in to comment.