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