示例#1
0
 /**
  * 应用程序初始化
  * @access public
  * @return void
  */
 public static function init()
 {
     // 加载动态应用公共文件和配置
     load_ext_file(COMMON_PATH);
     // 日志目录转换为绝对路径 默认情况下存储到公共模块下面
     C('LOG_PATH', realpath(LOG_PATH) . '/Common/');
     // 定义当前请求的系统常量
     runkit_constant_redefine('NOW_TIME', $_SERVER['REQUEST_TIME']);
     runkit_constant_redefine('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']);
     runkit_constant_redefine('IS_GET', REQUEST_METHOD == 'GET' ? true : false);
     runkit_constant_redefine('IS_POST', REQUEST_METHOD == 'POST' ? true : false);
     runkit_constant_redefine('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false);
     runkit_constant_redefine('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false);
     // URL调度
     Dispatcher::dispatch();
     if (C('REQUEST_VARS_FILTER')) {
         // 全局安全过滤
         array_walk_recursive($_GET, 'think_filter');
         array_walk_recursive($_POST, 'think_filter');
         array_walk_recursive($_REQUEST, 'think_filter');
     }
     // URL调度结束标签
     Hook::listen('url_dispatch');
     runkit_constant_redefine('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' || !empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')]) ? true : false);
     // TMPL_EXCEPTION_FILE 改为绝对地址
     C('TMPL_EXCEPTION_FILE', realpath(C('TMPL_EXCEPTION_FILE')));
     return;
 }
示例#2
0
 /**
  * @using runkit pecl extension
  * if not define PMA_USR_OS, then define it as Win
  * if installed runkit, then constant will not change
  */
 public function testWhichCrlf()
 {
     $runkit = function_exists('runkit_constant_redefine');
     if ($runkit && defined('PMA_USR_OS')) {
         $pma_usr_os = PMA_USR_OS;
     }
     if (defined('PMA_USR_OS') && !$runkit) {
         if (PMA_USR_OS == 'Win') {
             $this->assertEquals("\r\n", PMA_whichCrlf());
         } else {
             $this->assertEquals("\n", PMA_whichCrlf());
         }
         $this->markTestIncomplete('Cannot redefine constant');
     } else {
         if ($runkit) {
             define('PMA_USR_OS', 'Linux');
             $this->assertEquals("\n", PMA_whichCrlf());
         }
         if ($runkit) {
             runkit_constant_redefine('PMA_USR_OS', 'Win');
         } else {
             define('PMA_USR_OS', 'Win');
         }
         $this->assertEquals("\r\n", PMA_whichCrlf());
     }
     if ($runkit) {
         if (isset($pma_usr_os)) {
             runkit_constant_redefine('PMA_USR_OS', 'Win');
         } else {
             runkit_constant_remove('PMA_USR_OS');
         }
     }
 }
示例#3
0
 /**
  * @param RunkitConstant $constant
  *
  * @return boolean
  */
 public function redefineConstant(\Runkit\RunkitConstant $constant)
 {
     if (!function_exists('runkit_constant_redefine')) {
         return false;
     }
     return runkit_constant_redefine($constant->getName(), $constant->getValue());
 }
示例#4
0
 /**
  *	Reset original definition.
  */
 public static function resetConstant($constant)
 {
     $originalConstant = "__ORIGINAL_{$constant}";
     if (defined($originalConstant)) {
         runkit_constant_redefine($constant, constant($originalConstant));
         runkit_constant_remove($originalConstant);
     }
 }
示例#5
0
文件: PathTest.php 项目: spol/path
 public function testGetImplementation()
 {
     $nativePathClass = strtoupper(substr(PHP_OS, 0, 3)) === "WIN" ? "Spol\\Path\\WindowsPath" : "Spol\\Path\\UnixPath";
     $this->assertInstanceOf($nativePathClass, Path::getImplementation());
     runkit_constant_redefine("Spol\\Path\\Path::OS", "WINNT");
     $this->assertInstanceOf("Spol\\Path\\WindowsPath", Path::getImplementation());
     runkit_constant_redefine("Spol\\Path\\Path::OS", "Darwin");
     $this->assertInstanceOf("Spol\\Path\\UnixPath", Path::getImplementation());
 }
 /**
  * @param string $constant
  * @param mixed $expected
  *
  * @return null
  */
 protected static function ensureConstant($constant, $expected)
 {
     if (defined($constant)) {
         $value = constant($constant);
         if ($value !== $expected) {
             if (extension_loaded('runkit')) {
                 if (!runkit_constant_redefine($constant, $expected)) {
                     self::markTestSkipped(sprintf("Failed to redefine constant %s to %s", $constant, $expected));
                 }
             } else {
                 self::markTestSkipped(sprintf("Skipping test because constant %s is %s instead of %s", $constant, $value, $expected));
             }
         }
     } else {
         define($constant, $expected);
     }
 }
示例#7
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  * @return void
  */
 protected function setUp()
 {
     // Drizzle does not support GIS data types
     if (!defined("PMA_DRIZZLE")) {
         define("PMA_DRIZZLE", false);
     } else {
         if (PMA_DRIZZLE) {
             //PMA_DRIZZLE is defined and PMA_DRIZZLE = true
             if (PMA_HAS_RUNKIT) {
                 runkit_constant_redefine("PMA_DRIZZLE", false);
             } else {
                 //Drizzle does not support GIS data types
                 $this->markTestSkipped("Drizzle does not support GIS data types");
             }
         }
     }
     //setting
     $GLOBALS['plugin_param'] = 'table';
     $GLOBALS['finished'] = false;
     $GLOBALS['read_limit'] = 100000000;
     $GLOBALS['offset'] = 0;
     $GLOBALS['cfg']['Server']['DisableIS'] = false;
     $GLOBALS['cfg']['ServerDefault'] = 0;
     $GLOBALS['cfg']['AllowUserDropDatabase'] = false;
     $GLOBALS['import_file'] = 'test/test_data/timezone.shp.zip';
     //Mock DBI
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $GLOBALS['dbi'] = $dbi;
     include_once 'libraries/plugins/import/ImportShp.class.php';
     $this->object = new ImportShp();
     /**
      * Load interface for zip extension.
      */
     include_once 'libraries/zip_extension.lib.php';
     $result = PMA_getZipContents($GLOBALS['import_file']);
     $GLOBALS['import_text'] = $result["data"];
     $GLOBALS['compression'] = 'application/zip';
     $GLOBALS['read_multiply'] = 10;
     $GLOBALS['import_type'] = 'ods';
     $GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
 }
 /**
  * Test for whichCrlf
  *
  * @return void
  *
  * @using runkit pecl extension
  * if not define PMA_USR_OS, then define it as Win
  * if installed runkit, then constant will not change
  */
 public function testWhichCrlf()
 {
     if (PMA_HAS_RUNKIT && defined('PMA_USR_OS')) {
         $pma_usr_os = PMA_USR_OS;
     }
     if (defined('PMA_USR_OS') && !PMA_HAS_RUNKIT) {
         if (PMA_USR_OS == 'Win') {
             $this->assertEquals("\r\n", PMA_Util::whichCrlf());
         } else {
             $this->assertEquals("\n", PMA_Util::whichCrlf());
         }
         $this->markTestIncomplete('Cannot redefine constant');
     } else {
         if (PMA_HAS_RUNKIT) {
             if (!defined('PMA_USR_OS')) {
                 define('PMA_USR_OS', 'Linux');
             } else {
                 runkit_constant_redefine('PMA_USR_OS', 'Linux');
             }
             $this->assertEquals("\n", PMA_Util::whichCrlf());
         }
         if (PMA_HAS_RUNKIT) {
             runkit_constant_redefine('PMA_USR_OS', 'Win');
         } else {
             define('PMA_USR_OS', 'Win');
         }
         $this->assertEquals("\r\n", PMA_Util::whichCrlf());
     }
     if (PMA_HAS_RUNKIT) {
         if (isset($pma_usr_os)) {
             runkit_constant_redefine('PMA_USR_OS', 'Win');
         } else {
             runkit_constant_remove('PMA_USR_OS');
         }
     }
 }
示例#9
0
 /**
  * Configures environment
  *
  * @return void
  */
 protected function setUp()
 {
     //we test:
     //1. without Runkit,  PMA_DRIZZLE = false;
     //2. with Runkit,  PMA_DRIZZLE = true;
     if (!defined("PMA_DRIZZLE")) {
         define("PMA_DRIZZLE", false);
     }
     parent::setUp();
     //RunKit
     if (PMA_HAS_RUNKIT) {
         runkit_constant_redefine("PMA_DRIZZLE", true);
     }
 }
示例#10
0
<?php

namespace Think\Upload\Driver\Bcs;

use Think\Upload\Driver\Bcs\BCS_MimeTypes;
use Think\Upload\Driver\Bcs\BCS_RequestCore;
use Think\Upload\Driver\Bcs\BCS_ResponseCore;
if (!defined('BCS_API_PATH')) {
    runkit_constant_redefine('BCS_API_PATH', dirname(__FILE__));
}
//AK 公钥
define('BCS_AK', '');
//SK 私钥
define('BCS_SK', '');
//superfile 每个object分片后缀
define('BCS_SUPERFILE_POSTFIX', '_bcs_superfile_');
//sdk superfile分片大小 ,单位 B(字节)
define('BCS_SUPERFILE_SLICE_SIZE', 1024 * 1024);
require_once BCS_API_PATH . '/requestcore.class.php';
require_once BCS_API_PATH . '/mimetypes.class.php';
/**
 * Default BCS Exception.
 */
class BCS_Exception extends \Exception
{
}
/**
 * BCS API
 */
class BaiduBCS
{
    /**
     * Test for PMA_getSqlQueriesForDisplayAndAddUser
     *
     * @return void
     */
    public function testPMAGetSqlQueriesForDisplayAndAddUser()
    {
        $restoreMySQLVersion = "PMANORESTORE";

        if (! PMA_HAS_RUNKIT) {
            $this->markTestSkipped(
                'Cannot redefine constant. Missing runkit extension'
            );
        } else {
            $restoreMySQLVersion = PMA_MYSQL_INT_VERSION;
            runkit_constant_redefine('PMA_MYSQL_INT_VERSION', 50706);
        }

        $username = "******";
        $hostname = "PMA_hostname";
        $password = "******";
        $_POST['pred_password'] = '******';
        $_REQUEST['authentication_plugin'] = 'mysql_native_password';
        $dbname = "PMA_db";

        list($create_user_real, $create_user_show, $real_sql_query, $sql_query)
            = PMA_getSqlQueriesForDisplayAndAddUser($username, $hostname, $password);

        //validate 1: $create_user_real
        $this->assertEquals(
            "CREATE USER 'PMA_username'@'PMA_hostname' IDENTIFIED "
            . "WITH mysql_native_password AS 'pma_password';",
            $create_user_real
        );

        //validate 2: $create_user_show
        $this->assertEquals(
            "CREATE USER 'PMA_username'@'PMA_hostname' IDENTIFIED "
            . "WITH mysql_native_password AS '***';",
            $create_user_show
        );

        //validate 3:$real_sql_query
        $this->assertEquals(
            "GRANT USAGE ON *.* TO 'PMA_username'@'PMA_hostname' REQUIRE NONE;",
            $real_sql_query
        );

        //validate 4:$sql_query
        $this->assertEquals(
            "GRANT USAGE ON *.* TO 'PMA_username'@'PMA_hostname' REQUIRE NONE;",
            $sql_query
        );

        //test for PMA_addUserAndCreateDatabase
        list($sql_query, $message) = PMA_addUserAndCreateDatabase(
            false, $real_sql_query, $sql_query, $username, $hostname, $dbname
        );

        //validate 5: $sql_query
        $this->assertEquals(
            "GRANT USAGE ON *.* TO 'PMA_username'@'PMA_hostname' REQUIRE NONE;",
            $sql_query
        );

        //validate 6: $message
        $this->assertEquals(
            "You have added a new user.",
            $message->getMessage()
        );

        if ($restoreMySQLVersion !== "PMANORESTORE") {
            runkit_constant_redefine('PMA_MYSQL_INT_VERSION', $restoreMySQLVersion);
        }
    }
示例#12
0
 function define($k, $v)
 {
     if (defined($k)) {
         runkit_constant_redefine($k, $v);
     } else {
         runkit_constant_add($k, $v);
     }
 }
示例#13
0
 public static function redefineConstant($className, $constName, $value)
 {
     $runkitName = ($className === null ? "" : $className . "::") . $constName;
     yTest_debugCC("redefineConstant {$runkitName} to value " . var_export($value, true));
     $res = runkit_constant_redefine($runkitName, $value);
     yTest_assert($res);
 }
示例#14
0
 /**
  * Defines resp. redefines a constant.
  *
  * @param string $name  A name.
  * @param string $value A value.
  *
  * @return void
  */
 private function _defineConstant($name, $value)
 {
     if (!defined($name)) {
         define($name, $value);
     } else {
         runkit_constant_redefine($name, $value);
     }
 }
 /**
  * Test for PMA_sendHeaderLocation
  *
  * @return void
  */
 public function testSendHeaderLocationWithSidUrlWithoutQuestionMark()
 {
     if (defined('PMA_TEST_HEADERS')) {
         runkit_constant_redefine('SID', md5('test_hash'));
         $testUri = 'http://testurl.com/test.php';
         $header = array('Location: ' . $testUri . '?' . SID);
         PMA_sendHeaderLocation($testUri);
         // sets $GLOBALS['header']
         $this->assertEquals($header, $GLOBALS['header']);
     } else {
         $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension');
     }
 }
 /**
  * Tests for getDropdownValueForDbAction()
  *
  * Case three: foreign and Drizzle
  *
  * @return void
  * @test
  */
 public function testGetDropdownValueForDbActionThree()
 {
     if (!PMA_HAS_RUNKIT) {
         $this->markTestSkipped("Cannot redefine PMA_DRIZZLE constant");
     }
     runkit_constant_redefine('PMA_DRIZZLE', true);
     $tableMock = $this->getMockBuilder('PMA_Table')->disableOriginalConstructor()->getMock();
     $statusInfo = 'InnoDB';
     $tableMock->expects($this->any())->method('getStatusInfo')->will($this->returnValue($statusInfo));
     $GLOBALS['dbi']->expects($this->any())->method('getTable')->will($this->returnValue($tableMock));
     $GLOBALS['dbi']->expects($this->any())->method('fetchArray')->will($this->returnCallback(function () {
         static $count = 0;
         if ($count == 0) {
             $count++;
             return array('table');
         }
         return null;
     }));
     $container = Container::getDefaultContainer();
     $container->set('dbi', $GLOBALS['dbi']);
     $container->factory('PMA\\Controllers\\Table\\TableRelationController');
     $container->alias('TableRelationController', 'PMA\\Controllers\\Table\\TableRelationController');
     $ctrl = $container->get('TableRelationController', array('tbl_storage_engine' => 'INNODB'));
     $_REQUEST['foreign'] = 'true';
     $ctrl->getDropdownValueForDbAction();
     $json = $this->response->getJSONResult();
     $this->assertEquals(array('table'), $json['tables']);
 }
 /**
  * Test for PMA\libraries\plugins\export\ExportSql::exportDBFooter
  *
  * @return void
  */
 public function testExportDBFooterWithOlderMySQLVersion()
 {
     $restoreMySQLVersion = "PMANORESTORE";
     if (!PMA_HAS_RUNKIT) {
         $this->markTestSkipped('Cannot redefine constant. Missing runkit extension');
     } else {
         $restoreMySQLVersion = PMA_MYSQL_INT_VERSION;
         runkit_constant_redefine('PMA_MYSQL_INT_VERSION', 50100);
     }
     $GLOBALS['crlf'] = "\n";
     $GLOBALS['sql_constraints'] = "SqlConstraints";
     $GLOBALS['sql_structure_or_data'] = 'structure';
     $GLOBALS['sql_procedure_function'] = true;
     $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock();
     $GLOBALS['dbi'] = $dbi;
     ob_start();
     $this->assertTrue($this->object->exportDBFooter('db'));
     $result = ob_get_clean();
     $this->assertEquals('SqlConstraints', $result);
     if ($restoreMySQLVersion !== "PMANORESTORE") {
         runkit_constant_redefine('PMA_MYSQL_INT_VERSION', $restoreMySQLVersion);
     }
 }
 /**
  * Test for PMA_getDbCollation
  *
  * @return void
  * @test
  */
 public function testGetDbCollation()
 {
     if (!PMA_HAS_RUNKIT) {
         $this->markTestSkipped('Cannot redefine constant - missing runkit extension');
     } else {
         $GLOBALS['server'] = 1;
         // test case for system schema
         $this->assertEquals('utf8_general_ci', PMA_getDbCollation("information_schema"));
         $restoreDrizzle = '';
         // test case with no pma drizzle
         if (defined('PMA_DRIZZLE')) {
             $restoreDrizzle = PMA_DRIZZLE;
             runkit_constant_redefine('PMA_DRIZZLE', false);
         } else {
             $restoreDrizzle = 'PMA_TEST_CONSTANT_REMOVE';
             define('PMA_DRIZZLE', false);
         }
         $GLOBALS['cfg']['Server']['DisableIS'] = false;
         $GLOBALS['cfg']['DBG']['sql'] = false;
         $this->assertEquals('utf8_general_ci', PMA_getDbCollation('pma_test'));
         // test case with pma drizzle as true
         runkit_constant_redefine('PMA_DRIZZLE', true);
         $this->assertEquals('utf8_general_ci_pma_drizzle', PMA_getDbCollation('pma_test'));
         $GLOBALS['cfg']['Server']['DisableIS'] = true;
         $GLOBALS['db'] = 'pma_test2';
         $this->assertEquals('bar', PMA_getDbCollation('pma_test'));
         $this->assertNotEquals('pma_test', $GLOBALS['dummy_db']);
         if ($restoreDrizzle === 'PMA_TEST_CONSTANT_REMOVE') {
             runkit_constant_remove('PMA_DRIZZLE');
         } else {
             runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle);
         }
     }
 }
 /**
  * Test for PMA_checkConfigRw
  *
  * @return void
  */
 public function testPMACheckConfigRw()
 {
     if (!PMA_HAS_RUNKIT) {
         $this->markTestSkipped('Cannot redefine constant');
     }
     $redefine = null;
     $GLOBALS['cfg']['AvailableCharsets'] = array();
     $GLOBALS['server'] = 0;
     $GLOBALS['ConfigFile'] = new ConfigFile();
     if (!defined('SETUP_CONFIG_FILE')) {
         define('SETUP_CONFIG_FILE', 'test/test_data/configfile');
     } else {
         $redefine = 'SETUP_CONFIG_FILE';
         runkit_constant_redefine('SETUP_CONFIG_FILE', 'test/test_data/configfile');
     }
     $is_readable = false;
     $is_writable = false;
     $file_exists = false;
     PMA_checkConfigRw($is_readable, $is_writable, $file_exists);
     $this->assertTrue($is_readable);
     $this->assertTrue($is_writable);
     $this->assertFalse($file_exists);
     runkit_constant_redefine('SETUP_CONFIG_FILE', 'test/test_data/test.file');
     PMA_checkConfigRw($is_readable, $is_writable, $file_exists);
     $this->assertTrue($is_readable);
     $this->assertTrue($is_writable);
     $this->assertTrue($file_exists);
     if ($redefine !== null) {
         runkit_constant_redefine('SETUP_CONFIG_FILE', $redefine);
     } else {
         runkit_constant_remove('SETUP_CONFIG_FILE');
     }
 }
示例#20
0
 /**
  * 获取当前的模板主题
  * @access private
  * @return string
  */
 private function getTemplateTheme()
 {
     if ($this->theme) {
         // 指定模板主题
         $theme = $this->theme;
     } else {
         /* 获取模板主题名称 */
         $theme = C('DEFAULT_THEME');
         if (C('TMPL_DETECT_THEME')) {
             // 自动侦测模板主题
             $t = C('VAR_TEMPLATE');
             if (isset($_GET[$t])) {
                 $theme = $_GET[$t];
             } elseif (cookie('think_template')) {
                 $theme = cookie('think_template');
             }
             if (!in_array($theme, explode(',', C('THEME_LIST')))) {
                 $theme = C('DEFAULT_THEME');
             }
             cookie('think_template', $theme, 864000);
         }
     }
     defined('THEME_NAME') || runkit_constant_redefine('THEME_NAME', $theme);
     // 当前模板主题名称
     return $theme ? $theme . '/' : '';
 }
示例#21
0
 /**
  * Test for ExportXml::exportHeader
  *
  * @return void
  */
 public function testExportHeaderWithDrizzle()
 {
     $restoreDrizzle = 'PMANORESTORE';
     if (!PMA_DRIZZLE) {
         if (!PMA_HAS_RUNKIT) {
             $this->markTestSkipped("Cannot redefine constant. Missing runkit extension");
         } else {
             $restoreDrizzle = PMA_DRIZZLE;
             runkit_constant_redefine('PMA_DRIZZLE', true);
         }
     }
     $GLOBALS['output_charset_conversion'] = false;
     $GLOBALS['xml_export_triggers'] = true;
     $GLOBALS['cfg']['Server']['port'] = 80;
     $GLOBALS['cfg']['Server']['host'] = 'localhost';
     $GLOBALS['cfg']['Server']['DisableIS'] = false;
     $GLOBALS['crlf'] = "\n";
     $GLOBALS['db'] = 'd<b';
     $result = array(0 => array('DEFAULT_COLLATION_NAME' => 'utf8_general_ci', 'DEFAULT_CHARACTER_SET_NAME' => 'utf-8'), 'table' => array(null, '"tbl"'));
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->at(0))->method('fetchResult')->with("SELECT\n                        'utf8' AS DEFAULT_CHARACTER_SET_NAME,\n                        DEFAULT_COLLATION_NAME\n                    FROM data_dictionary.SCHEMAS\n                    WHERE SCHEMA_NAME = 'd<b'")->will($this->returnValue($result));
     $dbi->expects($this->at(1))->method('fetchResult')->with('SHOW CREATE TABLE `d<b`.`table`', 0)->will($this->returnValue($result));
     // isView
     $dbi->expects($this->at(2))->method('fetchResult')->will($this->returnValue(false));
     $dbi->expects($this->once())->method('getTable')->will($this->returnValue(new PMA_Table('table', 'd<b')));
     $GLOBALS['dbi'] = $dbi;
     $GLOBALS['tables'] = array();
     $GLOBALS['table'] = 'table';
     ob_start();
     $this->assertTrue($this->object->exportHeader());
     $result = ob_get_clean();
     if ($restoreDrizzle !== "PMANORESTORE") {
         runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle);
     }
 }
