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