1<?php
2require_once __DIR__ . '/../admin.php';
3
4/**
5 * tests for the linkfix plugin
6 *
7 * @group plugin_linkfix
8 * @group plugins
9 */
10class linkfix_plugin_linkfix_test extends DokuWikiTest {
11
12    public static function setUpBeforeClass(){
13        parent::setUpBeforeClass();
14        // copy our own config files to the test directory
15        TestUtils::rcopy(dirname(DOKU_TMP_DATA), dirname(__FILE__).'/data');
16        idx_addPage('linkfix:linkfix');
17    }
18
19
20    public function test_internal() {
21        $plugin = new test_admin_plugin_linkfix();
22
23        $plugin->changefrom = 'linkfix:';
24        $plugin->changeto   = 'linkfox:';
25        $plugin->execute();
26
27        $text = rawWiki('linkfix:linkfix');
28        $this->assertRegExp('/linkfox:linkfix\|case 1/', $text);
29    }
30
31    public function test_external() {
32        $plugin = new test_admin_plugin_linkfix();
33
34        $plugin->changefrom = 'http://www.google';
35        $plugin->changeto   = 'http://www.foogle';
36        $plugin->isextern   = true;
37        $plugin->execute();
38
39        $text = rawWiki('linkfix:linkfix');
40        $this->assertRegExp('/http:\/\/www\.foogle\.com\|case 2/', $text);
41    }
42
43    public function test_internalmedia() {
44        $plugin = new test_admin_plugin_linkfix();
45
46        $plugin->changefrom = 'something:logo.';
47        $plugin->changeto   = 'something:icon.';
48        $plugin->type = 'media';
49        $plugin->execute();
50
51        $text = rawWiki('linkfix:linkfix');
52        $this->assertRegExp('/\{\{ something:icon\.png \|case 3\}\}/', $text);
53    }
54
55    public function test_externalmedia() {
56        $plugin = new test_admin_plugin_linkfix();
57
58        $plugin->changefrom = 'http://www.google';
59        $plugin->changeto   = 'http://www.foogle';
60        $plugin->isextern   = true;
61        $plugin->type = 'media';
62        $plugin->execute();
63
64        $text = rawWiki('linkfix:linkfix');
65        $this->assertRegExp('/{{ http:\/\/www\.foogle\.com\/logo.png |case 4}}/', $text);
66    }
67
68    public function test_windowsshare() {
69        $plugin = new test_admin_plugin_linkfix();
70
71        $plugin->changefrom = '\\\\server\\';
72        $plugin->changeto   = '\\\\foobar\\';
73        $plugin->isextern   = true;
74        $plugin->execute();
75
76        $text = rawWiki('linkfix:linkfix');
77        $this->assertRegExp('/\\\\foobar\\share|case 5/', $text);
78    }
79}
80
81class test_admin_plugin_linkfix extends admin_plugin_linkfix {
82    public $searchin = '';
83    public $changefrom = '';
84    public $changeto = '';
85    public $dryrun = false;
86    public $type = 'links';
87    public $isextern = false;
88
89    public function __construct() {
90
91    }
92
93    public function execute(){
94        return parent::execute();
95    }
96
97    protected function prnt($string) {
98
99    }
100}