[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 use dokuwiki\Remote\Api; 4 use dokuwiki\Remote\ApiCore; 5 use dokuwiki\test\mock\AuthPlugin; 6 use dokuwiki\test\mock\AuthDeletePlugin; 7 8 /** 9 * Class remoteapicore_test 10 */ 11 class remoteapicore_test extends DokuWikiTest { 12 13 protected $userinfo; 14 protected $oldAuthAcl; 15 /** @var Api */ 16 protected $remote; 17 18 public function setUp() : void { 19 // we need a clean setup before each single test: 20 DokuWikiTest::setUpBeforeClass(); 21 22 parent::setUp(); 23 global $conf; 24 global $USERINFO; 25 global $AUTH_ACL; 26 global $auth; 27 $this->oldAuthAcl = $AUTH_ACL; 28 $this->userinfo = $USERINFO; 29 $auth = new AuthPlugin(); 30 31 $conf['remote'] = 1; 32 $conf['remoteuser'] = '@user'; 33 $conf['useacl'] = 0; 34 35 $this->remote = new Api(); 36 } 37 38 public function tearDown() : void { 39 parent::tearDown(); 40 41 global $USERINFO; 42 global $AUTH_ACL; 43 44 $USERINFO = $this->userinfo; 45 $AUTH_ACL = $this->oldAuthAcl; 46 } 47 48 /** Delay writes of old revisions by a second. */ 49 public function handle_write(Doku_Event $event, $param) { 50 if ($event->data[3] !== false) { 51 $this->waitForTick(); 52 } 53 } 54 55 public function test_getVersion() { 56 $this->assertEquals(getVersion(), $this->remote->call('dokuwiki.getVersion')); 57 } 58 59 public function test_getPageList() { 60 $file1 = wikiFN('wiki:dokuwiki'); 61 $file2 = wikiFN('wiki:syntax'); 62 $expected = array( 63 array( 64 'id' => 'wiki:dokuwiki', 65 'rev' => filemtime($file1), 66 'mtime' => filemtime($file1), 67 'size' => filesize($file1), 68 'hash' => md5(trim(rawWiki('wiki:dokuwiki'))) 69 ), 70 array( 71 'id' => 'wiki:syntax', 72 'rev' => filemtime($file2), 73 'mtime' => filemtime($file2), 74 'size' => filesize($file2), 75 'hash' => md5(trim(rawWiki('wiki:syntax'))) 76 ) 77 ); 78 $params = array( 79 'wiki:', 80 array( 81 'depth' => 0, // 0 for all 82 'hash' => 1, 83 'skipacl' => 1 // is ignored 84 ) 85 ); 86 $this->assertEquals($expected, $this->remote->call('dokuwiki.getPagelist', $params)); 87 } 88 89 public function test_search() { 90 $id = 'wiki:syntax'; 91 $file = wikiFN($id); 92 93 idx_addPage($id); //full text search depends on index 94 $expected = array( 95 array( 96 'id' => $id, 97 'score' => 1, 98 'rev' => filemtime($file), 99 'mtime' => filemtime($file), 100 'size' => filesize($file), 101 'snippet' => ' a footnote)) by using double parentheses. 102 103 ===== <strong class="search_hit">Sectioning</strong> ===== 104 105 You can use up to five different levels of', 106 'title' => 'wiki:syntax' 107 ) 108 ); 109 $params = array('Sectioning'); 110 $this->assertEquals($expected, $this->remote->call('dokuwiki.search', $params)); 111 } 112 113 public function test_getTime() { 114 $timeexpect = time(); 115 $timeactual = $this->remote->call('dokuwiki.getTime'); 116 $this->assertTrue(($timeexpect <= $timeactual) && ($timeactual <= $timeexpect + 1)); 117 } 118 119 public function test_setLocks() { 120 $expected = array( 121 'locked' => array('wiki:dokuwiki', 'wiki:syntax', 'nonexisting'), 122 'lockfail' => array(), 123 'unlocked' => array(), 124 'unlockfail' => array(), 125 ); 126 $params = array( 127 array( 128 'lock' => array('wiki:dokuwiki', 'wiki:syntax', 'nonexisting'), 129 'unlock' => array() 130 ) 131 ); 132 $this->assertEquals($expected, $this->remote->call('dokuwiki.setLocks', $params)); 133 134 $expected = array( 135 'locked' => array(), 136 'lockfail' => array(), 137 'unlocked' => array('wiki:dokuwiki', 'wiki:syntax', 'nonexisting'), 138 'unlockfail' => array('nonexisting2'), 139 ); 140 $params = array( 141 array( 142 'lock' => array(), 143 'unlock' => array('wiki:dokuwiki', 'wiki:syntax', 'nonexisting', 'nonexisting2') 144 ) 145 ); 146 $this->assertEquals($expected, $this->remote->call('dokuwiki.setLocks', $params)); 147 } 148 149 public function test_getTitle() { 150 global $conf; 151 $this->assertEquals($conf['title'], $this->remote->call('dokuwiki.getTitle')); 152 } 153 154 public function test_putPage() { 155 $id = 'putpage'; 156 157 $content = "====Title====\nText"; 158 $params = array( 159 $id, 160 $content, 161 array( 162 'minor' => false, 163 'sum' => 'Summary of nice text' 164 ) 165 ); 166 $this->assertTrue($this->remote->call('wiki.putPage', $params)); 167 $this->assertEquals($content, rawWiki($id)); 168 169 //remove page 170 $params = array( 171 $id, 172 '', 173 array( 174 'minor' => false, 175 ) 176 ); 177 $this->assertTrue($this->remote->call('wiki.putPage', $params)); 178 $this->assertFileNotExists(wikiFN($id)); 179 } 180 181 public function test_getPage() { 182 $id = 'getpage'; 183 $content = 'a test'; 184 saveWikiText($id, $content, 'test for getpage'); 185 186 $params = array($id); 187 $this->assertEquals($content, $this->remote->call('wiki.getPage', $params)); 188 } 189 190 public function test_appendPage() { 191 $id = 'appendpage'; 192 $content = 'a test'; 193 $morecontent = "\nOther text"; 194 saveWikiText($id, $content, 'local'); 195 196 $params = array( 197 $id, 198 $morecontent, 199 array() 200 ); 201 $this->assertEquals(true, $this->remote->call('dokuwiki.appendPage', $params)); 202 $this->assertEquals($content . $morecontent, rawWiki($id)); 203 } 204 205 public function test_getPageVersion() { 206 $id = 'pageversion'; 207 $file = wikiFN($id); 208 209 saveWikiText($id, 'first version', 'first'); 210 $rev1 = filemtime($file); 211 clearstatcache(false, $file); 212 $this->waitForTick(true); 213 saveWikiText($id, 'second version', 'second'); 214 $rev2 = filemtime($file); 215 216 $params = array($id, ''); 217 $this->assertEquals('second version', $this->remote->call('wiki.getPageVersion', $params), 'no revision given'); 218 219 $params = array($id, $rev1); 220 $this->assertEquals('first version', $this->remote->call('wiki.getPageVersion', $params), '1st revision given'); 221 222 $params = array($id, $rev2); 223 $this->assertEquals('second version', $this->remote->call('wiki.getPageVersion', $params), '2nd revision given'); 224 225 $params = array($id, 1234); 226 $this->assertEquals('', $this->remote->call('wiki.getPageVersion', $params), 'Non existing revision given'); 227 228 $params = array('foobar', 1234); 229 $this->assertEquals('', $this->remote->call('wiki.getPageVersion', $params), 'Non existing page given'); 230 } 231 232 public function test_getPageHTML() { 233 $id = 'htmltest'; 234 $content = "====Title====\nText"; 235 $html = "\n<h3 class=\"sectionedit1\" id=\"title\">Title</h3>\n<div class=\"level3\">\n\n<p>\nText\n</p>\n\n</div>\n"; 236 237 saveWikiText($id, $content, 'htmltest'); 238 239 $params = array($id); 240 $this->assertEquals($html, $this->remote->call('wiki.getPageHTML', $params)); 241 } 242 243 public function test_getPageHTMLVersion() { 244 $id = 'htmltest'; 245 $file = wikiFN($id); 246 247 $content1 = "====Title====\nText"; 248 $html1 = "\n<h3 class=\"sectionedit1\" id=\"title\">Title</h3>\n<div class=\"level3\">\n\n<p>\nText\n</p>\n\n</div>\n"; 249 $content2 = "====Foobar====\nText Bamm"; 250 $html2 = "\n<h3 class=\"sectionedit1\" id=\"foobar\">Foobar</h3>\n<div class=\"level3\">\n\n<p>\nText Bamm\n</p>\n\n</div>\n"; 251 252 saveWikiText($id, $content1, 'first'); 253 $rev1 = filemtime($file); 254 clearstatcache(false, $file); 255 $this->waitForTick(true); 256 saveWikiText($id, $content2, 'second'); 257 $rev2 = filemtime($file); 258 259 $params = array($id, ''); 260 $this->assertEquals($html2, $this->remote->call('wiki.getPageHTMLVersion', $params), 'no revision given'); 261 262 $params = array($id, $rev1); 263 $this->assertEquals($html1, $this->remote->call('wiki.getPageHTMLVersion', $params), '1st revision given'); 264 265 $params = array($id, $rev2); 266 $this->assertEquals($html2, $this->remote->call('wiki.getPageHTMLVersion', $params), '2nd revision given'); 267 268 $params = array($id, 1234); 269 $this->assertEquals('', $this->remote->call('wiki.getPageHTMLVersion', $params), 'Non existing revision given'); 270 271 $params = array('foobar', 1234); 272 $this->assertEquals('', $this->remote->call('wiki.getPageHTMLVersion', $params), 'Non existing page given'); 273 } 274 275 public function test_getAllPages() { 276 // all pages depends on index 277 idx_addPage('wiki:syntax'); 278 idx_addPage('wiki:dokuwiki'); 279 280 $file1 = wikiFN('wiki:syntax'); 281 $file2 = wikiFN('wiki:dokuwiki'); 282 283 $expected = array( 284 array( 285 'id' => 'wiki:syntax', 286 'perms' => 8, 287 'size' => filesize($file1), 288 'lastModified' => filemtime($file1) 289 ), 290 array( 291 'id' => 'wiki:dokuwiki', 292 'perms' => 8, 293 'size' => filesize($file2), 294 'lastModified' => filemtime($file2) 295 ) 296 ); 297 $this->assertEquals($expected, $this->remote->call('wiki.getAllPages')); 298 } 299 300 public function test_getBacklinks() { 301 saveWikiText('linky', '[[wiki:syntax]]', 'test'); 302 // backlinks need index 303 idx_addPage('wiki:syntax'); 304 idx_addPage('linky'); 305 306 $params = array('wiki:syntax'); 307 $result = $this->remote->call('wiki.getBackLinks', $params); 308 $this->assertTrue(count($result) > 0); 309 $this->assertEquals(ft_backlinks('wiki:syntax'), $result); 310 } 311 312 public function test_getPageInfo() { 313 $id = 'pageinfo'; 314 $file = wikiFN($id); 315 316 saveWikiText($id, 'test', 'test'); 317 318 $expected = array( 319 'name' => $id, 320 'lastModified' => filemtime($file), 321 'author' => clientIP(), 322 'version' => filemtime($file) 323 ); 324 $params = array($id); 325 $this->assertEquals($expected, $this->remote->call('wiki.getPageInfo', $params)); 326 } 327 328 public function test_getPageInfoVersion() { 329 $id = 'pageinfo'; 330 $file = wikiFN($id); 331 332 saveWikiText($id, 'first version', 'first'); 333 $rev1 = filemtime($file); 334 clearstatcache(false, $file); 335 $this->waitForTick(true); 336 saveWikiText($id, 'second version', 'second'); 337 $rev2 = filemtime($file); 338 339 $expected = array( 340 'name' => $id, 341 'lastModified' => $rev2, 342 'author' => clientIP(), 343 'version' => $rev2 344 ); 345 $params = array($id, ''); 346 $this->assertEquals($expected, $this->remote->call('wiki.getPageInfoVersion', $params), 'no revision given'); 347 348 $expected = array( 349 'name' => $id, 350 'lastModified' => $rev1, 351 'author' => clientIP(), 352 'version' => $rev1 353 ); 354 $params = array($id, $rev1); 355 $this->assertEquals($expected, $this->remote->call('wiki.getPageInfoVersion', $params), '1st revision given'); 356 357 $expected = array( 358 'name' => $id, 359 'lastModified' => $rev2, 360 'author' => clientIP(), 361 'version' => $rev2 362 ); 363 $params = array($id, $rev2); 364 $this->assertEquals($expected, $this->remote->call('wiki.getPageInfoVersion', $params), '2nd revision given'); 365 } 366 367 public function test_getRecentChanges() { 368 369 saveWikiText('pageone', 'test', 'test'); 370 $rev1 = filemtime(wikiFN('pageone')); 371 saveWikiText('pagetwo', 'test', 'test'); 372 $rev2 = filemtime(wikiFN('pagetwo')); 373 374 $expected = array( 375 array( 376 'name' => 'pageone', 377 'lastModified' => $rev1, 378 'author' => '', 379 'version' => $rev1, 380 'perms' => 8, 381 'size' => 4 382 ), 383 array( 384 'name' => 'pagetwo', 385 'lastModified' => $rev2, 386 'author' => '', 387 'version' => $rev2, 388 'perms' => 8, 389 'size' => 4 390 ) 391 ); 392 $params = array(strtotime("-1 year")); 393 $this->assertEquals($expected, $this->remote->call('wiki.getRecentChanges', $params)); 394 } 395 396 public function test_getPageVersions() { 397 /** @var $EVENT_HANDLER \dokuwiki\Extension\EventHandler */ 398 global $EVENT_HANDLER; 399 $EVENT_HANDLER->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'handle_write'); 400 global $conf; 401 402 $id = 'revpage'; 403 $file = wikiFN($id); 404 405 $rev = array(); 406 for($i = 0; $i < 6; $i++) { 407 $this->waitForTick(); 408 saveWikiText($id, "rev$i", "rev$i"); 409 clearstatcache(false, $file); 410 $rev[$i] = filemtime($file); 411 } 412 413 $params = array($id, 0); 414 $versions = $this->remote->call('wiki.getPageVersions', $params); 415 $this->assertEquals(6, count($versions)); 416 $this->assertEquals($rev[5], $versions[0]['version']); 417 $this->assertEquals($rev[4], $versions[1]['version']); 418 $this->assertEquals($rev[3], $versions[2]['version']); 419 $this->assertEquals($rev[2], $versions[3]['version']); 420 $this->assertEquals($rev[1], $versions[4]['version']); 421 $this->assertEquals($rev[0], $versions[5]['version']); 422 423 $params = array($id, 1); // offset 1 424 $versions = $this->remote->call('wiki.getPageVersions', $params); 425 $this->assertEquals(5, count($versions)); 426 $this->assertEquals($rev[4], $versions[0]['version']); 427 $this->assertEquals($rev[3], $versions[1]['version']); 428 $this->assertEquals($rev[2], $versions[2]['version']); 429 $this->assertEquals($rev[1], $versions[3]['version']); 430 $this->assertEquals($rev[0], $versions[4]['version']); 431 432 $conf['recent'] = 3; //set number of results per page 433 434 $params = array($id, 0); // first page 435 $versions = $this->remote->call('wiki.getPageVersions', $params); 436 $this->assertEquals(3, count($versions)); 437 $this->assertEquals($rev[5], $versions[0]['version']); 438 $this->assertEquals($rev[4], $versions[1]['version']); 439 $this->assertEquals($rev[3], $versions[2]['version']); 440 441 $params = array($id, $conf['recent']); // second page 442 $versions = $this->remote->call('wiki.getPageVersions', $params); 443 $this->assertEquals(3, count($versions)); 444 $this->assertEquals($rev[2], $versions[0]['version']); 445 $this->assertEquals($rev[1], $versions[1]['version']); 446 $this->assertEquals($rev[0], $versions[2]['version']); 447 448 $params = array($id, $conf['recent'] * 2); // third page 449 $versions = $this->remote->call('wiki.getPageVersions', $params); 450 $this->assertEquals(0, count($versions)); 451 } 452 453 public function test_deleteUser() 454 { 455 global $conf, $auth; 456 $auth = new AuthDeletePlugin(); 457 $conf['remote'] = 1; 458 $conf['remoteuser'] = 'testuser'; 459 $_SERVER['REMOTE_USER'] = 'testuser'; 460 $params = [ 461 ['testuser'] 462 ]; 463 $actualCallResult = $this->remote->call('dokuwiki.deleteUsers', $params); 464 $this->assertTrue($actualCallResult); 465 } 466 467 public function test_aclCheck() { 468 $id = 'aclpage'; 469 470 $params = array($id); 471 $this->assertEquals(AUTH_UPLOAD, $this->remote->call('wiki.aclCheck', $params)); 472 473 global $conf; 474 global $AUTH_ACL, $USERINFO; 475 $conf['useacl'] = 1; 476 $_SERVER['REMOTE_USER'] = 'john'; 477 $USERINFO['grps'] = array('user'); 478 $AUTH_ACL = array( 479 '* @ALL 0', 480 '* @user 2', //edit 481 ); 482 483 $params = array($id); 484 $this->assertEquals(AUTH_EDIT, $this->remote->call('wiki.aclCheck', $params)); 485 } 486 487 public function test_getXMLRPCAPIVersion() { 488 $this->assertEquals(ApiCore::API_VERSION, $this->remote->call('dokuwiki.getXMLRPCAPIVersion')); 489 } 490 491 public function test_getRPCVersionSupported() { 492 $this->assertEquals(2, $this->remote->call('wiki.getRPCVersionSupported')); 493 } 494 495 public function test_listLinks() { 496 $localdoku = array( 497 'type' => 'local', 498 'page' => 'DokuWiki', 499 'href' => DOKU_BASE . DOKU_SCRIPT . '?id=DokuWiki' 500 ); 501 $expected = array( //no local links 502 $localdoku, 503 array( 504 'type' => 'extern', 505 'page' => 'http://www.freelists.org', 506 'href' => 'http://www.freelists.org' 507 ), 508 array( 509 'type' => 'extern', 510 'page' => 'https://tools.ietf.org/html/rfc1855', 511 'href' => 'https://tools.ietf.org/html/rfc1855' 512 ), 513 array( 514 'type' => 'extern', 515 'page' => 'http://www.catb.org/~esr/faqs/smart-questions.html', 516 'href' => 'http://www.catb.org/~esr/faqs/smart-questions.html' 517 ), 518 $localdoku, 519 $localdoku 520 ); 521 $params = array('mailinglist'); 522 $this->assertEquals($expected, $this->remote->call('wiki.listLinks', $params)); 523 } 524 525 public function test_coreattachments() { 526 global $conf; 527 global $AUTH_ACL, $USERINFO; 528 529 $filecontent = io_readFile(mediaFN('wiki:dokuwiki-128.png'), false); 530 $params = array('test:dokuwiki-128_2.png', $filecontent, array('ow' => false)); 531 $this->assertEquals('test:dokuwiki-128_2.png', $this->remote->call('wiki.putAttachment', $params)); //prints a success div 532 533 $params = array('test:dokuwiki-128_2.png'); 534 $this->assertEquals($filecontent, $this->remote->call('wiki.getAttachment', $params)); 535 $rev = filemtime(mediaFN('test:dokuwiki-128_2.png')); 536 537 $expected = array( 538 'lastModified' => $rev, 539 'size' => 27895, 540 ); 541 $params = array('test:dokuwiki-128_2.png'); 542 $this->assertEquals($expected, $this->remote->call('wiki.getAttachmentInfo', $params)); 543 544 $params = array(strtotime("-5 year")); 545 $expected = array( 546 array( 547 'name' => 'test:dokuwiki-128_2.png', 548 'lastModified' => $rev, 549 'author' => '', 550 'version' => $rev, 551 'perms' => 8, 552 'size' => 27895 //actual size, not size change 553 ) 554 ); 555 $this->assertEquals($expected, $this->remote->call('wiki.getRecentMediaChanges', $params)); 556 557 $this->waitForTick(true); 558 $conf['useacl'] = 1; 559 $_SERVER['REMOTE_USER'] = 'john'; 560 $USERINFO['grps'] = array('user'); 561 $AUTH_ACL = array( 562 '* @ALL 0', 563 '* @user 16', 564 ); 565 566 $params = array('test:dokuwiki-128_2.png'); 567 $this->assertEquals(0, $this->remote->call('wiki.deleteAttachment', $params)); 568 569 $rev2 = filemtime($conf['media_changelog']); 570 $expected = array( 571 'lastModified' => $rev2, 572 'size' => 0, 573 ); 574 $params = array('test:dokuwiki-128_2.png'); 575 $this->assertEquals($expected, $this->remote->call('wiki.getAttachmentInfo', $params)); 576 577 $expected = array( 578 'lastModified' => 0, 579 'size' => 0, 580 ); 581 $params = array('test:nonexisting.png'); 582 $this->assertEquals($expected, $this->remote->call('wiki.getAttachmentInfo', $params)); 583 584 $media1 = mediaFN('wiki:dokuwiki-128.png'); 585 $expected = array( 586 array( 587 'id' => 'wiki:dokuwiki-128.png', 588 'file' => 'dokuwiki-128.png', 589 'size' => filesize($media1), 590 'mtime' => filemtime($media1), 591 'writable' => 1, 592 'isimg' => 1, 593 'hash' => md5(io_readFile($media1, false)), 594 'perms' => 16, 595 'lastModified' => filemtime($media1) 596 ) 597 ); 598 $params = array( 599 'wiki:', 600 array( 601 'depth' => 0, // 0 for all 602 'hash' => 1, 603 'skipacl' => 1, // is ignored 604 'showmsg' => true, //useless?? 605 'pattern' => '/128/' //filter 606 ) 607 ); 608 $this->assertEquals($expected, $this->remote->call('wiki.getAttachments', $params)); 609 } 610 611 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body