function test_register_mock_addon_success()
 {
     $this->_pretend_addon_hook_time();
     $this->assertArrayDoesNotContain('EEM_Mock', EE_Registry::instance()->non_abstract_db_models);
     $this->assertArrayDoesNotContain('EEM_Mock', EE_Registry::instance()->models);
     //register it for realz
     EE_Register_Model::register($this->_model_group, $this->_reg_args);
     EE_System::instance()->load_core_configuration();
     $this->assertArrayContains('EEM_Mock', EE_Registry::instance()->non_abstract_db_models);
     $this->assertArrayContains('EEM_Mock', EE_Registry::instance()->models);
     //now deregister it
     EE_Register_Model::deregister($this->_model_group);
     EE_System::instance()->load_core_configuration();
     $this->assertArrayDoesNotContain('EEM_Mock', EE_Registry::instance()->non_abstract_db_models);
     $this->assertArrayDoesNotContain('EEM_Mock', EE_Registry::instance()->models);
 }
 /**
  * This redirects to the about EE page after activation
  * @return void
  */
 public function redirect_to_about_ee()
 {
     $notices = EE_Error::get_notices(FALSE);
     //if current user is an admin and it's not an ajax request
     if ($this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') && !(defined('DOING_AJAX') && DOING_AJAX) && !isset($notices['errors'])) {
         $query_params = array('page' => 'espresso_about');
         if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
             $query_params['new_activation'] = TRUE;
         }
         if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
             $query_params['reactivation'] = TRUE;
         }
         $url = add_query_arg($query_params, admin_url('admin.php'));
         wp_safe_redirect($url);
         exit;
     }
 }
示例#3
0
 */
function espresso_load_error_handling()
{
    // load debugging tools
    if (WP_DEBUG === TRUE) {
        require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
        EEH_Debug_Tools::instance();
    }
    // load error handling
    if (is_readable(EE_CORE . 'EE_Error.core.php')) {
        require_once EE_CORE . 'EE_Error.core.php';
    } else {
        wp_die(__('The EE_Error core class could not be loaded.', 'event_espresso'));
    }
}
/**
 * 	espresso_load_required
 * 	given a class name and path, this function will load that file or throw an exception
 */
