Completed
Pull Request — master (#47)
by no
08:35 queued 06:16
created

testNewFromArrayWithInvalidArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace DataValues\Tests;
4
5
use DataValues\MonolingualTextValue;
6
7
/**
8
 * @covers DataValues\MonolingualTextValue
9
 *
10
 * @since 0.1
11
 *
12
 * @group DataValue
13
 * @group DataValueExtensions
14
 *
15
 * @license GPL-2.0+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class MonolingualTextValueTest extends DataValueTest {
19
20
	/**
21
	 * @see DataValueTest::getClass
22
	 *
23
	 * @return string
24
	 */
25
	public function getClass() {
26
		return 'DataValues\MonolingualTextValue';
27
	}
28
29
	public function validConstructorArgumentsProvider() {
30
		return [
31
			[ 'en', 'foo' ],
32
			[ 'en', ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ],
33
		];
34
	}
35
36
	public function invalidConstructorArgumentsProvider() {
37
		return [
38
			[ 42, null ],
39
			[ [], null ],
40
			[ false, null ],
41
			[ true, null ],
42
			[ null, null ],
43
			[ 'en', 42 ],
44
			[ 'en', false ],
45
			[ 'en', [] ],
46
			[ 'en', null ],
47
			[ '', 'foo' ],
48
		];
49
	}
50
51
	public function testNewFromArray() {
52
		$array = [ 'text' => 'foo', 'language' => 'en' ];
53
		$value = MonolingualTextValue::newFromArray( $array );
54
		$this->assertSame( $array, $value->getArrayValue() );
55
	}
56
57
	/**
58
	 * @dataProvider invalidArrayProvider
59
	 */
60
	public function testNewFromArrayWithInvalidArray( array $array ) {
61
		$this->setExpectedException( 'DataValues\IllegalValueException' );
62
		MonolingualTextValue::newFromArray( $array );
63
	}
64
65
	public function invalidArrayProvider() {
66
		return [
67
			[ [] ],
68
			[ [ null ] ],
69
			[ [ '' ] ],
70
			[ [ 'en', 'foo' ] ],
71
			[ [ 'language' => 'en' ] ],
72
			[ [ 'text' => 'foo' ] ],
73
		];
74
	}
75
76
	public function testGetSortKey() {
77
		$value = new MonolingualTextValue( 'en', 'foo' );
78
		$this->assertSame( 'enfoo', $value->getSortKey() );
79
	}
80
81
	/**
82
	 * @dataProvider instanceProvider
83
	 */
84
	public function testGetText( MonolingualTextValue $text, array $arguments ) {
85
		$this->assertEquals( $arguments[1], $text->getText() );
86
	}
87
88
	/**
89
	 * @dataProvider instanceProvider
90
	 */
91
	public function testGetLanguageCode( MonolingualTextValue $text, array $arguments ) {
92
		$this->assertEquals( $arguments[0], $text->getLanguageCode() );
93
	}
94
95
}
96