xref: /plugin/farmer/_test/getUserLine.test.php (revision 78c63d53eceed4e4fefa3c3a46e14844b75d6565)
1c66a21e9SMichael Große<?php
2c66a21e9SMichael Große
3*78c63d53SAndreas Gohrnamespace plugin\struct\test;
4*78c63d53SAndreas Gohr
5*78c63d53SAndreas Gohrclass admin_plugin_farmer_new extends \admin_plugin_farmer_new {
6*78c63d53SAndreas Gohr    public function getAdminLine() {
7*78c63d53SAndreas Gohr        return parent::getAdminLine();
8*78c63d53SAndreas Gohr    }
9*78c63d53SAndreas Gohr
10*78c63d53SAndreas Gohr}
11*78c63d53SAndreas Gohr
12c66a21e9SMichael Große
13c66a21e9SMichael Große/**
14c66a21e9SMichael Große * Tests for the validation functionality of the farmer plugin
15c66a21e9SMichael Große *
16c66a21e9SMichael Große * @group plugin_farmer
17c66a21e9SMichael Große * @group plugins
18c66a21e9SMichael Große */
19*78c63d53SAndreas Gohrclass getUserLine_plugin_farmer_test extends \DokuWikiTest {
20c66a21e9SMichael Große
21c66a21e9SMichael Große    protected $pluginsEnabled = array('farmer',);
22c66a21e9SMichael Große    private $usersfile;
23c66a21e9SMichael Große
24c66a21e9SMichael Große    public function setUp() {
25c66a21e9SMichael Große        parent::setUp();
26c66a21e9SMichael Große        $this->usersfile = DOKU_CONF . 'users.auth.php';
27c66a21e9SMichael Große        copy($this->usersfile, $this->usersfile . "org");
28c66a21e9SMichael Große        unlink($this->usersfile);
29c66a21e9SMichael Große    }
30c66a21e9SMichael Große
31c66a21e9SMichael Große    public function tearDown() {
32c66a21e9SMichael Große        parent::tearDown();
33c66a21e9SMichael Große        unlink($this->usersfile);
34c66a21e9SMichael Große        copy($this->usersfile . "org", $this->usersfile);
35c66a21e9SMichael Große        unlink($this->usersfile . "org");
36c66a21e9SMichael Große    }
37c66a21e9SMichael Große
38c66a21e9SMichael Große
39c66a21e9SMichael Große    public function test_getUserLine_oneUser () {
40*78c63d53SAndreas Gohr        $helper = new admin_plugin_farmer_new();
41c66a21e9SMichael Große        $usersfileData = "# users.auth.php
42c66a21e9SMichael Große# <?php exit()?>
43c66a21e9SMichael Große# Don't modify the lines above
44c66a21e9SMichael Große#
45c66a21e9SMichael Große# Userfile
46c66a21e9SMichael Große#
47c66a21e9SMichael Große# Format:
48c66a21e9SMichael Große#
49c66a21e9SMichael Große# user:MD5password:Real Name:email:groups,comma,seperated
50c66a21e9SMichael Große#
51c66a21e9SMichael Große# testuser : testpass
52c66a21e9SMichael Großetestuser:179ad45c6ce2cb97cf1029e212046e81:Arthur Dent:arthur@example.com:\n";
53c66a21e9SMichael Große        file_put_contents($this->usersfile,$usersfileData);
54c66a21e9SMichael Große
55*78c63d53SAndreas Gohr        $_SERVER['REMOTE_USER'] = 'testuser';
56c66a21e9SMichael Große        $expected_result = 'testuser:179ad45c6ce2cb97cf1029e212046e81:Arthur Dent:arthur@example.com:' . "\n";
57*78c63d53SAndreas Gohr        $actual_result = $helper->getAdminLine();
58c66a21e9SMichael Große
59c66a21e9SMichael Große        $this->assertSame($expected_result, $actual_result);
60c66a21e9SMichael Große    }
61c66a21e9SMichael Große
62c66a21e9SMichael Große    public function test_getUserLine_manyUser () {
63*78c63d53SAndreas Gohr        $helper = new admin_plugin_farmer_new();
64c66a21e9SMichael Große        $usersfileData = "# users.auth.php
65c66a21e9SMichael Große# <?php exit()?>
66c66a21e9SMichael Große# Don't modify the lines above
67c66a21e9SMichael Große#
68c66a21e9SMichael Große# Userfile
69c66a21e9SMichael Große#
70c66a21e9SMichael Große# Format:
71c66a21e9SMichael Große#
72c66a21e9SMichael Große# user:MD5password:Real Name:email:groups,comma,seperated
73c66a21e9SMichael Große#
74c66a21e9SMichael Große# testuser : testpass
75c66a21e9SMichael Große1testuser:179ad45c6ce43897cf1029e212046e81:Arthur Dent:brthur@example.com:admin
76c66a21e9SMichael Großetestuser:179ad45c6ce2cb97cf1029e212046e81:Arthur Dent:arthur@example.com:
77c66a21e9SMichael Große2testuser:179ad45c6ce2cb97cf10214712046e81:Arthur inDent:crthur@example.com:admin\n";
78c66a21e9SMichael Große        file_put_contents($this->usersfile,$usersfileData);
79c66a21e9SMichael Große
80*78c63d53SAndreas Gohr        $_SERVER['REMOTE_USER'] = 'testuser';
81c66a21e9SMichael Große        $expected_result = 'testuser:179ad45c6ce2cb97cf1029e212046e81:Arthur Dent:arthur@example.com:' . "\n";
82*78c63d53SAndreas Gohr        $actual_result = $helper->getAdminLine();
83c66a21e9SMichael Große
84c66a21e9SMichael Große        $this->assertSame($expected_result, $actual_result);
85c66a21e9SMichael Große    }
86c66a21e9SMichael Große}
87