示例#22
0
文件: npc.php 项目: smrealms/smrv2.0
function processContainer($container)
{
    global $forwardedContainer, $previousContainer, $player;
    if ($container == $previousContainer && $forwardedContainer['body'] != 'forces_attack.php') {
        debug('We are executing the same container twice?', array('ForwardedContainer' => $forwardedContainer, 'Container' => $container));
        if ($player->hasNewbieTurns() || $player->hasFederalProtection()) {
            // Only throw the exception if we have protection, otherwise let's hope that the NPC will be able to find its way to safety rather than dying in the open.
            throw new Exception('We are executing the same container twice?');
        }
    }
    clearCaches();
    //Clear caches of anything we have used for decision making before processing container and getting lock.
    $previousContainer = $container;
    debug('Executing container', $container);
    //Redefine MICRO_TIME and TIME, the rest of the game expects them to be the single point in time that the script is executing, with it being redefined for each page load - unfortunately NPCs are one consistent script so we have to do a hack and redefine it (or change every instance of the TIME constant.
    runkit_constant_redefine('MICRO_TIME', microtime());
    runkit_constant_redefine('TIME', (int) microtimeSec(MICRO_TIME));
    resetContainer($container);
    do_voodoo();
}
 /**
  * 获得实际的模块名称
  */
 private static function getModule($var)
 {
     $module = !empty($_GET[$var]) ? $_GET[$var] : C('DEFAULT_MODULE');
     unset($_GET[$var]);
     if ($maps = C('URL_MODULE_MAP')) {
         if (isset($maps[strtolower($module)])) {
             // 记录当前别名
             runkit_constant_redefine('MODULE_ALIAS', strtolower($module));
             // 获取实际的模块名
             return ucfirst($maps[MODULE_ALIAS]);
         } elseif (array_search(strtolower($module), $maps)) {
             // 禁止访问原始模块
             return '';
         }
     }
     return strip_tags(ucfirst($module));
 }
 /**
  * Test for PMA_sendHeaderLocation
  *
  * @return void
  */
 public function testSendHeaderLocationIisLongUri()
 {
     if (defined('PMA_IS_IIS') && PMA_HAS_RUNKIT) {
         runkit_constant_redefine('PMA_IS_IIS', true);
     } elseif (!defined('PMA_IS_IIS')) {
         define('PMA_IS_IIS', true);
     } elseif (!PMA_IS_IIS) {
         $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension');
     }
     // over 600 chars
     $testUri = 'http://testurl.com/test.php?testlonguri=over600chars&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test';
     $testUri_html = htmlspecialchars($testUri);
     $testUri_js = PMA_escapeJsString($testUri);
     $header = "<html><head><title>- - -</title>\n    <meta http-equiv=\"expires\" content=\"0\">" . "<meta http-equiv=\"Pragma\" content=\"no-cache\">" . "<meta http-equiv=\"Cache-Control\" content=\"no-cache\">" . "<meta http-equiv=\"Refresh\" content=\"0;url=" . $testUri_html . "\">" . "<script type=\"text/javascript\">//<![CDATA[\n        setTimeout(\"window.location = decodeURI('" . $testUri_js . "')\", 2000);\n        //]]></script></head>\n<body><script type=\"text/javascript\">//<![CDATA[\n    document.write('<p><a href=\"" . $testUri_html . "\">" . __('Go') . "</a></p>');\n    //]]></script></body></html>\n";
     $this->expectOutputString($header);
     $restoreInstance = PMA\libraries\Response::getInstance();
     $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('disable', 'header', 'headersSent'))->getMock();
     $mockResponse->expects($this->once())->method('disable');
     $mockResponse->expects($this->any())->method('headersSent')->with()->will($this->returnValue(false));
     $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance');
     $attrInstance->setAccessible(true);
     $attrInstance->setValue($mockResponse);
     PMA_sendHeaderLocation($testUri);
     $attrInstance->setValue($restoreInstance);
 }
 /**
  * Test for PMA_sendHeaderLocation
  *
  * @return void
  */
 public function testSendHeaderLocationIisLongUri()
 {
     if (defined('PMA_IS_IIS') && PMA_HAS_RUNKIT) {
         runkit_constant_redefine('PMA_IS_IIS', true);
     } elseif (!defined('PMA_IS_IIS')) {
         define('PMA_IS_IIS', true);
     } else {
         $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension');
     }
     // over 600 chars
     $testUri = 'http://testurl.com/test.php?testlonguri=over600chars&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test';
     $testUri_html = htmlspecialchars($testUri);
     $testUri_js = PMA_escapeJsString($testUri);
     $header = "<html><head><title>- - -</title>\n    <meta http-equiv=\"expires\" content=\"0\">" . "<meta http-equiv=\"Pragma\" content=\"no-cache\">" . "<meta http-equiv=\"Cache-Control\" content=\"no-cache\">" . "<meta http-equiv=\"Refresh\" content=\"0;url=" . $testUri_html . "\">" . "<script type=\"text/javascript\">//<![CDATA[\n        setTimeout(\"window.location = decodeURI('" . $testUri_js . "')\", 2000);\n        //]]></script></head>\n<body><script type=\"text/javascript\">//<![CDATA[\n    document.write('<p><a href=\"" . $testUri_html . "\">" . __('Go') . "</a></p>');\n    //]]></script></body></html>";
     $this->expectOutputString($header);
     PMA_sendHeaderLocation($testUri);
 }
 /**
  * Tests for adjustColumnPrivileges()
  * For the Drizzle environment
  *
  * @return void
  * @test
  */
 public function testAdjustColumnPrivilegesDrizzle()
 {
     if (!PMA_HAS_RUNKIT) {
         $this->markTestSkipped("Cannot redefine PMA_DRIZZLE constant");
     }
     $class = new ReflectionClass('\\PMA\\Controllers\\TableStructureController');
     $method = $class->getMethod('adjustColumnPrivileges');
     $method->setAccessible(true);
     $container = Container::getDefaultContainer();
     $container->set('dbi', $GLOBALS['dbi']);
     $container->factory('PMA\\Controllers\\TableStructureController');
     $container->alias('TableStructureController', 'PMA\\Controllers\\TableStructureController');
     $ctrl = $container->get('TableStructureController');
     $this->assertEquals(false, $method->invokeArgs($ctrl, array(null)));
     runkit_constant_redefine('PMA_DRIZZLE', false);
     $adjust_privileges = array('col1' => 'col2');
     $GLOBALS['col_priv'] = true;
     $GLOBALS['flush_priv'] = true;
     $this->assertEquals(true, $method->invokeArgs($ctrl, array($adjust_privileges)));
 }
