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
|
<?php
namespace SMW\Tests\Query\PrintRequest;
use SMW\DataValueFactory;
use SMW\DIWikiPage;
use SMW\Localizer;
use SMW\Query\PrintRequest;
use SMW\Query\PrintRequest\Serializer;
/**
* @covers SMW\Query\PrintRequest\Serializer
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 2.5
*
* @author mwjames
*/
class SerializerTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider textProvider
*/
public function testSerialize( $printRequest, $showParams, $expected ) {
$this->assertSame(
$expected,
Serializer::serialize( $printRequest, $showParams )
);
}
public function textProvider() {
$category = Localizer::getInstance()->getNamespaceTextById( NS_CATEGORY );
$provider['print-cats'] = [
new PrintRequest( PrintRequest::PRINT_CATS, 'Foo' ),
false,
"?{$category}=Foo"
];
$provider['print-ccat'] = [
new PrintRequest( PrintRequest::PRINT_CCAT, 'Foo', DIWikiPage::newFromText( 'Bar' )->getTitle() ),
false,
'?Bar=Foo'
];
$provider['print-this'] = [
new PrintRequest( PrintRequest::PRINT_THIS, 'Foo' ),
false,
'?=Foo'
];
$provider['print-this-plain'] = [
new PrintRequest( PrintRequest::PRINT_THIS, 'Foo', null, '-' ),
false,
'?=Foo#-'
];
$data = DataValueFactory::getInstance()->newPropertyValueByLabel( 'Bar' );
$provider['print-prop'] = [
new PrintRequest( PrintRequest::PRINT_PROP, 'Foo', $data ),
false,
'?Bar#=Foo'
];
$data = DataValueFactory::getInstance()->newPropertyValueByLabel( 'Bar' );
$provider['print-prop-output'] = [
new PrintRequest( PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar' ),
false,
'?Bar#foobar=Foo'
];
$data = DataValueFactory::getInstance()->newPropertyValueByLabel( 'Bar' );
$provider['print-prop-output-parameters-no-show'] = [
new PrintRequest( PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar', [ 'index' => 2 ] ),
false,
'?Bar#foobar=Foo'
];
$data = DataValueFactory::getInstance()->newPropertyValueByLabel( 'Bar' );
$provider['print-prop-output-parameters-show'] = [
new PrintRequest( PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar', [ 'index' => 2 ] ),
true,
'?Bar#foobar=Foo|+index=2'
];
$data = DataValueFactory::getInstance()->newPropertyValueByLabel( 'Modification date' );
$provider['predefined-property'] = [
new PrintRequest( PrintRequest::PRINT_PROP, '', $data ),
false,
'?Modification date#'
];
$data = DataValueFactory::getInstance()->newPropertyValueByLabel( 'Bar' );
$provider['print-prop-output-lang-index'] = [
new PrintRequest( PrintRequest::PRINT_PROP, 'Foo', $data, '', [ 'lang' => 'en', 'index' => '1' ] ),
true,
'?Bar=Foo|+lang=en'
];
return $provider;
}
}
|