Add `store_id` to system_status REST API (#41341)

This commit is contained in:
Leif Singer 2023-11-20 19:37:20 +01:00 committed by GitHub
commit 2d44b1f94b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Includes the store_id added by #40705 to the system_status REST API.

View File

@ -149,6 +149,12 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
'context' => array( 'view' ),
'readonly' => true,
),
'store_id' => array(
'description' => __( 'WooCommerce Store Identifier.', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view' ),
'readonly' => true,
),
'version' => array(
'description' => __( 'WooCommerce version.', 'woocommerce' ),
'type' => 'string',
@ -826,6 +832,7 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
return array(
'home_url' => get_option( 'home' ),
'site_url' => get_option( 'siteurl' ),
'store_id' => get_option( \WC_Install::STORE_ID_OPTION, null ),
'version' => WC()->version,
'log_directory' => WC_LOG_DIR,
'log_directory_writable' => (bool) @fopen( WC_LOG_DIR . 'test-log.log', 'a' ), // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen

View File

@ -110,14 +110,22 @@ class WC_Tests_REST_System_Status_V2 extends WC_REST_Unit_Test_Case {
public function test_get_system_status_info_environment() {
$this->skip_on_php_8_1();
$store_id = get_option( \WC_Install::STORE_ID_OPTION, null );
if ( empty( $store_id ) ) {
$store_id = 'a1b2c3d4-e5f6-a1b2-c3d4-a1b2c3d4e5f6';
update_option( \WC_Install::STORE_ID_OPTION, $store_id );
}
$environment = (array) $this->fetch_or_get_system_status_data_for_user( self::$administrator_user )['environment'];
// Make sure all expected data is present.
$this->assertEquals( 32, count( $environment ) );
$this->assertEquals( 33, count( $environment ) );
// Test some responses to make sure they match up.
$this->assertEquals( get_option( 'home' ), $environment['home_url'] );
$this->assertEquals( get_option( 'siteurl' ), $environment['site_url'] );
$this->assertEquals( get_option( \WC_Install::STORE_ID_OPTION, null ), $environment['store_id'] );
$this->assertEquals( $store_id, $environment['store_id'] );
$this->assertEquals( WC()->version, $environment['version'] );
}

View File

@ -117,14 +117,22 @@ class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
* @since 3.5.0
*/
public function test_get_system_status_info_environment() {
$store_id = get_option( \WC_Install::STORE_ID_OPTION, null );
if ( empty( $store_id ) ) {
$store_id = 'a1b2c3d4-e5f6-a1b2-c3d4-a1b2c3d4e5f6';
update_option( \WC_Install::STORE_ID_OPTION, $store_id );
}
$environment = (array) $this->fetch_or_get_system_status_data_for_user( self::$administrator_user )['environment'];
// Make sure all expected data is present.
$this->assertEquals( 32, count( $environment ) );
$this->assertEquals( 33, count( $environment ) );
// Test some responses to make sure they match up.
$this->assertEquals( get_option( 'home' ), $environment['home_url'] );
$this->assertEquals( get_option( 'siteurl' ), $environment['site_url'] );
$this->assertEquals( get_option( \WC_Install::STORE_ID_OPTION, null ), $environment['store_id'] );
$this->assertEquals( $store_id, $environment['store_id'] );
$this->assertEquals( WC()->version, $environment['version'] );
}