1
1
<?php
2
2
3
+
3
4
require_once 'tests/units/Base.php ' ;
4
5
5
6
use Kanboard \Core \Plugin \Loader ;
6
7
use Kanboard \Plugin \Wiki \Model \WikiModel ;
7
8
use Kanboard \Model \ProjectModel ;
9
+ use Kanboard \Core \Controller \PageNotFoundException ;
10
+ use Kanboard \Core \Controller \AccessForbiddenException ;
8
11
use Kanboard \Core \User \UserSession ;
9
12
use Kanboard \Core \Security \AuthenticationManager ;
10
13
use Kanboard \Auth \DatabaseAuth ;
@@ -15,11 +18,12 @@ class WikiModelTest extends Base
15
18
* @var Plugin
16
19
*/
17
20
protected $ plugin ;
21
+ private $ wikiModel ;
22
+ private $ db ;
18
23
19
24
protected function setUp (): void
20
25
{
21
26
parent ::setUp ();
22
- // $this->plugin = new Plugin($this->container);
23
27
24
28
$ plugin = new Loader ($ this ->container );
25
29
$ plugin ->scan ();
@@ -28,6 +32,11 @@ protected function setUp(): void
28
32
$ authManager ->register (new DatabaseAuth ($ this ->container ));
29
33
30
34
$ _SESSION ['user ' ] = array ('id ' => 1 , 'username ' => 'test ' , 'role ' => 'app-admin ' );
35
+
36
+ // $this->db = $this->createMock(Base::class);
37
+ $ this ->wikiModel = new WikiModel ($ this ->container );
38
+
39
+ // $this->wikiModel = new WikiModel($this->container);
31
40
}
32
41
33
42
public function testCreation ()
@@ -38,16 +47,16 @@ public function testCreation()
38
47
39
48
$ project = $ projectModel ->getById (1 );
40
49
41
- $ wikimodel = new WikiModel ($ this ->container );
50
+ // $this->wikiModel = new WikiModel($this->container);
42
51
// create wiki pages
43
52
44
53
$ titleValue = "Security " ;
45
54
$ contentValue = "Some content " ;
46
- $ this ->assertEquals (1 , $ wikimodel ->createpage ($ project ['id ' ], $ titleValue , $ contentValue , '2015-01-01 ' ), 'Failed to a create wiki page on project ' );
47
- $ this ->assertEquals (2 , $ wikimodel ->createpage ($ project ['id ' ], "Conventions " , 'More content ' ), 'Failed to an additional create wiki page on project ' );
55
+ $ this ->assertEquals (1 , $ this -> wikiModel ->createpage ($ project ['id ' ], $ titleValue , $ contentValue , '2015-01-01 ' ), 'Failed to a create wiki page on project ' );
56
+ $ this ->assertEquals (2 , $ this -> wikiModel ->createpage ($ project ['id ' ], "Conventions " , 'More content ' ), 'Failed to an additional create wiki page on project ' );
48
57
49
58
// grab editions for first wiki page
50
- $ editions = $ wikimodel ->getEditions (1 );
59
+ $ editions = $ this -> wikiModel ->getEditions (1 );
51
60
$ this ->assertEmpty ($ editions );
52
61
53
62
$ values = [
@@ -60,10 +69,10 @@ public function testCreation()
60
69
61
70
$ this ->userSession = new UserSession ($ this ->container );
62
71
// result is not a consistent 1. is this true or id for new edition?
63
- $ createEditionResult = $ wikimodel ->createEdition ($ values , 1 , 1 );
64
- // $this->assertEquals($wikimodel ->createEdition($values, 1, 1), 1, 'Failed to create wiki edition');
72
+ $ createEditionResult = $ this -> wikiModel ->createEdition ($ values , 1 , 1 );
73
+ // $this->assertEquals($this->wikiModel ->createEdition($values, 1, 1), 1, 'Failed to create wiki edition');
65
74
66
- $ editions = $ wikimodel ->getEditions (1 );
75
+ $ editions = $ this -> wikiModel ->getEditions (1 );
67
76
$ this ->assertNotEmpty ($ editions , 'Failed to get wiki editions ' );
68
77
69
78
$ this ->assertEquals ('Security ' , $ editions [0 ]['title ' ]);
@@ -78,20 +87,20 @@ public function testReOrder(){
78
87
79
88
$ project = $ projectModel ->getById (1 );
80
89
81
- $ wikimodel = new WikiModel ($ this ->container );
90
+ // $this->wikiModel = new WikiModel($this->container);
82
91
83
92
// create wiki pages
84
- $ this ->assertEquals (1 , $ wikimodel ->createpage ($ project ['id ' ], "Home " , "" , '2015-01-01 ' ), 1 , 'Failed to a create wiki page home on project ' );
93
+ $ this ->assertEquals (1 , $ this -> wikiModel ->createpage ($ project ['id ' ], "Home " , "" , '2015-01-01 ' ), 1 , 'Failed to a create wiki page home on project ' );
85
94
for ($ i =2 ; $ i <= 5 ; $ i ++) {
86
- $ this ->assertEquals ($ i , $ wikimodel ->createpage ($ project ['id ' ], "Page " . $ i , "" ), 'Failed to a create wiki page ' . $ i . ' on project ' );
95
+ $ this ->assertEquals ($ i , $ this -> wikiModel ->createpage ($ project ['id ' ], "Page " . $ i , "" ), 'Failed to a create wiki page ' . $ i . ' on project ' );
87
96
}
88
97
89
98
// reorder
90
- $ wikimodel ->reorderPages ($ project ['id ' ], 5 , 3 );
99
+ $ this -> wikiModel ->reorderPages ($ project ['id ' ], 5 , 3 );
91
100
// expected by id
92
101
$ expectedColumnOrders = [1 ,2 ,4 ,5 ,3 ];
93
102
94
- $ wikiPages = $ wikimodel ->getWikipages ($ project ['id ' ]);
103
+ $ wikiPages = $ this -> wikiModel ->getWikipages ($ project ['id ' ]);
95
104
$ this ->assertEquals (count ($ expectedColumnOrders ), count ($ wikiPages ), 'expected column order count doesn \'t match pages ' );
96
105
97
106
for ($ i =0 ; $ i < count ($ expectedColumnOrders ); $ i ++) {
@@ -107,34 +116,289 @@ public function testReOrderByIndex(){
107
116
108
117
$ project = $ projectModel ->getById (1 );
109
118
110
- $ wikimodel = new WikiModel ($ this ->container );
119
+ // $this->wikiModel = new WikiModel($this->container);
111
120
112
121
// create wiki pages
113
- $ this ->assertEquals (1 , $ wikimodel ->createpage ($ project ['id ' ], "Home " , "" , '2015-01-01 ' ), 1 , 'Failed to a create wiki page home on project ' );
122
+ $ this ->assertEquals (1 , $ this -> wikiModel ->createpage ($ project ['id ' ], "Home " , "" , '2015-01-01 ' ), 1 , 'Failed to a create wiki page home on project ' );
114
123
for ($ i =2 ; $ i <= 5 ; $ i ++) {
115
- $ this ->assertEquals ($ i , $ wikimodel ->createpage ($ project ['id ' ], "Page " . $ i , "" ), 'Failed to a create wiki page ' . $ i . ' on project ' );
124
+ $ this ->assertEquals ($ i , $ this -> wikiModel ->createpage ($ project ['id ' ], "Page " . $ i , "" ), 'Failed to a create wiki page ' . $ i . ' on project ' );
116
125
}
117
126
118
127
// make page 5 a child of home page
119
- $ wikimodel ->updatepage (array ('id ' => 5 , 'parent_id ' => 1 , 'title ' => 'Page 5 ' , 'editions ' => 1 , 'content ' => 'Some content ' ), 1 , '2015-01-01 ' );
128
+ $ this -> wikiModel ->updatepage (array ('id ' => 5 , 'parent_id ' => 1 , 'title ' => 'Page 5 ' , 'editions ' => 1 , 'content ' => 'Some content ' ), 1 , '2015-01-01 ' );
120
129
121
- $ childPage = $ wikimodel ->getWikipage (5 );
130
+ $ childPage = $ this -> wikiModel ->getWikipage (5 );
122
131
123
132
$ this ->assertEquals (5 , $ childPage ['id ' ]);
124
133
$ this ->assertEquals (1 , $ childPage ['parent_id ' ]);
125
134
$ this ->assertEquals ('Page 5 ' , $ childPage ['title ' ]);
126
135
$ this ->assertEquals ('Some content ' , $ childPage ['content ' ]);
127
136
128
137
// reorder
129
- $ wikimodel ->reorderPagesByIndex ($ project ['id ' ], 4 , 2 , null );
138
+ $ this -> wikiModel ->reorderPagesByIndex ($ project ['id ' ], 4 , 2 , null );
130
139
// expected by id
131
140
$ expectedColumnOrders = [1 ,3 ,4 ,2 ];
132
141
133
- $ wikiPages = $ wikimodel ->getWikiPagesByParentId ($ project ['id ' ], null );
142
+ $ wikiPages = $ this -> wikiModel ->getWikiPagesByParentId ($ project ['id ' ], null );
134
143
$ this ->assertEquals (count ($ expectedColumnOrders ), count ($ wikiPages ), 'expected column order count doesn \'t match pages ' );
135
144
136
145
for ($ i =0 ; $ i < count ($ expectedColumnOrders ); $ i ++) {
137
146
$ this ->assertEquals ($ expectedColumnOrders [$ wikiPages [$ i ]['id ' ]-1 ], $ wikiPages [$ i ]['ordercolumn ' ], 'Failed to reorder page id: ' . $ wikiPages [$ i ]['id ' ]);
138
147
}
139
148
}
140
- }
149
+ /*
150
+ public function testGetEditionsReturnsArray()
151
+ {
152
+ $wikiId = 1;
153
+ $expectedResult = [
154
+ ['id' => 1, 'title' => 'My page', 'content' => 'Content of the page', 'edition' => 1]
155
+ ];
156
+
157
+ // $this->db
158
+ // ->expects($this->once())
159
+ // ->method('table')
160
+ // ->with(WikiModel::WIKI_EDITION_TABLE)
161
+ // ->willReturn($this->db);
162
+
163
+ // $this->db
164
+ // ->expects($this->once())
165
+ // ->method('eq')
166
+ // ->with('wikipage_id', $wikiId)
167
+ // ->willReturn($this->db);
168
+
169
+ // $this->db
170
+ // ->expects($this->once())
171
+ // ->method('desc')
172
+ // ->with('edition')
173
+ // ->willReturn($this->db);
174
+
175
+ // $this->db
176
+ // ->expects($this->once())
177
+ // ->method('findAll')
178
+ // ->willReturn($expectedResult);
179
+
180
+ $result = $this->wikiModel->getEditions($wikiId);
181
+ $this->assertEquals(json_encode($expectedResult), json_encode($result));
182
+ }
183
+ */
184
+ public function testCreatePageSavesCorrectly ()
185
+ {
186
+ // $this->db
187
+ // ->expects($this->once())
188
+ // ->method('table')
189
+ // ->with(WikiModel::WIKITABLE)
190
+ // ->willReturnSelf();
191
+
192
+ // $this->db
193
+ // ->method('persist')
194
+ // ->willReturn(1);
195
+
196
+ $ result = $ this ->wikiModel ->createpage (1 , 'Test title ' , 'Test content ' );
197
+
198
+ $ this ->assertEquals (false , $ result );
199
+ }
200
+ /*
201
+ public function testUpdatePageUpdatesCorrectly()
202
+ {
203
+ // $this->db
204
+ // ->expects($this->once())
205
+ // ->method('table')
206
+ // ->with(WikiModel::WIKITABLE)
207
+ // ->willReturnSelf();
208
+
209
+ // $this->db
210
+ // ->method('eq')
211
+ // ->with('id', 1)
212
+ // ->willReturnSelf();
213
+
214
+ // $this->db
215
+ // ->method('update')
216
+ // ->willReturn(true);
217
+
218
+ // $result = $this->wikiModel->updatepage(['title' => 'New Title', 'content' => 'New content', 'id' => 1], 1);
219
+
220
+ // $this->assertEquals(1, $result);
221
+ }
222
+
223
+ public function testRemovePageRemovesCorrectly()
224
+ {
225
+ // $this->db
226
+ // ->expects($this->once())
227
+ // ->method('table')
228
+ // ->with(WikiModel::WIKITABLE)
229
+ // ->willReturnSelf();
230
+
231
+ // $this->db
232
+ // ->method('eq')
233
+ // ->with('id', 1)
234
+ // ->willReturnSelf();
235
+
236
+ // $this->db
237
+ // ->method('remove')
238
+ // ->willReturn(true);
239
+ /*
240
+ $result = $this->wikiModel->removepage(1);
241
+
242
+ $this->assertTrue($result);
243
+
244
+ }
245
+
246
+ public function testGetWikipageReturnsCorrectData()
247
+ {
248
+ // $this->db
249
+ // ->expects($this->once())
250
+ // ->method('table')
251
+ // ->with(WikiModel::WIKITABLE)
252
+ // ->willReturnSelf();
253
+
254
+ // $this->db
255
+ // ->method('columns')
256
+ // ->willReturnSelf();
257
+
258
+ // $this->db
259
+ // ->method('eq')
260
+ // ->with('id', 1)
261
+ // ->willReturnSelf();
262
+
263
+ $expected = ['id' => 1, 'title' => 'Test'];
264
+
265
+ // $this->db
266
+ // ->method('findOne')
267
+ // ->willReturn($expected);
268
+ /*
269
+ $result = $this->wikiModel->getWikipage(1);
270
+
271
+ $this->assertSame($expected, $result);
272
+
273
+ }
274
+
275
+ public function testGetLatestEditionReturnsArray()
276
+ {
277
+ $wikiId = 1;
278
+ $expectedResult = ['id' => 1, 'title' => 'Page Title', 'edition' => 2];
279
+
280
+ // $this->db
281
+ // ->expects($this->once())
282
+ // ->method('table')
283
+ // ->with(WikiModel::WIKI_EDITION_TABLE)
284
+ // ->willReturn($this->db);
285
+
286
+ // $this->db
287
+ // ->expects($this->once())
288
+ // ->method('eq')
289
+ // ->with('wikipage_id', $wikiId)
290
+ // ->willReturn($this->db);
291
+
292
+ // $this->db
293
+ // ->expects($this->once())
294
+ // ->method('desc')
295
+ // ->with('edition')
296
+ // ->willReturn($this->db);
297
+
298
+ // $this->db
299
+ // ->expects($this->once())
300
+ // ->method('findOne')
301
+ // ->willReturn($expectedResult);
302
+ /*
303
+ $result = $this->wikiModel->getLatestEdition($wikiId);
304
+ $this->assertEquals($expectedResult, $result);
305
+
306
+ }
307
+
308
+ public function testRemovePageWithNonExistentIdReturnsFalse()
309
+ {
310
+ $wikiId = 999;
311
+
312
+ // $this->db
313
+ // ->expects($this->once())
314
+ // ->method('table')
315
+ // ->with(WikiModel::WIKITABLE)
316
+ // ->willReturn($this->db);
317
+
318
+ // $this->db
319
+ // ->expects($this->once())
320
+ // ->method('eq')
321
+ // ->with('id', $wikiId)
322
+ // ->willReturn($this->db);
323
+
324
+ // $this->db
325
+ // ->expects($this->once())
326
+ // ->method('remove')
327
+ // ->willReturn(false);
328
+ /*
329
+ $result = $this->wikiModel->removepage($wikiId);
330
+ $this->assertFalse($result);
331
+
332
+ }
333
+
334
+ public function testGetWikipageThrowsPageNotFoundException()
335
+ {
336
+ // $this->db
337
+ // ->method('findOne')
338
+ // ->willReturn(null);
339
+ /*
340
+ $this->expectException(\Kanboard\Core\ExternalTask\NotFoundException::class);
341
+
342
+ $this->wikiModel->getWiki();
343
+
344
+ }
345
+
346
+ public function testGetWikiPageThrowsPageNotFoundException2()
347
+ {
348
+ $this->expectException(PageNotFoundException::class);
349
+ $wikiId = 999;
350
+
351
+ // $this->db
352
+ // ->expects($this->once())
353
+ // ->method('table')
354
+ // ->with(WikiModel::WIKITABLE)
355
+ // ->willReturn($this->db);
356
+
357
+ // $this->db
358
+ // ->expects($this->once())
359
+ // ->method('eq')
360
+ // ->with('id', $wikiId)
361
+ // ->willReturn($this->db);
362
+
363
+ // $this->db
364
+ // ->expects($this->once())
365
+ // ->method('findOne')
366
+ // ->willReturn(null);
367
+ /*
368
+ $this->wikiModel->getWikipage($wikiId);
369
+
370
+ }
371
+
372
+ public function testCreatePageWithValidData()
373
+ {
374
+ $project_id = 1;
375
+ $title = 'New Page';
376
+ $content = 'Content';
377
+ $date = date('Y-m-d');
378
+ $values = [
379
+ 'project_id' => $project_id,
380
+ 'title' => $title,
381
+ 'content' => $content,
382
+ 'date_creation' => $date,
383
+ 'ordercolumn' => 1
384
+ ];
385
+
386
+ // $this->db
387
+ // ->expects($this->once())
388
+ // ->method('table')
389
+ // ->with(WikiModel::WIKITABLE)
390
+ // ->willReturn($this->db);
391
+
392
+ // $this->db
393
+ // ->expects($this->once())
394
+ // ->method('persist')
395
+ // ->with($values);
396
+ /*
397
+ $result = $this->wikiModel->createpage($project_id, $title, $content, $date);
398
+ $this->assertNotNull($result);
399
+
400
+ }
401
+ */
402
+
403
+ // Additional test cases can be defined here for each method
404
+ }
0 commit comments