Skip to content

Commit 543733c

Browse files
committed
Fix tests
1 parent 019f04a commit 543733c

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

plugins/speculation-rules/tests/test-speculation-rules-settings.php

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ public function test_plsr_sanitize_setting( $input, array $expected ): void {
4848
/** @return array<string, mixed> */
4949
public function data_plsr_sanitize_setting(): array {
5050
$default_value = array(
51-
'mode' => 'prerender',
52-
'eagerness' => 'moderate',
51+
'mode' => 'prerender',
52+
'eagerness' => 'moderate',
53+
'authentication' => 'logged_out',
5354
);
5455

5556
return array(
@@ -67,46 +68,59 @@ public function data_plsr_sanitize_setting(): array {
6768
),
6869
'missing mode' => array(
6970
array( 'eagerness' => 'conservative' ),
70-
array(
71-
'mode' => $default_value['mode'],
72-
'eagerness' => 'conservative',
71+
array_merge(
72+
$default_value,
73+
array(
74+
'eagerness' => 'conservative',
75+
)
7376
),
7477
),
7578
'missing eagerness' => array(
7679
array( 'mode' => 'prefetch' ),
77-
array(
78-
'mode' => 'prefetch',
79-
'eagerness' => $default_value['eagerness'],
80+
array_merge(
81+
$default_value,
82+
array(
83+
'mode' => 'prefetch',
84+
)
8085
),
8186
),
8287
'invalid mode' => array(
8388
array(
8489
'mode' => 'something',
8590
'eagerness' => 'eager',
8691
),
87-
array(
88-
'mode' => 'prerender',
89-
'eagerness' => 'eager',
92+
array_merge(
93+
$default_value,
94+
array(
95+
'mode' => 'prerender',
96+
'eagerness' => 'eager',
97+
)
9098
),
9199
),
92100
'invalid eagerness' => array(
93101
array(
94102
'mode' => 'prefetch',
95103
'eagerness' => 'something',
96104
),
97-
array(
98-
'mode' => 'prefetch',
99-
'eagerness' => 'moderate',
105+
array_merge(
106+
$default_value,
107+
array(
108+
'mode' => 'prefetch',
109+
'eagerness' => 'moderate',
110+
)
100111
),
101112
),
102113
'valid fields' => array(
103114
array(
104115
'mode' => 'prefetch',
105116
'eagerness' => 'conservative',
106117
),
107-
array(
108-
'mode' => 'prefetch',
109-
'eagerness' => 'conservative',
118+
array_merge(
119+
$default_value,
120+
array(
121+
'mode' => 'prefetch',
122+
'eagerness' => 'conservative',
123+
)
110124
),
111125
),
112126
);
@@ -141,15 +155,17 @@ public function test_get_stored_setting_value(): void {
141155
update_option(
142156
'plsr_speculation_rules',
143157
array(
144-
'mode' => 'prefetch',
145-
'eagerness' => 'moderate',
158+
'mode' => 'prefetch',
159+
'eagerness' => 'moderate',
160+
'authentication' => 'logged_out',
146161
)
147162
);
148163
$settings = plsr_get_stored_setting_value();
149164
$this->assertEquals(
150165
array(
151-
'mode' => 'prefetch',
152-
'eagerness' => 'moderate',
166+
'mode' => 'prefetch',
167+
'eagerness' => 'moderate',
168+
'authentication' => 'logged_out',
153169
),
154170
$settings
155171
);

plugins/speculation-rules/tests/test-speculation-rules-wp-core-api.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ class Test_Speculation_Rules_WP_Core_API extends WP_UnitTestCase {
99

1010
/**
1111
* @covers ::plsr_filter_speculation_rules_configuration
12+
* @covers ::plsr_is_speculative_loading_enabled
1213
*/
1314
public function test_plsr_filter_speculation_rules_configuration_with_regular(): void {
15+
add_filter( 'plsr_enabled_without_pretty_permalinks', '__return_true' );
16+
$this->assertTrue( plsr_is_speculative_loading_enabled() );
1417
$this->assertSame(
1518
array(
1619
'mode' => 'prerender',
@@ -27,8 +30,11 @@ public function test_plsr_filter_speculation_rules_configuration_with_regular():
2730

2831
/**
2932
* @covers ::plsr_filter_speculation_rules_configuration
33+
* @covers ::plsr_is_speculative_loading_enabled
3034
*/
3135
public function test_plsr_filter_speculation_rules_configuration_with_invalid(): void {
36+
add_filter( 'plsr_enabled_without_pretty_permalinks', '__return_true' );
37+
$this->assertTrue( plsr_is_speculative_loading_enabled() );
3238
$this->assertSame(
3339
array(
3440
'mode' => 'prerender',

0 commit comments

Comments
 (0)