Completed
Pull Request — master (#188)
by Bene
03:46 queued 01:21
created

testNewAliasGroupListDeserializer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Tests\Wikibase\DataModel;
4
5
use DataValues\Deserializers\DataValueDeserializer;
6
use Deserializers\Deserializer;
7
use Wikibase\DataModel\DeserializerFactory;
8
use Wikibase\DataModel\Entity\BasicEntityIdParser;
9
10
/**
11
 * @licence GNU GPL v2+
12
 * @author Thomas Pellissier Tanon
13
 * @author Bene* < [email protected] >
14
 */
15
class DeserializerFactoryTest extends \PHPUnit_Framework_TestCase {
16
17
	private function buildDeserializerFactory() {
18
		return new DeserializerFactory( new DataValueDeserializer(), new BasicEntityIdParser() );
19
	}
20
21
	private function assertDeserializesWithoutException( Deserializer $deserializer, $serialization ) {
22
		$deserializer->deserialize( $serialization );
23
		$this->assertTrue( true, 'No exception occurred during deserialization' );
24
	}
25
26
	public function testNewEntityDeserializer() {
27
		$this->assertTrue( $this->buildDeserializerFactory()->newEntityDeserializer()->isDeserializerFor(
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Deser...newEntityDeserializer() has been deprecated with message: since 2.1, dispatching should happen when all entity types are known

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
28
			array(
29
				'type' => 'item'
30
			)
31
		) );
32
		$this->assertTrue( $this->buildDeserializerFactory()->newEntityDeserializer()->isDeserializerFor(
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Deser...newEntityDeserializer() has been deprecated with message: since 2.1, dispatching should happen when all entity types are known

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
33
			array(
34
				'type' => 'property'
35
			)
36
		) );
37
	}
38
39
	public function testNewItemDeserializer() {
40
		$this->assertDeserializesWithoutException(
41
			$this->buildDeserializerFactory()->newItemDeserializer(),
42
			array(
43
				'type' => 'item'
44
			)
45
		);
46
	}
47
48
	public function testNewPropertyDeserializer() {
49
		$this->assertDeserializesWithoutException(
50
			$this->buildDeserializerFactory()->newPropertyDeserializer(),
51
			array(
52
				'type' => 'property',
53
				'datatype' => 'string'
54
			)
55
		);
56
	}
57
58
	public function testNewSiteLinkDeserializer() {
59
		$this->assertDeserializesWithoutException(
60
			$this->buildDeserializerFactory()->newSiteLinkDeserializer(),
61
			array(
62
				'site' => 'enwiki',
63
				'title' => 'Nyan Cat'
64
			)
65
		);
66
	}
67
68
	public function testNewStatementDeserializer() {
69
		$this->assertTrue( $this->buildDeserializerFactory()->newStatementDeserializer()->isDeserializerFor(
70
			array(
71
				'mainsnak' => array(
72
					'snaktype' => 'novalue',
73
					'property' => 'P42'
74
				),
75
				'type' => 'claim'
76
			)
77
		) );
78
	}
79
80
	public function testStatementListDeserializer() {
81
		$this->assertDeserializesWithoutException(
82
			$this->buildDeserializerFactory()->newStatementListDeserializer(),
83
			array(
84
				'P42' => array(
85
				)
86
			)
87
		);
88
	}
89
90
	public function testNewReferencesDeserializer() {
91
		$this->assertDeserializesWithoutException(
92
			$this->buildDeserializerFactory()->newReferencesDeserializer(),
93
			array(
94
				array(
95
					'hash' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
96
					'snaks' => array()
97
				)
98
			)
99
		);
100
	}
101
102
	public function testNewReferenceDeserializer() {
103
		$this->assertDeserializesWithoutException(
104
			$this->buildDeserializerFactory()->newReferenceDeserializer(),
105
			array(
106
				'hash' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
107
				'snaks' => array()
108
			)
109
		);
110
	}
111
112
	public function testNewSnakDeserializer() {
113
		$this->assertDeserializesWithoutException(
114
			$this->buildDeserializerFactory()->newSnakDeserializer(),
115
			array(
116
				'snaktype' => 'novalue',
117
				'property' => 'P42'
118
			)
119
		);
120
	}
121
122
	public function testNewEntityIdDeserializer() {
123
		$this->assertDeserializesWithoutException(
124
			$this->buildDeserializerFactory()->newEntityIdDeserializer(),
125
			'Q42'
126
		);
127
	}
128
129
	public function testNewTermDeserializer() {
130
		$this->assertDeserializesWithoutException(
131
			$this->buildDeserializerFactory()->newTermDeserializer(),
132
			array( 'language' => 'en', 'value' => 'Some Term' )
133
		);
134
	}
135
136
	public function testNewTermListDeserializer() {
137
		$this->assertDeserializesWithoutException(
138
			$this->buildDeserializerFactory()->newTermListDeserializer(),
139
			array(
140
				'en' => array( 'language' => 'en', 'value' => 'Some Term' ),
141
				'de' => array( 'language' => 'de', 'value' => 'Some Term' ),
142
			)
143
		);
144
	}
145
146
	public function testNewAliasGroupListDeserializer() {
147
		$this->assertDeserializesWithoutException(
148
			$this->buildDeserializerFactory()->newAliasGroupListDeserializer(),
149
			array( 'en' => array( array( 'language' => 'en', 'value' => 'Some Term' ) ) )
150
		);
151
	}
152
153
}
154