Completed
Pull Request — master (#47)
by no
04:20 queued 02:14
created

MonolingualTextValueTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 78
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A validConstructorArgumentsProvider() 0 6 1
A invalidConstructorArgumentsProvider() 0 14 1
A testNewFromArray() 0 5 1
A testNewFromArrayWithInvalidArray() 0 4 1
A invalidArrayProvider() 0 10 1
A testGetSortKey() 0 4 1
A getClass() 0 3 1
A testGetText() 0 3 1
A testGetLanguageCode() 0 3 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 array(
31
			array( 'en', 'foo' ),
32
			array( '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 array(
38
			array( 42, null ),
39
			array( array(), null ),
40
			array( false, null ),
41
			array( true, null ),
42
			array( null, null ),
43
			array( 'en', 42 ),
44
			array( 'en', false ),
45
			array( 'en', array() ),
46
			array( 'en', null ),
47
			array( '', 'foo' ),
48
		);
49
	}
50
51
	public function testNewFromArray() {
52
		$array = 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 array(
67
			array( array() ),
68
			array( array( null ) ),
69
			array( array( '' ) ),
70
			array( array( 'en', 'foo' ) ),
71
			array( array( 'language' => 'en' ) ),
72
			array( array( '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