Skip to content

Commit 05d8102

Browse files
committed
Test database lookups for _title fields
1 parent b6306a3 commit 05d8102

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

_test/db.test.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
4+
/**
5+
* @group plugin_data
6+
* @group plugins
7+
* @group slow
8+
*/
9+
class db_data_entry_test extends DokuWikiTest {
10+
11+
protected $pluginsEnabled = array('data', 'sqlite',);
12+
13+
public static function setUpBeforeClass() {
14+
parent::setUpBeforeClass();
15+
}
16+
17+
18+
public function setUp() {
19+
parent::setUp();
20+
21+
saveWikiText('foo',"====== Page-Heading ======",'summary');
22+
$req = new TestRequest();
23+
$req->get(array(),'/doku.php?id=foo');
24+
25+
26+
saveWikiText('testpage',"---- dataentry Testentry ----\n"
27+
. "test1_title: foo|bar\n"
28+
. "----\n",'summary');
29+
//trigger save to db
30+
$req = new TestRequest();
31+
$req->get(array(),'/doku.php?id=testpage');
32+
}
33+
34+
function test_title_input_id () {
35+
36+
$test_table = "---- datatable Testtable ----\n"
37+
. "cols: %pageid%, test1\n"
38+
. "filter: test1~ *foo*\n";
39+
40+
/** @var syntax_plugin_data_entry $plugin */
41+
$plugin = plugin_load('syntax','data_table');
42+
43+
$handler = new Doku_Handler();
44+
$data = $plugin->handle($test_table, 0, 0, $handler);
45+
$renderer = new Doku_Renderer_xhtml();
46+
$plugin->render('xhtml',$renderer,$data);
47+
48+
$result = $renderer->doc;
49+
50+
$actual_value = substr($result,strpos($result,'<td class="align test1">')+24);
51+
$actual_value = substr($actual_value,0,strpos($actual_value,'</td>'));
52+
$expected_value = 'foo|bar';
53+
$this->assertSame($expected_value,$actual_value);
54+
55+
$actual_link = substr($result,strpos($result,'<td class="align pageid">')+25);
56+
$actual_link = substr($actual_link,strpos($actual_link,'doku.php'));
57+
$actual_link = substr($actual_link,0,strpos($actual_link,'</a>'));
58+
59+
$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);
60+
61+
}
62+
63+
function test_title_input_title () {
64+
65+
$test_table = "---- datatable Testtable ----\n"
66+
. "cols: %pageid%, test1\n"
67+
. "filter: test1~ *bar*\n";
68+
69+
/** @var syntax_plugin_data_entry $plugin */
70+
$plugin = plugin_load('syntax','data_table');
71+
72+
$handler = new Doku_Handler();
73+
$data = $plugin->handle($test_table, 0, 0, $handler);
74+
$renderer = new Doku_Renderer_xhtml();
75+
$plugin->render('xhtml',$renderer,$data);
76+
77+
$result = $renderer->doc;
78+
79+
$actual_value = substr($result,strpos($result,'<td class="align test1">')+24);
80+
$actual_value = substr($actual_value,0,strpos($actual_value,'</td>'));
81+
$expected_value = 'foo|bar';
82+
$this->assertSame($expected_value,$actual_value);
83+
84+
$actual_link = substr($result,strpos($result,'<td class="align pageid">')+25);
85+
$actual_link = substr($actual_link,strpos($actual_link,'doku.php'));
86+
$actual_link = substr($actual_link,0,strpos($actual_link,'</a>'));
87+
88+
$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);
89+
}
90+
91+
function test_title_input_Heading () {
92+
93+
$test_table = "---- datatable Testtable ----\n"
94+
. "cols: %pageid%, test1\n"
95+
. "filter: test1_title~ *Heading*\n";
96+
97+
/** @var syntax_plugin_data_entry $plugin */
98+
$plugin = plugin_load('syntax','data_table');
99+
100+
$handler = new Doku_Handler();
101+
$data = $plugin->handle($test_table, 0, 0, $handler);
102+
$renderer = new Doku_Renderer_xhtml();
103+
$plugin->render('xhtml',$renderer,$data);
104+
105+
$result = $renderer->doc;
106+
107+
$actual_value = substr($result,strpos($result,'<td class="align test1">')+24);
108+
$actual_value = substr($actual_value,0,strpos($actual_value,'</td>'));
109+
$expected_value = 'foo|bar';
110+
$this->assertSame($expected_value,$actual_value);
111+
112+
$actual_link = substr($result,strpos($result,'<td class="align pageid">')+25);
113+
$actual_link = substr($actual_link,strpos($actual_link,'doku.php'));
114+
$actual_link = substr($actual_link,0,strpos($actual_link,'</a>'));
115+
116+
$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);
117+
}
118+
119+
}

_test/syntax_plugin_data_entry.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function test_titleEntry_withTitle() {
205205
$result = substr($result,0,strpos($result,'</internallink>'));
206206
$result = substr($result,strpos($result,'<internallink>')+14);
207207
$result = unserialize($result);
208-
208+
209209
$this->assertSame('link:to:page',$result['id']);
210210
$this->assertSame('TitleOfPage',$result['name'], 'The Title provided should be the title shown.');
211211
}

0 commit comments

Comments
 (0)