testAddBaseurlToRelativeLinks()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Mos\TextFilter;
4
5
/**
6
 * A testclass
7
 *
8
 */
9
class CTextFilterUtilitiesTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * Provider for TextWithLinks
13
     *
14
     * @return array
15
     */
16
    public function providerTextWithLinks()
17
    {
18
        $baseurl = "doc";
19
20
        return [
21
            [
22
                $baseurl,
23
                "<a href=\"\">text</a>",
24
                "<a href=\"$baseurl\">text</a>",
25
            ],
26
            [
27
                $baseurl,
28
                "<a href=\"something\">text</a>",
29
                "<a href=\"$baseurl/something\">text</a>",
30
            ],
31
        ];
32
    }
33
34
35
36
     /**
37
      * Test.
38
      *
39
      * @dataProvider providerTextWithLinks
40
      *
41
      * @return void
42
      */
43
    public function testAddBaseurlToRelativeLinks($baseurl, $text, $exp)
44
    {
45
        $filter = new CTextFilter();
46
47
        $callback = function ($url, $baseurl) {
48
            return rtrim("$baseurl/$url", "/");
49
        };
50
51
        $res = $filter->addBaseurlToRelativeLinks($text, $baseurl, $callback);
52
        $this->assertEquals($exp, $res, "Relative links mssmatch");
53
    }
54
}
55