/** * Tests replace() method * * @return void */ public function testReplace() { //mock DBI $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock(); $find = 'findValue'; $replaceWith = 'replaceWithValue'; $charSet = 'charSetValue'; $expectedQuery = "UPDATE `dbName`.`tableName`" . " SET `column1` = REPLACE(`column1`, '" . $find . "', '" . $replaceWith . "') WHERE `column1` LIKE '%" . $find . "%' COLLATE " . $charSet . "_bin"; // set expectations $dbi->expects($this->once())->method('query')->with($expectedQuery); $GLOBALS['dbi'] = $dbi; $this->_object->replace(0, $find, $replaceWith, $charSet); }
*/ require_once 'libraries/common.inc.php'; require_once 'libraries/TableSearch.class.php'; $response = PMA_Response::getInstance(); $table_search = new PMA_TableSearch($db, $table, "replace"); $connectionCharSet = $GLOBALS['dbi']->fetchValue("SHOW VARIABLES LIKE 'character_set_connection'", 0, 1); if (isset($_POST['find'])) { $preview = $table_search->getReplacePreview($_POST['columnIndex'], $_POST['find'], $_POST['replaceWith'], $connectionCharSet); $response->addJSON('preview', $preview); exit; } $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('tbl_find_replace.js'); // Show secondary level of tabs $htmlOutput = $table_search->getSecondaryTabs(); if (isset($_POST['replace'])) { $htmlOutput .= $table_search->replace($_POST['columnIndex'], $_POST['findString'], $_POST['replaceWith'], $connectionCharSet); $htmlOutput .= PMA_Util::getMessage(__('Your SQL query has been executed successfully.'), null, 'success'); } if (!isset($goto)) { $goto = $GLOBALS['cfg']['DefaultTabTable']; } // Defines the url to return to in case of error in the next sql statement $err_url = $goto . '?' . PMA_URL_getCommon($db, $table); // Displays the find and replace form $htmlOutput .= $table_search->getSelectionForm($goto); $response->addHTML($htmlOutput); ?> >>>>>>> b875702c9c06ab5012e52ff4337439b03918f453
/** * Test for replace * * @return void */ public function testReplace() { $tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom"); $columnIndex = 0; $find = "Field"; $replaceWith = "Column"; $useRegex = false; $charSet = "UTF-8"; $tableSearch->replace($columnIndex, $find, $replaceWith, $useRegex, $charSet); $sql_query = $GLOBALS['sql_query']; $result = "UPDATE `PMA`.`PMA_BookMark` SET `Field1` = " . "REPLACE(`Field1`, 'Field', 'Column') " . "WHERE `Field1` LIKE '%Field%' COLLATE UTF-8_bin"; $this->assertEquals($result, $sql_query); }