Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Constructor
- */
- public function __construct() {
- if ( ! Iconic_WDS_Core_Helpers::is_plugin_active( 'woocommerce/woocommerce.php' ) && ! Iconic_WDS_Core_Helpers::is_plugin_active( 'woocommerce-old/woocommerce.php' ) ) {
- return;
- // It stops right here!!!
- }
- }
- install_dependencies() {
- WP_SITE_URL="http://localhost:8080"
- WP_PLUGIN_DIR=$(pwd)
- WP_DB_DATA="$WP_PLUGIN_DIR/tests/data/db.sql"
- cd "$WP_CORE_DIR"
- curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
- php wp-cli.phar core config --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=$DB_HOST --dbprefix=wptests_
- php wp-cli.phar db import $WP_DB_DATA
- php wp-cli.phar search-replace "http://local.wordpress.test" "$WP_SITE_URL"
- php wp-cli.phar theme install twentyseventeen --activate
- php wp-cli.phar plugin install https://downloads.wordpress.org/plugin/woocommerce.${WC_VERSION}.zip --activate
- php wp-cli.phar plugin install https://downloads.wordpress.org/plugin/posts-to-posts.${P2P_VERSION}.zip --activate
- php wp-cli.phar plugin install $WP_PLUGIN_DIR/plugins/iconic-private-plugin.zip --activate
- php wp-cli.phar plugin list
- }
- /**
- * Setup the unit testing environment.
- */
- public function __construct() {
- // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions
- ini_set( 'display_errors', 'on' );
- error_reporting( E_ALL );
- // phpcs:enable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions
- // Ensure server variable is set for WP email functions.
- // phpcs:disable WordPress.VIP.SuperGlobalInputUsage.AccessDetected
- if ( ! isset( $_SERVER['SERVER_NAME'] ) ) {
- $_SERVER['SERVER_NAME'] = 'localhost';
- }
- // phpcs:enable WordPress.VIP.SuperGlobalInputUsage.AccessDetected
- $this->tests_dir = dirname( __FILE__ );
- $this->plugin_dir = dirname( $this->tests_dir );
- $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : rtrim( sys_get_temp_dir(), '/\' ) . '/wordpress-tests-lib';
- // load test function so tests_add_filter() is available.
- require_once $this->wp_tests_dir . '/includes/functions.php';
- // load Dependencies.
- tests_add_filter( 'muplugins_loaded', array( $this, 'my_custom_plugin_manually_load_plugin' ) );
- // load the WP testing environment.
- require_once $this->wp_tests_dir . '/includes/bootstrap.php';
- }
- /**
- * Load Dependencies
- */
- public function my_custom_plugin_manually_load_plugin() {
- $this->plugins_dir = ABSPATH . str_replace( site_url() . '/', '', plugins_url() ) . '/';
- // Load dependencies.
- require_once $this->plugins_dir . 'woocommerce/woocommerce.php';
- require_once $this->plugins_dir . 'iconic/iconic-private-plugin.php';
- // Load plugin.
- require_once $this->plugin_dir . '/my-custom-plugin.php';
- global $my_custom_plugin;
- $my_custom_plugin = new My_Custom_Plugin_Class();
- }
- <?php
- /**
- * Sql test case.
- */
- class SqlTest extends WP_UnitTestCase {
- /**
- * Set up fixtures before class for all tests in SqlTest Class.
- *
- * @param object $factory passed by WP_UnitTestCase.
- */
- public static function wpSetUpBeforeClass( $factory ) {
- self::createFixtures();
- self::createSettings();
- }
- public function setUp() {
- self::set_active_plugins();
- }
- public static function set_active_plugins() {
- $plugins = array (
- 'iconic-woo-delivery-slots-premium/iconic-woo-delivery-slots.php',
- 'posts-to-posts/posts-to-posts.php',
- 'woocommerce/woocommerce.php'
- );
- update_option('active_plugins', $plugins);
- }
- /**
- * Warehouses fixtures
- */
- public static function createFixtures() {
- // [...]
- }
- /**
- * Create timeslots
- */
- public static function createSettings() {
- $settings = array (
- // [...]
- );
- update_option( 'iconic_private_plugin_settings', $settings );
- global $iconic_private_plugin;
- $iconic_private_plugin->settings = $settings;
- }
- /**
- * Test for custom_function.
- */
- public function test_custom_function() {
- global $my_custom_plugin, $iconic_private_plugin;
- print_r($iconic_private_plugin);
- // Class properties are empty, since construct method stop at WooCommerce activation check.
- $this->assertTrue(true);
- }
- }
Add Comment
Please, Sign In to add comment