/**
  * Constructor
  */
 public function __construct()
 {
     $container = Container::getDefaultContainer();
     $this->container = $container;
     $this->dbi = $this->container->get('dbi');
     $this->response = $this->container->get('response');
 }
Пример #2
0
 function __construct()
 {
     $container = Container::getDefaultContainer();
     $this->container = $container;
     $this->dbi = $this->container->get('dbi');
     $this->response = PMA_Response::getInstance();
 }
 /**
  * Tests for getValuesForInnodbTable()
  *
  * @return void
  * @test
  */
 public function testGetValuesForInnodbTable()
 {
     $container = Container::getDefaultContainer();
     $container->set('db', 'db');
     $container->set('table', 'table');
     $container->set('dbi', $GLOBALS['dbi']);
     $response = new \PMA\Test\Stubs\PMA_Response();
     $container->set('PMA_Response', $response);
     $container->alias('response', 'PMA_Response');
     $class = new ReflectionClass('PMA\\Controllers\\DatabaseStructureController');
     $method = $class->getMethod('getValuesForInnodbTable');
     $method->setAccessible(true);
     // Showing statistics
     $is_show_stats = true;
     $ctrl = new DatabaseStructureController(null, null, null, null, null, null, $is_show_stats);
     $GLOBALS['cfg']['MaxExactCount'] = 10;
     $current_table = array('ENGINE' => 'InnoDB', 'TABLE_ROWS' => 5, 'Data_length' => 16384, 'Index_length' => 0, 'TABLE_NAME' => 'table');
     list($current_table, , , $sum_size) = $method->invokeArgs($ctrl, array($current_table, 10));
     $this->assertEquals(true, $current_table['COUNTED']);
     $this->assertEquals(6, $current_table['TABLE_ROWS']);
     $this->assertEquals(16394, $sum_size);
     $current_table['ENGINE'] = 'MYISAM';
     list($current_table, , , $sum_size) = $method->invokeArgs($ctrl, array($current_table, 10));
     $this->assertEquals(false, $current_table['COUNTED']);
     $this->assertEquals(16394, $sum_size);
     // Not showing statistics
     $is_show_stats = false;
     $ctrl = new DatabaseStructureController(null, null, null, null, null, null, $is_show_stats);
     $current_table['ENGINE'] = 'InnoDB';
     list($current_table, , , $sum_size) = $method->invokeArgs($ctrl, array($current_table, 10));
     $this->assertEquals(true, $current_table['COUNTED']);
     $this->assertEquals(10, $sum_size);
     $current_table['ENGINE'] = 'MYISAM';
     list($current_table, , , $sum_size) = $method->invokeArgs($ctrl, array($current_table, 10));
     $this->assertEquals(false, $current_table['COUNTED']);
     $this->assertEquals(10, $sum_size);
 }
    $form_params['orig_num_fields'] = $num_fields;
}
$form_params = array_merge($form_params, array('orig_field_where' => Util\get($_REQUEST, 'field_where'), 'orig_after_field' => Util\get($_REQUEST, 'after_field')));
if (isset($selected) && is_array($selected)) {
    foreach ($selected as $o_fld_nr => $o_fld_val) {
        $form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
    }
}
$is_backup = $action != 'tbl_create.php' && $action != 'tbl_addfield.php';
require_once './libraries/transformations.lib.php';
$cfgRelation = PMA_getRelationsParam();
$comments_map = PMA_getComments($db, $table);
$move_columns = array();
if (isset($fields_meta)) {
    /** @var PMA_DatabaseInterface $dbi */
    $dbi = \PMA\DI\Container::getDefaultContainer()->get('dbi');
    $move_columns = $dbi->getTable($db, $table)->getColumnsMeta();
}
$available_mime = array();
if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
    $mime_map = PMA_getMIME($db, $table);
    $available_mime = PMA_getAvailableMIMEtypes();
}
//  workaround for field_fulltext, because its submitted indices contain
//  the index as a value, not a key. Inserted here for easier maintenance
//  and less code to change in existing files.
if (isset($field_fulltext) && is_array($field_fulltext)) {
    foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
        $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
    }
}
Пример #5
0
 * @todo if above todos are fullfilled we can add all fields meet requirements
 * in the select dropdown
 * @package PhpMyAdmin
 */
/**
 * Get the TableRelationController
 */
namespace PMA;

