Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions tests/phpunit/tests/wp-includes/functions/WpGetUpdatePhpUrlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace WordPress\Tests\WP_Includes\Functions;

use WP_UnitTestCase;

/**
* Tests for the `wp_get_update_php_url()` function.
*
* @group functions
*
* @covers ::wp_get_update_php_url
*/
class WpGetUpdatePhpUrlTest extends WP_UnitTestCase {

/**
* Original PHP update URL environment value.
*
* @var string|false
*/
private $original_update_php_url;

/**
* Saves and clears the PHP update URL environment variable.
*/
public function set_up() {
parent::set_up();
$this->original_update_php_url = getenv( 'WP_UPDATE_PHP_URL' );
putenv( 'WP_UPDATE_PHP_URL' );
}

/**
* Restores the PHP update URL environment variable.
*/
public function tear_down() {
if ( false === $this->original_update_php_url ) {
putenv( 'WP_UPDATE_PHP_URL' );
} else {
putenv( 'WP_UPDATE_PHP_URL=' . $this->original_update_php_url );
}

parent::tear_down();
}

/**
* Tests that wp_get_update_php_url() returns the default URL.
*
* @ticket 65653
*/
public function test_wp_get_update_php_url_default() {
$this->assertSame( 'https://wordpress.org/support/update-php/', wp_get_update_php_url() );
}

/**
* Tests that wp_get_update_php_url() respects the WP_UPDATE_PHP_URL environment variable.
*
* @ticket 65653
*/
public function test_wp_get_update_php_url_env_var() {
$custom_url = 'https://example.com/update-php/';
putenv( 'WP_UPDATE_PHP_URL=' . $custom_url );

$url = wp_get_update_php_url();

// Clean up.
putenv( 'WP_UPDATE_PHP_URL' );

$this->assertSame( $custom_url, $url );
}

/**
* Tests that wp_get_update_php_url() respects the wp_update_php_url filter.
*
* @ticket 65653
*/
public function test_wp_get_update_php_url_filter() {
$custom_url = 'https://example.org/custom-php-update/';
$callback = static function () use ( $custom_url ) {
return $custom_url;
};

add_filter( 'wp_update_php_url', $callback );

$url = wp_get_update_php_url();

// Clean up the filter to prevent bleeding into other tests.
remove_filter( 'wp_update_php_url', $callback );

$this->assertSame( $custom_url, $url );
}

/**
* Tests that wp_get_update_php_url() falls back to the default URL if an empty string is provided.
*
* @ticket 65653
*
* @dataProvider data_wp_get_update_php_url_empty_fallbacks
*
* @param string $empty_value The empty value to test.
*/
public function test_wp_get_update_php_url_empty_fallbacks( $empty_value ) {
add_filter(
'wp_update_php_url',
function () use ( $empty_value ) {
return $empty_value;
}
);

$this->assertSame( 'https://wordpress.org/support/update-php/', wp_get_update_php_url() );
}

/**
* Data provider for test_wp_get_update_php_url_empty_fallbacks().
*
* @return array<string, array{
* empty_value: string,
* }>
*/
public function data_wp_get_update_php_url_empty_fallbacks(): array {
return array(
'empty string' => array( '' ),
'null' => array( null ),
'false' => array( false ),
);
}
}
Loading