Completed
Push — master ( ed8db1...9bd532 )
by Mikael
26:12 queued 20:28
created

CTextFilterTest::testMarkdownAndBBCodeAsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
rs 9.6667
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Mos\TextFilter;
4
5
/**
6
 * A testclass
7
 *
8
 */
9
class CTextFilterTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * Test.
13
     *
14
     * @return void
15
     */
16 View Code Duplication
    public function testMarkdown()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18
        $filter = new CTextFilter();
19
20
        $html = "Header\n=========";
21
        $exp  = "<h1>Header</h1>\n";
22
        $res = $filter->doFilter($html, "markdown");
23
        $this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'");
24
    }
25
26
27
28
    /**
29
     * Test.
30
     *
31
     * @return void
32
     */
33 View Code Duplication
    public function testMarkdownAndBBCode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $filter = new CTextFilter();
36
37
        $html = "Header[b]text[/b]\n=========";
38
        $exp  = "<h1>Header<strong>text</strong></h1>\n";
39
        $res = $filter->doFilter($html, "markdown, bbcode");
40
        $this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'");
41
    }
42
43
44
45
    /**
46
     * Test.
47
     *
48
     * @return void
49
     */
50 View Code Duplication
    public function testMarkdownAndBBCodeAsArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $filter = new CTextFilter();
53
54
        $html = "Header[b]text[/b]\n=========";
55
        $exp  = "<h1>Header<strong>text</strong></h1>\n";
56
        $res = $filter->doFilter($html, ["markdown", "bbcode"]);
57
        $this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'");
58
    }
59
60
61
62
    /**
63
     * Test.
64
     *
65
     * @return void
66
     */
67 View Code Duplication
    public function testMarkdownArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $filter = new CTextFilter();
70
71
        $html = "Header\n=========";
72
        $exp  = "<h1>Header</h1>\n";
73
        $res = $filter->doFilter($html, ["markdown"]);
74
        $this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'");
75
    }
76
77
78
79
    /**
80
     * Test.
81
     *
82
     * @return void
83
     */
84 View Code Duplication
    public function testUppercase()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        $filter = new CTextFilter();
87
88
        $html = "Header\n=========";
89
        $exp  = "<h1>Header</h1>\n";
90
        $res = $filter->doFilter($html, "MARKDOWN");
91
        $this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'");
92
    }
93
94
95
96
    /**
97
     * Test.
98
     *
99
     * @return void
100
     */
101 View Code Duplication
    public function testBBCode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103
        $filter = new CTextFilter();
104
105
        $html = "[b]text[/b]";
106
        $exp  = "<strong>text</strong>";
107
        $res = $filter->doFilter($html, "bbcode");
108
        $this->assertEquals($exp, $res, "BBCode [b] failed: '$res'");
109
    }
110
111
112
113
    /**
114
     * Test.
115
     *
116
     * @return void
117
     */
118 View Code Duplication
    public function testClickable()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
    {
120
        $filter = new CTextFilter();
121
122
        $html = "http://example.com/humans.txt";
123
        $exp  = "<a href='$html'>$html</a>";
124
        $res = $filter->doFilter($html, "clickable");
125
        $this->assertEquals($exp, $res, "clickable failed: '$res'");
126
    }
127
128
129
130
    /**
131
     * Test.
132
     *
133
     * @return void
134
     */
135 View Code Duplication
    public function testNl2Br()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
136
    {
137
        $filter = new CTextFilter();
138
139
        $html = "hej\nhej";
140
        $exp  = "hej<br />\nhej";
141
        $res = $filter->doFilter($html, "nl2br");
142
        $this->assertEquals($exp, $res, "nl2br failed: '$res'");
143
    }
144
145
146
147
    /**
148
     * Test.
149
     *
150
     * @return void
151
     */
152
    public function testShortCodeFigure()
153
    {
154
        $filter = new CTextFilter();
155
156
        $src = "/img/me.png";
157
        $caption = "This is me.";
158
        
159
        $html = <<<EOD
160
[FIGURE src=$src caption="$caption"]
161
EOD;
162
163
        $exp  = <<<EOD
164
<figure class='figure'>
165
<a href='$src'><img src='$src' alt='$caption'/></a>
166
<figcaption markdown=1>$caption</figcaption>
167
</figure>
168
EOD;
169
        $res = $filter->doFilter($html, "shortcode");
170
        $this->assertEquals($exp, $res, "shortcode failed: '$res'");
171
    }
172
173
174
175
    /**
176
     * Test.
177
     *
178
     * @expectedException Exception
179
     *
180
     * @return void
181
     */
182
    public function testDoItException()
183
    {
184
        $filter = new CTextFilter();
185
        $res = $filter->doFilter("void", "no-such-filter");
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
186
    }
187
}
188