Guest User

Untitled

a guest
Feb 7th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. /**
  2. * Constructor
  3. */
  4. public function __construct() {
  5.  
  6. if ( ! Iconic_WDS_Core_Helpers::is_plugin_active( 'woocommerce/woocommerce.php' ) && ! Iconic_WDS_Core_Helpers::is_plugin_active( 'woocommerce-old/woocommerce.php' ) ) {
  7. return;
  8. // It stops right here!!!
  9. }
  10.  
  11. }
  12.  
  13. install_dependencies() {
  14. WP_SITE_URL="http://localhost:8080"
  15. WP_PLUGIN_DIR=$(pwd)
  16. WP_DB_DATA="$WP_PLUGIN_DIR/tests/data/db.sql"
  17.  
  18. cd "$WP_CORE_DIR"
  19. curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  20. php wp-cli.phar core config --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=$DB_HOST --dbprefix=wptests_
  21. php wp-cli.phar db import $WP_DB_DATA
  22. php wp-cli.phar search-replace "http://local.wordpress.test" "$WP_SITE_URL"
  23. php wp-cli.phar theme install twentyseventeen --activate
  24. php wp-cli.phar plugin install https://downloads.wordpress.org/plugin/woocommerce.${WC_VERSION}.zip --activate
  25. php wp-cli.phar plugin install https://downloads.wordpress.org/plugin/posts-to-posts.${P2P_VERSION}.zip --activate
  26. php wp-cli.phar plugin install $WP_PLUGIN_DIR/plugins/iconic-private-plugin.zip --activate
  27. php wp-cli.phar plugin list
  28. }
  29.  
  30. /**
  31. * Setup the unit testing environment.
  32. */
  33. public function __construct() {
  34. // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions
  35. ini_set( 'display_errors', 'on' );
  36. error_reporting( E_ALL );
  37. // phpcs:enable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions
  38.  
  39. // Ensure server variable is set for WP email functions.
  40. // phpcs:disable WordPress.VIP.SuperGlobalInputUsage.AccessDetected
  41. if ( ! isset( $_SERVER['SERVER_NAME'] ) ) {
  42. $_SERVER['SERVER_NAME'] = 'localhost';
  43. }
  44. // phpcs:enable WordPress.VIP.SuperGlobalInputUsage.AccessDetected
  45.  
  46. $this->tests_dir = dirname( __FILE__ );
  47. $this->plugin_dir = dirname( $this->tests_dir );
  48. $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : rtrim( sys_get_temp_dir(), '/\' ) . '/wordpress-tests-lib';
  49.  
  50. // load test function so tests_add_filter() is available.
  51. require_once $this->wp_tests_dir . '/includes/functions.php';
  52.  
  53. // load Dependencies.
  54. tests_add_filter( 'muplugins_loaded', array( $this, 'my_custom_plugin_manually_load_plugin' ) );
  55.  
  56. // load the WP testing environment.
  57. require_once $this->wp_tests_dir . '/includes/bootstrap.php';
  58. }
  59.  
  60. /**
  61. * Load Dependencies
  62. */
  63. public function my_custom_plugin_manually_load_plugin() {
  64. $this->plugins_dir = ABSPATH . str_replace( site_url() . '/', '', plugins_url() ) . '/';
  65.  
  66. // Load dependencies.
  67. require_once $this->plugins_dir . 'woocommerce/woocommerce.php';
  68. require_once $this->plugins_dir . 'iconic/iconic-private-plugin.php';
  69.  
  70. // Load plugin.
  71. require_once $this->plugin_dir . '/my-custom-plugin.php';
  72.  
  73. global $my_custom_plugin;
  74. $my_custom_plugin = new My_Custom_Plugin_Class();
  75. }
  76.  
  77. <?php
  78. /**
  79. * Sql test case.
  80. */
  81. class SqlTest extends WP_UnitTestCase {
  82.  
  83. /**
  84. * Set up fixtures before class for all tests in SqlTest Class.
  85. *
  86. * @param object $factory passed by WP_UnitTestCase.
  87. */
  88. public static function wpSetUpBeforeClass( $factory ) {
  89. self::createFixtures();
  90. self::createSettings();
  91. }
  92.  
  93. public function setUp() {
  94. self::set_active_plugins();
  95. }
  96.  
  97. public static function set_active_plugins() {
  98. $plugins = array (
  99. 'iconic-woo-delivery-slots-premium/iconic-woo-delivery-slots.php',
  100. 'posts-to-posts/posts-to-posts.php',
  101. 'woocommerce/woocommerce.php'
  102. );
  103.  
  104. update_option('active_plugins', $plugins);
  105. }
  106.  
  107. /**
  108. * Warehouses fixtures
  109. */
  110. public static function createFixtures() {
  111. // [...]
  112. }
  113.  
  114. /**
  115. * Create timeslots
  116. */
  117. public static function createSettings() {
  118. $settings = array (
  119. // [...]
  120. );
  121.  
  122. update_option( 'iconic_private_plugin_settings', $settings );
  123. global $iconic_private_plugin;
  124. $iconic_private_plugin->settings = $settings;
  125. }
  126.  
  127. /**
  128. * Test for custom_function.
  129. */
  130. public function test_custom_function() {
  131. global $my_custom_plugin, $iconic_private_plugin;
  132.  
  133. print_r($iconic_private_plugin);
  134. // Class properties are empty, since construct method stop at WooCommerce activation check.
  135.  
  136. $this->assertTrue(true);
  137. }
  138.  
  139. }
Add Comment
Please, Sign In to add comment