From dc12908890fcf01d20231d567589793d7c0bac72 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 20 Apr 2018 00:19:42 +0200 Subject: [PATCH] Update scaffolded files --- bin/test.sh | 4 ++++ features/bootstrap/utils.php | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/bin/test.sh b/bin/test.sh index bd3ae6e91..84e2460b8 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -8,6 +8,10 @@ then phpunit fi +if [ $WP_VERSION = "latest" ]; then + export WP_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r ".offers[0].current") +fi + # Run the functional tests BEHAT_TAGS=$(php utils/behat-tags.php) behat --format progress $BEHAT_TAGS --strict diff --git a/features/bootstrap/utils.php b/features/bootstrap/utils.php index 26b3dbbed..8033dcb7c 100644 --- a/features/bootstrap/utils.php +++ b/features/bootstrap/utils.php @@ -24,7 +24,7 @@ function extract_from_phar( $path ) { $fname = basename( $path ); - $tmp_path = get_temp_dir() . "wp-cli-$fname"; + $tmp_path = get_temp_dir() . uniqid( 'wp-cli-extract-from-phar-', true ) . "-$fname"; copy( $path, $tmp_path ); @@ -351,19 +351,21 @@ function pick_fields( $item, $fields ) { * @category Input * * @param string $content Some form of text to edit (e.g. post content) + * @param string $title Title to display in the editor. + * @param string $ext Extension to use with the temp file. * @return string|bool Edited text, if file is saved from editor; false, if no change to file. */ -function launch_editor_for_input( $input, $filename = 'WP-CLI' ) { +function launch_editor_for_input( $input, $title = 'WP-CLI', $ext = 'tmp' ) { check_proc_available( 'launch_editor_for_input' ); $tmpdir = get_temp_dir(); do { - $tmpfile = basename( $filename ); + $tmpfile = basename( $title ); $tmpfile = preg_replace( '|\.[^.]*$|', '', $tmpfile ); $tmpfile .= '-' . substr( md5( mt_rand() ), 0, 6 ); - $tmpfile = $tmpdir . $tmpfile . '.tmp'; + $tmpfile = $tmpdir . $tmpfile . '.' . $ext; $fp = fopen( $tmpfile, 'xb' ); if ( ! $fp && is_writable( $tmpdir ) && file_exists( $tmpfile ) ) { $tmpfile = ''; @@ -772,6 +774,31 @@ function trailingslashit( $string ) { return rtrim( $string, '/\\' ) . '/'; } +/** + * Normalize a filesystem path. + * + * On Windows systems, replaces backslashes with forward slashes + * and forces upper-case drive letters. + * Allows for two leading slashes for Windows network shares, but + * ensures that all other duplicate slashes are reduced to a single one. + * Ensures upper-case drive letters on Windows systems. + * + * @access public + * @category System + * + * @param string $path Path to normalize. + * @return string Normalized path. + */ +function normalize_path( $path ) { + $path = str_replace( '\\', '/', $path ); + $path = preg_replace( '|(?<=.)/+|', '/', $path ); + if ( ':' === substr( $path, 1, 1 ) ) { + $path = ucfirst( $path ); + } + return $path; +} + + /** * Convert Windows EOLs to *nix. * @@ -1307,6 +1334,7 @@ function get_php_binary() { // Available since PHP 5.4. if ( defined( 'PHP_BINARY' ) ) { + // @codingStandardsIgnoreLine return PHP_BINARY; }