function espresso_load_required($classname, $full_path_to_file)
{
    espresso_load_error_handling();
    if (is_readable($full_path_to_file)) {
        require_once $full_path_to_file;
    } else {
        throw new EE_Error(sprintf(__('The %s class file could not be located or is not readable due to file permissions.', 'event_espresso'), $classname));
    }
}
espresso_load_required('EE_System', EE_CORE . 'EE_System.core.php');
EE_System::instance();
 public function tearDown()
 {
     if (isset($this->_addon_name) && isset(EE_Registry::instance()->addons->EE_New_Addon)) {
         $main_file_path_before_deregistration = EE_Registry::instance()->addons->EE_New_Addon->get_main_plugin_file_basename();
         EE_Register_Addon::deregister($this->_addon_name);
         try {
             EE_Registry::instance()->addons->EE_New_Addon;
             $this->fail('EE_New_Addon is still registered. Deregister failed');
         } catch (PHPUnit_Framework_Error_Notice $e) {
             $this->assertEquals(EE_UnitTestCase::error_code_undefined_property, $e->getCode());
         }
         //verify the deactvation hook was removed
         $this->assertFalse(has_action('deactivate_' . $main_file_path_before_deregistration));
         //verify the models were deregistered
         EE_System::instance()->load_core_configuration();
         $this->assertArrayDoesNotContain('EEM_New_Addon_Thing', EE_Registry::instance()->non_abstract_db_models);
         $this->assertArrayDoesNotContain('EEM_New_Addon_Thing', EE_Registry::instance()->models);
         EE_Registry::instance()->reset_model('Attendee');
         //verify that the model and class extensions have been removed
         $this->assertFalse($this->_class_has_been_extended());
         $this->assertFalse($this->_model_has_been_extended());
     }
     //verify DMSs deregistered
     $DMSs_available = EE_Data_Migration_Manager::reset()->get_all_data_migration_scripts_available();
     $this->assertArrayNotHasKey('EE_DMS_New_Addon_1_0_0', $DMSs_available);
     $this->_stop_pretending_addon_hook_time();
     $this->_stop_pretending_after_plugin_activation();
     remove_all_filters('AHEE__EE_System__load_espresso_addons');
     parent::tearDown();
 }
 /**
  * Verifies the EE addons' database is up-to-date and records that we've done it on
  * EEM_Base::$_db_verification_level
  * @param $wpdb_method
  * @param $arguments_to_provide
  * @return string
  */
 private function _verify_addons_db($wpdb_method, $arguments_to_provide)
 {
     /** @type WPDB $wpdb */
     global $wpdb;
     //ok remember that we've already attempted fixing the addons dbs, in case the problem persists
     EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
     $error_message = sprintf(__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), $wpdb->last_error, $wpdb_method, json_encode($arguments_to_provide));
     EE_System::instance()->initialize_addons();
     return $error_message;
 }
 /**
  * Gets the request type for the plugin (core or addon) that corresponds to this DMS
  * @return int one of EE_System::_req_type_* constants
  * @throws EE_Error
  */
 private function _get_req_type_for_plugin_corresponding_to_this_dms()
 {
     if ($this->slug() == 'Core') {
         return EE_System::instance()->detect_req_type();
     } else {
         //it must be for an addon
         $addon_name = $this->slug();
         if (EE_Registry::instance()->get_addon_by_name($addon_name)) {
             return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type();
         } else {
             throw new EE_Error(sprintf(__("The DMS slug '%s' should correspond to the addon's name, which should also be '%s', but no such addon was registered. These are the registered addons' names: %s", "event_espresso"), $this->slug(), $addon_name, implode(",", array_keys(EE_Registry::instance()->get_addons_by_name()))));
         }
     }
 }
 /**
  * Resets the entire EE4 database.
  * Currently basically only sets up ee4 database for a fresh install- doesn't
  * actually clean out the old wp options, or cpts (although does erase old ee table data)
  * @param boolean $nuke_old_ee4_data controls whether or not we
  * destroy the old ee4 data, or just try initializing ee4 default data
  */
 public function _reset_db($nuke_old_ee4_data = TRUE)
 {
     EE_Registry::instance()->load_helper('Activation');
     EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
     if ($nuke_old_ee4_data) {
         EEH_Activation::delete_all_espresso_cpt_data();
         EEH_Activation::delete_all_espresso_tables_and_data(FALSE);
         EEH_Activation::remove_cron_tasks();
     }
     //make sure when we reset the registry's config that it
     //switches to using the new singleton
     EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(TRUE);
     EE_System::instance()->initialize_db_if_no_migrations_required(TRUE);
     EE_System::instance()->redirect_to_about_ee();
 }
 /**
  * Resets the entire EE4 database.
  * Currently basically only sets up ee4 database for a fresh install- doesn't
  * actually clean out the old wp options, or cpts (although does erase old ee table data)
  * @param boolean $nuke_old_ee4_data controls whether or not we
  * destroy the old ee4 data, or just try initializing ee4 default data
  */
 public function _reset_db($nuke_old_ee4_data = TRUE)
 {
     EE_Registry::instance()->load_helper('Activation');
     EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
     if ($nuke_old_ee4_data) {
         EEH_Activation::delete_all_espresso_cpt_data();
         EEH_Activation::delete_all_espresso_tables_and_data(FALSE);
     }
     EE_System::instance()->initialize_db_if_no_migrations_required();
     EE_System::instance()->redirect_to_about_ee();
 }
 /**
  * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon
  * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is
  * in the queue, calls EE_System::initialize_db_if_no_migrations_required().
  */
 public function initialize_db_for_enqueued_ee_plugins()
 {
     //		EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' );
     $queue = $this->get_db_initialization_queue();
     foreach ($queue as $plugin_slug) {
         $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug);
         if (!$most_up_to_date_dms) {
             //if there is NO DMS for this plugin, obviously there's no schema to verify anyways
             $verify_db = false;
         } else {
             $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms);
             $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to);
         }
         if ($plugin_slug == 'Core') {
             EE_System::instance()->initialize_db_if_no_migrations_required(false, $verify_db);
         } else {
             //just loop through the addons to make sure their database is setup
             foreach (EE_Registry::instance()->addons as $addon) {
                 if ($addon->name() == $plugin_slug) {
                     $addon->initialize_db_if_no_migrations_required($verify_db);
                     break;
                 }
             }
         }
     }
     //		EEH_Debug_Tools::instance()->stop_timer( 'initialize_db_for_enqueued_ee_plugins' );
     //		EEH_Debug_Tools::instance()->show_times();
     //because we just initialized the DBs for the enqueued ee plugins
     //we don't need to keep remembering which ones needed to be initialized
     delete_option(self::db_init_queue_option_name);
 }
 /**
  * @group 8154
  */
 function test__new_version_is_higher()
 {
     $class = new ReflectionClass("EE_System");
     $method = $class->getMethod("_new_version_is_higher");
     $method->setAccessible(true);
     $current_version = '4.7.0.rc.000';
     $activation_history = array($current_version => array('2015-03-12 04:53:12'), '3.1.37.1.P' => array(0 => 'unknown-date'));
     $this->assertEquals(0, $method->invoke(EE_System::instance(), $activation_history, $current_version));
     $this->assertEquals(1, $method->invoke(EE_System::instance(), $activation_history, '4.8.0.rc.000'));
     $this->assertEquals(-1, $method->invoke(EE_System::instance(), $activation_history, '4.4.0.rc.000'));
     $this->assertEquals(1, $method->invoke(EE_System::instance(), array(), '4.8.0.rc.000'));
 }
 /**
  * tests that we're correctly detecting activation or upgrades in registered
  * addons.
  * @group agg
  */
 function test_detect_activations_or_upgrades__new_install_on_core_and_addon_simultaneously()
 {
     ob_start();
     error_log('message taht shouldnt be outputte dbut is');
     ob_end_clean();
     global $wp_actions, $wpdb;
     //pretend core was just activated
     delete_option('espresso_db_update');
     update_option('ee_espresso_activation', TRUE);
     delete_option('ee_pers_admin_notices');
     //its activation history wp option shouldn't exist
     $this->assertWPOptionDoesNotExist($this->_addon->get_activation_history_option_name());
     //and it also shouldn't be in the current db state
     $current_db_state = get_option(EE_Data_Migration_Manager::current_database_state);
     //just for assurance, make sure New Addon is the only existing addon
     $this->assertArrayNotHasKey($this->_addon_name, $current_db_state);
     $times_addon_new_install_hook_fired = isset($wp_actions["AHEE__{$this->_addon_classname}__new_install"]) ? $wp_actions["AHEE__{$this->_addon_classname}__new_install"] : 0;
     $times_core_new_install_hook_fired = isset($wp_actions['AHEE__EE_System__detect_if_activation_or_upgrade__new_activation']) ? $wp_actions['AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'] : 0;
     //set the activator option
     update_option($this->_addon->get_activation_indicator_option_name(), TRUE);
     $this->assertWPOptionExists($this->_addon->get_activation_indicator_option_name());
     $this->assertTableDoesNotExist('esp_new_addon_thing');
     EE_System::reset();
     $this->assertEquals(EE_System::req_type_new_activation, EE_System::instance()->detect_req_type());
     $this->assertEquals(EE_System::req_type_new_activation, $this->_addon->detect_req_type());
     $this->assertEquals($times_addon_new_install_hook_fired + 1, $wp_actions["AHEE__{$this->_addon_classname}__new_install"]);
     $this->assertEquals($times_core_new_install_hook_fired + 1, $wp_actions['AHEE__EE_System__detect_if_activation_or_upgrade__new_activation']);
     $this->assertWPOptionDoesNotExist($this->_addon->get_activation_indicator_option_name());
     $this->assertWPOptionDoesNotExist('ee_espresso_activation');
     $this->assertTableExists('esp_new_addon_thing');
     //verify we haven't remarked that there we tried adding a duplicate table
     $notices = get_option('ee_pers_admin_notices', array());
     $this->assertArrayNotHasKey('bad_table_' . $wpdb->prefix . 'esp_new_addon_thing_detected', $notices);
     //double-check that when we intentionally try to add a table we just asserted exists
     //that the warning gets sent out
     global $track_it;
     $track_it = TRUE;
     try {
         EEH_Activation::create_table('esp_new_addon_thing', 'BORKED SQL', 'ENGINE=MyISAM ', TRUE);
         $this->fail('Borked SQL didnt\'t cause EEH_Activation::create_table to throw an EE_Error. It should have');
     } catch (EE_Error $e) {
         $this->assertTrue(TRUE);
     }
 }
 /**
  * note this should be moved to the system tests folder.
  */
 function test_system_initialization()
 {
     $EE_SYS = EE_System::instance();
     $this->assertTrue($EE_SYS instanceof EE_System);
 }
 /**
  * Checks if there was a version change or something that merits invalidating the cached
  * route data. If so, invalidates the cached route data so that it gets refreshed
  * next time the WP API is used
  */
 public static function invalidate_cached_route_data_on_version_change()
 {
     if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) {
         EED_Core_Rest_Api::invalidate_cached_route_data();
     }
     foreach (EE_Registry::instance()->addons as $addon) {
         if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) {
             EED_Core_Rest_Api::invalidate_cached_route_data();
         }
     }
 }
/**
 * 	espresso_plugin_deactivation
 */
function espresso_plugin_deactivation()
{
    if (EE_System::instance()->minimum_php_version_required()) {
        espresso_load_required('EEH_Activation', EE_HELPERS . 'EEH_Activation.helper.php');
        EEH_Activation::plugin_deactivation();
    }
}