-
Notifications
You must be signed in to change notification settings - Fork 19
/
test-preference-conflict-detector.php
123 lines (96 loc) · 3.41 KB
/
test-preference-conflict-detector.php
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
122
123
<?php
namespace FortAwesome;
require_once dirname( __FILE__ ) . '/../includes/class-fontawesome-preference-conflict-detector.php';
use Yoast\WPTestUtils\WPIntegration\TestCase;
/**
* Class PreferenceConflictDetectorTest
*
* @noinspection PhpCSValidationInspection
*/
class PreferenceConflictDetectorTest extends TestCase {
public function test_when_all_prefs_match() {
$options = array(
'technology' => 'webfont',
'v4Compat' => false,
'usePro' => false,
'removeConflicts' => false,
'pseudoElements' => false,
'version' => '5.8.2',
);
$client_preferences = array(
'technology' => 'webfont',
'v4Compat' => false,
'usePro' => false,
'removeConflicts' => false,
'pseudoElements' => false,
'version' => array( array( '5.8.2', '=' ) ),
);
$this->assertEquals( array(), FontAwesome_Preference_Conflict_Detector::detect( $options, $client_preferences ) );
}
public function test_when_something_does_not_match() {
$options = array(
'method' => 'svg',
'v4Compat' => false,
);
$client_preferences = array(
'method' => 'webfont',
'v4Compat' => false,
);
$this->assertEquals( array( 'method' ), FontAwesome_Preference_Conflict_Detector::detect( $options, $client_preferences ) );
}
public function test_when_version_does_not_match() {
$options = array(
'version' => '5.2.0',
);
$client_preferences = array(
'version' => array( array( '5.8.2', '>' ) ),
);
$this->assertEquals( array( 'version' ), FontAwesome_Preference_Conflict_Detector::detect( $options, $client_preferences ) );
}
public function test_success_when_configured_version_is_symbolically_latest() {
$options = array(
'version' => 'latest',
);
$client_preferences = array(
'version' => array( array( '5.8.2', '>' ) ),
);
$this->assertEquals( array(), FontAwesome_Preference_Conflict_Detector::detect( $options, $client_preferences, '5.12.0', '6.1.1' ) );
}
public function test_failure_when_configured_version_is_symbolically_latest() {
$options = array(
'version' => 'latest',
);
$client_preferences = array(
'version' => array( array( '5.8.2', '=' ) ),
);
$this->assertEquals( array( 'version' ), FontAwesome_Preference_Conflict_Detector::detect( $options, $client_preferences, '5.12.0', '6.1.1' ) );
}
public function test_with_empty_preference() {
$options = array(
'method' => 'svg',
'v4Compat' => false,
);
$client_preferences = array();
$this->assertEquals( array(), FontAwesome_Preference_Conflict_Detector::detect( $options, $client_preferences ) );
}
public function test_satisfies() {
$this->assertTrue(
FontAwesome_Preference_Conflict_Detector::version_satisfies( '42.1.3', array( array( '42.1.3', '=' ) ) )
);
$this->assertTrue(
FontAwesome_Preference_Conflict_Detector::version_satisfies( '42.1.3', array( array( '42.1.2', '>=' ), array( '43', '<' ) ) )
);
}
public function test_satisfies_bad_operator() {
$this->expectException( ClientPreferencesSchemaException::class );
$this->assertTrue(
FontAwesome_Preference_Conflict_Detector::version_satisfies( '42.1.3', array( array( '42.1.2', 'xyz' ) ) )
);
}
public function test_satisfies_bad_argument_1() {
$this->expectException( ClientPreferencesSchemaException::class );
$this->assertTrue(
FontAwesome_Preference_Conflict_Detector::version_satisfies( '42.1.3', array( '42.1.2', 'xyz' ) )
);
}
}