xref: /plugin/farmer/_test/helper.test.php (revision 4d6fc85b7f5b87b5971ca4550dd9c738b31b0c4f)
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    protected $pluginsEnabled = array('farmer',);
12
13    public function validationProvider() {
14        return array(
15            array('ant', true),
16            array('ant.lion', true),
17            array('ant.lion.cow', true),
18            array('ant-lion', true),
19            array('ant-lion.cow', true),
20            array('4ant', true),
21            array('ant4', true),
22            array('ant44lion', true),
23            array('44', true),
24
25            array('ant.', false),
26            array('.ant', false),
27            array('ant-', false),
28            array('-ant', false),
29            array('ant--lion', false),
30            array('ant..lion', false),
31            array('ant.-lion', false),
32            array('ant/lion', false),
33            array('!ant', false),
34            array('ant lion', false),
35        );
36    }
37
38    /**
39     * @dataProvider validationProvider
40     * @param $input
41     * @param $expect
42     */
43    public function test_validateAnimalName($input, $expect) {
44        /** @var helper_plugin_farmer $helper */
45        $helper = plugin_load('helper', 'farmer');
46        $this->assertEquals($expect, $helper->validateAnimalName($input));
47    }
48
49    public function test_isInPath() {
50        /** @var helper_plugin_farmer $helper */
51        $helper = plugin_load('helper', 'farmer');
52
53        $this->assertTrue($helper->isInPath('/var/www/foo', '/var/www'));
54        $this->assertFalse($helper->isInPath('/var/www/../foo', '/var/www'));
55
56        // same dir should return false, too
57        $this->assertFalse($helper->isInPath('/var/www/foo', '/var/www/foo'));
58        $this->assertFalse($helper->isInPath('/var/www/foo/', '/var/www/foo'));
59        $this->assertFalse($helper->isInPath('/var/www/foo/bar/../', '/var/www/foo'));
60    }
61}
62