diff --git a/features/maintenance-mode.feature b/features/maintenance-mode.feature index 68da153..eab4568 100644 --- a/features/maintenance-mode.feature +++ b/features/maintenance-mode.feature @@ -55,3 +55,34 @@ Feature: Manage maintenance mode of WordPress install. """ Error: Maintenance mode already deactivated. """ + + When I run `wp maintenance-mode activate` + Then STDOUT should be: + """ + Enabling Maintenance mode... + Success: Activated Maintenance mode. + """ + + Scenario: Check maintenance mode status when expression is used. + + When I run `wp eval "file_put_contents('.maintenance', 'abspath() ) . '.maintenance'; - return $wp_filesystem->exists( $maintenance_file ); + if ( ! $wp_filesystem->exists( $maintenance_file ) ) { + return false; + } + + // We use the timestamp defined in the .maintenance file + // to check if the maintenance is available. + $upgrading = 0; + + $contents = $wp_filesystem->get_contents( $maintenance_file ); + $matches = []; + if ( preg_match( '/upgrading\s*=\s*(\d+)\s*;/i', $contents, $matches ) ) { + $upgrading = (int) $matches[1]; + } else { + WP_CLI::warning( 'Unable to read the maintenance file timestamp, non-numeric value detected.' ); + } + // The logic here is based on the core WordPress `wp_is_maintenance_mode()` function. + if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) { + return false; + } + return true; } /**