Completed
Push — master ( 3d831c...fcc0b1 )
by Jeroen De
07:01 queued 02:46
created

invalidConstructorArgumentsProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 31
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
namespace DataValues\Tests;
4
5
use DataValues\MonolingualTextValue;
6
use DataValues\MultilingualTextValue;
7
8
/**
9
 * @covers DataValues\MultilingualTextValue
10
 *
11
 * @since 0.1
12
 *
13
 * @group DataValue
14
 * @group DataValueExtensions
15
 *
16
 * @license GPL-2.0+
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
class MultilingualTextValueTest extends DataValueTest {
20
21
	/**
22
	 * @see DataValueTest::getClass
23
	 *
24
	 * @return string
25
	 */
26
	public function getClass() {
27
		return 'DataValues\MultilingualTextValue';
28
	}
29
30
	public function validConstructorArgumentsProvider() {
31
		return [
32
			[ [] ],
33
			[ [
34
				new MonolingualTextValue( 'en', 'foo' ),
35
			] ],
36
			[ [
37
				new MonolingualTextValue( 'en', 'foo' ),
38
				new MonolingualTextValue( 'de', 'foo' ),
39
			] ],
40
			[ [
41
				new MonolingualTextValue( 'en', 'foo' ),
42
				new MonolingualTextValue( 'de', 'bar' ),
43
			] ],
44
			[ [
45
				new MonolingualTextValue( 'en', 'foo' ),
46
				new MonolingualTextValue( 'de', ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ),
47
			] ],
48
		];
49
	}
50
51
	public function invalidConstructorArgumentsProvider() {
52
		return [
53
			[ [ 42 ] ],
54
			[ [ false ] ],
55
			[ [ true ] ],
56
			[ [ null ] ],
57
			[ [ [] ] ],
58
			[ [ 'foo' ] ],
59
60
			[ [ 42 => 'foo' ] ],
61
			[ [ '' => 'foo' ] ],
62
			[ [ 'en' => 42 ] ],
63
			[ [ 'en' => null ] ],
64
			[ [ 'en' => true ] ],
65
			[ [ 'en' => [] ] ],
66
			[ [ 'en' => 4.2 ] ],
67
68
			[ [
69
				new MonolingualTextValue( 'en', 'foo' ),
70
				false,
71
			] ],
72
			[ [
73
				new MonolingualTextValue( 'en', 'foo' ),
74
				'foobar',
75
			] ],
76
			[ [
77
				new MonolingualTextValue( 'en', 'foo' ),
78
				new MonolingualTextValue( 'en', 'bar' ),
79
			] ],
80
		];
81
	}
82
83
	public function testNewFromArray() {
84
		$array = [ [ 'text' => 'foo', 'language' => 'en' ] ];
85
		$value = MultilingualTextValue::newFromArray( $array );
0 ignored issues
show
Deprecated Code introduced by
The method DataValues\MultilingualTextValue::newFromArray() has been deprecated with message: since 0.3.2. Static DataValue::newFromArray constructors like this are underspecified (not in the DataValue interface), and misleadingly named (should be named newFromArrayValue). Instead, use DataValue builder callbacks in @see DataValueDeserializer.

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...
86
		$this->assertSame( $array, $value->getArrayValue() );
87
	}
88
89
	/**
90
	 * @dataProvider invalidArrayProvider
91
	 */
92
	public function testNewFromArrayWithInvalidArray( array $array ) {
93
		$this->setExpectedException( 'DataValues\IllegalValueException' );
94
		MultilingualTextValue::newFromArray( $array );
0 ignored issues
show
Deprecated Code introduced by
The method DataValues\MultilingualTextValue::newFromArray() has been deprecated with message: since 0.3.2. Static DataValue::newFromArray constructors like this are underspecified (not in the DataValue interface), and misleadingly named (should be named newFromArrayValue). Instead, use DataValue builder callbacks in @see DataValueDeserializer.

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...
95
	}
96
97
	public function invalidArrayProvider() {
98
		return [
99
			[ [ null ] ],
100
			[ [ '' ] ],
101
			[ [ [] ] ],
102
			[ [ [ 'en', 'foo' ] ] ],
103
		];
104
	}
105
106
	/**
107
	 * @dataProvider getSortKeyProvider
108
	 */
109
	public function testGetSortKey( array $monolingualValues, $expected ) {
110
		$value = new MultilingualTextValue( $monolingualValues );
111
		$this->assertSame( $expected, $value->getSortKey() );
112
	}
113
114
	public function getSortKeyProvider() {
115
		return [
116
			[ [], '' ],
117
			[ [
118
				new MonolingualTextValue( 'en', 'foo' ),
119
			], 'enfoo' ],
120
			[ [
121
				new MonolingualTextValue( 'en', 'foo' ),
122
				new MonolingualTextValue( 'de', 'bar' ),
123
			], 'enfoo' ],
124
		];
125
	}
126
127
	/**
128
	 * @dataProvider instanceProvider
129
	 */
130
	public function testGetTexts( MultilingualTextValue $texts, array $arguments ) {
131
		$actual = $texts->getTexts();
132
133
		$this->assertInternalType( 'array', $actual );
134
		$this->assertContainsOnlyInstancesOf( '\DataValues\MonolingualTextValue', $actual );
135
		$this->assertEquals( $arguments[0], array_values( $actual ) );
136
	}
137
138
	/**
139
	 * @dataProvider instanceProvider
140
	 */
141
	public function testGetValue( MultilingualTextValue $texts, array $arguments ) {
0 ignored issues
show
Unused Code introduced by
The parameter $arguments is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
142
		$this->assertInstanceOf( $this->getClass(), $texts->getValue() );
143
	}
144
145
}
146