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 [[Bar::tincidunt semper|abc]] facilisi' |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$provider[] = array( |
73
|
|
|
'Suspendisse [[Bar::tincidunt semper]] facilisi', |
74
|
|
|
'Suspendisse tincidunt semper facilisi', |
75
|
|
|
'Suspendisse [[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
|
|
|
'[[Foo::Foobar::テスト]] [[Bar:::ABC|DEF]] [[Foo:::0049 30 12345678/::Foo]]' |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$provider[] = array( |
91
|
|
|
'%5B%5BFoo%20Bar::foobaz%5D%5D', |
92
|
|
|
'foobaz', |
93
|
|
|
'[[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
|
|
|
'[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]' |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$provider[] = array( |
110
|
|
|
'[[Foo::@@@]] [[Bar::@@@|123]]', |
111
|
|
|
' 123', |
112
|
|
|
'[[Foo::@@@]] [[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 [[SMW::off]][[Bar::tincidunt semper|abc]] facilisi[[SMW::on]] [[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
|
|
|
'[[Foo]]' |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
$provider[] = array( |
139
|
|
|
'[[Foo|Bar]]', |
140
|
|
|
'[[Foo|Bar]]' |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$provider[] = array( |
144
|
|
|
'[[Foo::[[Bar]]]]', |
145
|
|
|
'[[Foo::[[Bar]]]]' |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
return $provider; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|