use PMA_Table;
use PMA_Util;
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/TableRelationController.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/Util.class.php';
$container = DI\Container::getDefaultContainer();
$container->factory('PMA\\Controllers\\Table\\TableRelationController');
$container->alias('TableRelationController', 'PMA\\Controllers\\Table\\TableRelationController');
/* Define dependencies for the concerned controller */
$db = $container->get('db');
$table = $container->get('table');
$dbi = $container->get('dbi');
$options_array = array('CASCADE' => 'CASCADE', 'SET_NULL' => 'SET NULL', 'NO_ACTION' => 'NO ACTION', 'RESTRICT' => 'RESTRICT');
$cfgRelation = PMA_getRelationsParam();
$tbl_storage_engine = mb_strtoupper(PMA_Table::sGetStatusInfo($db, $table, 'Engine'));
$upd_query = new PMA_Table($table, $db, $dbi);
$dependency_definitions = array("options_array" => $options_array, "cfgRelation" => $cfgRelation, "tbl_storage_engine" => $tbl_storage_engine, "upd_query" => $upd_query);
if ($cfgRelation['relwork']) {
    $dependency_definitions['existrel'] = PMA_getForeigners($db, $table, '', 'internal');
}
if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
Пример #6
0
 /**
  * Tests for displayFormAction()
  *
  * @return void
  * @test
  */
 public function testDisplayFormAction()
 {
     $table = $this->getMockBuilder('PMA_Table')->disableOriginalConstructor()->getMock();
     $table->expects($this->any())->method('getStatusInfo')->will($this->returnValue(""));
     $table->expects($this->any())->method('isView')->will($this->returnValue(false));
     $table->expects($this->any())->method('getNameAndTypeOfTheColumns')->will($this->returnValue(array("field_name" => "field_type")));
     $GLOBALS['dbi']->expects($this->any())->method('getTable')->will($this->returnValue($table));
     $container = Container::getDefaultContainer();
     $container->set('db', 'db');
     $container->set('table', 'table');
     $container->set('dbi', $GLOBALS['dbi']);
     $response = new \PMA\Test\Stubs\PMA_Response();
     $container->set('PMA_Response', $response);
     $container->alias('response', 'PMA_Response');
     $index = new PMA_Index();
     $ctrl = new TableIndexesController($index);
     $_REQUEST['create_index'] = true;
     $_REQUEST['added_fields'] = 3;
     $ctrl->displayFormAction();
     $html = $response->getHTMLResult();
     //PMA_URL_getHiddenInputs
     $this->assertContains(PMA_URL_getHiddenInputs(array('db' => 'db', 'table' => 'table', 'create_index' => 1)), $html);
     $doc_html = PMA_Util::showHint(PMA_Message::notice(__('"PRIMARY" <b>must</b> be the name of' . ' and <b>only of</b> a primary key!')));
     $this->assertContains($doc_html, $html);
     $this->assertContains(PMA_Util::showMySQLDocu('ALTER_TABLE'), $html);
     // generateIndexSelector
     $this->assertContains(PMA\Template::trim($index->generateIndexChoiceSelector(false)), $html);
     $this->assertContains(sprintf(__('Add %s column(s) to index'), 1), $html);
     //$field_name & $field_type
     $this->assertContains("field_name", $html);
     $this->assertContains("field_type", $html);
 }
 /**
  * Test for getDataForSubmitMult()
  *
  * @return void
  * @test
  */
 public function testPMAGetDataForSubmitMult()
 {
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->any())->method('query')->will($this->returnValue(true));
     $class = new ReflectionClass('PMA\\Controllers\\TableStructureController');
     $method = $class->getMethod('getDataForSubmitMult');
     $method->setAccessible(true);
     $container = Container::getDefaultContainer();
     $container->set('dbi', $dbi);
     $container->factory('PMA\\Controllers\\TableStructureController');
     $container->alias('TableStructureController', 'PMA\\Controllers\\TableStructureController');
     $ctrl = $container->get('TableStructureController');
     $submit_mult = "index";
     $db = "PMA_db";
     $table = "PMA_table";
     $selected = array("table1", "table2");
     $action = 'db_delete_row';
     list($what, $query_type, $is_unset_submit_mult, $mult_btn, $centralColsError) = $method->invokeArgs($ctrl, array($submit_mult, $db, $table, $selected, $action));
     //validate 1: $what
     $this->assertEquals(null, $what);
     //validate 2: $query_type
     $this->assertEquals('index_fld', $query_type);
     //validate 3: $is_unset_submit_mult
     $this->assertEquals(true, $is_unset_submit_mult);
     //validate 4:
     $this->assertEquals(__('Yes'), $mult_btn);
     //validate 5: $centralColsError
     $this->assertEquals(null, $centralColsError);
     $submit_mult = "unique";
     list($what, $query_type, $is_unset_submit_mult, $mult_btn, $centralColsError) = $method->invokeArgs($ctrl, array($submit_mult, $db, $table, $selected, $action));
     //validate 1: $what
     $this->assertEquals(null, $what);
     //validate 2: $query_type
     $this->assertEquals('unique_fld', $query_type);
     //validate 3: $is_unset_submit_mult
     $this->assertEquals(true, $is_unset_submit_mult);
     //validate 4: $mult_btn
     $this->assertEquals(__('Yes'), $mult_btn);
     //validate 5: $centralColsError
     $this->assertEquals(null, $centralColsError);
 }
 /**
  * Tests for getDropdownValueForDbAction()
  *
  * Case two: not foreign
  *
  * @return void
  * @test
  */
 public function testGetDropdownValueForDbActionTwo()
 {
     $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'] = 'false';
     $ctrl->getDropdownValueForDbAction();
     $json = $this->response->getJSONResult();
     $this->assertEquals(array('table'), $json['tables']);
 }
            if (!PMA_DatabaseInterface::checkDbExtension($extension)) {
                // warn about both extensions missing and exit
                PMA_warnMissingExtension('mysqli|mysql', true, $doclink);
            } elseif (empty($_SESSION['mysqlwarning'])) {
                trigger_error(__('You are using the mysql extension which is deprecated in ' . 'phpMyAdmin. Please consider installing the mysqli ' . 'extension.') . ' ' . $doclink, E_USER_WARNING);
                // tell the user just once per session
                $_SESSION['mysqlwarning'] = true;
            }
        } else {
            // mysql extension is not part of PHP 7+, so warn and exit
            PMA_warnMissingExtension('mysqli', true, $doclink);
        }
    }
    /**
     * Including The DBI Plugin
     */
    switch ($extension) {
        case 'mysql':
            include_once './libraries/dbi/DBIMysql.class.php';
            $extension = new PMA_DBI_Mysql();
            break;
        case 'mysqli':
            include_once './libraries/dbi/DBIMysqli.class.php';
            $extension = new PMA_DBI_Mysqli();
            break;
    }
}
$GLOBALS['dbi'] = new PMA_DatabaseInterface($extension);
$container = \PMA\DI\Container::getDefaultContainer();
$container->set('PMA_DatabaseInterface', $GLOBALS['dbi']);
$container->alias('dbi', 'PMA_DatabaseInterface');
Пример #10
0
 /**
  * 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']);
 }
Пример #11
0
 /**
  * Tests for getDataRowAction()
  *
  * @return void
  * @test
  */
 public function testGetDataRowAction()
 {
     $meta_one = new stdClass();
     $meta_one->type = 'int';
     $meta_one->length = 11;
     $meta_two = new stdClass();
     $meta_two->length = 11;
     $meta_two->type = 'int';
     $fields_meta = array($meta_one, $meta_two);
     $GLOBALS['dbi']->expects($this->any())->method('getFieldsMeta')->will($this->returnValue($fields_meta));
     $GLOBALS['dbi']->expects($this->any())->method('fetchAssoc')->will($this->returnCallback(function () {
         static $count = 0;
         if ($count == 0) {
             $count++;
             return array('col1' => 1, 'col2' => 2);
         } else {
             return null;
         }
     }));
     $container = Container::getDefaultContainer();
     $container->set('dbi', $GLOBALS['dbi']);
     $container->factory('\\PMA\\Controllers\\Table\\TableSearchController');
     $container->alias('TableSearchController', 'PMA\\Controllers\\Table\\TableSearchController');
     $ctrl = $container->get('TableSearchController');
     $_REQUEST['db'] = 'PMA';
     $_REQUEST['table'] = 'PMA_BookMark';
     $_REQUEST['where_clause'] = '`col1` = 1';
     $expected = array('col1' => 1, 'col2' => 2);
     $ctrl->getDataRowAction();
     $json = $this->response->getJSONResult();
     $this->assertEquals($expected, $json['row_info']);
 }