2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Selenium TestCase for export related tests
6 * @package PhpMyAdmin-test
10 require_once 'TestBase.php';
13 * PmaSeleniumExportTest class
15 * @package PhpMyAdmin-test
16 * @subpackage Selenium
19 class PMA_SeleniumExportTest
extends PMA_SeleniumBase
22 * Setup the browser environment to run the selenium test case
26 public function setUp()
30 "CREATE TABLE `test_table` ("
31 . " `id` int(11) NOT NULL AUTO_INCREMENT,"
32 . " `val` int(11) NOT NULL,"
33 . " PRIMARY KEY (`id`)"
37 "INSERT INTO `test_table` (val) VALUES (2);"
42 * setUp function that can use the selenium session (called before each test)
46 public function setUpPage()
52 * Test for server level export
54 * @param string $plugin Export format
55 * @param array $expected Array of expected strings
58 * @dataProvider exportDataProvider
62 public function testServerImport($plugin, $expected)
64 $text = $this->_doExport('server', $plugin);
66 foreach ($expected as $str) {
67 $this->assertContains($str, $text);
73 * Test for db level export
75 * @param string $plugin Export format
76 * @param array $expected Array of expected strings
79 * @dataProvider exportDataProvider
83 public function testDbExport($plugin, $expected)
85 $this->waitForElement("byLinkText", $this->database_name
)->click();
86 $this->waitForElement(
88 "//a[@class='item' and contains(., 'Database: "
89 . $this->database_name
. "')]"
92 $text = $this->_doExport('db', $plugin);
94 foreach ($expected as $str) {
95 $this->assertContains($str, $text);
100 * Test for table level export
102 * @param string $plugin Export format
103 * @param array $expected Array of expected strings
106 * @dataProvider exportDataProvider
110 public function testTableExport($plugin, $expected)
112 $this->dbQuery("INSERT INTO `test_table` (val) VALUES (3);");
114 $this->navigateTable('test_table');
116 $text = $this->_doExport('table', $plugin);
118 foreach ($expected as $str) {
119 $this->assertContains($str, $text);
125 * Data provider for testServerExport
127 * @return array Test cases data
129 public function exportDataProvider()
139 "CREATE TABLE IF NOT EXISTS `test_table`",
140 "INSERT INTO `test_table` (`id`, `val`) VALUES",
146 array('[{"id":"1","val":"2"}]')
152 * Function that goes to the import page, uploads a file and submit form
154 * @param string $type level: server, db or import
155 * @param string $plugin format: csv, json, etc
157 * @return string export string
159 private function _doExport($type, $plugin)
163 $this->waitForElement('byLinkText', "Export")->click();
166 $this->waitForElement("byId", "quick_or_custom");
168 * FIXME: There should be better way to wait for javascript to be executed
171 $this->byCssSelector("label[for=radio_custom_export]")->click();
173 if ($type == 'server') {
174 $this->byLinkText('Unselect all')->click();
175 $this->byCssSelector(
176 "option[value=" . $this->database_name
. "]"
180 if ($type == 'table') {
181 $this->byCssSelector("label[for=radio_allrows_0]")->click();
183 $this->byName("limit_to")->clear();
184 $this->byName("limit_to")->value("1");
187 $this->select($this->byId("plugins"))->selectOptionByLabel($plugin);
188 $this->byCssSelector("label[for=radio_view_as_text]")->click();
190 if ($plugin == "SQL") {
191 $this->byCssSelector(
192 "label[for=radio_sql_structure_or_data_structure_and_data]"
195 if ($type != "table") {
196 $this->byCssSelector(
197 "label[for=checkbox_sql_create_database]"
202 $this->byId("buttonGo")->click();
204 $text = $this->waitForElement("byId", "textSQLDUMP")->text();