2014-11-18 16:22:14 +00:00
|
|
|
<?php
|
2015-03-06 15:32:40 +00:00
|
|
|
|
2014-11-18 16:22:14 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Class Conditional_Functions.
|
2015-03-06 15:32:40 +00:00
|
|
|
* @package WooCommerce\Tests\Util
|
2014-11-18 16:22:14 +00:00
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
2016-03-23 12:14:13 +00:00
|
|
|
class WC_Tests_Conditional_Functions extends WC_Unit_Test_Case {
|
2014-11-18 16:22:14 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test is_store_notice_showing().
|
2014-11-18 16:22:14 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_is_store_notice_showing() {
|
|
|
|
|
|
|
|
$this->assertEquals( false, is_store_notice_showing() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_tax_enabled().
|
2014-11-18 16:22:14 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_tax_enabled() {
|
|
|
|
|
|
|
|
$this->assertEquals( false, wc_tax_enabled() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_prices_include_tax().
|
2014-11-18 16:22:14 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_prices_include_tax() {
|
|
|
|
|
|
|
|
$this->assertEquals( false, wc_prices_include_tax() );
|
|
|
|
}
|
2015-03-03 11:37:49 +00:00
|
|
|
|
2015-04-14 13:34:35 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Data provider for test_wc_is_webhook_valid_topic.
|
2015-04-14 13:34:35 +00:00
|
|
|
*
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function data_provider_test_wc_is_webhook_valid_topic() {
|
|
|
|
return array(
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'action.woocommerce_add_to_cart' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'action.wc_add_to_cart' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'product.created' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'product.updated' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'product.deleted' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'order.created' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'order.updated' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'order.deleted' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'customer.created' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'customer.updated' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'customer.deleted' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'coupon.created' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'coupon.updated' ) ),
|
|
|
|
array( true, wc_is_webhook_valid_topic( 'coupon.deleted' ) ),
|
|
|
|
array( false, wc_is_webhook_valid_topic( 'coupon.upgraded' ) ),
|
|
|
|
array( false, wc_is_webhook_valid_topic( 'wc.product.updated' ) ),
|
|
|
|
array( false, wc_is_webhook_valid_topic( 'missingdot' ) ),
|
2016-08-27 02:08:49 +00:00
|
|
|
array( false, wc_is_webhook_valid_topic( 'with space' ) ),
|
2015-04-14 13:34:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-08 15:55:40 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_is_webhook_valid_topic().
|
2015-04-08 15:55:40 +00:00
|
|
|
*
|
2015-04-14 13:34:35 +00:00
|
|
|
* @dataProvider data_provider_test_wc_is_webhook_valid_topic
|
2015-04-08 15:55:40 +00:00
|
|
|
* @since 2.4
|
|
|
|
*/
|
2015-04-14 13:34:35 +00:00
|
|
|
public function test_wc_is_webhook_valid_topic( $assert, $values ) {
|
|
|
|
$this->assertEquals( $assert, $values );
|
2015-04-08 15:55:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 11:37:49 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Data provider for test_wc_is_valid_url.
|
2015-03-03 11:37:49 +00:00
|
|
|
*
|
2015-04-14 13:34:35 +00:00
|
|
|
* @since 2.4
|
2015-03-03 11:37:49 +00:00
|
|
|
*/
|
2015-04-14 13:34:35 +00:00
|
|
|
public function data_provider_test_wc_is_valid_url() {
|
|
|
|
return array(
|
|
|
|
// Test some invalid URLs
|
|
|
|
array( false, wc_is_valid_url( 'google.com' ) ),
|
|
|
|
array( false, wc_is_valid_url( 'ftp://google.com' ) ),
|
|
|
|
array( false, wc_is_valid_url( 'sftp://google.com' ) ),
|
|
|
|
array( false, wc_is_valid_url( 'https://google.com/test invalid' ) ),
|
2015-03-03 11:37:49 +00:00
|
|
|
|
2015-04-14 13:34:35 +00:00
|
|
|
// Test some valid URLs
|
|
|
|
array( true, wc_is_valid_url( 'http://google.com' ) ),
|
|
|
|
array( true, wc_is_valid_url( 'https://google.com' ) ),
|
|
|
|
array( true, wc_is_valid_url( 'https://google.com/test%20valid' ) ),
|
|
|
|
array( true, wc_is_valid_url( 'https://google.com/test-valid/?query=test' ) ),
|
2016-08-27 02:08:49 +00:00
|
|
|
array( true, wc_is_valid_url( 'https://google.com/test-valid/#hash' ) ),
|
2015-04-14 13:34:35 +00:00
|
|
|
);
|
|
|
|
}
|
2015-03-03 11:37:49 +00:00
|
|
|
|
2016-08-01 11:21:55 +00:00
|
|
|
/**
|
|
|
|
* Test wc_site_is_https().
|
|
|
|
*/
|
|
|
|
public function test_wc_site_is_https() {
|
|
|
|
$this->assertFalse( wc_site_is_https() );
|
|
|
|
|
2016-08-01 16:08:42 +00:00
|
|
|
add_filter( 'pre_option_home', array( $this, '_https_url' ) );
|
2016-08-01 11:21:55 +00:00
|
|
|
|
|
|
|
$this->assertTrue( wc_site_is_https() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for chaning home url to https.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function _https_url() {
|
|
|
|
return 'https://example.org';
|
|
|
|
}
|
|
|
|
|
2015-04-14 13:34:35 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_is_valid_url().
|
2015-04-14 13:34:35 +00:00
|
|
|
*
|
|
|
|
* @dataProvider data_provider_test_wc_is_valid_url
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_is_valid_url( $assert, $values ) {
|
|
|
|
$this->assertEquals( $assert, $values );
|
2015-03-03 11:37:49 +00:00
|
|
|
}
|
2014-11-18 16:22:14 +00:00
|
|
|
}
|