summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/export/ExpDataTest.php
blob: 421207077afa361b1fa8e6b89989b9c8630f1f40 (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php

namespace SMW\Tests\Exporter;

use SMW\Exporter\Element\ExpLiteral;
use SMW\Exporter\Element\ExpNsResource;
use SMWExpData as ExpData;

/**
 * @covers \SMWExpData
 *
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 2.2
 *
 * @author mwjames
 */
class ExpDataTest extends \PHPUnit_Framework_TestCase {

	public function testCanConstructor() {

		$expNsResource = $this->getMockBuilder( '\SMW\Exporter\Element\ExpNsResource' )
			->disableOriginalConstructor()
			->getMock();

		$this->assertInstanceOf(
			'\SMWExpData',
			new ExpData( $expNsResource )
		);
	}

	/**
	 * @dataProvider expDataHashProvider
	 */
	public function testGetHash( $expData, $expected ) {

		$this->assertEquals(
			$expected,
			$expData->getHash()
		);
	}

	public function expDataHashProvider() {

		#0
		$expData = new ExpData(
			new ExpNsResource( 'Foo', 'Bar', 'Mo', null )
		);

		$provider[] = [
			$expData,
			'4dc04c87e9660854a5609ff132175fd5'
		];

		#1
		$expData = new ExpData(
			new ExpNsResource( 'Foo', 'Bar', 'Mo', null )
		);

		$expData->addPropertyObjectValue(
			new ExpNsResource( 'Li', 'La', 'Lu', null ),
			new ExpLiteral( 'Foo', 'Bar' )
		);

		$provider[] = [
			$expData,
			'5702e5e8c6145aaf8d89840a4a3b18c2'
		];

		#2
		$expData = new ExpData(
			new ExpNsResource( 'Foo', 'Bar', 'Mo', null )
		);

		$expData->addPropertyObjectValue(
			new ExpNsResource( 'Li', 'La', 'Lu', null ),
			new ExpLiteral( 'Foo', 'Bar' )
		);

		$expData->addPropertyObjectValue(
			new ExpNsResource( 'Li', 'La', 'Lu', null ),
			new ExpLiteral( 'Bar', 'Foo' )
		);

		$provider[] = [
			$expData,
			'13edcedd007979f5638fbc958f0cdaf8'
		];

		#3 Same as 2 but different sorting/same hash
		$expData = new ExpData(
			new ExpNsResource( 'Foo', 'Bar', 'Mo', null )
		);

		$expData->addPropertyObjectValue(
			new ExpNsResource( 'Li', 'La', 'Lu', null ),
			new ExpLiteral( 'Bar', 'Foo' )
		);

		$expData->addPropertyObjectValue(
			new ExpNsResource( 'Li', 'La', 'Lu', null ),
			new ExpLiteral( 'Foo', 'Bar' )
		);

		$provider[] = [
			$expData,
			'13edcedd007979f5638fbc958f0cdaf8'
		];

		#4 Nesting
		$expDataLevel2 = new ExpData(
			new ExpNsResource( 'Foo', 'Bar', 'Mo', null )
		);

		$expDataLevel2->addPropertyObjectValue(
			new ExpNsResource( 'Li', 'La', 'Lu', null ),
			new ExpLiteral( 'Foo', 'Bar' )
		);

		$expData = new ExpData(
			new ExpNsResource( 'Foo', 'Bar', 'Mo', null )
		);

		$expData->addPropertyObjectValue(
			new ExpNsResource( 'Li', 'La', 'Lu', null ),
			new ExpLiteral( 'Foo', 'Bar' )
		);

		$expData->addPropertyObjectValue(
			new ExpNsResource( 'Li', 'La', 'Lu', null ),
			$expDataLevel2
		);

		$provider[] = [
			$expData,
			'e684e7640a201d2d33e035aaa866c1ac'
		];

		return $provider;
	}

}