Merge pull request #19552 from kamil-tekiela/Fix-default-values
[phpmyadmin.git] / tests / end-to-end / ImportTest.php
blob3539c308bbecc57143cdfbcb5ffcb00ea8be5774
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests\Selenium;
7 use PHPUnit\Framework\Attributes\CoversNothing;
8 use PHPUnit\Framework\Attributes\Large;
10 #[CoversNothing]
11 #[Large]
12 class ImportTest extends TestBase
14 /**
15 * setUp function
17 protected function setUp(): void
19 parent::setUp();
21 $this->login();
24 /**
25 * Test for server level import
27 public function testServerImport(): void
29 $this->doImport('server');
30 $this->dbQuery(
31 'SHOW DATABASES LIKE \'test_import%\'',
32 function (): void {
33 self::assertSame('test_import1', $this->getCellByTableClass('table_results', 1, 1));
34 self::assertSame('test_import2', $this->getCellByTableClass('table_results', 2, 1));
38 // clear db
39 $this->dbQuery('DROP DATABASE test_import1;DROP DATABASE test_import2;');
42 /**
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');
52 $this->dbQuery(
53 'USE `' . $this->databaseName . '`;'
54 . 'SHOW TABLES FROM `' . $this->databaseName . '`',
55 function (): void {
56 self::assertTrue($this->isElementPresent('className', 'table_results'));
57 self::assertSame('test_table', $this->getCellByTableClass('table_results', 1, 1));
62 /**
63 * Test for table level import
65 public function testTableImport(): void
67 // setup the db
68 $this->dbQuery(
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');
78 $this->dbQuery(
79 'SELECT * FROM `' . $this->databaseName . '`.test_table',
80 function (): void {
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));
88 /**
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();
96 $this->waitAjax();
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());