Example #1
0
 /**
  *	Reset original function.
  */
 public static function resetFunction($function)
 {
     $originalFunction = "__original_{$function}";
     if (function_exists($originalFunction)) {
         runkit_function_remove($function);
         runkit_function_rename($originalFunction, $function);
     }
 }
 /**
  * Disable
  *
  * @return \MockFunction
  */
 public function disable()
 {
     if ($this->active) {
         $this->active = false;
         runkit_function_remove($this->functionName);
         runkit_function_rename($this->functionAlias, $this->functionName);
     }
     return $this;
 }
Example #3
0
 /**
  * Restore
  *
  * @return \MockFunction
  */
 public function restore()
 {
     if (!$this->_mock) {
         return $this;
     }
     $this->_mock = false;
     runkit_function_remove($this->_function_name);
     runkit_function_rename($this->_function_alias, $this->_function_name);
     return $this;
 }
Example #4
0
 public function tearDown()
 {
     if (function_exists('TEST_SAVED_file_get_contents')) {
         runkit_function_remove('file_get_contents');
         runkit_function_rename('TEST_SAVED_file_get_contents', 'file_get_contents');
     }
     if (function_exists('TEST_SAVED_stream_context_create')) {
         runkit_function_remove('stream_context_create');
         runkit_function_rename('TEST_SAVED_stream_context_create', 'stream_context_create');
     }
     self::$fgcReturn = '{}';
 }
Example #5
0
 /**
  *    Removes the mock function implementation
  *    @access public
  */
 function restore()
 {
     runkit_function_remove($this->_function) or trigger_error('Error removing mock function', E_USER_ERROR);
 }
Example #6
0
 public function testConvertSID2StrNoBCMath()
 {
     if (function_exists('\\bcadd')) {
         $removed = false;
         if (function_exists('runkit_function_remove')) {
             $removed = !runkit_function_remove('\\bcadd');
         }
         if (!$removed) {
             $this->markTestSkipped('bcadd could not be removed for ' . 'testing without bcmath');
         }
     }
     list($lw, $con, $um) = $this->getConnecterAndLdapMock();
     $access = new Access($con, $lw, $um);
     $sidBinary = file_get_contents(__DIR__ . '/data/sid.dat');
     $sidExpected = '';
     $this->assertSame($sidExpected, $access->convertSID2Str($sidBinary));
 }
Example #7
0
 /**
  * @param string $name
  *
  * @return boolean
  */
 public function removeFunction($name)
 {
     if (!function_exists('runkit_function_remove')) {
         return false;
     }
     return runkit_function_remove($name);
 }
