Skip to content

Commit 0cf464e

Browse files
kushh23Copilot
andauthored
Update tests/test-generic.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9e725b8 commit 0cf464e

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

tests/test-generic.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,21 @@ function test_add_schema_non_ssl() {
181181
* Regression: operator-precedence bug caused https: to be returned bare instead of https://example.org/...
182182
*/
183183
function test_add_schema_ssl() {
184-
$_SERVER['HTTPS'] = 'on';
185-
$result = $this->add_schema( '//example.org/image.jpg' );
186-
unset( $_SERVER['HTTPS'] );
187-
188-
$this->assertEquals( 'https://example.org/image.jpg', $result );
184+
$had_https = array_key_exists( 'HTTPS', $_SERVER );
185+
$previous_https = $had_https ? $_SERVER['HTTPS'] : null;
186+
187+
try {
188+
$_SERVER['HTTPS'] = 'on';
189+
$result = $this->add_schema( '//example.org/image.jpg' );
190+
191+
$this->assertEquals( 'https://example.org/image.jpg', $result );
192+
} finally {
193+
if ( $had_https ) {
194+
$_SERVER['HTTPS'] = $previous_https;
195+
} else {
196+
unset( $_SERVER['HTTPS'] );
197+
}
198+
}
189199
}
190200

191201
/**

0 commit comments

Comments
 (0)