1<?php
2
3namespace dokuwiki\plugin\oauth\test;
4
5use DokuWikiTest;
6
7/**
8 * Mail Restriction tests for the oauth plugin
9 *
10 * @group plugin_oauth
11 * @group plugins
12 */
13class CheckMailTest extends DokuWikiTest
14{
15    protected $pluginsEnabled = ['oauth'];
16
17    /**
18     * @return array[]
19     * @see testCheckMail
20     */
21    public function provideCheckMailData()
22    {
23        return [
24            ['@foo.org,@example.com', 'bar@foo.org', true],
25            ['@foo.org,@example.com', 'bar@example.com', true],
26            ['@foo.org,@example.com', 'bar@bar.org', false],
27            ['@foo.org', 'bar@foo.org', true],
28            ['@foo.org', 'bar@example.com', false],
29            ['@foo.org', 'bar@bar.org', false],
30            ['', 'bar@bar.org', true],
31
32        ];
33    }
34
35    /**
36     * @dataProvider provideCheckMailData
37     * @param string $restriction
38     * @param string $input
39     * @param string $expected
40     * @return void
41     */
42    public function testCheckMail($restriction, $input, $expected)
43    {
44        global $conf;
45        $conf['plugin']['oauth']['mailRestriction'] = $restriction;
46
47        /** @var \helper_plugin_oauth $hlp */
48        $hlp = plugin_load('helper', 'oauth');
49        $this->assertSame($expected, $hlp->checkMail($input));
50    }
51}
52