1<?php
2
3namespace dokuwiki\plugin\oauth\test;
4
5use dokuwiki\plugin\oauth\Exception;
6use dokuwiki\plugin\oauth\OAuthManager;
7use DokuWikiTest;
8
9/**
10 * user data validation tests for the oauth plugin
11 *
12 * @group plugin_oauth
13 * @group plugins
14 */
15class ValidateUserDataTest extends DokuWikiTest
16{
17
18    protected $pluginsEnabled = ['oauth'];
19
20    /**
21     * @see testValidateUserData
22     */
23    public function provideUserData()
24    {
25        return [
26            [
27                ['mail' => 'test@ExamPLe.com'],
28                ['user' => 'test', 'name' => 'test', 'mail' => 'test@example.com', 'grps' => []],
29            ],
30            [
31                ['user' => 'tuser', 'mail' => 'test@example.com', 'grps' => ['one grp', 'Two']],
32                ['user' => 'tuser', 'name' => 'tuser', 'mail' => 'test@example.com', 'grps' => ['one_grp', 'two']],
33            ],
34            [
35                ['user' => 'TEST', 'name' => 'Test User', 'mail' => 'test@example.com', 'grps' => ['one', 'two']],
36                ['user' => 'test', 'name' => 'Test User', 'mail' => 'test@example.com', 'grps' => ['one', 'two']],
37            ],
38        ];
39    }
40
41    /**
42     * @dataProvider provideUserData
43     */
44    public function testValidateUserData($input, $expect)
45    {
46        $oauthMgr = new OAuthManager();
47        $result = $this->callInaccessibleMethod($oauthMgr, 'validateUserData', [$input, 'service']);
48        $this->assertEquals($expect, $result);
49    }
50
51    public function testMissingMail()
52    {
53        $this->expectException(Exception::class);
54
55        $input = [
56            'user' => 'test',
57            'name' => 'Test USer',
58        ];
59        $oauthMgr = new OAuthManager();
60        $this->callInaccessibleMethod($oauthMgr, 'validateUserData', [$input, 'service']);
61    }
62}
63