1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<?php
/**
* Tests for the validation functionality of the farmer plugin
*
* @group plugin_farmer
* @group plugins
*/
class helper_plugin_farmer_test extends DokuWikiTest {
protected $pluginsEnabled = array('farmer',);
public function validationProvider() {
return array(
array('ant', true),
array('ant.lion', true),
array('ant.lion.cow', true),
array('ant-lion', true),
array('ant-lion.cow', true),
array('4ant', true),
array('ant4', true),
array('ant44lion', true),
array('44', true),
array('ant.', false),
array('.ant', false),
array('ant-', false),
array('-ant', false),
array('ant--lion', false),
array('ant..lion', false),
array('ant.-lion', false),
array('ant/lion', false),
array('!ant', false),
array('ant lion', false),
);
}
/**
* @dataProvider validationProvider
* @param $input
* @param $expect
*/
public function test_validateAnimalName($input, $expect) {
/** @var helper_plugin_farmer $helper */
$helper = plugin_load('helper', 'farmer');
$this->assertEquals($expect, $helper->validateAnimalName($input));
}
public function test_isInPath() {
/** @var helper_plugin_farmer $helper */
$helper = plugin_load('helper', 'farmer');
$this->assertTrue($helper->isInPath('/var/www/foo', '/var/www'));
$this->assertFalse($helper->isInPath('/var/www/../foo', '/var/www'));
// same dir should return false, too
$this->assertFalse($helper->isInPath('/var/www/foo', '/var/www/foo'));
$this->assertFalse($helper->isInPath('/var/www/foo/', '/var/www/foo'));
$this->assertFalse($helper->isInPath('/var/www/foo/bar/../', '/var/www/foo'));
// https://github.com/cosmocode/dokuwiki-plugin-farmer/issues/30
$this->assertFalse($helper->isInPath('/var/lib/dokuwiki.animals', '/var/lib/dokuwiki'));
}
}
|