Example #8
0
 protected function _reverseFunctionCallRedirection()
 {
     $newOrigFuncName = $this->_functionName . $this->_origFuncSuffix;
     $spyFuncName = $this->_functionName . $this->_spyFuncSuffix;
     runkit_function_remove($spyFuncName);
     //keep memory address of function to prevent seg fault
     runkit_function_redefine($this->_functionName, '', '$args = func_get_args();
         return call_user_func_array("' . $newOrigFuncName . '", $args);');
 }
 public function __construct()
 {
     $this->storage = new WOOCS_STORAGE(get_option('woocs_storage', 'session'));
     $this->init_no_cents();
     if (!defined('DOING_AJAX')) {
         //we need it if shop uses cache plugin, in such way prices will be redraw by AJAX
         $this->shop_is_cached = get_option('woocs_shop_is_cached', 0);
     }
     //+++
     $currencies = $this->get_currencies();
     if (!empty($currencies) and is_array($currencies)) {
         foreach ($currencies as $key => $currency) {
             if ($currency['is_etalon']) {
                 $this->default_currency = $key;
                 break;
             }
         }
     }
     //+++
     if (!$this->storage->is_isset('woocs_first_unique_visit')) {
         $this->storage->set_val('woocs_first_unique_visit', 0);
     }
     $this->is_multiple_allowed = get_option('woocs_is_multiple_allowed', 0);
     $this->rate_auto_update = 'no';
     //$this->decimal_sep = wp_specialchars_decode(stripslashes(get_option('woocommerce_price_decimal_sep')), ENT_QUOTES);
     //$this->thousands_sep = wp_specialchars_decode(stripslashes(get_option('woocommerce_price_thousand_sep')), ENT_QUOTES);
     //+++
     $this->currency_positions = array('left', 'right', 'left_space', 'right_space');
     $this->init_currency_symbols();
     //+++
     $is_first_activation = (int) get_option('woocs_first_activation', 0);
     if (!$is_first_activation) {
         update_option('woocs_first_activation', 1);
         update_option('woocs_drop_down_view', 'ddslick');
         update_option('woocs_currencies_aggregator', 'yahoo');
         update_option('woocs_welcome_currency', $this->default_currency);
         update_option('woocs_is_multiple_allowed', 0);
         update_option('woocs_show_flags', 1);
         update_option('woocs_show_money_signs', 1);
         update_option('woocs_customer_signs', '');
         update_option('woocs_customer_price_format', '');
         update_option('woocs_currencies_rate_auto_update', 'no');
         update_option('woocs_use_curl', 0);
         update_option('woocs_storage', 'session');
         update_option('woocs_geo_rules', '');
         update_option('woocs_use_geo_rules', 0);
         update_option('woocs_hide_cents', '');
         update_option('woocs_price_info', 0);
         update_option('woocs_no_cents', '');
         update_option('woocs_restrike_on_checkout_page', 0);
         update_option('woocs_shop_is_cached', 0);
     }
     //+++
     //simple checkout itercept
     if (isset($_REQUEST['action']) and $_REQUEST['action'] == 'woocommerce_checkout') {
         //$this->storage->set_val('woocs_first_unique_visit', 0);
         $_REQUEST['woocommerce-currency-switcher'] = $this->storage->get_val('woocs_current_currency');
         $this->current_currency = $_REQUEST['woocommerce-currency-switcher'];
         $_REQUEST['woocs_in_order_currency'] = $this->current_currency;
     }
     //paypal query itercept
     if (isset($_REQUEST['mc_currency']) and !empty($_REQUEST['mc_currency'])) {
         if (array_key_exists($_REQUEST['mc_currency'], $currencies)) {
             //$this->storage->set_val('woocs_first_unique_visit', 0);
             $_REQUEST['woocommerce-currency-switcher'] = $_REQUEST['mc_currency'];
         }
     }
     //WELCOME USER CURRENCY ACTIVATION
     if ($this->storage->get_val('woocs_first_unique_visit') == 0) {
         //$this->storage->set_val('woocs_first_unique_visit', 0);
         $this->is_first_unique_visit = true;
         $this->storage->set_val('woocs_current_currency', $this->get_welcome_currency());
         $file_path = WP_PLUGIN_DIR . '/woocommerce/includes/class-wc-geolocation.php';
         if (file_exists($file_path)) {
             $wc_clean_is_defined = true;
             if (function_exists('runkit_function_remove')) {
                 if (!function_exists('wc_clean')) {
                     $wc_clean_is_defined = false;
                     function wc_clean($var)
                     {
                         return sanitize_text_field($var);
                     }
                 }
             }
             //***
             include_once $file_path;
             $this->init_geo_currency();
             //***
             if (function_exists('runkit_function_remove') and !$wc_clean_is_defined) {
                 runkit_function_remove('wc_clean');
             }
         }
     }
     //+++
     if (isset($_REQUEST['woocommerce-currency-switcher'])) {
         if (array_key_exists($_REQUEST['woocommerce-currency-switcher'], $currencies)) {
             $this->storage->set_val('woocs_current_currency', $_REQUEST['woocommerce-currency-switcher']);
         } else {
             $this->storage->set_val('woocs_current_currency', $this->default_currency);
         }
     }
     //+++
     //*** check currency in browser address
     if (isset($_GET['currency']) and !empty($_GET['currency'])) {
         if (array_key_exists(strtoupper($_GET['currency']), $currencies)) {
             $this->storage->set_val('woocs_current_currency', strtoupper($_GET['currency']));
         }
     }
     //+++
     if ($this->storage->is_isset('woocs_current_currency')) {
         $this->current_currency = $this->storage->get_val('woocs_current_currency');
     } else {
         $this->current_currency = $this->default_currency;
     }
     $this->storage->set_val('woocs_default_currency', $this->default_currency);
     //+++
     //if we want to be paid in the basic currency - not multiple mode
     //old code for woocomerce < 2.4, left for comatibility with old versions of woocommerce
     if (isset($_REQUEST['action']) and !$this->is_multiple_allowed) {
         if ($_REQUEST['action'] == 'woocommerce_update_order_review') {
             $this->reset_currency();
         }
     }
     //+++ FILTERS
     add_filter('woocommerce_paypal_args', array($this, 'apply_conversion'));
     add_filter('woocommerce_paypal_supported_currencies', array($this, 'enable_custom_currency'), 9999);
     add_filter('woocommerce_currency_symbol', array($this, 'woocommerce_currency_symbol'), 9999);
     add_filter('woocommerce_currency', array($this, 'get_woocommerce_currency'), 9999);
     //add_filter('woocommerce_reports_get_order_report_data', array($this, 'woocommerce_reports_get_order_report_data'), 9999, 2);
     //main recount hook
     if ($this->is_multiple_allowed) {
         //add_filter('woocommerce_get_price', array($this, 'raw_woocommerce_price_memo'), 9999, 2);
         add_filter('woocommerce_get_price', array($this, 'raw_woocommerce_price'), 9999);
     } else {
         add_filter('raw_woocommerce_price', array($this, 'raw_woocommerce_price'), 9999);
     }
     //+++
     if ($this->is_multiple_allowed) {
         //wp-content\plugins\woocommerce\includes\abstracts\abstract-wc-product.php #795
         /* Alda: Had to removed the filter as it is redundant with the woocommerce_get_price hook */
         //I back it 07-01-2016 because of it is really need.
         //Comment next 2 hooks if double recount is for sale price http://c2n.me/3sCQFkX
         add_filter('woocommerce_get_regular_price', array($this, 'raw_woocommerce_price'), 9999);
         add_filter('woocommerce_get_sale_price', array($this, 'raw_woocommerce_price'), 9999);
         //***
         add_filter('woocommerce_get_variation_regular_price', array($this, 'raw_woocommerce_price'), 9999);
         add_filter('woocommerce_get_variation_sale_price', array($this, 'raw_woocommerce_price'), 9999);
         add_filter('woocommerce_variation_prices', array($this, 'woocommerce_variation_prices'), 9999, 1);
         //***
         //add_filter('woocommerce_get_variation_price', array($this, 'raw_woocommerce_price'), 9999, 1);
         add_filter('woocommerce_variation_prices_price', array($this, 'woocommerce_variation_prices'), 9999, 1);
         add_filter('woocommerce_variation_prices_regular_price', array($this, 'woocommerce_variation_prices'), 9999, 1);
         add_filter('woocommerce_variation_prices_sale_price', array($this, 'woocommerce_variation_prices'), 9999, 1);
         add_filter('woocommerce_get_variation_prices_hash', array($this, 'woocommerce_get_variation_prices_hash'), 9999, 3);
     }
     //***
     add_filter('woocommerce_price_format', array($this, 'woocommerce_price_format'), 9999);
     add_filter('woocommerce_thankyou_order_id', array($this, 'woocommerce_thankyou_order_id'), 9999);
     add_filter('woocommerce_before_resend_order_emails', array($this, 'woocommerce_before_resend_order_emails'), 9999);
     add_filter('woocommerce_email_actions', array($this, 'woocommerce_email_actions'), 9999);
     add_action('woocommerce_order_status_completed', array($this, 'woocommerce_order_status_completed'), 1);
     //add_filter('formatted_woocommerce_price', array($this, 'formatted_woocommerce_price'), 9999);
     add_filter('woocommerce_package_rates', array($this, 'woocommerce_package_rates'), 9999);
     add_filter('woocommerce_product_is_on_sale', array($this, 'woocommerce_product_is_on_sale'), 9999, 2);
     //for shop cart
     add_filter('woocommerce_cart_totals_order_total_html', array($this, 'woocommerce_cart_totals_order_total_html'), 10, 1);
     add_filter('wc_price_args', array($this, 'wc_price_args'), 9999);
     //for refreshing mini-cart widget
     add_filter('woocommerce_before_mini_cart', array($this, 'woocommerce_before_mini_cart'), 9999);
     add_filter('woocommerce_after_mini_cart', array($this, 'woocommerce_after_mini_cart'), 9999);
     //shipping
     add_filter('woocommerce_shipping_free_shipping_is_available', array($this, 'woocommerce_shipping_free_shipping_is_available'), 99, 2);
     //add_filter('woocommerce_update_shipping_method', array($this, 'woocommerce_update_shipping_method'), 1);
     //orders view on front
     //add_filter('woocommerce_view_order', array($this, 'woocommerce_view_order'), 1);
     add_action('woocommerce_get_order_currency', array($this, 'woocommerce_get_order_currency'), 1, 2);
     //add_filter('woocommerce_get_formatted_order_total', array($this, 'woocommerce_get_formatted_order_total'), 1, 2);
     //+++
     //+++ AJAX ACTIONS
     add_action('wp_ajax_woocs_save_etalon', array($this, 'save_etalon'));
     add_action('wp_ajax_woocs_get_rate', array($this, 'get_rate'));
     add_action('wp_ajax_woocs_convert_currency', array($this, 'woocs_convert_currency'));
     add_action('wp_ajax_nopriv_woocs_convert_currency', array($this, 'woocs_convert_currency'));
     add_action('wp_ajax_woocs_rates_current_currency', array($this, 'woocs_rates_current_currency'));
     add_action('wp_ajax_nopriv_woocs_rates_current_currency', array($this, 'woocs_rates_current_currency'));
     add_action('wp_ajax_woocs_get_products_price_html', array($this, 'woocs_get_products_price_html'));
     add_action('wp_ajax_nopriv_woocs_get_products_price_html', array($this, 'woocs_get_products_price_html'));
     add_action('wp_ajax_woocs_recalculate_order_data', array($this, 'woocs_recalculate_order_data'));
     //+++
     add_action('woocommerce_settings_tabs_array', array($this, 'woocommerce_settings_tabs_array'), 9999);
     add_action('woocommerce_settings_tabs_woocs', array($this, 'print_plugin_options'), 9999);
     //+++
     add_action('widgets_init', array($this, 'widgets_init'));
     add_action('wp_head', array($this, 'wp_head'), 1);
     add_action('wp_footer', array($this, 'wp_footer'), 9999);
     add_action('body_class', array($this, 'body_class'), 9999);
     //***
     add_action('save_post', array($this, 'save_post'), 1);
     add_action('admin_head', array($this, 'admin_head'), 1);
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
     add_action('admin_init', array($this, 'admin_init'), 1);
     //price formatting on front ***********
     add_action('woocommerce_price_html', array($this, 'woocommerce_price_html'), 1, 2);
     add_action('woocommerce_variable_price_html', array($this, 'woocommerce_price_html'), 1, 2);
     add_action('woocommerce_variable_sale_price_html', array($this, 'woocommerce_price_html'), 1, 2);
     add_action('woocommerce_sale_price_html', array($this, 'woocommerce_price_html'), 1, 2);
     add_action('woocommerce_grouped_price_html', array($this, 'woocommerce_price_html'), 1, 2);
     //*** additional
     //wpo_wcpdf_order_number is -> compatibility for https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/stats/
     add_action('wpo_wcpdf_order_number', array($this, 'wpo_wcpdf_order_number'), 1);
     add_action('woocs_exchange_value', array($this, 'woocs_exchange_value'), 1);
     //add_action('wcml_raw_price_amount', array($this, 'wcml_raw_price_amount'), 1);
     //for coupons
     add_filter('woocommerce_coupon_get_discount_amount', array($this, 'woocommerce_coupon_get_discount_amount'), 9999, 5);
     //*************************************
     add_shortcode('woocs', array($this, 'woocs_shortcode'));
     add_shortcode('woocs_get_sign_rate', array($this, 'get_sign_rate'));
     add_shortcode('woocs_converter', array($this, 'woocs_converter'));
     add_shortcode('woocs_rates', array($this, 'woocs_rates'));
     add_shortcode('woocs_show_current_currency', array($this, 'woocs_show_current_currency'));
     add_shortcode('woocs_show_custom_price', array($this, 'woocs_show_custom_price'));
     if ($this->is_multiple_allowed) {
         add_action('the_post', array($this, 'the_post'), 1);
         add_action('load-post.php', array($this, 'admin_action_post'), 1);
     }
     //+++
     $this->storage->set_val('woocs_first_unique_visit', 1);
 }
Example #10
0
 /**
  * Unmock a PHP function.
  *
  * @param String $name Function name
  *
  * @return void
  */
 protected function unmock_function($name)
 {
     runkit_function_remove($name);
     runkit_function_rename($name . self::FUNCTION_ID, $name);
 }
Example #11
0
 /**
  * Clean-up function.
  *
  * Removes mocked function and restored the original was there is any.
  * Also removes the reference to the object from self::$instances.
  */
 public function restore()
 {
     if ($this->active) {
         runkit_function_remove($this->function_name);
         if (isset($this->restore_name)) {
             runkit_function_rename($this->restore_name, $this->function_name);
         }
         $this->active = false;
     }
     if (isset(self::$instances[$this->id])) {
         unset(self::$instances[$this->id]);
     }
 }
Example #12
0
 /**
  *	@author João Reis
  *	Para Servidor
  */
 function pararServidor()
 {
     // Comando para parar servidor
     # shell_exec("sudo tmux kill-session -t '".$this->Id."'");
     @(include "modulos/modulos.conf.php");
     @(include "../modulos/modulos.conf.php");
     #@include_once(__DIR__."/modulos/modulos.conf.php");
     $existe = false;
     $index = 1;
     $i = 0;
     if (isset($Vmodulos)) {
         $modulos = array();
         $modulos = $Vmodulos;
         foreach ($modulos as $modulo) {
             $i++;
             if ($modulo['tipoServidor'] == $this->getTipoServidor()) {
                 $existe = true;
                 $index = $i;
                 break;
             }
         }
         if ($existe) {
             if (function_exists('_pararServidor')) {
                 runkit_function_remove('_pararServidor');
             }
             @(include $modulos[$index]['dir']);
             @(include "../" . $modulos[$index]['dir']);
             if (isset($modulos)) {
                 return _pararServidor($this->Id);
             }
             return false;
         } else {
             return false;
         }
     }
 }
                 break;
             case JSON_ERROR_CTRL_CHAR:
                 throw new RuntimeException('Decoding failed: Unexpected control character found');
                 break;
             case JSON_ERROR_SYNTAX:
                 throw new RuntimeException('Decoding failed: Syntax error');
                 break;
             default:
                 throw new RuntimeException('Decoding error message: ' . json_last_error_msg());
                 break;
         }
         return null;
     }
 }
 runkit_function_copy('json_encode', '__json_encode__');
 runkit_function_remove('json_encode');
 if (!(function_exists('json_encode') || is_callable('json_encode'))) {
     function json_encode($value, $options = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
     {
         $encode = __json_encode__($value, $options);
         switch (json_last_error()) {
             case JSON_ERROR_NONE:
                 return $encode;
                 break;
             case JSON_ERROR_DEPTH:
                 throw new RuntimeException('Decoding failed: Maximum stack depth exceeded');
                 break;
             case JSON_ERROR_CTRL_CHAR:
                 throw new RuntimeException('Decoding failed: Unexpected control character found');
                 break;
             case JSON_ERROR_SYNTAX:
Example #14
0
 /**
  * Revert redefenition of the function
  *
  * @param string $function
  */
 public function revertRedefinedFunction($function)
 {
     $this->checkFunctionExists($function);
     $backupFunction = $this->getBackupName($function);
     try {
         $this->checkFunctionExists($backupFunction);
     } catch (PStub_RunkitAdapter_Exception $e) {
         throw new PStub_RunkitAdapter_Exception('Function ' . $function . ' was never redefined');
     }
     runkit_function_remove($function);
     runkit_function_rename($backupFunction, $function);
 }
Example #15
0
 public static function restoreFunction($functionName)
 {
     yTest_debugCC("restoreFunction {$functionName}");
     // [RS] runkit will crash if you try to call runkit_function_rename()
     $res = runkit_function_remove(strtolower($functionName));
     yTest_assert($res);
     $res = runkit_function_copy(strtolower(self::getOriginalFunctionName($functionName)), strtolower($functionName));
     yTest_assert($res);
     $res = runkit_function_remove(strtolower(self::getOriginalFunctionName($functionName)));
     yTest_assert($res);
 }
Example #16
0
 /**
  * Revert previously overridden function
  *
  * @param string $func
  */
 protected function runkitRevert($func)
 {
     $this->skipTestIfNoRunkit();
     if (!array_key_exists($func, self::$override_functions)) {
         throw new \RuntimeException("Function '{$func}' is not marked as mocked");
     }
     unset(self::$override_functions[$func]);
     \runkit_function_remove($func);
     \runkit_function_copy($func . self::BACKUP_SUFFIX, $func);
     \runkit_function_remove($func . self::BACKUP_SUFFIX);
 }
 protected function updateState($type, $id, $state)
 {
     $parts = explode('|', $id);
     switch ($type) {
         case self::STATIC_METHOD:
         case self::DYNAMIC_METHOD:
             $className = $parts[1];
             $methodName = $parts[2];
             $savedName = self::SAVED_PREFIX . $methodName;
             if ($state) {
                 // enable
                 is_callable("{$className}::{$methodName}");
                 $flags = RUNKIT_ACC_PUBLIC | ($type == self::STATIC_METHOD ? RUNKIT_ACC_STATIC : 0);
                 runkit_method_rename($className, $methodName, $savedName);
                 // save the original method
                 runkit_method_add($className, $methodName, '', $this->getExecuteCallCode($type, $id, $type === self::DYNAMIC_METHOD), $flags);
             } else {
                 // diable
                 runkit_method_remove($className, $methodName);
                 // remove the redefined instance
                 runkit_method_rename($className, $savedName, $methodName);
                 // restore the original
             }
             break;
         case self::GLOBAL_FUNCTION:
             $functionName = $parts[1];
             list($namespace, $baseName) = self::parseGlobalFunctionName($functionName);
             $functionName = $namespace . $baseName;
             $savedName = $namespace . self::SAVED_PREFIX . $baseName;
             if ($state) {
                 // enable
                 $tempName = "WikiaMockProxyTempFuncName";
                 // workaround for namespaces functions
                 runkit_function_rename($functionName, $savedName);
                 runkit_function_add($tempName, '', $this->getExecuteCallCode($type, $id));
                 runkit_function_rename($tempName, $functionName);
             } else {
                 // disable
                 runkit_function_remove($functionName);
                 // remove the redefined instance
                 runkit_function_rename($savedName, $functionName);
                 // restore the original
             }
             break;
     }
 }
 /**
  * Restore the original function
  */
 public function reset()
 {
     runkit_function_remove($this->funcName);
     runkit_function_rename($this->tmpFuncName, $this->funcName);
     MockFunctionContainer::unregister($this->funcName);
 }