xref: /dokuwiki/_test/tests/Parsing/ParserMode/FormattingTest.php (revision 504c13e8df88563c11b3720b317991bc38835a35)
1*504c13e8SAndreas Gohr<?php
2*504c13e8SAndreas Gohr
3*504c13e8SAndreas Gohrnamespace dokuwiki\test\Parsing\ParserMode;
4*504c13e8SAndreas Gohr
5*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Deleted;
6*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Emphasis;
7*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Monospace;
8*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Strong;
9*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Subscript;
10*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Superscript;
11*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Underline;
12*504c13e8SAndreas Gohr
13*504c13e8SAndreas Gohr/**
14*504c13e8SAndreas Gohr * Tests for the individual formatting modes (bold, italic, underline, etc.)
15*504c13e8SAndreas Gohr */
16*504c13e8SAndreas Gohrclass FormattingTest extends ParserTestBase
17*504c13e8SAndreas Gohr{
18*504c13e8SAndreas Gohr    function testStrong()
19*504c13e8SAndreas Gohr    {
20*504c13e8SAndreas Gohr        $this->P->addMode('strong', new Strong());
21*504c13e8SAndreas Gohr        $this->P->parse('Foo **Bar** Baz');
22*504c13e8SAndreas Gohr        $calls = [
23*504c13e8SAndreas Gohr            ['document_start', []],
24*504c13e8SAndreas Gohr            ['p_open', []],
25*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
26*504c13e8SAndreas Gohr            ['strong_open', []],
27*504c13e8SAndreas Gohr            ['cdata', ['Bar']],
28*504c13e8SAndreas Gohr            ['strong_close', []],
29*504c13e8SAndreas Gohr            ['cdata', [' Baz']],
30*504c13e8SAndreas Gohr            ['p_close', []],
31*504c13e8SAndreas Gohr            ['document_end', []],
32*504c13e8SAndreas Gohr        ];
33*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
34*504c13e8SAndreas Gohr    }
35*504c13e8SAndreas Gohr
36*504c13e8SAndreas Gohr    function testEmphasis()
37*504c13e8SAndreas Gohr    {
38*504c13e8SAndreas Gohr        $this->P->addMode('emphasis', new Emphasis());
39*504c13e8SAndreas Gohr        $this->P->parse('Foo //Bar// Baz');
40*504c13e8SAndreas Gohr        $calls = [
41*504c13e8SAndreas Gohr            ['document_start', []],
42*504c13e8SAndreas Gohr            ['p_open', []],
43*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
44*504c13e8SAndreas Gohr            ['emphasis_open', []],
45*504c13e8SAndreas Gohr            ['cdata', ['Bar']],
46*504c13e8SAndreas Gohr            ['emphasis_close', []],
47*504c13e8SAndreas Gohr            ['cdata', [' Baz']],
48*504c13e8SAndreas Gohr            ['p_close', []],
49*504c13e8SAndreas Gohr            ['document_end', []],
50*504c13e8SAndreas Gohr        ];
51*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
52*504c13e8SAndreas Gohr    }
53*504c13e8SAndreas Gohr
54*504c13e8SAndreas Gohr    function testUnderline()
55*504c13e8SAndreas Gohr    {
56*504c13e8SAndreas Gohr        $this->P->addMode('underline', new Underline());
57*504c13e8SAndreas Gohr        $this->P->parse('Foo __Bar__ Baz');
58*504c13e8SAndreas Gohr        $calls = [
59*504c13e8SAndreas Gohr            ['document_start', []],
60*504c13e8SAndreas Gohr            ['p_open', []],
61*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
62*504c13e8SAndreas Gohr            ['underline_open', []],
63*504c13e8SAndreas Gohr            ['cdata', ['Bar']],
64*504c13e8SAndreas Gohr            ['underline_close', []],
65*504c13e8SAndreas Gohr            ['cdata', [' Baz']],
66*504c13e8SAndreas Gohr            ['p_close', []],
67*504c13e8SAndreas Gohr            ['document_end', []],
68*504c13e8SAndreas Gohr        ];
69*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
70*504c13e8SAndreas Gohr    }
71*504c13e8SAndreas Gohr
72*504c13e8SAndreas Gohr    function testMonospace()
73*504c13e8SAndreas Gohr    {
74*504c13e8SAndreas Gohr        $this->P->addMode('monospace', new Monospace());
75*504c13e8SAndreas Gohr        $this->P->parse("Foo ''Bar'' Baz");
76*504c13e8SAndreas Gohr        $calls = [
77*504c13e8SAndreas Gohr            ['document_start', []],
78*504c13e8SAndreas Gohr            ['p_open', []],
79*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
80*504c13e8SAndreas Gohr            ['monospace_open', []],
81*504c13e8SAndreas Gohr            ['cdata', ['Bar']],
82*504c13e8SAndreas Gohr            ['monospace_close', []],
83*504c13e8SAndreas Gohr            ['cdata', [' Baz']],
84*504c13e8SAndreas Gohr            ['p_close', []],
85*504c13e8SAndreas Gohr            ['document_end', []],
86*504c13e8SAndreas Gohr        ];
87*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
88*504c13e8SAndreas Gohr    }
89*504c13e8SAndreas Gohr
90*504c13e8SAndreas Gohr    function testSubscript()
91*504c13e8SAndreas Gohr    {
92*504c13e8SAndreas Gohr        $this->P->addMode('subscript', new Subscript());
93*504c13e8SAndreas Gohr        $this->P->parse('Foo <sub>Bar</sub> Baz');
94*504c13e8SAndreas Gohr        $calls = [
95*504c13e8SAndreas Gohr            ['document_start', []],
96*504c13e8SAndreas Gohr            ['p_open', []],
97*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
98*504c13e8SAndreas Gohr            ['subscript_open', []],
99*504c13e8SAndreas Gohr            ['cdata', ['Bar']],
100*504c13e8SAndreas Gohr            ['subscript_close', []],
101*504c13e8SAndreas Gohr            ['cdata', [' Baz']],
102*504c13e8SAndreas Gohr            ['p_close', []],
103*504c13e8SAndreas Gohr            ['document_end', []],
104*504c13e8SAndreas Gohr        ];
105*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
106*504c13e8SAndreas Gohr    }
107*504c13e8SAndreas Gohr
108*504c13e8SAndreas Gohr    function testSuperscript()
109*504c13e8SAndreas Gohr    {
110*504c13e8SAndreas Gohr        $this->P->addMode('superscript', new Superscript());
111*504c13e8SAndreas Gohr        $this->P->parse('Foo <sup>Bar</sup> Baz');
112*504c13e8SAndreas Gohr        $calls = [
113*504c13e8SAndreas Gohr            ['document_start', []],
114*504c13e8SAndreas Gohr            ['p_open', []],
115*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
116*504c13e8SAndreas Gohr            ['superscript_open', []],
117*504c13e8SAndreas Gohr            ['cdata', ['Bar']],
118*504c13e8SAndreas Gohr            ['superscript_close', []],
119*504c13e8SAndreas Gohr            ['cdata', [' Baz']],
120*504c13e8SAndreas Gohr            ['p_close', []],
121*504c13e8SAndreas Gohr            ['document_end', []],
122*504c13e8SAndreas Gohr        ];
123*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
124*504c13e8SAndreas Gohr    }
125*504c13e8SAndreas Gohr
126*504c13e8SAndreas Gohr    function testDeleted()
127*504c13e8SAndreas Gohr    {
128*504c13e8SAndreas Gohr        $this->P->addMode('deleted', new Deleted());
129*504c13e8SAndreas Gohr        $this->P->parse('Foo <del>Bar</del> Baz');
130*504c13e8SAndreas Gohr        $calls = [
131*504c13e8SAndreas Gohr            ['document_start', []],
132*504c13e8SAndreas Gohr            ['p_open', []],
133*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
134*504c13e8SAndreas Gohr            ['deleted_open', []],
135*504c13e8SAndreas Gohr            ['cdata', ['Bar']],
136*504c13e8SAndreas Gohr            ['deleted_close', []],
137*504c13e8SAndreas Gohr            ['cdata', [' Baz']],
138*504c13e8SAndreas Gohr            ['p_close', []],
139*504c13e8SAndreas Gohr            ['document_end', []],
140*504c13e8SAndreas Gohr        ];
141*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
142*504c13e8SAndreas Gohr    }
143*504c13e8SAndreas Gohr
144*504c13e8SAndreas Gohr    function testNesting()
145*504c13e8SAndreas Gohr    {
146*504c13e8SAndreas Gohr        $this->P->addMode('strong', new Strong());
147*504c13e8SAndreas Gohr        $this->P->addMode('emphasis', new Emphasis());
148*504c13e8SAndreas Gohr        $this->P->parse('Foo **bold //and italic// text** Bar');
149*504c13e8SAndreas Gohr        $calls = [
150*504c13e8SAndreas Gohr            ['document_start', []],
151*504c13e8SAndreas Gohr            ['p_open', []],
152*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
153*504c13e8SAndreas Gohr            ['strong_open', []],
154*504c13e8SAndreas Gohr            ['cdata', ['bold ']],
155*504c13e8SAndreas Gohr            ['emphasis_open', []],
156*504c13e8SAndreas Gohr            ['cdata', ['and italic']],
157*504c13e8SAndreas Gohr            ['emphasis_close', []],
158*504c13e8SAndreas Gohr            ['cdata', [' text']],
159*504c13e8SAndreas Gohr            ['strong_close', []],
160*504c13e8SAndreas Gohr            ['cdata', [' Bar']],
161*504c13e8SAndreas Gohr            ['p_close', []],
162*504c13e8SAndreas Gohr            ['document_end', []],
163*504c13e8SAndreas Gohr        ];
164*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
165*504c13e8SAndreas Gohr    }
166*504c13e8SAndreas Gohr
167*504c13e8SAndreas Gohr    function testNoSelfNesting()
168*504c13e8SAndreas Gohr    {
169*504c13e8SAndreas Gohr        $this->P->addMode('strong', new Strong());
170*504c13e8SAndreas Gohr        $this->P->parse('Foo **bold **not nested** end** Bar');
171*504c13e8SAndreas Gohr        $calls = [
172*504c13e8SAndreas Gohr            ['document_start', []],
173*504c13e8SAndreas Gohr            ['p_open', []],
174*504c13e8SAndreas Gohr            ['cdata', ["\nFoo "]],
175*504c13e8SAndreas Gohr            ['strong_open', []],
176*504c13e8SAndreas Gohr            ['cdata', ['bold ']],
177*504c13e8SAndreas Gohr            ['strong_close', []],
178*504c13e8SAndreas Gohr            ['cdata', ['not nested']],
179*504c13e8SAndreas Gohr            ['strong_open', []],
180*504c13e8SAndreas Gohr            ['cdata', [' end']],
181*504c13e8SAndreas Gohr            ['strong_close', []],
182*504c13e8SAndreas Gohr            ['cdata', [' Bar']],
183*504c13e8SAndreas Gohr            ['p_close', []],
184*504c13e8SAndreas Gohr            ['document_end', []],
185*504c13e8SAndreas Gohr        ];
186*504c13e8SAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
187*504c13e8SAndreas Gohr    }
188*504c13e8SAndreas Gohr}
189