Skip to content

Title fields use headings #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions _test/db.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php


/**
* @group plugin_data
* @group plugins
* @group slow
*/
class db_data_entry_test extends DokuWikiTest {

protected $pluginsEnabled = array('data', 'sqlite',);

public static function setUpBeforeClass() {
parent::setUpBeforeClass();
}


public function setUp() {
parent::setUp();

saveWikiText('foo',"====== Page-Heading ======",'summary');
$req = new TestRequest();
$req->get(array(),'/doku.php?id=foo');


saveWikiText('testpage',"---- dataentry Testentry ----\n"
. "test1_title: foo|bar\n"
. "----\n",'summary');
//trigger save to db
$req = new TestRequest();
$req->get(array(),'/doku.php?id=testpage');
}

function test_title_input_id () {

$test_table = "---- datatable Testtable ----\n"
. "cols: %pageid%, test1\n"
. "filter: test1~ *foo*\n";

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_table');

$handler = new Doku_Handler();
$data = $plugin->handle($test_table, 0, 0, $handler);
$renderer = new Doku_Renderer_xhtml();
$plugin->render('xhtml',$renderer,$data);

$result = $renderer->doc;

$actual_value = substr($result,strpos($result,'<td class="align test1">')+24);
$actual_value = substr($actual_value,0,strpos($actual_value,'</td>'));
$expected_value = 'foo|bar';
$this->assertSame($expected_value,$actual_value);

$actual_link = substr($result,strpos($result,'<td class="align pageid">')+25);
$actual_link = substr($actual_link,strpos($actual_link,'doku.php'));
$actual_link = substr($actual_link,0,strpos($actual_link,'</a>'));

$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);

}

function test_title_input_title () {

$test_table = "---- datatable Testtable ----\n"
. "cols: %pageid%, test1\n"
. "filter: test1~ *bar*\n";

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_table');

$handler = new Doku_Handler();
$data = $plugin->handle($test_table, 0, 0, $handler);
$renderer = new Doku_Renderer_xhtml();
$plugin->render('xhtml',$renderer,$data);

$result = $renderer->doc;

$actual_value = substr($result,strpos($result,'<td class="align test1">')+24);
$actual_value = substr($actual_value,0,strpos($actual_value,'</td>'));
$expected_value = 'foo|bar';
$this->assertSame($expected_value,$actual_value);

$actual_link = substr($result,strpos($result,'<td class="align pageid">')+25);
$actual_link = substr($actual_link,strpos($actual_link,'doku.php'));
$actual_link = substr($actual_link,0,strpos($actual_link,'</a>'));

$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);
}

function test_title_input_Heading () {

$test_table = "---- datatable Testtable ----\n"
. "cols: %pageid%, test1\n"
. "filter: test1_title~ *Heading*\n";

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_table');

$handler = new Doku_Handler();
$data = $plugin->handle($test_table, 0, 0, $handler);
$renderer = new Doku_Renderer_xhtml();
$plugin->render('xhtml',$renderer,$data);

$result = $renderer->doc;

$actual_value = substr($result,strpos($result,'<td class="align test1">')+24);
$actual_value = substr($actual_value,0,strpos($actual_value,'</td>'));
$expected_value = 'foo|bar';
$this->assertSame($expected_value,$actual_value);

$actual_link = substr($result,strpos($result,'<td class="align pageid">')+25);
$actual_link = substr($actual_link,strpos($actual_link,'doku.php'));
$actual_link = substr($actual_link,0,strpos($actual_link,'</a>'));

$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);
}

