xref: /dokuwiki/_test/tests/Parsing/ParserMode/EmaillinkTest.php (revision e7dae73bcd947f44c901faaac9dd45de67633a3b)
1<?php
2
3namespace dokuwiki\test\Parsing\ParserMode;
4
5use dokuwiki\Parsing\ParserMode\Emaillink;
6
7/**
8 * Tests for the {@see Emaillink} parser mode: bare email addresses inside `<...>` envelopes.
9 *
10 * @group parser_links
11 */
12class EmaillinkTest extends ParserTestBase
13{
14    function testEmail() {
15        $this->P->addMode('emaillink', new Emaillink());
16        $this->P->parse("Foo <bugs@php.net> Bar");
17        $calls = [
18            ['document_start', []],
19            ['p_open', []],
20            ['cdata', ["\n" . 'Foo ']],
21            ['emaillink', ['bugs@php.net', null]],
22            ['cdata', [' Bar']],
23            ['p_close', []],
24            ['document_end', []],
25        ];
26        $this->assertCalls($calls, $this->H->calls);
27    }
28
29    function testEmailRFC2822() {
30        $this->P->addMode('emaillink', new Emaillink());
31        $this->P->parse("Foo <~fix+bug's.for/ev{e}r@php.net> Bar");
32        $calls = [
33            ['document_start', []],
34            ['p_open', []],
35            ['cdata', ["\n" . 'Foo ']],
36            ['emaillink', ["~fix+bug's.for/ev{e}r@php.net", null]],
37            ['cdata', [' Bar']],
38            ['p_close', []],
39            ['document_end', []],
40        ];
41        $this->assertCalls($calls, $this->H->calls);
42    }
43
44    function testEmailCase() {
45        $this->P->addMode('emaillink', new Emaillink());
46        $this->P->parse("Foo <bugs@pHp.net> Bar");
47        $calls = [
48            ['document_start', []],
49            ['p_open', []],
50            ['cdata', ["\n" . 'Foo ']],
51            ['emaillink', ['bugs@pHp.net', null]],
52            ['cdata', [' Bar']],
53            ['p_close', []],
54            ['document_end', []],
55        ];
56        $this->assertCalls($calls, $this->H->calls);
57    }
58}
59