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