function test_title_input_stackns () {

$test_table = "---- datatable Testtable ----\n"
. "cols: %pageid%, test1\n";

global $ID;
$ID = 'foo:bar:start';

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_table');

$handler = new Doku_Handler();
$data = $plugin->handle($test_table, 0, 0, $handler);
$renderer = new Doku_Renderer_xhtml();
$plugin->render('xhtml',$renderer,$data);

$result = $renderer->doc;

$actual_value = substr($result,strpos($result,'<td class="align test1">')+24);
$actual_value = substr($actual_value,0,strpos($actual_value,'</td>'));
$expected_value = 'foo|bar';
$this->assertSame($expected_value,$actual_value);

$actual_link = substr($result,strpos($result,'<td class="align pageid">')+25);
$actual_link = substr($actual_link,strpos($actual_link,'doku.php'));
$actual_link = substr($actual_link,0,strpos($actual_link,'</a>'));

$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);
}

}
4 changes: 2 additions & 2 deletions _test/helper.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ 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',
Expand Down
137 changes: 125 additions & 12 deletions _test/syntax_plugin_data_entry.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

require_once DOKU_INC . 'inc/parser/xhtml.php';

class Doku_Renderer_xhtml_mock extends Doku_Renderer_xhtml {

function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') {
$inputvalues = array(
'id' => $id,
'name' => $name,
'search' => $search,
'returnonly' => $returnonly,
'linktype' => $linktype
);
return "<internallink>" . serialize($inputvalues) . "</internallink>";
}
}

/**
* @group plugin_data
* @group plugins
Expand All @@ -12,6 +26,10 @@ class syntax_plugin_data_entry_test extends DokuWikiTest {

private $exampleEntry;

public function setUp() {
parent::setUp();
}

function __construct() {
$this->exampleEntry = "---- dataentry projects ----\n"
. "type : web development\n"
Expand Down Expand Up @@ -65,36 +83,131 @@ function testHandle() {
$this->assertEquals($cols, $result['cols'], 'Cols array corrupted');
}

function test_pageEntry_noTitle() {
$test_entry = '---- dataentry ----
test1_page: foo
----';

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_entry');

$handler = new Doku_Handler();
$data = $plugin->handle($test_entry, 0, 10, $handler);
$renderer = new Doku_Renderer_xhtml_mock();
$plugin->render('xhtml',$renderer,$data);
$result = $renderer->doc;
$result = substr($result,0,strpos($result,'</internallink>'));
$result = substr($result,strpos($result,'<internallink>')+14);
$result = unserialize($result);

$this->assertSame(':foo',$result['id']);
$this->assertSame(null,$result['name'], 'page does not accept a title. useheading decides');
}

function test_pageEntry_withTitle() {
$test_entry = '---- dataentry ----
test1_page: foo|bar
----';

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_entry');

$handler = new Doku_Handler();
$data = $plugin->handle($test_entry, 0, 10, $handler);
$renderer = new Doku_Renderer_xhtml_mock();
$plugin->render('xhtml',$renderer,$data);
$result = $renderer->doc;
$result = substr($result,0,strpos($result,'</internallink>'));
$result = substr($result,strpos($result,'<internallink>')+14);
$result = unserialize($result);

$this->assertSame(':foo_bar',$result['id'], 'for type page a title becomes part of the id');
$this->assertSame(null,$result['name'], 'page never accepts a title. useheading decides');
}

function test_pageidEntry_noTitle() {
$test_entry = '---- dataentry ----
test1_pageid: foo
----';

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_entry');

$handler = new Doku_Handler();
$data = $plugin->handle($test_entry, 0, 10, $handler);
$renderer = new Doku_Renderer_xhtml_mock();
$plugin->render('xhtml',$renderer,$data);
$result = $renderer->doc;
$result = substr($result,0,strpos($result,'</internallink>'));
$result = substr($result,strpos($result,'<internallink>')+14);
$result = unserialize($result);

$this->assertSame('foo',$result['id']);
$this->assertSame('foo',$result['name'], 'pageid: use the pageid as title if no title is provided.');
}

function test_pageidEntry_withTitle() {
$test_entry = '---- dataentry ----
test1_pageid: foo|bar
----';

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_entry');

$handler = new Doku_Handler();
$data = $plugin->handle($test_entry, 0, 10, $handler);
$renderer = new Doku_Renderer_xhtml_mock();
$plugin->render('xhtml',$renderer,$data);
$result = $renderer->doc;
$result = substr($result,0,strpos($result,'</internallink>'));
$result = substr($result,strpos($result,'<internallink>')+14);
$result = unserialize($result);

$this->assertSame('foo',$result['id'], "wrong id handed to internal link");
$this->assertSame('bar',$result['name'], 'pageid: use the provided title');
}

function test_titleEntry_noTitle() {
$test_entry = '---- dataentry ----
test_title: bar
test1_title: foo
----';
$plugin = new syntax_plugin_data_entry();

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_entry');

$handler = new Doku_Handler();
$data = $plugin->handle($test_entry, 0, 10, $handler);
$renderer = new Doku_Renderer_xhtml();
$renderer = new Doku_Renderer_xhtml_mock();
$plugin->render('xhtml',$renderer,$data);
$result = $renderer->doc;
$result = substr($result,0,strpos($result,'</a>')+4);
$result = substr($result,strpos($result,'<a'));
$this->assertSame('<a href="/./doku.php?id=bar" class="wikilink2" title="bar" rel="nofollow">bar</a>',$result);
$result = substr($result,0,strpos($result,'</internallink>'));
$result = substr($result,strpos($result,'<internallink>')+14);
$result = unserialize($result);

$this->assertSame(':foo',$result['id']);
$this->assertSame(null,$result['name'], 'no title should be given to internal link. Let useheading decide.');
}


function test_titleEntry_withTitle() {
$test_entry = '---- dataentry ----
test_title: link:to:page|TitleOfPage
test3_title: link:to:page|TitleOfPage
----';
$plugin = new syntax_plugin_data_entry();

/** @var syntax_plugin_data_entry $plugin */
$plugin = plugin_load('syntax','data_entry');

