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