1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
<?php
namespace SMW\Tests\PropertyAnnotators;
use SMW\MediaWiki\RedirectTargetFinder;
use SMW\PropertyAnnotators\NullPropertyAnnotator;
use SMW\PropertyAnnotators\RedirectPropertyAnnotator;
use SMW\Tests\Utils\UtilityFactory;
/**
* @covers \SMW\PropertyAnnotators\RedirectPropertyAnnotator
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 1.9
*
* @author mwjames
*/
class RedirectPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
private $semanticDataFactory;
private $semanticDataValidator;
protected function setUp() {
parent::setUp();
$this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();
$this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator();
}
public function testCanConstruct() {
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
->disableOriginalConstructor()
->getMock();
$redirectTargetFinder = $this->getMockBuilder( '\SMW\MediaWiki\RedirectTargetFinder' )
->disableOriginalConstructor()
->getMock();
$instance = new RedirectPropertyAnnotator(
new NullPropertyAnnotator( $semanticData ),
$redirectTargetFinder
);
$this->assertInstanceOf(
'\SMW\PropertyAnnotators\RedirectPropertyAnnotator',
$instance
);
}
/**
* @dataProvider redirectsDataProvider
*/
public function testAddAnnotation( array $parameter, array $expected ) {
$semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ );
$redirectTargetFinder = new RedirectTargetFinder();
$instance = new RedirectPropertyAnnotator(
new NullPropertyAnnotator( $semanticData ),
$redirectTargetFinder->findRedirectTargetFromText( $parameter['text'] )
);
$instance->addAnnotation();
$this->semanticDataValidator->assertThatPropertiesAreSet(
$expected,
$instance->getSemanticData()
);
}
public function redirectsDataProvider() {
// #0 Free text
$provider[] = [
[ 'text' => '#REDIRECT [[:Lala]]' ],
[
'propertyCount' => 1,
'propertyKeys' => '_REDI',
'propertyValues' => ':Lala'
]
];
// #1 Free text
$provider[] = [
[ 'text' => '#REDIRECT [[Lala]]' ],
[
'propertyCount' => 1,
'propertyKeys' => '_REDI',
'propertyValues' => ':Lala'
]
];
// #2 Invalid free text
$provider[] = [
[ 'text' => '#REDIR [[:Lala]]' ],
[
'propertyCount' => 0,
]
];
// #3 Empty
$provider[] = [
[ 'text' => '' ],
[
'propertyCount' => 0,
]
];
return $provider;
}
}
|