testNotWrapHaystackOnFailureByDefault()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the Axstrad library.
4
 *
5
 * (c) Dan Kempster <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @copyright 2014-2015 Dan Kempster <[email protected]>
11
 */
12
namespace Axstrad\Common\Tests\Util\StrUtil;
13
14
use Axstrad\Common\Util\StrUtil;
15
16
17
/**
18
 * Axstrad\Common\Tests\Util\StrUtil\WrapSubstrTest
19
 *
20
 * covers Axstrad\Common\Util\StrUtil::wrapSubstr
21
 * @group unittests
22
 */
23
class WrapSubstrTest extends \PHPUnit_Framework_TestCase
24
{
25
    public function testCanWrapStartOfString()
26
    {
27
        $this->assertEquals(
28
            "<span>Hello</span> World",
29
            StrUtil::wrapSubstr(
30
                "Hello World",
31
                "Hello",
32
                "span"
33
            )
34
        );
35
    }
36
37
    public function testCanWrapEndOfString()
38
    {
39
        $this->assertEquals(
40
            "Hello <span>World</span>",
41
            StrUtil::wrapSubstr(
42
                "Hello World",
43
                "World",
44
                "span"
45
            )
46
        );
47
    }
48
49
    public function testCanWrapMiddleOfString()
50
    {
51
        $this->assertEquals(
52
            "Hello <span>There</span> World",
53
            StrUtil::wrapSubstr(
54
                "Hello There World",
55
                "There",
56
                "span"
57
            )
58
        );
59
    }
60
61
    /**
62
     * @depends testCanWrapStartOfString
63
     */
64
    public function testIsCaseInsensitive()
65
    {
66
        $this->assertEquals(
67
            "<span>HELLO</span> WORLD",
68
            StrUtil::wrapSubstr(
69
                "HELLO WORLD",
70
                "hello",
71
                "span"
72
            )
73
        );
74
    }
75
76
    public function testWrapsUsingSpansAsDefault()
77
    {
78
        $this->assertEquals(
79
            "<span>this</span> should be rapped a span",
80
            StrUtil::wrapSubstr(
81
                "this should be rapped a span",
82
                "this"
83
            )
84
        );
85
    }
86
87
    /**
88
     * @depends testWrapsUsingSpansAsDefault
89
     */
90
    public function testFallsbackToSpanElements()
91
    {
92
        $this->assertEquals(
93
            "<span>this</span> should be rapped in a span",
94
            StrUtil::wrapSubstr(
95
                "this should be rapped in a span",
96
                "this",
97
                null
98
            )
99
        );
100
    }
101
102
    public function testNotWrapHaystackOnFailure()
103
    {
104
        $this->assertEquals(
105
            'nothing should be wrapped',
106
            StrUtil::wrapSubstr(
107
                'nothing should be wrapped',
108
                'needle',
109
                'span',
110
                false
111
            )
112
        );
113
    }
114
115
    /**
116
     * @depends testNotWrapHaystackOnFailure
117
     */
118
    public function testNotWrapHaystackOnFailureByDefault()
119
    {
120
        $this->assertEquals(
121
            'nothing should be wrapped',
122
            StrUtil::wrapSubstr(
123
                'nothing should be wrapped',
124
                'needle',
125
                'span'
126
            )
127
        );
128
    }
129
130
    public function testWrapHaystackOnFailure()
131
    {
132
        $this->assertEquals(
133
            '<span>everything should be wrapped</span>',
134
            StrUtil::wrapSubstr(
135
                'everything should be wrapped',
136
                'needle',
137
                'span',
138
                true
139
            )
140
        );
141
    }
142
143
    public function testRemovesTrailingS()
144
    {
145
        $this->assertEquals(
146
            'hello <span>world</span>',
147
            StrUtil::wrapSubstr(
148
                'hello world',
149
                'worlds',
150
                'span'
151
            )
152
        );
153
    }
154
}
155