/** * @dataProvider dataProvider * @return void */ function testMaximumUploadSize($size, $unit, $res) { $this->assertEquals( "(" . __('Max: '). $res . $unit .")", PMA_Util::getFormattedMaximumUploadSize($size) ); }
/** * return HTML for Sql Query Form Upload * * @return string * * @usedby PMA_getHtmlForSqlQueryForm() */ function PMA_getHtmlForSqlQueryFormUpload() { global $timeout_passed, $local_import_file; $errors = array(); // we allow only SQL here $matcher = '@\\.sql(\\.(' . PMA_supportedDecompressions() . '))?$@'; if (!empty($GLOBALS['cfg']['UploadDir'])) { $files = PMA_getFileSelectOptions(PMA_Util::userDir($GLOBALS['cfg']['UploadDir']), $matcher, isset($timeout_passed) && $timeout_passed && isset($local_import_file) ? $local_import_file : ''); } else { $files = ''; } // start output $html = '<fieldset id="">'; $html .= '<legend>'; $html .= __('Browse your computer:') . '</legend>'; $html .= '<div class="formelement">'; $html .= '<input type="file" name="sql_file" class="textfield" /> '; $html .= PMA_Util::getFormattedMaximumUploadSize($GLOBALS['max_upload_size']); // some browsers should respect this :) $html .= PMA_Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n"; $html .= '</div>'; if ($files === false) { $errors[] = PMA_Message::error(__('The directory you set for upload work cannot be reached.')); } elseif (!empty($files)) { $html .= '<div class="formelement">'; $html .= '<strong>' . __('web server upload directory:') . '</strong>'; $html .= '<select size="1" name="sql_localfile">' . "\n"; $html .= '<option value="" selected="selected"></option>' . "\n"; $html .= $files; $html .= '</select>' . "\n"; $html .= '</div>'; } $html .= '<div class="clearfloat"></div>' . "\n"; $html .= '</fieldset>'; $html .= '<fieldset id="" class="tblFooters">'; $html .= __('Character set of the file:') . "\n"; $html .= PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', null, 'utf8', false); $html .= '<input type="submit" name="SQL" value="' . __('Go') . '" />' . "\n"; $html .= '<div class="clearfloat"></div>' . "\n"; $html .= '</fieldset>'; foreach ($errors as $error) { $html .= $error->getDisplay(); } return $html; }
/** * Retrieve the maximum upload file size * * @param array $column description of column in given table * @param integer $biggest_max_file_size biggest max file size for uploading * * @return array an html snippet and $biggest_max_file_size */ function PMA_getMaxUploadSize($column, $biggest_max_file_size) { // find maximum upload size, based on field type /** * @todo with functions this is not so easy, as you can basically * process any data with function like MD5 */ global $max_upload_size; $max_field_sizes = array('tinyblob' => '256', 'blob' => '65536', 'mediumblob' => '16777216', 'longblob' => '4294967296'); $this_field_max_size = $max_upload_size; // from PHP max if ($this_field_max_size > $max_field_sizes[$column['pma_type']]) { $this_field_max_size = $max_field_sizes[$column['pma_type']]; } $html_output = PMA_Util::getFormattedMaximumUploadSize($this_field_max_size) . "\n"; // do not generate here the MAX_FILE_SIZE, because we should // put only one in the form to accommodate the biggest field if ($this_field_max_size > $biggest_max_file_size) { $biggest_max_file_size = $this_field_max_size; } return array($html_output, $biggest_max_file_size); }
/** * Test for PMA_getHtmlForSqlQueryFormUpload * * @return void */ public function testPMAGetHtmlForSqlQueryFormUpload() { //Call the test function $html = PMA_getHtmlForSqlQueryFormUpload(); //validate 1: Browse your computer $this->assertContains(__('Browse your computer:'), $html); //validate 2: $GLOBALS['max_upload_size'] $this->assertContains(PMA_Util::getFormattedMaximumUploadSize($GLOBALS['max_upload_size']), $html); $this->assertContains(PMA_Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size']), $html); //validate 3: Dropdown Box $this->assertContains(PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', null, 'utf8', false), $html); }