Add unit test and a sample Woo plugin file

This commit is contained in:
vedanshujain 2020-05-01 22:47:08 +05:30
parent e97fd683c6
commit 13dfb8180f
4 changed files with 54 additions and 0 deletions

6
sample-woo-plugin.php Normal file
View File

@ -0,0 +1,6 @@
<?php // phpcs:ignoreFile
/**
* Plugin Name: Sample WooCommerce PLugin
* Woo: 1:sample-woo-plugin
*/

View File

@ -44,6 +44,15 @@ class WC_Unit_Tests_Bootstrap {
$this->plugin_dir = dirname( dirname( $this->tests_dir ) ); $this->plugin_dir = dirname( dirname( $this->tests_dir ) );
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib'; $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib';
if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
define( 'WP_PLUGIN_DIR', $this->plugin_dir );
}
if ( file_exists( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ) ) {
unlink( WP_PLUGIN_DIR . '/sample-woo-plugin.php' );
}
copy( __DIR__ . '/data/sample-woo-plugin.php', WP_PLUGIN_DIR . '/sample-woo-plugin.php' );
// load test function so tests_add_filter() is available. // load test function so tests_add_filter() is available.
require_once $this->wp_tests_dir . '/includes/functions.php'; require_once $this->wp_tests_dir . '/includes/functions.php';

View File

@ -0,0 +1,6 @@
<?php // phpcs:ignoreFile
/**
* Plugin Name: Sample WooCommerce PLugin
* Woo: 1:sample-woo-plugin
*/

View File

@ -0,0 +1,33 @@
<?php
/**
* Class WC_Tests_WC_Helper file.
*
* @package WooCommerce|Tests|WC_Helper.
*/
/**
* Class WC_Tests_WC_Helper.
*/
class WC_Tests_WC_Helper extends WC_Unit_Test_Case {
/**
* Test that woo plugins are loaded correctly even if incorrect cache is intially set.
*/
public function test_get_local_woo_plugins_without_woo_header_cache() {
$woocommerce_key = 'sample-woo-plugin.php';
remove_filter( 'extra_plugin_headers', 'wc_enable_wc_plugin_headers' );
wp_clean_plugins_cache( false );
get_plugins();
add_filter( 'extra_plugin_headers', 'wc_enable_wc_plugin_headers' );
$woo_plugins = WC_Helper::get_local_woo_plugins();
// Restore previous state.
wp_clean_plugins_cache( false );
$this->assertArrayHasKey( $woocommerce_key, $woo_plugins );
}
}