Passed
Push — trimNormalizer ( b2284d...0e0038 )
by no
05:06
created

MonolingualTextValueTest::testNewFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace DataValues\Tests;
4
5
use DataValues\IllegalValueException;
6
use DataValues\MonolingualTextValue;
7
8
/**
9
 * @covers DataValues\MonolingualTextValue
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 MonolingualTextValueTest extends DataValueTest {
20
21
	/**
22
	 * @see DataValueTest::getClass
23
	 *
24
	 * @return string
25
	 */
26
	public function getClass() {
27
		return MonolingualTextValue::class;
28
	}
29
30
	public function validConstructorArgumentsProvider() {
31
		return [
32
			[ 'en', 'foo' ],
33
			[ 'en', ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ],
34
		];
35
	}
36
37
	public function invalidConstructorArgumentsProvider() {
38
		return [
39
			[ 42, null ],
40
			[ [], null ],
41
			[ false, null ],
42
			[ true, null ],
43
			[ null, null ],
44
			[ 'en', 42 ],
45
			[ 'en', false ],
46
			[ 'en', [] ],
47
			[ 'en', null ],
48
			[ '', 'foo' ],
49
		];
50
	}
51
52
	public function testNewFromArray() {
53
		$array = [ 'text' => 'foo', 'language' => 'en' ];
54
		$value = MonolingualTextValue::newFromArray( $array );
0 ignored issues
show
Deprecated Code introduced by
The method DataValues\MonolingualTextValue::newFromArray() has been deprecated with message: since 1.0.0. 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...
55
		$this->assertSame( $array, $value->getArrayValue() );
56
	}
57
58
	/**
59
	 * @dataProvider invalidArrayProvider
60
	 */
61
	public function testNewFromArrayWithInvalidArray( array $array ) {
62
		$this->setExpectedException( IllegalValueException::class );
63
		MonolingualTextValue::newFromArray( $array );
0 ignored issues
show
Deprecated Code introduced by
The method DataValues\MonolingualTextValue::newFromArray() has been deprecated with message: since 1.0.0. 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...
64
	}
65
66
	public function invalidArrayProvider() {
67
		return [
68
			[ [] ],
69
			[ [ null ] ],
70
			[ [ '' ] ],
71
			[ [ 'en', 'foo' ] ],
72
			[ [ 'language' => 'en' ] ],
73
			[ [ 'text' => 'foo' ] ],
74
		];
75
	}
76
77
	public function testGetSortKey() {
78
		$value = new MonolingualTextValue( 'en', 'foo' );
79
		$this->assertSame( 'enfoo', $value->getSortKey() );
80
	}
81
82
	/**
83
	 * @dataProvider instanceProvider
84
	 */
85
	public function testGetText( MonolingualTextValue $text, array $arguments ) {
86
		$this->assertEquals( $arguments[1], $text->getText() );
87
	}
88
89
	/**
90
	 * @dataProvider instanceProvider
91
	 */
92
	public function testGetLanguageCode( MonolingualTextValue $text, array $arguments ) {
93
		$this->assertEquals( $arguments[0], $text->getLanguageCode() );
94
	}
95
96
}
97