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
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php
namespace SMW\Tests\Integration\MediaWiki;
use SMW\Tests\Util\SemanticDataValidator;
use SMW\Tests\Util\ParserFactory;
use SMW\ContentParser;
use SMW\ParserData;
use Title;
use Parser;
/**
* @ingroup Test
*
* @group SMW
* @group SMWExtension
* @group semantic-mediawiki-integration
* @group mediawiki-databaseless
* @group medium
*
* @license GNU GPL v2+
* @since 1.9.1.1
*
* @author mwjames
*/
class InTextParseParserOutputIntegrationTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider textDataProvider
*/
public function testTextParse( $parameters, $expected ) {
$instance = new ContentParser(
$parameters['title'],
ParserFactory::newFromTitle( $parameters['title'] )
);
$instance->parse( $parameters['text'] );
$this->assertInstanceAfterParse( $instance );
$this->assertSemanticDataAfterParse(
$instance,
$expected
);
}
protected function assertInstanceAfterParse( $instance ) {
$this->assertInstanceOf( 'ParserOutput', $instance->getOutput() );
$this->assertInternalType( 'string', $instance->getOutput()->getText() );
}
protected function assertSemanticDataAfterParse( $instance, $expected ) {
$parserData = new ParserData( $instance->getTitle(), $instance->getOutput() );
$semanticDataValidator = new SemanticDataValidator;
$semanticDataValidator->assertThatPropertiesAreSet(
$expected,
$parserData->getSemanticData()
);
}
/**
* @return array
*/
public function textDataProvider() {
$title = Title::newFromText( __METHOD__ );
$provider = array();
// #0 Empty
$provider[] = array(
array(
'text' => '',
'title' => $title
),
array(
'propertyCount' => 0
)
);
// #1 With a single category
$provider[] = array(
array(
'text' => '[[Category:Foo]]',
'title' => $title
),
array(
'propertyCount' => 2,
'propertyKey' => array( '_INST', '_SKEY' ),
'propertyValues' => array( 'Foo', $title->getText() )
)
);
// #2 With a sortkey
$provider[] = array(
array(
'text' => '{{DEFAULTSORTKEY:Bar}}',
'title' => $title
),
array(
'propertyCount' => 1,
'propertyKey' => '_SKEY',
'propertyValues' => array( 'Bar' )
)
);
// #3 Combined
$provider[] = array(
array(
'text' => '[[Fuyu::Natsu]], [[Category:Foo]], {{DEFAULTSORTKEY:Bar}}',
'title' => $title
),
array(
'propertyCount' => 3,
'propertyKey' => array( '_SKEY', '_INST', 'Fuyu' ),
'propertyValues' => array( 'Bar', 'Foo', 'Natsu' )
)
);
return $provider;
}
}
|