From b6306a3e82df90cdbfdb12cb5c9ae876c5ae922b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Thu, 7 May 2015 14:40:10 +0200 Subject: [PATCH 1/3] Respect $conf[useheading] for title fields w/o title Also add tests for fields of the type page, title, and pageid --- _test/syntax_plugin_data_entry.test.php | 137 +++++++++++++++++++++--- helper.php | 4 + 2 files changed, 129 insertions(+), 12 deletions(-) diff --git a/_test/syntax_plugin_data_entry.test.php b/_test/syntax_plugin_data_entry.test.php index b1aee65..5f3904f 100644 --- a/_test/syntax_plugin_data_entry.test.php +++ b/_test/syntax_plugin_data_entry.test.php @@ -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 "" . serialize($inputvalues) . ""; + } +} + /** * @group plugin_data * @group plugins @@ -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" @@ -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,'')); + $result = substr($result,strpos($result,'')+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,'')); + $result = substr($result,strpos($result,'')+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,'')); + $result = substr($result,strpos($result,'')+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,'')); + $result = substr($result,strpos($result,'')+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,'')+4); - $result = substr($result,strpos($result,'assertSame('bar',$result); + $result = substr($result,0,strpos($result,'')); + $result = substr($result,strpos($result,'')+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,'')+4); - $result = substr($result,strpos($result,'assertSame('TitleOfPage',$result); + $result = substr($result,0,strpos($result,'')); + $result = substr($result,strpos($result,'')+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() { diff --git a/helper.php b/helper.php index 5d6c4e4..6a8f60f 100644 --- a/helper.php +++ b/helper.php @@ -235,6 +235,10 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) { $outs[] = $R->internallink($val, null, null, true); break; case 'title': + list($id, $title) = explode('|', $val, 2); + $id = $this->_addPrePostFixes($column['type'], $id); + $outs[] = $R->internallink($id, $title, null, true); + break; case 'pageid': list($id, $title) = explode('|', $val, 2); From 05d8102b57f0c19dafa83c9f89d3665a93e8074a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Thu, 7 May 2015 17:10:15 +0200 Subject: [PATCH 2/3] Test database lookups for _title fields --- _test/db.test.php | 119 ++++++++++++++++++++++++ _test/syntax_plugin_data_entry.test.php | 2 +- 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 _test/db.test.php diff --git a/_test/db.test.php b/_test/db.test.php new file mode 100644 index 0000000..dc5128c --- /dev/null +++ b/_test/db.test.php @@ -0,0 +1,119 @@ +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,'')+24); + $actual_value = substr($actual_value,0,strpos($actual_value,'')); + $expected_value = 'foo|bar'; + $this->assertSame($expected_value,$actual_value); + + $actual_link = substr($result,strpos($result,'')+25); + $actual_link = substr($actual_link,strpos($actual_link,'doku.php')); + $actual_link = substr($actual_link,0,strpos($actual_link,'')); + + $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,'')+24); + $actual_value = substr($actual_value,0,strpos($actual_value,'')); + $expected_value = 'foo|bar'; + $this->assertSame($expected_value,$actual_value); + + $actual_link = substr($result,strpos($result,'')+25); + $actual_link = substr($actual_link,strpos($actual_link,'doku.php')); + $actual_link = substr($actual_link,0,strpos($actual_link,'')); + + $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,'')+24); + $actual_value = substr($actual_value,0,strpos($actual_value,'')); + $expected_value = 'foo|bar'; + $this->assertSame($expected_value,$actual_value); + + $actual_link = substr($result,strpos($result,'')+25); + $actual_link = substr($actual_link,strpos($actual_link,'doku.php')); + $actual_link = substr($actual_link,0,strpos($actual_link,'')); + + $this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link); + } + +} diff --git a/_test/syntax_plugin_data_entry.test.php b/_test/syntax_plugin_data_entry.test.php index 5f3904f..c85155f 100644 --- a/_test/syntax_plugin_data_entry.test.php +++ b/_test/syntax_plugin_data_entry.test.php @@ -205,7 +205,7 @@ function test_titleEntry_withTitle() { $result = substr($result,0,strpos($result,'')); $result = substr($result,strpos($result,'')+14); $result = unserialize($result); - + $this->assertSame('link:to:page',$result['id']); $this->assertSame('TitleOfPage',$result['name'], 'The Title provided should be the title shown.'); } From 15b9cc3c2267ec41c84e70d165e2bd887c70685e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Thu, 7 May 2015 18:16:36 +0200 Subject: [PATCH 3/3] Values for page and title are always absolute _resolveData always resolves the id from title and page fields starting from the root namespace, since it doesn't know about the namespace of the corresponding dataentry. Hence the dataentry dialog should always consider the entered ids to be absolute and link them accordingly. --- _test/db.test.php | 30 +++++++++++++++++++++++++ _test/helper.test.php | 4 ++-- _test/syntax_plugin_data_entry.test.php | 8 +++---- helper.php | 10 +++++++++ 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/_test/db.test.php b/_test/db.test.php index dc5128c..ea6c2d4 100644 --- a/_test/db.test.php +++ b/_test/db.test.php @@ -116,4 +116,34 @@ function test_title_input_Heading () { $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,'')+24); + $actual_value = substr($actual_value,0,strpos($actual_value,'')); + $expected_value = 'foo|bar'; + $this->assertSame($expected_value,$actual_value); + + $actual_link = substr($result,strpos($result,'')+25); + $actual_link = substr($actual_link,strpos($actual_link,'doku.php')); + $actual_link = substr($actual_link,0,strpos($actual_link,'')); + + $this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link); + } + } diff --git a/_test/helper.test.php b/_test/helper.test.php index 939b652..c85c59e 100644 --- a/_test/helper.test.php +++ b/_test/helper.test.php @@ -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', diff --git a/_test/syntax_plugin_data_entry.test.php b/_test/syntax_plugin_data_entry.test.php index c85155f..0b70ef2 100644 --- a/_test/syntax_plugin_data_entry.test.php +++ b/_test/syntax_plugin_data_entry.test.php @@ -100,7 +100,7 @@ function test_pageEntry_noTitle() { $result = substr($result,strpos($result,'')+14); $result = unserialize($result); - $this->assertSame('foo',$result['id']); + $this->assertSame(':foo',$result['id']); $this->assertSame(null,$result['name'], 'page does not accept a title. useheading decides'); } @@ -121,7 +121,7 @@ function test_pageEntry_withTitle() { $result = substr($result,strpos($result,'')+14); $result = unserialize($result); - $this->assertSame('foo_bar',$result['id'], 'for type page a title becomes part of the id'); + $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'); } @@ -184,7 +184,7 @@ function test_titleEntry_noTitle() { $result = substr($result,strpos($result,'')+14); $result = unserialize($result); - $this->assertSame('foo',$result['id']); + $this->assertSame(':foo',$result['id']); $this->assertSame(null,$result['name'], 'no title should be given to internal link. Let useheading decide.'); } @@ -206,7 +206,7 @@ function test_titleEntry_withTitle() { $result = substr($result,strpos($result,'')+14); $result = unserialize($result); - $this->assertSame('link:to:page',$result['id']); + $this->assertSame(':link:to:page',$result['id']); $this->assertSame('TitleOfPage',$result['name'], 'The Title provided should be the title shown.'); } diff --git a/helper.php b/helper.php index 6a8f60f..51752b8 100644 --- a/helper.php +++ b/helper.php @@ -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 * @@ -232,11 +239,13 @@ 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': @@ -253,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':