3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests\Selenium
;
7 use PHPUnit\Framework\Attributes\CoversNothing
;
8 use PHPUnit\Framework\Attributes\Large
;
12 class ImportTest
extends TestBase
17 protected function setUp(): void
25 * Test for server level import
27 public function testServerImport(): void
29 $this->doImport('server');
31 'SHOW DATABASES LIKE \'test_import%\'',
33 self
::assertSame('test_import1', $this->getCellByTableClass('table_results', 1, 1));
34 self
::assertSame('test_import2', $this->getCellByTableClass('table_results', 2, 1));
39 $this->dbQuery('DROP DATABASE test_import1;DROP DATABASE test_import2;');
43 * Test for db level import
45 public function testDbImport(): void
47 $this->dbQuery('CREATE DATABASE IF NOT EXISTS `' . $this->databaseName
. '`');
48 $this->navigateDatabase($this->databaseName
);
50 $this->doImport('db');
53 'USE `' . $this->databaseName
. '`;'
54 . 'SHOW TABLES FROM `' . $this->databaseName
. '`',
56 self
::assertTrue($this->isElementPresent('className', 'table_results'));
57 self
::assertSame('test_table', $this->getCellByTableClass('table_results', 1, 1));
63 * Test for table level import
65 public function testTableImport(): void
69 'CREATE DATABASE IF NOT EXISTS `' . $this->databaseName
. '`;'
70 . 'USE `' . $this->databaseName
. '`;'
71 . 'CREATE TABLE IF NOT EXISTS `test_table` (`val` int(11) NOT NULL);',
74 $this->navigateTable('test_table');
76 $this->doImport('table');
79 'SELECT * FROM `' . $this->databaseName
. '`.test_table',
81 self
::assertTrue($this->isElementPresent('className', 'table_results'));
82 self
::assertSame('8', $this->getCellByTableClass('table_results', 1, 1));
83 self
::assertSame('9', $this->getCellByTableClass('table_results', 2, 1));
89 * Function that goes to the import page, uploads a file and submit form
91 * @param string $type level: server, db or import
93 private function doImport(string $type): void
95 $this->waitForElement('partialLinkText', 'Import')->click();
98 $this->waitForElement('id', 'localFileTab')->click();
99 $this->waitForElement('id', 'input_import_file');
100 $this->selectByValue($this->byName('local_import_file'), $type . '_import.sql');
102 $this->scrollToBottom();
103 $this->waitUntilElementIsVisible('id', 'sql_options', 30);
105 $this->scrollToBottom();
106 $this->waitUntilElementIsVisible('id', 'buttonGo', 30);
107 $this->byId('buttonGo')->click();
109 $success = $this->waitUntilElementIsVisible('cssSelector', '.alert-success', 30);
110 self
::assertStringContainsString('Import has been successfully', $success->getText());