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