示例#27
0
    /**
     * Test for PMA_Tracker::_transformTrackingSet
     *
     * @return void
     * @test
     */
    public function testTransformTrackingSet()
    {
        if (! PMA_HAS_RUNKIT) {
            $this->markTestSkipped("Cannot redefine constant");
        }

        runkit_constant_redefine("PMA_DRIZZLE", true);

        $method = new \ReflectionMethod("PMA_Tracker", "_transformTrackingSet");
        $method->setAccessible(true);

        $this->assertEquals(
            $method->invoke(null, "CREATE DATABASE,ALTER DATABASE,DROP DATABASE"),
            224
        );

        $this->assertEquals(
            $method->invoke(null, 224),
            "CREATE DATABASE,ALTER DATABASE,DROP DATABASE"
        );
    }
示例#28
0
     fputs($toEngine, $s . EOL);
     if ($read === true) {
         readFromEngine($block);
     }
 }
 readFromEngine();
 writeToEngine('uci');
 writeToEngine('setoption name Hash value ' . UCI_HASH_SIZE_MB, false);
 writeToEngine('isready');
 writeToEngine('ucinewgame', false);
 SmrSession::$game_id = NPC_GAME_ID;
 require_once get_file_loc('ChessGame.class.inc');
 while (true) {
     //Redefine MICRO_TIME and TIME, the rest of the game expects them to be the single point in time that the script is executing, with it being redefined for each page load - unfortunately NPCs are one consistent script so we have to do a hack and redefine it (or change every instance of the TIME constant).
     runkit_constant_redefine('MICRO_TIME', microtime());
     runkit_constant_redefine('TIME', (int) microtimeSec(MICRO_TIME));
     $chessGames =& ChessGame::getNPCMoveGames(true);
     foreach ($chessGames as &$chessGame) {
         debug('Looking at game: ' . $chessGame->getChessGameID());
         writeToEngine('position fen ' . $chessGame->getFENString(), false);
         writeToEngine('go ' . ($chessGame->getCurrentTurnColour() == ChessGame::PLAYER_WHITE ? 'w' : 'b') . 'time ' . UCI_TIME_PER_MOVE_MS, true, false);
         stream_set_blocking($fromEngine, 1);
         while (stripos($move = trim(fgets($fromEngine)), 'bestmove') !== 0) {
             debug('<-- ' . $move);
             if (stripos($move, 'Seg') === 0) {
                 // Segfault
                 debug('UCI engine segfaulted?');
                 exit;
             }
         }
         debug('Move info: ', $move);
 /**
  * Test for ExportSql::getTableDef
  *
  * @return void
  */
 public function testGetTableDefWithError()
 {
     $restoreDrizzle = 'PMANORESTORE';
     if (PMA_DRIZZLE) {
         if (!PMA_HAS_RUNKIT) {
             $this->markTestSkipped("Cannot redefine constant. Missing runkit extension");
         } else {
             $restoreDrizzle = PMA_DRIZZLE;
             runkit_constant_redefine('PMA_DRIZZLE', false);
         }
     }
     $GLOBALS['sql_compatibility'] = '';
     $GLOBALS['sql_auto_increment'] = true;
     $GLOBALS['sql_drop_table'] = true;
     $GLOBALS['sql_backquotes'] = false;
     $GLOBALS['sql_if_not_exists'] = true;
     $GLOBALS['sql_include_comments'] = true;
     $GLOBALS['crlf'] = "\n";
     if (isset($GLOBALS['sql_constraints'])) {
         unset($GLOBALS['sql_constraints']);
     }
     if (isset($GLOBALS['no_constraints_comments'])) {
         unset($GLOBALS['no_constraints_comments']);
     }
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->at(0))->method('query')->with('SHOW TABLE STATUS FROM `db` WHERE Name = \'table\'', null, PMA_DatabaseInterface::QUERY_STORE)->will($this->returnValue('res'));
     $dbi->expects($this->never())->method('fetchSingleRow');
     $dbi->expects($this->once())->method('numRows')->with('res')->will($this->returnValue(2));
     $dbi->expects($this->any())->method('fetchValue')->will($this->returnValue(false));
     $tmpres = array('Auto_increment' => 1, 'Create_time' => '2000-01-01 10:00:00', 'Update_time' => '2000-01-02 12:00:00', 'Check_time' => '2000-01-02 13:00:00');
     $dbi->expects($this->once())->method('fetchAssoc')->with('res')->will($this->returnValue($tmpres));
     $dbi->expects($this->at(5))->method('query')->with('SET SQL_QUOTE_SHOW_CREATE = 0')->will($this->returnValue('res'));
     $dbi->expects($this->once())->method('tryQuery')->with('SHOW CREATE TABLE `db`.`table`')->will($this->returnValue('res'));
     $dbi->expects($this->once())->method('getError')->will($this->returnValue('error occurred'));
     $GLOBALS['dbi'] = $dbi;
     $GLOBALS['cfg']['Server']['DisableIS'] = false;
     $result = $this->object->getTableDef('db', 'table', "\n", "example.com/err", true, true, true);
     $this->assertContains('-- in use(error occurred)', $result);
     if ($restoreDrizzle !== "PMANORESTORE") {
         runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle);
     }
 }
 /**
  * Test for PMA_userprefsRedirect
  *
  * @return void
  */
 public function testUserprefsRedirect()
 {
     if (!defined('PMA_TEST_HEADERS')) {
         $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension');
     }
     $GLOBALS['PMA_Config']->set('PmaAbsoluteUri', '');
     $GLOBALS['cfg']['ServerDefault'] = 1;
     $GLOBALS['lang'] = '';
     $redefine = null;
     if (!defined('PMA_IS_IIS')) {
         define('PMA_IS_IIS', false);
     } else {
         $redefine = PMA_IS_IIS;
         runkit_constant_redefine('PMA_IS_IIS', false);
     }
     PMA_userprefsRedirect('file.html', array('a' => 'b'), 'h ash');
     $this->assertContains('Location: /phpmyadmin/file.html?a=b&saved=1&server=0#h+ash', $GLOBALS['header'][0]);
     if ($redefine !== null) {
         runkit_constant_redefine('PMA_IS_IIS', $redefine);
     } else {
         runkit_constant_remove('PMA_IS_IIS');
     }
 }