1<?php
2
3/**
4 * Test cases for the move plugin
5 *
6 * @group plugin_move
7 * @group plugins
8 */
9class plugin_move_handler_test extends DokuWikiTest {
10
11    public function setUp(): void {
12        $this->pluginsEnabled[] = 'move';
13        parent::setUp();
14    }
15
16    public function test_relativeLink() {
17        $handler = new helper_plugin_move_handler();
18        $handler->init('deep:namespace:page', 'used:to:be:here', array(), array(), array());
19
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
29        foreach($tests as $new => $rel) {
30            $this->assertEquals($rel, $handler->relativeLink('foo', $new, 'page'));
31        }
32
33        $this->assertEquals('.deeper:', $handler->relativeLink('.deeper:', 'deep:namespace:deeper:start', 'page'));
34        $this->assertEquals('.:', $handler->relativeLink('.:', 'deep:namespace:start', 'page'));
35    }
36
37    public function test_resolveMoves() {
38        $handler = new helper_plugin_move_handler();
39        $handler->init(
40            'deep:namespace:page',
41            'used:to:be:here',
42            array(
43                 array('used:to:be:here', 'deep:namespace:page'),
44                 array('foo', 'bar'),
45                 array('used:to:be:this1', 'used:to:be:that1'),
46                 array('used:to:be:this2', 'deep:namespace:that1'),
47                 array('used:to:be:this3', 'deep:that3'),
48                 array('deep:that3', 'but:got:moved3'),
49            ),
50            array(),
51            array()
52        );
53
54        $tests = array(
55            'used:to:be:here' => 'deep:namespace:page', // full link to self
56            ':foo' => 'bar', // absolute link that moved
57            ':bang' => 'bang', // absolute link that did not move
58            'foo' => 'used:to:be:foo', // relative link that did not move
59            'this1' => 'used:to:be:that1', // relative link that did not move but is in move list
60            'this2' => 'deep:namespace:that1', // relative link that moved
61            'this3' => 'but:got:moved3', // relative link that moved twice
62        );
63
64        foreach($tests as $match => $id) {
65            $this->assertEquals($id, $handler->resolveMoves($match, 'page'));
66        }
67    }
68
69}
70