diff --git a/e107_core/sql/core_sql.php b/e107_core/sql/core_sql.php index f00ceb8b2a..babeb2d004 100755 --- a/e107_core/sql/core_sql.php +++ b/e107_core/sql/core_sql.php @@ -166,7 +166,7 @@ cron_active INT(1) UNSIGNED NOT NULL, PRIMARY KEY (cron_id), UNIQUE KEY cron_function (cron_function) -) ENGINE = MYISAM; +) ENGINE=InnoDB; # Table structure for table `dblog` - db/debug/rolling diff --git a/e107_handlers/db_verify_class.php b/e107_handlers/db_verify_class.php index 819e20b84b..a71d70999e 100755 --- a/e107_handlers/db_verify_class.php +++ b/e107_handlers/db_verify_class.php @@ -382,7 +382,7 @@ public function compare($selection, $language='') $maybeCharset = isset($sqlDataArr['charset'][0]) ? $sqlDataArr['charset'][0] : 'INTERNAL_ERROR:CHARSET'; $fileData['charset'] = $this->getIntendedCharset($this->sqlFileTables[$selection]['charset'][$key]); - $sqlData['charset'] = $this->getCanonicalCharset($maybeCharset); + $sqlData['charset'] = $sqlDataArr['charset'][0]; // check the actual charset. $this->getCanonicalCharset($maybeCharset); /* $debugA = print_r($fileFieldData,TRUE); // Extracted Field Arrays @@ -399,10 +399,15 @@ public function compare($selection, $language='') if(isset($debugA) && (e_PAGE === 'db.php')) { - + $engineA = !empty($this->sqlFileTables[$selection]['engine'][0]) ? $this->sqlFileTables[$selection]['engine'][0] : 'unknown'; + $engineB = !empty($sqlDataArr['engine'][0]) ? $sqlDataArr['engine'][0] : 'unknown'; + + $charsetA = !empty($this->sqlFileTables[$selection]['charset'][0]) ? $this->sqlFileTables[$selection]['charset'][0] : 'not specified'; + $charsetB = !empty($sqlDataArr['charset'][0]) ? $sqlDataArr['charset'][0] : 'unknown'; + $debug = " - - + +
FILE: ".$tbl." (key=".$key.")SQL: ".$tbl."
FILE: $tbl (key=$key) $engineA $charsetASQL: $tbl $engineB $charsetB
".$debugA."
".$debugB."
"; @@ -489,13 +494,13 @@ public function prepareResults($tbl, $selection, $sqlData, $fileData) } - if ($fileData['engine'] != $sqlData['engine']) + if ($fileData['engine'] !== $sqlData['engine']) { $this->errors[$tbl]['_status'] |= self::STATUS_TABLE_MISMATCH_STORAGE_ENGINE; $this->errors[$tbl]['_valid_' . self::STATUS_TABLE_MISMATCH_STORAGE_ENGINE] = $fileData['engine']; $this->errors[$tbl]['_invalid_' . self::STATUS_TABLE_MISMATCH_STORAGE_ENGINE] = $sqlData['engine']; } - if ($fileData['charset'] != $sqlData['charset']) + if ($fileData['charset'] !== $sqlData['charset']) { $this->errors[$tbl]['_status'] |= self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET; $this->errors[$tbl]['_valid_' . self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET] = $fileData['charset']; @@ -520,7 +525,7 @@ function compileResults() { foreach($this->results as $tabs => $field) { - $file = varset($this->results[$tabs]['_file']); + $file = varset($this->results[$tabs]['_file'],$tabs); $errorStatus = is_int($this->errors[$tabs]['_status']) ? $this->errors[$tabs]['_status'] : self::STATUS_TABLE_OK; @@ -599,6 +604,10 @@ public function errors() return $badTableCount; } + public function getErrors() + { + return $this->errors; + } /** * @param $fileArray @@ -642,7 +651,7 @@ function renderResults($fileArray=array()) self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET => DBVLAN_18, 'mismatch' => DBVLAN_8, 'missing_field' => DBVLAN_11, - 'ok' => ADMIN_TRUE_ICON, + 'ok' => defset('ADMIN_TRUE_ICON','true'), 'missing_index' => DBVLAN_25, ); @@ -931,7 +940,7 @@ function getFixQuery( $fdata = $this->getIndex($sqlFileData); $newval = $this->toMysql($fdata[$field],'index'); } - else + elseif($mode == 'alter' || $mode === 'insert' || $mode === 'index') { $fdata = $this->getFields($sqlFileData); $newval = $this->toMysql($fdata[$field]); @@ -971,10 +980,14 @@ function getFixQuery( case 'convert': $showCreateTable = $this->getSqlData($table); $currentSchema = $this->getSqlFileTables($showCreateTable); - if ($engine != $currentSchema['engine'][0]) - $query .= "ALTER TABLE `".MPREFIX.$table."` ENGINE=".$engine.";"; - if ($charset != $currentSchema['charset'][0]) - $query .= "ALTER TABLE `".MPREFIX.$table."` CONVERT TO CHARACTER SET ".$charset.";"; + if($engine != $currentSchema['engine'][0]) + { + $query .= "ALTER TABLE `" . MPREFIX . $table . "` ENGINE=" . $engine . ";"; + } + if($charset != $currentSchema['charset'][0]) + { + $query .= "ALTER TABLE `" . MPREFIX . $table . "` CONVERT TO CHARACTER SET " . $charset . ";"; + } break; } @@ -998,10 +1011,10 @@ function runFix($fixArray='') $fixArray = $this->fixList; // Fix All } - + foreach($fixArray as $j=>$file) { - + foreach($file as $table=>$val) { @@ -1074,7 +1087,9 @@ function getSqlFileTables($sql_data) $sql_data = preg_replace("#\/\*.*?\*\/#mis", '', $sql_data); // remove comments - $regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?([\w]*)`?\s*?\(([^;]*)\)\s*((?:[\w\s]+=[^\s]+)+\s*)*;/i"; + // $regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?([\w]*)`?\s*?\(([^;]*)\)\s*((?:[\w\s]+=[^\s]+)+\s*)*;/i"; + // $regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?(\w*)`?\s*?\(([^;]*)\)\s*((?:[\w\s]+=\S+)+\s*)*;/i"; + $regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?(\w*)`?\s*?\(([^;]*)\)\s*((?:[\w\s]+=[^;]+)+\s*)*;/i"; preg_match_all($regex,$sql_data,$match); @@ -1116,7 +1131,8 @@ function getSqlFileTables($sql_data) $engine = null; $charset = null; - $tableOptionsRegex = "/([\w\s]+=[\w]+)+?\s*/"; + // $tableOptionsRegex = "/([\w\s]+=[\w]+)+?\s*/"; + $tableOptionsRegex = "/([\w\s]+=\s?\w+)+?\s*/"; preg_match_all($tableOptionsRegex, $rawTableOptions, $tableOptionsSplit); $tableOptionsSplit = current($tableOptionsSplit); foreach ($tableOptionsSplit as $rawTableOption) @@ -1139,7 +1155,7 @@ function getSqlFileTables($sql_data) } } - $ret['engine'][] = $engine; + $ret['engine'][] = str_replace('MYISAM', 'MyISAM', $engine); $ret['charset'][] = $charset; } @@ -1383,7 +1399,7 @@ function renderTableSelect() - + @@ -1408,7 +1424,7 @@ function renderTableSelect() } else { - $icon = E_16_E107; + $icon = defset('E_16_E107'); $name = LAN_CORE; } $text .= ($c === 0) ? "\n" : ''; @@ -1461,7 +1477,7 @@ function renderTableSelect() * * @return string[] An unordered list of the storage engines supported by the current MySQL server */ - private static function getAvailableStorageEngines() + private function getAvailableStorageEngines() { $db = e107::getDb(); $db->gen("SHOW ENGINES;"); @@ -1481,8 +1497,20 @@ private static function getAvailableStorageEngines() */ public function getIntendedStorageEngine($maybeStorageEngine = null) { - if ($maybeStorageEngine === null) + + if($maybeStorageEngine === null) + { return $this->getIntendedStorageEngine(self::MOST_PREFERRED_STORAGE_ENGINE); + } + + if(strtoupper($maybeStorageEngine) === 'MYISAM') + { + $maybeStorageEngine = 'MyISAM'; + } + elseif(strtoupper($maybeStorageEngine) === 'INNODB') + { + $maybeStorageEngine = 'InnoDB'; + } if (!array_key_exists($maybeStorageEngine, $this->storageEnginePreferenceMap)) { diff --git a/e107_tests/tests/unit/db_verifyTest.php b/e107_tests/tests/unit/db_verifyTest.php index 3902086479..e0f5befe4e 100644 --- a/e107_tests/tests/unit/db_verifyTest.php +++ b/e107_tests/tests/unit/db_verifyTest.php @@ -1,38 +1,38 @@ dbv = $this->make('db_verify'); - } - catch (Exception $e) - { - $this->fail("Couldn't load db_verify object"); - } - - $this->dbv->__construct(); + $this->dbv = $this->make('db_verify'); } - - public function testGetFields() + catch(Exception $e) { - $data = "table_id int(10) unsigned NOT NULL auto_increment, + self::fail("Couldn't load db_verify object"); + } + + $this->dbv->__construct(); + } + + public function testGetFields() + { + $data = "table_id int(10) unsigned NOT NULL auto_increment, table_name varchar(100) NOT NULL default '', table_email varchar(100) NOT NULL default '', table_user int(10) unsigned NOT NULL default '0', @@ -53,240 +53,240 @@ public function testGetFields() e107_name varchar(100) NOT NULL default '', PRIMARY KEY (table_id)"; - $expected = array ( - 'table_id' => - array ( - 'type' => 'INT', - 'value' => '10', - 'attributes' => 'UNSIGNED', - 'null' => 'NOT NULL', - 'default' => 'AUTO_INCREMENT', - ), - 'table_name' => - array ( - 'type' => 'VARCHAR', - 'value' => '100', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'\'', - ), - 'table_email' => - array ( - 'type' => 'VARCHAR', - 'value' => '100', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'\'', - ), - 'table_user' => - array ( - 'type' => 'INT', - 'value' => '10', - 'attributes' => 'UNSIGNED', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'0\'', - ), - 'table_title' => - array ( - 'type' => 'VARCHAR', - 'value' => '200', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'\'', - ), - 'table_category' => - array ( - 'type' => 'TINYINT', - 'value' => '3', - 'attributes' => 'UNSIGNED', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'0\'', - ), - 'table_json' => - array ( - 'type' => 'JSON', - 'value' => '', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => '', - ), - 'table_item' => - array ( - 'type' => 'TEXT', - 'value' => '', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => '', - ), - 'table_datestamp' => - array ( - 'type' => 'INT', - 'value' => '10', - 'attributes' => 'UNSIGNED', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'0\'', - ), - 'table_ip' => - array ( - 'type' => 'VARCHAR', - 'value' => '45', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'\'', - ), - 'table_auth' => - array ( - 'type' => 'TINYINT', - 'value' => '3', - 'attributes' => 'UNSIGNED', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'0\'', - ), - 'table_file' => - array ( - 'type' => 'TEXT', - 'value' => '', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => '', - ), - 'table_keywords' => - array ( - 'type' => 'VARCHAR', - 'value' => '255', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'\'', - ), - 'table_description' => - array ( - 'type' => 'TEXT', - 'value' => '', - 'attributes' => '', - 'null' => '', - 'default' => '', - ), - 'table_summary' => - array ( - 'type' => 'TEXT', - 'value' => '', - 'attributes' => '', - 'null' => '', - 'default' => '', - ), - 'table_media' => - array ( - 'type' => 'TEXT', - 'value' => '', - 'attributes' => '', - 'null' => '', - 'default' => '', - ), - 'table_email2' => - array ( - 'type' => 'TINYINT', - 'value' => '3', - 'attributes' => 'UNSIGNED', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'0\'', - ), - 'table_email90' => - array ( - 'type' => 'TINYINT', - 'value' => '3', - 'attributes' => 'UNSIGNED', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'0\'', - ), - 'e107_name' => - array ( - 'type' => 'VARCHAR', - 'value' => '100', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'\'', - ), + $expected = array( + 'table_id' => + array( + 'type' => 'INT', + 'value' => '10', + 'attributes' => 'UNSIGNED', + 'null' => 'NOT NULL', + 'default' => 'AUTO_INCREMENT', + ), + 'table_name' => + array( + 'type' => 'VARCHAR', + 'value' => '100', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'\'', + ), + 'table_email' => + array( + 'type' => 'VARCHAR', + 'value' => '100', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'\'', + ), + 'table_user' => + array( + 'type' => 'INT', + 'value' => '10', + 'attributes' => 'UNSIGNED', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'0\'', + ), + 'table_title' => + array( + 'type' => 'VARCHAR', + 'value' => '200', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'\'', + ), + 'table_category' => + array( + 'type' => 'TINYINT', + 'value' => '3', + 'attributes' => 'UNSIGNED', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'0\'', + ), + 'table_json' => + array( + 'type' => 'JSON', + 'value' => '', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => '', + ), + 'table_item' => + array( + 'type' => 'TEXT', + 'value' => '', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => '', + ), + 'table_datestamp' => + array( + 'type' => 'INT', + 'value' => '10', + 'attributes' => 'UNSIGNED', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'0\'', + ), + 'table_ip' => + array( + 'type' => 'VARCHAR', + 'value' => '45', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'\'', + ), + 'table_auth' => + array( + 'type' => 'TINYINT', + 'value' => '3', + 'attributes' => 'UNSIGNED', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'0\'', + ), + 'table_file' => + array( + 'type' => 'TEXT', + 'value' => '', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => '', + ), + 'table_keywords' => + array( + 'type' => 'VARCHAR', + 'value' => '255', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'\'', + ), + 'table_description' => + array( + 'type' => 'TEXT', + 'value' => '', + 'attributes' => '', + 'null' => '', + 'default' => '', + ), + 'table_summary' => + array( + 'type' => 'TEXT', + 'value' => '', + 'attributes' => '', + 'null' => '', + 'default' => '', + ), + 'table_media' => + array( + 'type' => 'TEXT', + 'value' => '', + 'attributes' => '', + 'null' => '', + 'default' => '', + ), + 'table_email2' => + array( + 'type' => 'TINYINT', + 'value' => '3', + 'attributes' => 'UNSIGNED', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'0\'', + ), + 'table_email90' => + array( + 'type' => 'TINYINT', + 'value' => '3', + 'attributes' => 'UNSIGNED', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'0\'', + ), + 'e107_name' => + array( + 'type' => 'VARCHAR', + 'value' => '100', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'\'', + ), ); - $actual = $this->dbv->getFields($data); - $this->assertEquals($expected,$actual); + $actual = $this->dbv->getFields($data); + self::assertEquals($expected, $actual); + } - } -/* - public function testClearCache() - { + /* + public function testClearCache() + { - } + } - public function testRenderNotes() - { + public function testRenderNotes() + { - } + } - public function testCompareAll() - { + public function testCompareAll() + { - } + } - public function testRenderTableName() - { + public function testRenderTableName() + { - } + } - public function testGetId() - { + public function testGetId() + { - } + } - public function testGetSqlData() - { + public function testGetSqlData() + { - } -*/ - public function testGetIndex() - { + } + */ + public function testGetIndex() + { - $data = "`schedule_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + $data = "`schedule_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `schedule_cust_id` int(11) NOT NULL, `schedule_complete` int(1) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`schedule_id`), UNIQUE KEY `schedule_cust_id` (`schedule_cust_id`), KEY `schedule_invoice_id` (`schedule_invoice_id`)"; - $expected = array( - 'schedule_id' => - array( + $expected = array( + 'schedule_id' => + array( 'type' => 'PRIMARY', 'keyname' => 'schedule_id', 'field' => 'schedule_id', ), - 'schedule_cust_id' => - array( - 'type' => 'UNIQUE', - 'keyname' => 'schedule_cust_id', - 'field' => 'schedule_cust_id', - ), - 'schedule_invoice_id' => - array( - 'type' => '', - 'keyname' => 'schedule_invoice_id', - 'field' => 'schedule_invoice_id', - ), - ); + 'schedule_cust_id' => + array( + 'type' => 'UNIQUE', + 'keyname' => 'schedule_cust_id', + 'field' => 'schedule_cust_id', + ), + 'schedule_invoice_id' => + array( + 'type' => '', + 'keyname' => 'schedule_invoice_id', + 'field' => 'schedule_invoice_id', + ), + ); - $result = $this->dbv->getIndex($data); - $this->assertEquals($expected,$result); - } + $result = $this->dbv->getIndex($data); + self::assertEquals($expected, $result); + } - /** - * @see https://github.com/e107inc/e107/issues/5054 - */ - public function testGetIndexOptionalLengthAndSortOrder() - { - $data = << - array( - 'type' => '', - 'keyname' => 'field1', - 'field' => 'field1', - ), - 'field2' => - array( - 'type' => '', - 'keyname' => 'field2', - 'field' => 'field2', - ), - 'field3' => - array( - 'type' => '', - 'keyname' => 'field3', - 'field' => 'field3', - ), - 'field4' => - array( - 'type' => '', - 'keyname' => 'field4', - 'field' => 'field4', - ), - ); + $expected = array( + 'field1' => + array( + 'type' => '', + 'keyname' => 'field1', + 'field' => 'field1', + ), + 'field2' => + array( + 'type' => '', + 'keyname' => 'field2', + 'field' => 'field2', + ), + 'field3' => + array( + 'type' => '', + 'keyname' => 'field3', + 'field' => 'field3', + ), + 'field4' => + array( + 'type' => '', + 'keyname' => 'field4', + 'field' => 'field4', + ), + ); - $result = $this->dbv->getIndex($data); - $this->assertEquals($expected,$result); - } + $result = $this->dbv->getIndex($data); + self::assertEquals($expected, $result); + } - /** - * FIXME: This test has no assertions! - */ - /* - public function testCompare() - { + /** + * FIXME: This test has no assertions! + */ + /* + public function testCompare() + { - e107::getDb()->gen('ALTER TABLE `#submitnews` CHANGE `submitnews_id` `submitnews_id` INT(10) UNSIGNED NOT NULL;'); - e107::getDb()->gen('ALTER TABLE `#submitnews` DROP INDEX submitnews_id;'); + e107::getDb()->gen('ALTER TABLE `#submitnews` CHANGE `submitnews_id` `submitnews_id` INT(10) UNSIGNED NOT NULL;'); + e107::getDb()->gen('ALTER TABLE `#submitnews` DROP INDEX submitnews_id;'); - $this->dbv->__construct(); + $this->dbv->__construct(); - // print_r($this->dbv->sqlFileTables); + // print_r($this->dbv->sqlFileTables); - $this->dbv->compare('core'); - $this->dbv->compileResults(); + $this->dbv->compare('core'); + $this->dbv->compileResults(); - //FIXME + //FIXME - // print_r($this->dbv->errors); - // print_r($this->dbv->results['submitnews']); - // print_r($this->dbv->indices['submitnews']); - // print_r($this->dbv->results); - } - */ + // print_r($this->dbv->errors); + // print_r($this->dbv->results['submitnews']); + // print_r($this->dbv->indices['submitnews']); + // print_r($this->dbv->results); + } + */ - public function testGetFixQuery() - { + public function testGetFixQuery() + { - $sqlFileData = "table_id int(10) unsigned NOT NULL auto_increment, + $sqlFileData = "table_id int(10) unsigned NOT NULL auto_increment, table_name varchar(100) NOT NULL default '', table_email varchar(100) NOT NULL default '', table_user int(10) unsigned NOT NULL default '0', @@ -379,29 +379,29 @@ public function testGetFixQuery() KEY `table_user` (`table_user`) "; - $actual = $this->dbv->getFixQuery('alter', 'table', 'table_ip', $sqlFileData); - $expected = "ALTER TABLE `e107_table` CHANGE `table_ip` `table_ip` VARCHAR(45) NOT NULL DEFAULT ''"; - $this->assertEquals($expected,$actual); + $actual = $this->dbv->getFixQuery('alter', 'table', 'table_ip', $sqlFileData); + $expected = "ALTER TABLE `e107_table` CHANGE `table_ip` `table_ip` VARCHAR(45) NOT NULL DEFAULT ''"; + self::assertEquals($expected, $actual); - $actual = $this->dbv->getFixQuery('insert', 'table', 'table_auth', $sqlFileData); - $expected = "ALTER TABLE `e107_table` ADD `table_auth` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER table_ip"; - $this->assertEquals($expected,$actual); + $actual = $this->dbv->getFixQuery('insert', 'table', 'table_auth', $sqlFileData); + $expected = "ALTER TABLE `e107_table` ADD `table_auth` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER table_ip"; + self::assertEquals($expected, $actual); - $actual = $this->dbv->getFixQuery('insert', 'table', 'table_json', $sqlFileData); - $expected = "ALTER TABLE `e107_table` ADD `table_json` JSON NOT NULL AFTER table_category"; - $this->assertEquals($expected,$actual); + $actual = $this->dbv->getFixQuery('insert', 'table', 'table_json', $sqlFileData); + $expected = "ALTER TABLE `e107_table` ADD `table_json` JSON NOT NULL AFTER table_category"; + self::assertEquals($expected, $actual); - $actual = $this->dbv->getFixQuery('index', 'table', 'table_email', $sqlFileData); - $expected = 'ALTER TABLE `e107_table` ADD UNIQUE `table_email` (table_email);'; - $this->assertEquals($expected,$actual); + $actual = $this->dbv->getFixQuery('index', 'table', 'table_email', $sqlFileData); + $expected = 'ALTER TABLE `e107_table` ADD UNIQUE `table_email` (table_email);'; + self::assertEquals($expected, $actual); - $actual = $this->dbv->getFixQuery('index', 'table', 'table_user', $sqlFileData); - $expected = 'ALTER TABLE `e107_table` ADD INDEX `table_user` (table_user);'; - $this->assertEquals($expected,$actual); + $actual = $this->dbv->getFixQuery('index', 'table', 'table_user', $sqlFileData); + $expected = 'ALTER TABLE `e107_table` ADD INDEX `table_user` (table_user);'; + self::assertEquals($expected, $actual); - $actual = $this->dbv->getFixQuery('create', 'table', 'table_user', $sqlFileData, 'InnoDB'); - $expected = 'CREATE TABLE `e107_table` (table_id int(10) unsigned NOT NULL auto_increment, + $actual = $this->dbv->getFixQuery('create', 'table', 'table_user', $sqlFileData, 'InnoDB'); + $expected = 'CREATE TABLE `e107_table` (table_id int(10) unsigned NOT NULL auto_increment, table_name varchar(100) NOT NULL default \'\', table_email varchar(100) NOT NULL default \'\', table_user int(10) unsigned NOT NULL default \'0\', @@ -422,87 +422,89 @@ public function testGetFixQuery() KEY `table_user` (`table_user`) ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;'; - $expected = str_replace("\t", "",$expected); - $actual = str_replace("\t", "",$actual); + $expected = str_replace("\t", "", $expected); + $actual = str_replace("\t", "", $actual); - $this->assertEquals($expected,$actual); + self::assertEquals($expected, $actual); // // echo $actual; - } + } - public function testToMysql() - { - $tests = array( - 0 => - array ( - 'type' => 'TINYINT', - 'value' => '3', - 'attributes' => 'UNSIGNED', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'0\'', - ), - 1 => - array ( - 'type' => 'JSON', - 'value' => '', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => '', - ), - ); - - - $expected = array( - "TINYINT(3) UNSIGNED NOT NULL DEFAULT '0'", - "JSON NOT NULL", - ); - - - foreach($tests as $k=>$data) - { - $result = $this->dbv->toMysql($data); - $this->assertEquals($expected[$k], $result); + public function testToMysql() + { + $tests = array( + 0 => + array( + 'type' => 'TINYINT', + 'value' => '3', + 'attributes' => 'UNSIGNED', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'0\'', + ), + 1 => + array( + 'type' => 'JSON', + 'value' => '', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => '', + ), + ); - } - } -/* - public function testRunFix() - { + $expected = array( + "TINYINT(3) UNSIGNED NOT NULL DEFAULT '0'", + "JSON NOT NULL", + ); - } - public function testRenderTableSelect() + foreach($tests as $k => $data) { + $result = $this->dbv->toMysql($data); + self::assertEquals($expected[$k], $result); } - public function testVerify() - { + } - } + /* + public function testRunFix() + { - public function testGetPrevious() - { + } - } + public function testRenderTableSelect() + { - public function testRenderResults() - { + } - } + public function testVerify() + { - public function testErrors() - { + } + + public function testGetPrevious() + { + + } + + public function testRenderResults() + { + + } + + public function testErrors() + { + + } + */ + public function testGetSqlFileTables() + { + $tests = array( - } -*/ - public function testGetSqlFileTables() - { - $tests = array( 'missing_index' => "CREATE TABLE `e107_submitnews` ( @@ -540,7 +542,7 @@ public function testGetSqlFileTables() ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", 'banlist' => - "CREATE TABLE `e107_banlist` ( + "CREATE TABLE `e107_banlist` ( `banlist_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `banlist_ip` varchar(100) NOT NULL DEFAULT '', `banlist_bantype` tinyint(3) NOT NULL DEFAULT '0', @@ -556,7 +558,7 @@ public function testGetSqlFileTables() ) ENGINE=MyISAM AUTO_INCREMENT=182 DEFAULT CHARSET=utf8;", 'test_json' => - "CREATE TABLE `e107_test_comment` ( + "CREATE TABLE `e107_test_comment` ( `eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `eml_hash` varchar(20) NOT NULL, `eml_datestamp` int(11) unsigned NOT NULL, @@ -567,7 +569,7 @@ public function testGetSqlFileTables() ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", 'test_comment' => - "CREATE TABLE `e107_test_comment` ( + "CREATE TABLE `e107_test_comment` ( `eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `eml_hash` varchar(20) NOT NULL, `eml_datestamp` int(11) unsigned NOT NULL, @@ -577,9 +579,9 @@ public function testGetSqlFileTables() UNIQUE KEY `eml_hash` (`eml_hash`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", - 'multiple' => + 'multiple' => - "CREATE TABLE e107_plugin ( + "CREATE TABLE e107_plugin ( plugin_id int(10) unsigned NOT NULL auto_increment, plugin_name varchar(100) NOT NULL default '', plugin_version varchar(10) NOT NULL default '', @@ -603,19 +605,27 @@ public function testGetSqlFileTables() ) ENGINE=MyISAM; ", + 'syntax_variant' => + "CREATE TABLE e107_test ( + `test_id` int(10) unsigned NOT NULL, + `test_name` varchar(100) not null default '', + + `test_summary` text, - ); + ) ENGINE = MYISAM;", - $expected = array( + ); - 'missing_index' => array ( - 'tables' => - array ( - 0 => 'submitnews', - ), - 'data' => - array ( - 0 => '`submitnews_id` int(10) unsigned NOT NULL, + $expected = array( + + 'missing_index' => array( + 'tables' => + array( + 0 => 'submitnews', + ), + 'data' => + array( + 0 => '`submitnews_id` int(10) unsigned NOT NULL, `submitnews_name` varchar(100) NOT NULL DEFAULT \'\', `submitnews_email` varchar(100) NOT NULL DEFAULT \'\', `submitnews_title` varchar(200) NOT NULL DEFAULT \'\', @@ -630,22 +640,22 @@ public function testGetSqlFileTables() `submitnews_summary` text, `submitnews_media` text, `submitnews_user` int(10) unsigned NOT NULL DEFAULT \'0\'', - ), - 'engine' => - array ( - 0 => 'MyISAM', - ), ), + 'engine' => + array( + 0 => 'MyISAM', + ), + ), - 'user_extended' => array ( - 'tables' => - array ( - 0 => 'user_extended', - ), - 'data' => - array ( - 0 => '`user_extended_id` int(10) unsigned NOT NULL DEFAULT \'0\', + 'user_extended' => array( + 'tables' => + array( + 0 => 'user_extended', + ), + 'data' => + array( + 0 => '`user_extended_id` int(10) unsigned NOT NULL DEFAULT \'0\', `user_hidden_fields` text, `user_country` varchar(255) DEFAULT NULL, `user_szulido` date NOT NULL, @@ -656,21 +666,21 @@ public function testGetSqlFileTables() `user_belepesi` varchar(255) DEFAULT \'Egyeztetés alatt\', `user_timezone` varchar(255) DEFAULT \'+0\', PRIMARY KEY (`user_extended_id`)', - ), - 'engine' => - array ( - 0 => 'MyISAM', - ), - ), + ), + 'engine' => + array( + 0 => 'MyISAM', + ), + ), - 'banlist' => array ( - 'tables' => - array ( - 0 => 'banlist', - ), - 'data' => - array ( - 0 => '`banlist_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + 'banlist' => array( + 'tables' => + array( + 0 => 'banlist', + ), + 'data' => + array( + 0 => '`banlist_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `banlist_ip` varchar(100) NOT NULL DEFAULT \'\', `banlist_bantype` tinyint(3) NOT NULL DEFAULT \'0\', `banlist_datestamp` int(10) unsigned NOT NULL DEFAULT \'0\', @@ -682,66 +692,66 @@ public function testGetSqlFileTables() KEY `banlist_datestamp` (`banlist_datestamp`), KEY `banlist_banexpires` (`banlist_banexpires`), KEY `banlist_ip` (`banlist_ip`)', - ), - 'engine' => - array ( - 0 => 'MyISAM', - ), - ), + ), + 'engine' => + array( + 0 => 'MyISAM', + ), + ), - 'test_json' => array ( - 'tables' => - array ( - 0 => 'test_comment', - ), - 'data' => - array ( - 0 => '`eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT, + 'test_json' => array( + 'tables' => + array( + 0 => 'test_comment', + ), + 'data' => + array( + 0 => '`eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `eml_hash` varchar(20) NOT NULL, `eml_datestamp` int(11) unsigned NOT NULL, `eml_json` JSON NOT NULL, `eml_to` varchar(50) NOT NULL, PRIMARY KEY (`eml_id`), UNIQUE KEY `eml_hash` (`eml_hash`)', - ), - 'engine' => - array ( - 0 => 'MyISAM', - ), - ), + ), + 'engine' => + array( + 0 => 'MyISAM', + ), + ), - 'test_comment' => array ( - 'tables' => - array ( - 0 => 'test_comment', - ), - 'data' => - array ( - 0 => '`eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT, + 'test_comment' => array( + 'tables' => + array( + 0 => 'test_comment', + ), + 'data' => + array( + 0 => '`eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `eml_hash` varchar(20) NOT NULL, `eml_datestamp` int(11) unsigned NOT NULL, `eml_from` varchar(50) NOT NULL COMMENT \'This is the from field\', `eml_to` varchar(50) NOT NULL, PRIMARY KEY (`eml_id`), UNIQUE KEY `eml_hash` (`eml_hash`)', - ), - 'engine' => - array ( - 0 => 'InnoDB', - ), - ), - - 'multiple' => - array ( - 'tables' => - array ( - 0 => 'plugin', - 1 => 'rate', - ), - 'data' => - array ( - 0 => 'plugin_id int(10) unsigned NOT NULL auto_increment, + ), + 'engine' => + array( + 0 => 'InnoDB', + ), + ), + + 'multiple' => + array( + 'tables' => + array( + 0 => 'plugin', + 1 => 'rate', + ), + 'data' => + array( + 0 => 'plugin_id int(10) unsigned NOT NULL auto_increment, plugin_name varchar(100) NOT NULL default \'\', plugin_version varchar(10) NOT NULL default \'\', plugin_path varchar(100) NOT NULL default \'\', @@ -750,7 +760,7 @@ public function testGetSqlFileTables() plugin_category varchar(100) NOT NULL default \'\', PRIMARY KEY (plugin_id), UNIQUE KEY plugin_path (plugin_path)', - 1 => 'rate_id int(10) unsigned NOT NULL auto_increment, + 1 => 'rate_id int(10) unsigned NOT NULL auto_increment, rate_table varchar(100) NOT NULL default \'\', rate_itemid int(10) unsigned NOT NULL default \'0\', rate_rating int(10) unsigned NOT NULL default \'0\', @@ -759,46 +769,61 @@ public function testGetSqlFileTables() rate_up int(10) unsigned NOT NULL default \'0\', rate_down int(10) unsigned NOT NULL default \'0\', PRIMARY KEY (rate_id)', - ), - 'engine' => - array ( - 0 => 'MyISAM', - 1 => 'MyISAM', - ), - ) - - - - ); + ), + 'engine' => + array( + 0 => 'MyISAM', + 1 => 'MyISAM', + ), + ), + 'syntax_variant' => array( + 'tables' => + array( + 0 => 'test', + ), + 'data' => + array( + 0 => '`test_id` int(10) unsigned NOT NULL, + `test_name` varchar(100) not null default \'\', - foreach($tests as $table => $sql) - { + `test_summary` text,', + ), + 'engine' => + array( + 0 => 'MyISAM', + ), + ), + ); - $actual = $this->dbv->getSqlFileTables($sql); - $this->assertEquals($actual['tables'], $expected[$table]['tables'], "Table ".$table." could not be parsed."); + foreach($tests as $table => $sql) + { - foreach($expected[$table]['data'] as $k=>$data) - { - $data = str_replace("\t", '', $data); - $this->assertEquals($actual['data'][$k], $data, "Table ".$table."['data'][".$k."] did not match."); - } + $actual = $this->dbv->getSqlFileTables($sql); - $this->assertEquals($actual['engine'], $expected[$table]['engine']); + self::assertEquals($expected[$table]['tables'], $actual['tables'], "Table " . $table . " could not be parsed."); + foreach($expected[$table]['data'] as $k => $data) + { + $data = str_replace("\t", '', $data); + self::assertEquals($data, $actual['data'][$k], "Table " . $table . "['data'][" . $k . "] did not match."); } + self::assertEquals($expected[$table]['engine'], $actual['engine'], "Test Key: '" . $table. "' failed on 'engine'"); + } + } + - public function testPrepareResults() - { + public function testPrepareResults() + { - $fileData = array(); - $sqlData = array(); + $fileData = array(); + $sqlData = array(); - $sql = "`schedule_id` int(10) unsigned NOT NULL auto_increment, + $sql = "`schedule_id` int(10) unsigned NOT NULL auto_increment, `schedule_user_id` int(11) NOT NULL, `schedule_invoice_id` int(11) NOT NULL, `schedule_name` varchar(50) NOT NULL default '', @@ -807,7 +832,7 @@ public function testPrepareResults() `schedule_results` text NOT NULL, PRIMARY KEY (`schedule_id`);"; - $file = "`schedule_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + $file = "`schedule_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `schedule_user_id` int(11) NOT NULL, `schedule_invoice_id` int(11) NOT NULL, `schedule_name` varchar(100) NOT NULL DEFAULT '', @@ -821,223 +846,274 @@ public function testPrepareResults() "; - $fileData['field'] = $this->dbv->getFields($file); - $sqlData['field'] = $this->dbv->getFields($sql); - - $fileData['index'] = $this->dbv->getIndex($file); - $sqlData['index'] = $this->dbv->getIndex($sql); + $fileData['field'] = $this->dbv->getFields($file); + $sqlData['field'] = $this->dbv->getFields($sql); + + $fileData['index'] = $this->dbv->getIndex($file); + $sqlData['index'] = $this->dbv->getIndex($sql); + + $fileData['engine'] = $this->dbv->getIntendedStorageEngine("InnoDB"); + $sqlData['engine'] = $this->dbv->getCanonicalStorageEngine("InnoDB"); + + $fileData['charset'] = $this->dbv->getIntendedCharset("utf8mb4"); + $sqlData['charset'] = $this->dbv->getCanonicalCharset("utf8mb4"); + + $this->dbv->prepareResults('schedule', 'myplugin', $sqlData, $fileData); + + $resultFields = $this->dbv->getResults(); + $expected = array( + 'schedule' => + array( + 'schedule_id' => + array( + '_status' => 'ok', + ), + 'schedule_user_id' => + array( + '_status' => 'ok', + ), + 'schedule_invoice_id' => + array( + '_status' => 'ok', + ), + 'schedule_name' => + array( + '_status' => 'mismatch', + '_diff' => + array( + 'value' => '100', + ), + '_valid' => + array( + 'type' => 'VARCHAR', + 'value' => '100', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'\'', + ), + '_invalid' => + array( + 'type' => 'VARCHAR', + 'value' => '50', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => 'DEFAULT \'\'', + ), + '_file' => 'myplugin', + ), + 'schedule_location' => + array( + '_status' => 'ok', + ), + 'schedule_begin_date' => + array( + '_status' => 'missing_field', + '_valid' => + array( + 'type' => 'INT', + 'value' => '11', + 'attributes' => '', + 'null' => 'NOT NULL', + 'default' => '', + ), + '_file' => 'myplugin', + ), + 'schedule_data' => + array( + '_status' => 'ok', + ), + 'schedule_results' => + array( + '_status' => 'ok', + ), + ), + ); - $fileData['engine'] = $this->dbv->getIntendedStorageEngine("InnoDB"); - $sqlData['engine'] = $this->dbv->getCanonicalStorageEngine("InnoDB"); - $fileData['charset'] = $this->dbv->getIntendedCharset("utf8mb4"); - $sqlData['charset'] = $this->dbv->getCanonicalCharset("utf8mb4"); + self::assertEquals($expected, $resultFields); + + + $resultIndices = $this->dbv->getResults('indices'); + $expected = array( + 'schedule' => + array( + 'schedule_id' => + array( + '_status' => 'ok', + ), + 'schedule_user_id' => + array( + '_status' => 'missing_index', + '_valid' => + array( + 'type' => 'UNIQUE', + 'keyname' => 'schedule_user_id', + 'field' => 'schedule_user_id', + ), + '_file' => 'myplugin', + ), + 'schedule_invoice_id' => + array( + '_status' => 'missing_index', + '_valid' => + array( + 'type' => '', + 'keyname' => 'schedule_invoice_id', + 'field' => 'schedule_invoice_id', + ), + '_file' => 'myplugin', + ), + ), + ); - $this->dbv->prepareResults('schedule', 'myplugin', $sqlData, $fileData); + self::assertEquals($expected, $resultIndices); - $resultFields = $this->dbv->getResults('fields'); - $expected = array( - 'schedule' => - array( - 'schedule_id' => - array( - '_status' => 'ok', - ), - 'schedule_user_id' => - array( - '_status' => 'ok', - ), - 'schedule_invoice_id' => - array( - '_status' => 'ok', - ), - 'schedule_name' => - array( - '_status' => 'mismatch', - '_diff' => - array( - 'value' => '100', - ), - '_valid' => - array( - 'type' => 'VARCHAR', - 'value' => '100', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'\'', - ), - '_invalid' => - array( - 'type' => 'VARCHAR', - 'value' => '50', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => 'DEFAULT \'\'', - ), - '_file' => 'myplugin', - ), - 'schedule_location' => - array( - '_status' => 'ok', - ), - 'schedule_begin_date' => - array( - '_status' => 'missing_field', - '_valid' => - array( - 'type' => 'INT', - 'value' => '11', - 'attributes' => '', - 'null' => 'NOT NULL', - 'default' => '', - ), - '_file' => 'myplugin', - ), - 'schedule_data' => - array( - '_status' => 'ok', - ), - 'schedule_results' => - array( - '_status' => 'ok', - ), - ), - ); + $fileData['charset'] = "utf8mb4"; + $sqlData['charset'] = "utf8"; + $result = $this->dbv->prepareResults('schedule', 'myplugin', $sqlData, $fileData); + $resultFields = $this->dbv->getErrors(); + $expected = array ( + 'schedule' => + array ( + '_status' => 8, + '_file' => 'myplugin', + '_valid_8' => 'utf8mb4', + '_invalid_8' => 'utf8', + ), + ); + self::assertSame($expected, $resultFields); + self::assertSame(1, $this->dbv->errors()); + } - $this->assertEquals($expected, $resultFields); + /* + public function testFixForm() + { - $resultIndices = $this->dbv->getResults('indices'); - $expected = array( - 'schedule' => - array( - 'schedule_id' => - array( - '_status' => 'ok', - ), - 'schedule_user_id' => - array( - '_status' => 'missing_index', - '_valid' => - array( - 'type' => 'UNIQUE', - 'keyname' => 'schedule_user_id', - 'field' => 'schedule_user_id', - ), - '_file' => 'myplugin', - ), - 'schedule_invoice_id' => - array( - '_status' => 'missing_index', - '_valid' => - array( - 'type' => '', - 'keyname' => 'schedule_invoice_id', - 'field' => 'schedule_invoice_id', - ), - '_file' => 'myplugin', - ), - ), - ); + } - $this->assertEquals($expected, $resultIndices); + public function testRunComparison() + { - } + } + public function testCompileResults() + { + } -/* - public function testFixForm() - { + public function testGetSqlLanguages() + { - } + }*/ - public function testRunComparison() - { + public function testGetCanonicalStorageEngine() + { + $input = "InnoDB"; - } + $output = $this->dbv->getCanonicalStorageEngine($input); - public function testCompileResults() - { + self::assertEquals($input, $output); + } - } + public function testGetCanonicalStorageEngineUnknownStorageEngine() + { + $this->expectException(UnexpectedValueException::class); - public function testGetSqlLanguages() - { + $this->dbv->getCanonicalStorageEngine("FakeEngine"); + } - }*/ + public function testGetCanonicalCharsetUtf8Alias() + { + $input = "utf8"; + $expected = "utf8mb4"; - public function testGetCanonicalStorageEngine() - { - $input = "InnoDB"; + $output = $this->dbv->getCanonicalCharset($input); - $output = $this->dbv->getCanonicalStorageEngine($input); + self::assertEquals($expected, $output); + } - $this->assertEquals($input, $output); - } + public function testGetCanonicalCharsetOther() + { + $inputs = ["latin1", "utf8mb3", "utf8mb4"]; - public function testGetCanonicalStorageEngineUnknownStorageEngine() + foreach($inputs as $input) { - $this->expectException(UnexpectedValueException::class); + $output = $this->dbv->getCanonicalCharset($input); - $this->dbv->getCanonicalStorageEngine("FakeEngine"); + self::assertEquals($input, $output); } + } - public function testGetCanonicalCharsetUtf8Alias() - { - $input = "utf8"; - $expected = "utf8mb4"; + public function testGetIntendedStorageEngine() + { + $output = $this->dbv->getIntendedStorageEngine("MyISAM"); + self::assertEquals("InnoDB", $output); - $output = $this->dbv->getCanonicalCharset($input); + $output = $this->dbv->getIntendedStorageEngine("MYISAM"); + self::assertEquals("InnoDB", $output); + + $output = $this->dbv->getIntendedStorageEngine("InnoDB"); + self::assertEquals("InnoDB", $output); - $this->assertEquals($expected, $output); - } + $output = $this->dbv->getIntendedStorageEngine("INNODB"); + self::assertEquals("InnoDB", $output); - public function testGetCanonicalCharsetOther() - { - $inputs = ["latin1", "utf8mb3", "utf8mb4"]; + $output = $this->dbv->getIntendedStorageEngine("Aria"); + self::assertContains($output, ["Aria", "Maria", "MyISAM"]); - foreach ($inputs as $input) - { - $output = $this->dbv->getCanonicalCharset($input); + $output = $this->dbv->getIntendedStorageEngine("MEMORY"); + self::assertEquals("MEMORY", $output); + } - $this->assertEquals($input, $output); - } - } + public function testGetIntendedCharset() + { + $output = $this->dbv->getIntendedCharset(""); + self::assertEquals("utf8mb4", $output); - public function testGetIntendedStorageEngine() - { - $output = $this->dbv->getIntendedStorageEngine("MyISAM"); - $this->assertEquals("InnoDB", $output); + $output = $this->dbv->getIntendedCharset(); + self::assertEquals("utf8mb4", $output); - $output = $this->dbv->getIntendedStorageEngine("InnoDB"); - $this->assertEquals("InnoDB", $output); + $output = $this->dbv->getIntendedCharset("utf8"); + self::assertEquals("utf8mb4", $output); - $output = $this->dbv->getIntendedStorageEngine("Aria"); - $this->assertContains($output, ["Aria", "Maria", "MyISAM"]); + $output = $this->dbv->getIntendedCharset("utf8mb3"); + self::assertEquals("utf8mb3", $output); - $output = $this->dbv->getIntendedStorageEngine("MEMORY"); - $this->assertEquals("MEMORY", $output); - } + $output = $this->dbv->getIntendedCharset("latin1"); + self::assertEquals("latin1", $output); + } - public function testGetIntendedCharset() - { - $output = $this->dbv->getIntendedCharset(""); - $this->assertEquals("utf8mb4", $output); + /*function testGetAvailableStorageEngines() + { + $result = $this->dbv->getAvailableStorageEngines(); - $output = $this->dbv->getIntendedCharset(); - $this->assertEquals("utf8mb4", $output); + }*/ - $output = $this->dbv->getIntendedCharset("utf8"); - $this->assertEquals("utf8mb4", $output); + public function testRunFix() + { + $sql = e107::getDb(); - $output = $this->dbv->getIntendedCharset("utf8mb3"); - $this->assertEquals("utf8mb3", $output); + // Prepare table. + $sql->gen('ALTER TABLE `#rss` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;'); + $sql->gen('SHOW CREATE TABLE `#rss`'); + $row = $sql->rows(); + self::assertStringNotContainsString('CHARSET=utf8mb4', $row[1]['Create Table']); + + // Fix table. + $this->dbv->compare('rss'); + $this->dbv->compileResults(); + $this->dbv->runFix(); + + // validate table. + $sql->gen('SHOW CREATE TABLE `#rss`'); + $row = $sql->rows(); + + self::assertStringContainsString('CHARSET=utf8mb4', $row[1]['Create Table']); - $output = $this->dbv->getIntendedCharset("latin1"); - $this->assertEquals("latin1", $output); - } } + +}