xref: /plugin/farmer/_test/helper.test.php (revision 655fe6c1fa0e8eca0207e883f3a88be96a9a98a2)
178c63d53SAndreas Gohr<?php
278c63d53SAndreas Gohr
378c63d53SAndreas Gohr/**
478c63d53SAndreas Gohr * Tests for the validation functionality of the farmer plugin
578c63d53SAndreas Gohr *
678c63d53SAndreas Gohr * @group plugin_farmer
778c63d53SAndreas Gohr * @group plugins
878c63d53SAndreas Gohr */
95b5c8486SAndreas Gohrclass helper_plugin_farmer_test extends DokuWikiTest
105b5c8486SAndreas Gohr{
1178c63d53SAndreas Gohr
125b5c8486SAndreas Gohr    protected $pluginsEnabled = ['farmer',];
1378c63d53SAndreas Gohr
145b5c8486SAndreas Gohr    public function validationProvider()
155b5c8486SAndreas Gohr    {
165b5c8486SAndreas Gohr        return [
175b5c8486SAndreas Gohr            ['ant', true],
185b5c8486SAndreas Gohr            ['ant.lion', true],
195b5c8486SAndreas Gohr            ['ant.lion.cow', true],
205b5c8486SAndreas Gohr            ['ant-lion', true],
215b5c8486SAndreas Gohr            ['ant-lion.cow', true],
225b5c8486SAndreas Gohr            ['4ant', true],
235b5c8486SAndreas Gohr            ['ant4', true],
245b5c8486SAndreas Gohr            ['ant44lion', true],
255b5c8486SAndreas Gohr            ['44', true],
2678c63d53SAndreas Gohr
27*655fe6c1SAndreas Gohr            ['aNt', false],
28*655fe6c1SAndreas Gohr            ['anT.Lion', false],
29*655fe6c1SAndreas Gohr            ['ant.Lion.cow', false],
30*655fe6c1SAndreas Gohr            ['ant-Lion', false],
31*655fe6c1SAndreas Gohr            ['ant-Lion.cow', false],
32*655fe6c1SAndreas Gohr            ['4aNt', false],
33*655fe6c1SAndreas Gohr            ['aNt4', false],
34*655fe6c1SAndreas Gohr            ['ant44Lion', false],
35*655fe6c1SAndreas Gohr
365b5c8486SAndreas Gohr            ['ant.', false],
375b5c8486SAndreas Gohr            ['.ant', false],
385b5c8486SAndreas Gohr            ['ant-', false],
395b5c8486SAndreas Gohr            ['-ant', false],
405b5c8486SAndreas Gohr            ['ant--lion', false],
415b5c8486SAndreas Gohr            ['ant..lion', false],
425b5c8486SAndreas Gohr            ['ant.-lion', false],
435b5c8486SAndreas Gohr            ['ant/lion', false],
445b5c8486SAndreas Gohr            ['!ant', false],
455b5c8486SAndreas Gohr            ['ant lion', false],
465b5c8486SAndreas Gohr        ];
4778c63d53SAndreas Gohr    }
4878c63d53SAndreas Gohr
4978c63d53SAndreas Gohr    /**
5078c63d53SAndreas Gohr     * @dataProvider validationProvider
5178c63d53SAndreas Gohr     * @param $input
5278c63d53SAndreas Gohr     * @param $expect
5378c63d53SAndreas Gohr     */
545b5c8486SAndreas Gohr    public function test_validateAnimalName($input, $expect)
555b5c8486SAndreas Gohr    {
5678c63d53SAndreas Gohr        /** @var helper_plugin_farmer $helper */
5778c63d53SAndreas Gohr        $helper = plugin_load('helper', 'farmer');
5878c63d53SAndreas Gohr        $this->assertEquals($expect, $helper->validateAnimalName($input));
5978c63d53SAndreas Gohr    }
6078c63d53SAndreas Gohr
615b5c8486SAndreas Gohr    public function test_isInPath()
625b5c8486SAndreas Gohr    {
6378c63d53SAndreas Gohr        /** @var helper_plugin_farmer $helper */
6478c63d53SAndreas Gohr        $helper = plugin_load('helper', 'farmer');
6578c63d53SAndreas Gohr
6678c63d53SAndreas Gohr        $this->assertTrue($helper->isInPath('/var/www/foo', '/var/www'));
6778c63d53SAndreas Gohr        $this->assertFalse($helper->isInPath('/var/www/../foo', '/var/www'));
6878c63d53SAndreas Gohr
69dfdaf33eSAndreas Gohr        // same dir should return false, too
70dfdaf33eSAndreas Gohr        $this->assertFalse($helper->isInPath('/var/www/foo', '/var/www/foo'));
71dfdaf33eSAndreas Gohr        $this->assertFalse($helper->isInPath('/var/www/foo/', '/var/www/foo'));
72dfdaf33eSAndreas Gohr        $this->assertFalse($helper->isInPath('/var/www/foo/bar/../', '/var/www/foo'));
730f0a264cSAndreas Gohr
740f0a264cSAndreas Gohr        // https://github.com/cosmocode/dokuwiki-plugin-farmer/issues/30
750f0a264cSAndreas Gohr        $this->assertFalse($helper->isInPath('/var/lib/dokuwiki.animals', '/var/lib/dokuwiki'));
7678c63d53SAndreas Gohr    }
7778c63d53SAndreas Gohr}
78