1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?php
/*
* studip_format_test.php - unit tests for the StudipCoreFormat class
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author Elmar Ludwig
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
function markupBold($markup, $matches, $contents)
{
return '<b>' . $contents . '</b>';
}
class StudipFormatTest extends \Codeception\Test\Unit
{
function setUp(): void {
$this->old_rules = StudipCoreFormat::getStudipMarkups();
}
function tearDown(): void
{
foreach(StudipCoreFormat::getStudipMarkups() as $key => $value) {
StudipCoreFormat::removeStudipMarkup($key);
}
foreach($this->old_rules as $key => $value) {
StudipCoreFormat::addStudipMarkup($key, @$value['start'], @$value['end'], @$value['callback']);
}
}
public function testAddStudipMarkup()
{
StudipCoreFormat::addStudipMarkup('bb-bold', '\[b\]', '\[\/b\]', 'markupBold', 'links');
$markup = new StudipCoreFormat();
$input = '[b]some %%code%%[/b]';
$expected = '<b>some <em>code</em></b>';
$this->assertEquals($expected, $markup->format($input));
}
public function testRemoveStudipMarkup()
{
StudipCoreFormat::removeStudipMarkup('bold');
$markup = new StudipCoreFormat();
$input = '**some %%code%%**';
$expected = '**some <em>code</em>**';
$this->assertEquals($expected, $markup->format($input));
}
public function testTextSizing()
{
$markup = new StudipCoreFormat();
$input = '++++abc++++ **++123++**';
$expected = '<big><big>abc</big></big> <strong><big>123</big></strong>';
$this->assertEquals($expected, $markup->format($input));
}
public function testHtmlEnclosedMarkup()
{
$markup = new StudipCoreFormat();
$index = 0;
forEach ([
'<p>' . PHP_EOL
. '- single item' . PHP_EOL
. '</p>'
=>
'<p>' . PHP_EOL
. '<ul><li>single item</li></ul>'
. '</p>',
'<p>' . PHP_EOL
. '- a' . PHP_EOL
. '- list' . PHP_EOL
. '</p>'
=> '<p>' . PHP_EOL
. '<ul>'
. '<li>a</li>'
. '<li>list</li>'
. '</ul>'
. '</p>'
] as $in => $out) {
++$index;
$this->assertEquals($out, $markup->format($in), 'test number ' . $index);
}
}
public function testTable()
{
$markup = new StudipCoreFormat();
$index = 0;
forEach ([
'|a|table' . PHP_EOL
=>
'<table class="content">'
. '<tr><td>a</td><td>table</td></tr>'
. '</table>',
'| this | is a | table |' . PHP_EOL
. '| with | two | rows |'
=>
'<table class="content">'
. '<tr><td>this</td><td>is a</td><td>table</td></tr>'
. '<tr><td>with</td><td>two</td><td>rows</td></tr>'
. '</table>'
] as $in => $out) {
++$index;
$this->assertEquals($out, $markup->format($in), 'test number ' . $index);
}
}
}
|