/** * Tests getReplacePreview() method * * @return void * @group medium */ public function testGetReplacePreview() { //mock DBI $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock(); $find = 'findValue'; $replaceWith = 'replaceWithValue'; $useRegex = false; $charSet = 'charSetValue'; // set expectations $dbi->expects($this->once())->method('fetchResult')->will($this->returnValue(array(array('val1', 'replace1', 5), array('va<2', 'replac<2', 1)))); $GLOBALS['dbi'] = $dbi; $ret = $this->_object->getReplacePreview(0, $find, $replaceWith, $useRegex, $charSet); // assert whether hidden values are properly set $this->assertContains('<input type="hidden" name="replace" value="true" />', $ret); $this->assertContains('<input type="hidden" name="columnIndex" value="0" />', $ret); $this->assertContains('<input type="hidden" name="findString"' . ' value="' . $find . '" />', $ret); $this->assertContains('<input type="hidden" name="replaceWith"' . ' value="' . $replaceWith . '" />', $ret); // assert values displayed in the preview and escaping /** * @todo Find out a better method to test for HTML * * $this->assertContains( * '<td class="right">5</td><td>val1</td><td>replace1</td>', * $ret * ); * * $this->assertContains( * '<td class="right">1</td><td>va<2</td><td>replac<2</td>', * $ret * ); */ }
/** * Tests getReplacePreview() method * * @return void * @group medium */ public function testGetReplacePreview() { //mock DBI $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock(); $find = 'findValue'; $replaceWith = 'replaceWithValue'; $charSet = 'charSetValue'; $expectedQuery = "SELECT `column1`, REPLACE(`column1`, '" . $find . "', '" . $replaceWith . "'), COUNT(*) FROM `dbName`.`tableName` WHERE `column1`" . " LIKE '%" . $find . "%' COLLATE " . $charSet . "_bin GROUP BY" . " `column1` ORDER BY `column1` ASC"; // set expectations $dbi->expects($this->once())->method('query')->with($expectedQuery); $dbi->expects($this->at(1))->method('fetchRow')->will($this->returnValue(array('val1', 'replace1', 5))); $dbi->expects($this->at(2))->method('fetchRow')->will($this->returnValue(array('va<2', 'replac<2', 1))); $dbi->expects($this->at(3))->method('fetchRow')->will($this->returnValue(false)); $GLOBALS['dbi'] = $dbi; $ret = $this->_object->getReplacePreview(0, $find, $replaceWith, $charSet); // assert whether hidden values are properly set $this->assertContains('<input type="hidden" name="replace" value="true" />', $ret); $this->assertContains('<input type="hidden" name="columnIndex" value="0" />', $ret); $this->assertContains('<input type="hidden" name="findString"' . ' value="' . $find . '" />', $ret); $this->assertContains('<input type="hidden" name="replaceWith"' . ' value="' . $replaceWith . '" />', $ret); // assert values displayed in the preview and escaping $this->assertContains('<td class="right">5</td><td>val1</td><td>replace1</td>', $ret); $this->assertContains('<td class="right">1</td><td>va<2</td><td>replac<2</td>', $ret); }
* Handles find and replace tab * * Displays find and replace form, allows previewing and do the replacing * * @package PhpMyAdmin */ /** * Gets some core libraries */ 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']; }
/** * Test for getReplacePreview * * @return void */ public function testGetReplacePreview() { $value = array('value', 'replace_value', 'count'); $dbi = $GLOBALS['dbi']; $dbi->expects($this->once())->method('fetchResult')->will($this->returnValue(array($value))); $GLOBALS['dbi'] = $dbi; $tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom"); $columnIndex = 0; $find = "Field"; $replaceWith = "Column"; $useRegex = false; $charSet = "UTF-8"; $html = $tableSearch->getReplacePreview($columnIndex, $find, $replaceWith, $useRegex, $charSet); /** * @todo Find out a better method to test for HTML * * $this->assertContains( * '<form method="post" action="tbl_find_replace.php"', * $html * ); */ $this->assertContains('<input type="hidden" name="replace" value="true" />', $html); $this->assertContains(__('Find and replace - preview'), $html); $this->assertContains(__('Original string'), $html); $this->assertContains(__('Replaced string'), $html); $this->assertContains('<td>value</td>', $html); $this->assertContains('<td>replace_value</td>', $html); $this->assertContains('<td class="right">count</td>', $html); }