-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathSearchConfigTest.php
More file actions
239 lines (189 loc) · 9.9 KB
/
Copy pathSearchConfigTest.php
File metadata and controls
239 lines (189 loc) · 9.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
namespace dokuwiki\plugin\struct\test;
use dokuwiki\plugin\struct\meta;
use dokuwiki\plugin\struct\test\mock\SearchConfig;
/**
* @group plugin_struct
* @group plugins
*
*/
class SearchConfigTest extends StructTest
{
public function test_filtervars_simple()
{
global $INFO;
$INFO['id'] = 'foo:bar:baz';
$searchConfig = new SearchConfig([]);
$this->assertEquals('foo:bar:baz', $searchConfig->applyFilterVars('$ID$'));
$this->assertEquals('baz', $searchConfig->applyFilterVars('$PAGE$'));
$this->assertEquals('foo:bar', $searchConfig->applyFilterVars('$NS$'));
$this->assertEquals(date('Y-m-d'), $searchConfig->applyFilterVars('$TODAY$'));
$this->assertEquals('', $searchConfig->applyFilterVars('$USER$'));
$_SERVER['REMOTE_USER'] = 'user';
$this->assertEquals('user', $searchConfig->applyFilterVars('$USER$'));
$this->assertEquals('user baz', $searchConfig->applyFilterVars('$USER$ $PAGE$'));
$this->assertEquals('$user', $searchConfig->applyFilterVars('$user'));
$this->assertEquals(date('Y-m-d'), $searchConfig->applyFilterVars('$DATE(now)$'));
}
public function test_filtervars_missing_pageid()
{
global $INFO, $ID;
$ID = 'foo:bar:baz';
saveWikiText($ID, 'initial page', 'created for filter var test');
$INFO = [];
$searchConfig = new SearchConfig([]);
$this->assertEquals($ID, $searchConfig->applyFilterVars('$ID$'));
$this->assertEquals('foo:bar', $searchConfig->applyFilterVars('$NS$'));
$this->assertEquals('baz', $searchConfig->applyFilterVars('$PAGE$'));
saveWikiText($ID, '', 'cleanup');
clearstatcache();
}
public function test_filtervars_ignore_dynamic_filters()
{
global $INPUT;
$INPUT->set(meta\SearchConfigParameters::$PARAM_SORT, '^alias2.athird');
$INPUT->set(meta\SearchConfigParameters::$PARAM_OFFSET, 25);
$_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]['alias1.first*~'] = 'test';
$_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]['afirst='] = 'test2';
$this->loadSchemaJSON('schema1');
$config = [
'schemas' => [
['schema1', 'alias1']
],
'cols' => ['first']
];
$searchConfig = new SearchConfig($config, false);
$this->assertSame(0, $searchConfig->getOffset());
$this->assertSame([], $searchConfig->getSorts());
$this->assertEquals([], $this->getInaccessibleProperty($searchConfig, 'filter'));
$INPUT->remove(meta\SearchConfigParameters::$PARAM_SORT);
$INPUT->remove(meta\SearchConfigParameters::$PARAM_OFFSET);
unset($_REQUEST[meta\SearchConfigParameters::$PARAM_FILTER]);
}
public function test_filtervars_nsorid()
{
global $INFO;
$searchConfig = new SearchConfig([]);
// normal page
$INFO['id'] = 'foo:bar:baz';
$this->assertEquals('foo:bar:baz', $searchConfig->applyFilterVars('$NSORID$'));
// start page: start in namespace
$INFO['id'] = 'foo:bar:start';
saveWikiText($INFO['id'], 'start page', 'start created');
$this->assertEquals('foo:bar', $searchConfig->applyFilterVars('$NSORID$'));
saveWikiText($INFO['id'], '', 'start page deleted');
clearstatcache();
// start page: same as namespace in namespace
$INFO['id'] = 'foo:bar:bar';
saveWikiText($INFO['id'], 'start page', 'start created');
$this->assertEquals('foo:bar', $searchConfig->applyFilterVars('$NSORID$'));
saveWikiText($INFO['id'], '', 'start page deleted');
clearstatcache();
// start page: same as namespace in above namespace
// incidally this is the same as a normal page
$INFO['id'] = 'foo:bar';
saveWikiText($INFO['id'], 'start page', 'start created');
$this->assertEquals('foo:bar', $searchConfig->applyFilterVars('$NSORID$'));
saveWikiText($INFO['id'], '', 'start page deleted');
clearstatcache();
}
public function test_filtervars_struct()
{
global $INFO;
$INFO['id'] = 'foo:bar:baz';
// prepare some struct data
$sb = new meta\SchemaImporter('schema1', file_get_contents(__DIR__ . '/json/schema1.struct.json'));
$sb->build();
$schemaData = meta\AccessTable::getPageAccess('schema1', $INFO['id'], time());
$schemaData->saveData(
[
'first' => 'test',
'second' => ['multi1', 'multi2']
]
);
$searchConfig = new SearchConfig(['schemas' => [['schema1', 'alias']]]);
$this->assertEquals('test', $searchConfig->applyFilterVars('$STRUCT.first$'));
$this->assertEquals('test', $searchConfig->applyFilterVars('$STRUCT.alias.first$'));
$this->assertEquals('test', $searchConfig->applyFilterVars('$STRUCT.schema1.first$'));
$this->assertEquals('pretestpost', $searchConfig->applyFilterVars('pre$STRUCT.first$post'));
$this->assertEquals('pretestpost', $searchConfig->applyFilterVars('pre$STRUCT.alias.first$post'));
$this->assertEquals('pretestpost', $searchConfig->applyFilterVars('pre$STRUCT.schema1.first$post'));
$this->assertEquals(['multi1', 'multi2'], $searchConfig->applyFilterVars('$STRUCT.second$'));
$this->assertEquals(['multi1', 'multi2'], $searchConfig->applyFilterVars('$STRUCT.alias.second$'));
$this->assertEquals(['multi1', 'multi2'], $searchConfig->applyFilterVars('$STRUCT.schema1.second$'));
$this->assertEquals(['premulti1post', 'premulti2post'], $searchConfig->applyFilterVars('pre$STRUCT.second$post'));
$this->assertEquals(['premulti1post', 'premulti2post'], $searchConfig->applyFilterVars('pre$STRUCT.alias.second$post'));
$this->assertEquals(['premulti1post', 'premulti2post'], $searchConfig->applyFilterVars('pre$STRUCT.schema1.second$post'));
$this->assertEquals('', $searchConfig->applyFilterVars('$STRUCT.notexisting$'));
}
public function test_filtervars_struct_other()
{
global $INFO;
$INFO['id'] = 'foo:bar:baz';
// prepare some struct data
$sb = new meta\SchemaImporter('schema2', file_get_contents(__DIR__ . '/json/schema2.struct.json'));
$sb->build();
$sb = new meta\SchemaImporter('schema3', file_get_contents(__DIR__ . '/json/schema2int.struct.json'));
$sb->build();
$schemaData = meta\AccessTable::getPageAccess('schema2', $INFO['id'], time());
$schemaData->saveData(
[
'afirst' => 'test',
'asecond' => ['multi1', 'multi2']
]
);
$schemaData = meta\AccessTable::getPageAccess('schema3', 'foo:test:baz', time());
$schemaData->saveData(
[
'afirst' => 'test1',
'asecond' => ['multi1a', 'multi2a']
]
);
$searchConfig = new SearchConfig(['schemas' => [['schema3', 'alias']]]);
$this->assertEquals('', $searchConfig->applyFilterVars('$STRUCT.afirst$'));
$this->assertEquals('test', $searchConfig->applyFilterVars('$STRUCT.schema2.afirst$'));
$this->assertEquals('prepost', $searchConfig->applyFilterVars('pre$STRUCT.afirst$post'));
$this->assertEquals('pretestpost', $searchConfig->applyFilterVars('pre$STRUCT.schema2.afirst$post'));
$this->assertEquals('', $searchConfig->applyFilterVars('$STRUCT.asecond$'));
$this->assertEquals(['multi1', 'multi2'], $searchConfig->applyFilterVars('$STRUCT.schema2.asecond$'));
$this->assertEquals('prepost', $searchConfig->applyFilterVars('pre$STRUCT.asecond$post'));
$this->assertEquals(['premulti1post', 'premulti2post'], $searchConfig->applyFilterVars('pre$STRUCT.schema2.asecond$post'));
$this->assertEquals('', $searchConfig->applyFilterVars('$STRUCT.notexisting$'));
$this->assertEquals('', $searchConfig->applyFilterVars('$STRUCT.afirst$'));
$this->assertEquals('test', $searchConfig->applyFilterVars('$STRUCT.schema2.afirst$'));
}
public function test_filtervars_user()
{
global $INFO, $USERINFO;
$searchConfig = new SearchConfig([]);
$_SERVER['REMOTE_USER'] = 'john';
$USERINFO['name'] = 'John Smith';
$USERINFO['mail'] = 'john.smith@example.com';
$USERINFO['grps'] = ['user', 'test'];
//update info array
$INFO['userinfo'] = $USERINFO;
$this->assertEquals('John Smith', $searchConfig->applyFilterVars('$USER.name$'));
$this->assertEquals('john.smith@example.com', $searchConfig->applyFilterVars('$USER.mail$'));
$this->assertEquals(['user', 'test'], $searchConfig->applyFilterVars('$USER.grps$'));
}
public function test_cacheflags()
{
$searchConfig = new SearchConfig([]);
$flag = $searchConfig->determineCacheFlag(['foo', 'bar']);
$this->assertTrue((bool)($flag & SearchConfig::$CACHE_DEFAULT));
$this->assertFalse((bool)($flag & SearchConfig::$CACHE_USER));
$this->assertFalse((bool)($flag & SearchConfig::$CACHE_DATE));
$flag = $searchConfig->determineCacheFlag(['foo', '$USER$']);
$this->assertTrue((bool)($flag & SearchConfig::$CACHE_DEFAULT));
$this->assertTrue((bool)($flag & SearchConfig::$CACHE_USER));
$this->assertFalse((bool)($flag & SearchConfig::$CACHE_DATE));
$flag = $searchConfig->determineCacheFlag(['foo', '$TODAY$']);
$this->assertTrue((bool)($flag & SearchConfig::$CACHE_DEFAULT));
$this->assertFalse((bool)($flag & SearchConfig::$CACHE_USER));
$this->assertTrue((bool)($flag & SearchConfig::$CACHE_DATE));
$flag = $searchConfig->determineCacheFlag(['foo', '$TODAY$', '$USER$']);
$this->assertTrue((bool)($flag & SearchConfig::$CACHE_DEFAULT));
$this->assertTrue((bool)($flag & SearchConfig::$CACHE_USER));
$this->assertTrue((bool)($flag & SearchConfig::$CACHE_DATE));
}
}