1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DataValues\Tests; |
4
|
|
|
|
5
|
|
|
use DataValues\IllegalValueException; |
6
|
|
|
use DataValues\MonolingualTextValue; |
7
|
|
|
use Exception; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \DataValues\MonolingualTextValue |
12
|
|
|
* |
13
|
|
|
* @since 0.1 |
14
|
|
|
* |
15
|
|
|
* @group DataValue |
16
|
|
|
* @group DataValueExtensions |
17
|
|
|
* |
18
|
|
|
* @license GPL-2.0+ |
19
|
|
|
* @author Jeroen De Dauw < [email protected] > |
20
|
|
|
*/ |
21
|
|
|
class MonolingualTextValueTest extends TestCase { |
22
|
|
|
|
23
|
|
|
public function testGetters() { |
24
|
|
|
$value = new MonolingualTextValue( 'en', 'foo' ); |
25
|
|
|
$this->assertSame( 'monolingualtext', $value->getType() ); |
26
|
|
|
$this->assertSame( 'foo', $value->getText() ); |
27
|
|
|
$this->assertSame( 'en', $value->getLanguageCode() ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testArrayAndEquals() { |
31
|
|
|
$value = new MonolingualTextValue( 'en', 'foo' ); |
32
|
|
|
$array = $value->getArrayValue(); |
33
|
|
|
$value2 = MonolingualTextValue::newFromArray( $array ); |
|
|
|
|
34
|
|
|
$this->assertTrue( $value->equals( $value2 ) ); |
35
|
|
|
$this->assertEquals( $value, $value2 ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testSerialize() { |
39
|
|
|
$value = new MonolingualTextValue( 'en', 'foo' ); |
40
|
|
|
$serialization = serialize( $value ); |
41
|
|
|
$value2 = unserialize( $serialization ); |
42
|
|
|
$this->assertEquals( $value, $value2 ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @dataProvider invalidConstructorArgumentsProvider |
47
|
|
|
*/ |
48
|
|
|
public function testConstructorWithInvalidArguments( $languageCode, $text ) { |
49
|
|
|
$this->expectException( Exception::class ); |
50
|
|
|
|
51
|
|
|
$dataItem = new MonolingualTextValue( $languageCode, $text ); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function invalidConstructorArgumentsProvider() { |
55
|
|
|
return [ |
56
|
|
|
[ 42, null ], |
57
|
|
|
[ [], null ], |
58
|
|
|
[ false, null ], |
59
|
|
|
[ true, null ], |
60
|
|
|
[ null, null ], |
61
|
|
|
[ 'en', 42 ], |
62
|
|
|
[ 'en', false ], |
63
|
|
|
[ 'en', [] ], |
64
|
|
|
[ 'en', null ], |
65
|
|
|
[ '', 'foo' ], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @dataProvider invalidArrayProvider |
71
|
|
|
*/ |
72
|
|
|
public function testNewFromArrayWithInvalidArray( array $array ) { |
73
|
|
|
$this->expectException( IllegalValueException::class ); |
74
|
|
|
MonolingualTextValue::newFromArray( $array ); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function invalidArrayProvider() { |
78
|
|
|
return [ |
79
|
|
|
[ [] ], |
80
|
|
|
[ [ null ] ], |
81
|
|
|
[ [ '' ] ], |
82
|
|
|
[ [ 'en', 'foo' ] ], |
83
|
|
|
[ [ 'language' => 'en' ] ], |
84
|
|
|
[ [ 'text' => 'foo' ] ], |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
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.