You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

76 lines
2.7 KiB

  1. <?php
  2. // must be run within Dokuwiki
  3. if(!defined('DOKU_INC')) die();
  4. require_once(__DIR__ . '/../helper/handler.php');
  5. /**
  6. * Test cases for the move plugin
  7. *
  8. * @group plugin_move
  9. * @group plugins
  10. */
  11. class plugin_move_handler_test extends DokuWikiTest {
  12. public function setUp(): void {
  13. $this->pluginsEnabled[] = 'move';
  14. parent::setUp();
  15. }
  16. public function test_relativeLink() {
  17. /** @var $handler helper_plugin_move_handler */
  18. $handler = plugin_load('helper', 'move_handler');
  19. $handler->init('deep:namespace:page', 'used:to:be:here', array(), array(), array());
  20. $tests = array(
  21. 'deep:namespace:new1' => 'new1',
  22. 'deep:new2' => '..:new2',
  23. 'new3' => ':new3', // absolute is shorter than relative
  24. 'deep:namespace:deeper:new4' => '.deeper:new4',
  25. 'deep:namespace:deeper:deepest:new5' => '.deeper:deepest:new5',
  26. 'deep:foobar:new6' => '..:foobar:new6',
  27. );
  28. foreach($tests as $new => $rel) {
  29. $this->assertEquals($rel, $handler->relativeLink('foo', $new, 'page'));
  30. }
  31. $this->assertEquals('.deeper:', $handler->relativeLink('.deeper:', 'deep:namespace:deeper:start', 'page'));
  32. $this->assertEquals('.:', $handler->relativeLink('.:', 'deep:namespace:start', 'page'));
  33. }
  34. public function test_resolveMoves() {
  35. /** @var $handler helper_plugin_move_handler */
  36. $handler = plugin_load('helper', 'move_handler');
  37. $handler->init(
  38. 'deep:namespace:page',
  39. 'used:to:be:here',
  40. array(
  41. array('used:to:be:here', 'deep:namespace:page'),
  42. array('foo', 'bar'),
  43. array('used:to:be:this1', 'used:to:be:that1'),
  44. array('used:to:be:this2', 'deep:namespace:that1'),
  45. array('used:to:be:this3', 'deep:that3'),
  46. array('deep:that3', 'but:got:moved3'),
  47. ),
  48. array(),
  49. array()
  50. );
  51. $tests = array(
  52. 'used:to:be:here' => 'deep:namespace:page', // full link to self
  53. ':foo' => 'bar', // absolute link that moved
  54. ':bang' => 'bang', // absolute link that did not move
  55. 'foo' => 'used:to:be:foo', // relative link that did not move
  56. 'this1' => 'used:to:be:that1', // relative link that did not move but is in move list
  57. 'this2' => 'deep:namespace:that1', // relative link that moved
  58. 'this3' => 'but:got:moved3', // relative link that moved twice
  59. );
  60. foreach($tests as $match => $id) {
  61. $this->assertEquals($id, $handler->resolveMoves($match, 'page'));
  62. }
  63. }
  64. }