<?php
/**
 * PHPUnit bootstrap file for Wiaas plugin
 *
 * @package Wiaas
 */


# Folder where wordpress testing library is installed
$_tests_dir = '/tmp/wordpress-tests-lib';

if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
	echo "Could not find $_tests_dir/includes/functions.php, have you run bin/setup.sh ?" . PHP_EOL;
	exit( 1 );
}

# Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';

#load setup
tests_add_filter( 'muplugins_loaded', 'load_wiaas_test_setup' );

tests_add_filter( 'pre_option_active_plugins', 'load_active_plugins_list');

# Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';

# Require Wiaas Unit Test case class
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/wiaas-unit-test-case.php';
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/wiaas-api-unit-test-case.php';

function load_active_plugins_list() {
	return array(
		'woocommerce/woocommerce.php',
		'woocommerce-product-bundles/woocommerce-product-bundles.php',
		'woocommerce-jetpack/woocommerce-jetpack.php',
		'jwt-authentication-for-wp-rest-api/jwt-auth.php',
		'gravityforms/gravityforms.php',
		'gravityflow/gravityflow.php',
		'groups/groups.php',
		'wp-user-groups/wp-user-groups.php',
		'wiaas/wiaas.php'
	);
}

function load_wiaas_test_setup() {

	# Activate plugins needed for testing
	require_once '/tmp/wiaas-backend-test/app/plugins/woocommerce/woocommerce.php';

	require_once '/tmp/wiaas-backend-test/app/plugins/woocommerce-product-bundles/woocommerce-product-bundles.php';

	require_once '/tmp/wiaas-backend-test/app/plugins/gravityforms/gravityforms.php';

	require_once '/tmp/wiaas-backend-test/app/plugins/gravityflow/gravityflow.php';

	require_once '/tmp/wiaas-backend-test/app/plugins/groups/groups.php';

	require_once '/tmp/wiaas-backend-test/app/plugins/wp-user-groups/wp-user-groups.php';
	_wp_user_groups();

	require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/wiaas.php';


	# Require classes needed for db updates
	require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/class-wiaas-db-update.php';
	require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/db-updates/wiaas-db-update-general.php';
}
