From 08b814f9be5c02b6826c81ab1da8a6515f3a7b63 Mon Sep 17 00:00:00 2001 From: Champ Camba Date: Thu, 8 Jun 2017 22:18:57 +0800 Subject: [PATCH] Add tests bootstrap --- .travis.yml | 2 +- tests/php/bootstrap.php | 102 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tests/php/bootstrap.php diff --git a/.travis.yml b/.travis.yml index f032ac82..8e931e24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,4 +78,4 @@ notifications: email: - heychampsupertramp@gmail.com # Encrypted Slack notification address. - - secure: "WQdTdmYuifSW0hiJGXpQGKystMASC50QvxHlyUL5SM3h5GP8aCgeSsHuXvKPe3dT3Pffhk0dSHBfDtdWFwSHW/upURhg0vs4dm7+nxxvGZiTPzKcuAIjgvCoqWM7teyda/XqFGNSnv+XsT34uoyPhhFgd45T3oS+QQ3aNCruFak=" + #- secure: "WQdTdmYuifSW0hiJGXpQGKystMASC50QvxHlyUL5SM3h5GP8aCgeSsHuXvKPe3dT3Pffhk0dSHBfDtdWFwSHW/upURhg0vs4dm7+nxxvGZiTPzKcuAIjgvCoqWM7teyda/XqFGNSnv+XsT34uoyPhhFgd45T3oS+QQ3aNCruFak=" diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php new file mode 100644 index 00000000..b982621c --- /dev/null +++ b/tests/php/bootstrap.php @@ -0,0 +1,102 @@ +tests_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'tests'; + $this->includes_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'includes'; + $this->plugin_dir = dirname( dirname( dirname( $this->tests_dir ) ) ); + $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib'; + + // load test function so tests_add_filter() is available + require_once( $this->wp_tests_dir . '/includes/functions.php' ); + + // load UltimateMember + tests_add_filter( 'plugins_loaded', array( $this, 'load_plugin' ) ); + + // install UltimateMember + tests_add_filter( 'setup_theme', array( $this, 'install_plugin' ) ); + + // load the WP testing environment + require_once( $this->wp_tests_dir . '/includes/bootstrap.php' ); + + // load UltimateMember testing framework + $this->includes(); + } + + /** + * Load UltimateMember. + * + * @since 1.3.84 + */ + public function load_plugin() { + //require_once( $this->plugin_dir . '/index.php' ); + } + + /** + * Install UltimateMember after the test environment and UltimateMember have been loaded. + * + * @since 1.3.84 + */ + public function install_plugin() { + global $wp_version; + + // reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374 + if ( version_compare( $wp_version, '4.7.0' ) >= 0 ) { + $GLOBALS['wp_roles'] = new WP_Roles(); + } else { + $GLOBALS['wp_roles']->reinit(); + } + } + + /** + * Load UltimateMember-specific test cases and framework. + * + * @since 1.3.84 + */ + public function includes() { + // framework + //require_once( $this->includes_dir . '/factories/class-UltimateMember-factory.php' ); + //require_once( $this->includes_dir . '/class-UltimateMember-base-test.php' ); + } + + /** + * Get the single class instance. + * + * @since 1.3.84 + * @return UltimateMember_Unit_Tests_Bootstrap + */ + public static function instance() { + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + return self::$instance; + } +} +UltimateMember_Unit_Tests_Bootstrap::instance();