$handler = new Doku_Handler();
$data = $plugin->handle($test_entry, 0, 10, $handler);
$renderer = new Doku_Renderer_xhtml();
$renderer = new Doku_Renderer_xhtml_mock();
$plugin->render('xhtml',$renderer,$data);
$result = $renderer->doc;
$result = substr($result,0,strpos($result,'</a>')+4);
$result = substr($result,strpos($result,'<a'));
$this->assertSame('<a href="/./doku.php?id=link:to:page" class="wikilink2" title="link:to:page" rel="nofollow">TitleOfPage</a>',$result);
$result = substr($result,0,strpos($result,'</internallink>'));
$result = substr($result,strpos($result,'<internallink>')+14);
$result = unserialize($result);

$this->assertSame(':link:to:page',$result['id']);
$this->assertSame('TitleOfPage',$result['name'], 'The Title provided should be the title shown.');
}

function test_editToWiki() {
Expand Down
14 changes: 14 additions & 0 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ function _resolveData($value, $colname) {
return $value;
}

public function ensureAbsoluteId($id) {
if (substr($id,0,1) !== ':') {
$id = ':' . $id;
}
return $id;
}

/**
* Return XHTML formated data, depending on column type
*
Expand Down Expand Up @@ -232,9 +239,15 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) {
switch($type) {
case 'page':
$val = $this->_addPrePostFixes($column['type'], $val);
$val = $this->ensureAbsoluteId($val);
$outs[] = $R->internallink($val, null, null, true);
break;
case 'title':
list($id, $title) = explode('|', $val, 2);
$id = $this->_addPrePostFixes($column['type'], $id);
$id = $this->ensureAbsoluteId($id);
$outs[] = $R->internallink($id, $title, null, true);
break;
case 'pageid':
list($id, $title) = explode('|', $val, 2);

Expand All @@ -249,6 +262,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) {
}

$id = $this->_addPrePostFixes($column['type'], $id);

$outs[] = $R->internallink($id, $title, null, true);
break;
case 'nspage':
Expand Down