File: OperationsTest.php

package info (click to toggle)
phpmyadmin 4%3A5.2.2-really%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 140,312 kB
  • sloc: javascript: 228,447; php: 166,904; xml: 17,847; sql: 504; sh: 275; makefile: 209; python: 205
file content (136 lines) | stat: -rw-r--r-- 4,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php

declare(strict_types=1);

namespace PhpMyAdmin\Tests\Selenium\Database;

use PhpMyAdmin\Tests\Selenium\TestBase;

/**
 * @coversNothing
 */
#[\PHPUnit\Framework\Attributes\CoversNothing]
class OperationsTest extends TestBase
{
    /**
     * setUp function
     */
    protected function setUp(): void
    {
        parent::setUp();
        $this->login();
    }

    private function getToDBOperations(): void
    {
        $this->gotoHomepage();

        $this->navigateDatabase($this->databaseName);
        $this->expandMore();
        $this->waitForElement('partialLinkText', 'Operations')->click();
        $this->waitForElement('xpath', '//div[contains(., \'Rename database to\')]');
    }

    /**
     * Test for adding database comment
     *
     * @group large
     */
    #[\PHPUnit\Framework\Attributes\Group('large-group')]
    public function testDbComment(): void
    {
        $this->skipIfNotPMADB();

        $this->getToDBOperations();
        $this->byName('comment')->sendKeys('comment_foobar');
        $this->byCssSelector("form#formDatabaseComment input[type='submit']")->click();

        self::assertNotNull($this->waitForElement(
            'xpath',
            "//span[@class='breadcrumb-comment' and contains(., 'comment_foobar')]"
        ));
    }

    /**
     * Test for renaming database
     *
     * @group large
     */
    #[\PHPUnit\Framework\Attributes\Group('large-group')]
    public function testRenameDB(): void
    {
        $this->getToDBOperations();

        $new_db_name = $this->databaseName . 'rename';

        $this->scrollIntoView('createTableMinimalForm');
        $newNameInput = $this->byCssSelector('form#rename_db_form input[name=newname]');
        $newNameInput->clear();
        $newNameInput->sendKeys($new_db_name);

        $this->byCssSelector("form#rename_db_form input[type='submit']")->click();

        $this->waitForElement('cssSelector', 'button.submitOK')->click();

        $this->waitForElement(
            'xpath',
            "//a[contains(text(),'Database: ') and contains(text(),'" . $new_db_name . "')]"
        );

        $this->dbQuery(
            'SHOW DATABASES LIKE \'' . $new_db_name . '\'',
            function () use ($new_db_name): void {
                self::assertTrue($this->isElementPresent('className', 'table_results'));
                self::assertEquals($new_db_name, $this->getCellByTableClass('table_results', 1, 1));
            }
        );

        $this->dbQuery(
            'SHOW DATABASES LIKE \'' . $this->databaseName . '\'',
            function (): void {
                self::assertTrue($this->isElementPresent('className', 'table_results'));
                self::assertFalse($this->isElementPresent('cssSelector', '.table_results tbody tr'));
            }
        );

        $this->databaseName = $new_db_name;
    }

    /**
     * Test for copying database
     *
     * @group large
     */
    #[\PHPUnit\Framework\Attributes\Group('large-group')]
    public function testCopyDb(): void
    {
        $this->getToDBOperations();

        $this->reloadPage();// Reload or scrolling will not work ..
        $new_db_name = $this->databaseName . 'copy';
        $this->scrollIntoView('renameDbNameInput');
        $newNameInput = $this->byCssSelector('form#copy_db_form input[name=newname]');
        $newNameInput->clear();
        $newNameInput->sendKeys($new_db_name);

        $this->scrollIntoView('copy_db_form', -150);
        $this->byCssSelector('form#copy_db_form input[name="submit_copy"]')->click();

        $this->waitForElement(
            'xpath',
            "//div[@class='alert alert-success' and contains(., 'Database "
            . $this->databaseName
            . ' has been copied to ' . $new_db_name . "')]"
        );

        $this->dbQuery(
            'SHOW DATABASES LIKE \'' . $new_db_name . '\'',
            function () use ($new_db_name): void {
                self::assertTrue($this->isElementPresent('className', 'table_results'));
                self::assertEquals($new_db_name, $this->getCellByTableClass('table_results', 1, 1));
            }
        );

        $this->dbQuery('DROP DATABASE `' . $new_db_name . '`;');
    }
}