Completed
Push — master ( 7b9b22...6b6f7b )
by mw
149:46 queued 114:56
created

ObfuscatorTest::stripTextWithAnnotationProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 61
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 39
nc 1
nop 0
dl 0
loc 61
rs 9.5147
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SMW\Tests\Parser;
4
5
use SMW\Parser\Obfuscator;
6
7
/**
8
 * @covers \SMW\Parser\Obfuscator
9
 * @group semantic-mediawiki
10
 *
11
 * @license GNU GPL v2+
12
 * @since 2.5
13
 *
14
 * @author mwjames
15
 */
16
class ObfuscatorTest extends \PHPUnit_Framework_TestCase {
17
18
	/**
19
	 * @dataProvider obfuscateProvider
20
	 */
21
	public function testRoundTripLinkObfuscation( $text ) {
22
23
		$newText = Obfuscator::encodeLinks( $text );
24
25
		$this->assertEquals(
26
			$text,
27
			Obfuscator::removeLinkObfuscation( $newText )
28
		);
29
	}
30
31
	/**
32
	 * @dataProvider obfuscateProvider
33
	 */
34
	public function testObfuscateLinks( $text, $expected ) {
35
36
		$inTextAnnotationParser = $this->getMockBuilder( 'SMW\InTextAnnotationParser' )
37
			->disableOriginalConstructor()
38
			->getMock();
39
40
		$this->assertEquals(
41
			$expected,
42
			Obfuscator::obfuscateLinks( $text, $inTextAnnotationParser )
43
		);
44
	}
45
46
	/**
47
	 * @dataProvider stripTextWithAnnotationProvider
48
	 */
49
	public function testStrip( $text, $expectedRemoval, $expectedObscuration ) {
50
51
		$this->assertEquals(
52
			$expectedRemoval,
53
			Obfuscator::removeAnnotation( $text )
54
		);
55
56
		$this->assertEquals(
57
			$expectedObscuration,
58
			Obfuscator::obfuscateAnnotation( $text )
59
		);
60
	}
61
62
	public function stripTextWithAnnotationProvider() {
63
64
		$provider = array();
65
66
		$provider[] = array(
67
			'Suspendisse [[Bar::tincidunt semper|abc]] facilisi',
68
			'Suspendisse abc facilisi',
69
			'Suspendisse &#x005B;&#x005B;Bar::tincidunt semper|abc]] facilisi'
70
		);
71
72
		$provider[] = array(
73
			'Suspendisse [[Bar::tincidunt semper]] facilisi',
74
			'Suspendisse tincidunt semper facilisi',
75
			'Suspendisse &#x005B;&#x005B;Bar::tincidunt semper]] facilisi'
76
		);
77
78
		$provider[] = array(
79
			'Suspendisse [[:Tincidunt semper|tincidunt semper]]',
80
			'Suspendisse [[:Tincidunt semper|tincidunt semper]]',
81
			'Suspendisse [[:Tincidunt semper|tincidunt semper]]'
82
		);
83
84
		$provider[] = array(
85
			'[[Foo::Foobar::テスト]] [[Bar:::ABC|DEF]] [[Foo:::0049 30 12345678/::Foo]]',
86
			'Foobar::テスト DEF :0049 30 12345678/::Foo',
87
			'&#x005B;&#x005B;Foo::Foobar::テスト]] &#x005B;&#x005B;Bar:::ABC|DEF]] &#x005B;&#x005B;Foo:::0049 30 12345678/::Foo]]'
88
		);
89
90
		$provider[] = array(
91
			'%5B%5BFoo%20Bar::foobaz%5D%5D',
92
			'foobaz',
93
			'&#x005B;&#x005B;Foo%20Bar::foobaz]]'
94
		);
95
96
		$provider[] = array(
97
			'Suspendisse tincidunt semper facilisi',
98
			'Suspendisse tincidunt semper facilisi',
99
			'Suspendisse tincidunt semper facilisi'
100
		);
101
102
		// #1747
103
		$provider[] = array(
104
			'[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]',
105
			'[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]',
106
			'&#x005B;&#x005B;Foo|Bar::Foobar]] &#x005B;&#x005B;File:Example.png|alt=Bar::Foobar|Caption]] &#x005B;&#x005B;File:Example.png|Bar::Foobar|link=Foo]]'
107
		);
108
109
		$provider[] = array(
110
			'[[Foo::@@@]] [[Bar::@@@|123]]',
111
			' 123',
112
			'&#x005B;&#x005B;Foo::@@@]] &#x005B;&#x005B;Bar::@@@|123]]'
113
		);
114
115
		$provider[] = array(
116
			'Suspendisse [[SMW::off]][[Bar::tincidunt semper|abc]] facilisi[[SMW::on]] [[Bar:::ABC|DEF]]',
117
			'Suspendisse abc facilisi DEF',
118
			'Suspendisse &#x005B;&#x005B;SMW::off]]&#x005B;&#x005B;Bar::tincidunt semper|abc]] facilisi&#x005B;&#x005B;SMW::on]] &#x005B;&#x005B;Bar:::ABC|DEF]]'
119
		);
120
121
		return $provider;
122
	}
123
124
	public function obfuscateProvider() {
125
126
		$provider = array();
127
128
		$provider[] = array(
129
			'Foo',
130
			'Foo'
131
		);
132
133
		$provider[] = array(
134
			'[[Foo]]',
135
			'&#91;&#91;Foo&#93;&#93;'
136
		);
137
138
		$provider[] = array(
139
			'[[Foo|Bar]]',
140
			'&#91;&#91;Foo&#124;Bar&#93;&#93;'
141
		);
142
143
		$provider[] = array(
144
			'[[Foo::[[Bar]]]]',
145
			'[[Foo::&#91;&#91;Bar&#93;&#93;]]'
146
		);
147
148
		return $provider;
149
	}
150
151
}
152