1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DataValues\Tests; |
4
|
|
|
|
5
|
|
|
use DataValues\IllegalValueException; |
6
|
|
|
use DataValues\MonolingualTextValue; |
7
|
|
|
use DataValues\MultilingualTextValue; |
8
|
|
|
use Exception; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \DataValues\MultilingualTextValue |
13
|
|
|
* |
14
|
|
|
* @since 0.1 |
15
|
|
|
* |
16
|
|
|
* @group DataValue |
17
|
|
|
* @group DataValueExtensions |
18
|
|
|
* |
19
|
|
|
* @license GPL-2.0+ |
20
|
|
|
* @author Jeroen De Dauw < [email protected] > |
21
|
|
|
*/ |
22
|
|
|
class MultilingualTextValueTest extends TestCase { |
23
|
|
|
|
24
|
|
|
public function testGetters() { |
25
|
|
|
$monolingualTextValue1 = new MonolingualTextValue( 'en', 'foo' ); |
26
|
|
|
$monolingualTextValue2 = new MonolingualTextValue( 'de', 'foo' ); |
27
|
|
|
$value = new MultilingualTextValue( [ $monolingualTextValue1, $monolingualTextValue2 ] ); |
28
|
|
|
$this->assertSame( 'multilingualtext', $value->getType() ); |
29
|
|
|
$this->assertSame( |
30
|
|
|
[ 'en' => $monolingualTextValue1, 'de' => $monolingualTextValue2 ], |
31
|
|
|
$value->getTexts() |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetters_empty() { |
36
|
|
|
$value = new MultilingualTextValue( [] ); |
37
|
|
|
$this->assertSame( [], $value->getTexts() ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testArrayAndEquals() { |
41
|
|
|
$monolingualTextValue1 = new MonolingualTextValue( 'en', 'foo' ); |
42
|
|
|
$monolingualTextValue2 = new MonolingualTextValue( 'de', 'foo' ); |
43
|
|
|
$value = new MultilingualTextValue( [ $monolingualTextValue1, $monolingualTextValue2 ] ); |
44
|
|
|
$array = $value->getArrayValue(); |
45
|
|
|
$value2 = MultilingualTextValue::newFromArray( $array ); |
|
|
|
|
46
|
|
|
$this->assertTrue( $value->equals( $value2 ) ); |
47
|
|
|
$this->assertEquals( $value, $value2 ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testSerialize() { |
51
|
|
|
$monolingualTextValue1 = new MonolingualTextValue( 'en', 'foo' ); |
52
|
|
|
$monolingualTextValue2 = new MonolingualTextValue( 'de', 'foo' ); |
53
|
|
|
$value = new MultilingualTextValue( [ $monolingualTextValue1, $monolingualTextValue2 ] ); |
54
|
|
|
$serialization = serialize( $value ); |
55
|
|
|
$value2 = unserialize( $serialization ); |
56
|
|
|
$this->assertEquals( $value, $value2 ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @dataProvider invalidConstructorArgumentsProvider |
61
|
|
|
*/ |
62
|
|
|
public function testConstructorWithInvalidArguments( $monolingualValues ) { |
63
|
|
|
$this->expectException( Exception::class ); |
64
|
|
|
|
65
|
|
|
$dataItem = new MultilingualTextValue( $monolingualValues ); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function invalidConstructorArgumentsProvider() { |
69
|
|
|
return [ |
70
|
|
|
[ [ 42 ] ], |
71
|
|
|
[ [ false ] ], |
72
|
|
|
[ [ true ] ], |
73
|
|
|
[ [ null ] ], |
74
|
|
|
[ [ [] ] ], |
75
|
|
|
[ [ 'foo' ] ], |
76
|
|
|
|
77
|
|
|
[ [ 42 => 'foo' ] ], |
78
|
|
|
[ [ '' => 'foo' ] ], |
79
|
|
|
[ [ 'en' => 42 ] ], |
80
|
|
|
[ [ 'en' => null ] ], |
81
|
|
|
[ [ 'en' => true ] ], |
82
|
|
|
[ [ 'en' => [] ] ], |
83
|
|
|
[ [ 'en' => 4.2 ] ], |
84
|
|
|
|
85
|
|
|
[ [ |
86
|
|
|
new MonolingualTextValue( 'en', 'foo' ), |
87
|
|
|
false, |
88
|
|
|
] ], |
89
|
|
|
[ [ |
90
|
|
|
new MonolingualTextValue( 'en', 'foo' ), |
91
|
|
|
'foobar', |
92
|
|
|
] ], |
93
|
|
|
[ [ |
94
|
|
|
new MonolingualTextValue( 'en', 'foo' ), |
95
|
|
|
new MonolingualTextValue( 'en', 'bar' ), |
96
|
|
|
] ], |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @dataProvider invalidArrayProvider |
102
|
|
|
*/ |
103
|
|
|
public function testNewFromArrayWithInvalidArray( array $array ) { |
104
|
|
|
$this->expectException( IllegalValueException::class ); |
105
|
|
|
MultilingualTextValue::newFromArray( $array ); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function invalidArrayProvider() { |
109
|
|
|
return [ |
110
|
|
|
[ [ null ] ], |
111
|
|
|
[ [ '' ] ], |
112
|
|
|
[ [ [] ] ], |
113
|
|
|
[ [ [ 'en', 'foo' ] ] ], |
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
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.