Merge pull request #31227 from woocommerce/fix/count_param
Update count param consistently.
This commit is contained in:
commit
5773089e8c
|
@ -270,7 +270,7 @@ class WC_Download_Handler {
|
|||
);
|
||||
|
||||
$count = 0;
|
||||
$file_path = str_replace( array_keys( $replacements ), array_values( $replacements ), $file_path );
|
||||
$file_path = str_replace( array_keys( $replacements ), array_values( $replacements ), $file_path, $count );
|
||||
$parsed_file_path = wp_parse_url( $file_path );
|
||||
$remote_file = null === $count || 0 === $count; // Remote file only if there were no replacements.
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Class WC_Download_Handler_Tests.
|
||||
*/
|
||||
class WC_Download_Handler_Tests extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test for local file path.
|
||||
*/
|
||||
public function test_parse_file_path_for_local_file() {
|
||||
$local_file_path = trailingslashit( wp_upload_dir()['basedir'] ) . 'dummy_file.jpg';
|
||||
$parsed_file_path = WC_Download_Handler::parse_file_path( $local_file_path );
|
||||
$this->assertFalse( $parsed_file_path['remote_file'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for local URL without protocol.
|
||||
*/
|
||||
public function test_parse_file_path_for_local_url() {
|
||||
$local_file_path = trailingslashit( wp_upload_dir()['baseurl'] ) . 'dummy_file.jpg';
|
||||
$parsed_file_path = WC_Download_Handler::parse_file_path( $local_file_path );
|
||||
$this->assertFalse( $parsed_file_path['remote_file'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for local file with `file` protocol.
|
||||
*/
|
||||
public function test_parse_file_path_for_local_file_protocol() {
|
||||
$local_file_path = 'file:/' . trailingslashit( wp_upload_dir()['basedir'] ) . 'dummy_file.jpg';
|
||||
$parsed_file_path = WC_Download_Handler::parse_file_path( $local_file_path );
|
||||
$this->assertFalse( $parsed_file_path['remote_file'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for local file with https protocom.
|
||||
*/
|
||||
public function test_parse_file_path_for_local_file_https_protocol() {
|
||||
$local_file_path = site_url( '/', 'https' ) . 'dummy_file.jpg';
|
||||
$parsed_file_path = WC_Download_Handler::parse_file_path( $local_file_path );
|
||||
$this->assertFalse( $parsed_file_path['remote_file'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for remote file.
|
||||
*/
|
||||
public function test_parse_file_path_for_remote_file() {
|
||||
$remote_file_path = 'https://dummy.woocommerce.com/dummy_file.jpg';
|
||||
$parsed_file_path = WC_Download_Handler::parse_file_path( $remote_file_path );
|
||||
$this->assertTrue( $parsed_file_path['remote_file'] );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue