Passed
Push — master ( 450d0c...ced8c3 )
by Maurício
07:19
created

StructureTest::testTruncateTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
/**
4
 * Selenium TestCase for table related tests
5
 *
6
 * @package    PhpMyAdmin-test
7
 * @subpackage Selenium
8
 */
9
declare(strict_types=1);
10
11
namespace PhpMyAdmin\Tests\Selenium\Database;
12
13
use PhpMyAdmin\Tests\Selenium\TestBase;
14
15
/**
16
 * StructureTest class
17
 *
18
 * @package    PhpMyAdmin-test
19
 * @subpackage Selenium
20
 * @group      selenium
21
 */
22
class StructureTest extends TestBase
23
{
24
    /**
25
     * Setup the browser environment to run the selenium test case
26
     *
27
     * @return void
28
     */
29
    protected function setUp()
30
    {
31
        parent::setUp();
32
        $this->dbQuery(
33
            "CREATE TABLE `test_table` ("
34
            . " `id` int(11) NOT NULL AUTO_INCREMENT,"
35
            . " `val` int(11) NOT NULL,"
36
            . " PRIMARY KEY (`id`)"
37
            . ")"
38
        );
39
        $this->dbQuery(
40
            "CREATE TABLE `test_table2` ("
41
            . " `id` int(11) NOT NULL AUTO_INCREMENT,"
42
            . " `val` int(11) NOT NULL,"
43
            . " PRIMARY KEY (`id`)"
44
            . ")"
45
        );
46
        $this->dbQuery(
47
            "INSERT INTO `test_table` (val) VALUES (2);"
48
        );
49
50
        $this->login();
51
        $this->navigateDatabase($this->database_name);
52
53
        // Let the Database page load
54
        $this->waitAjax();
55
        $this->expandMore();
56
        $this->maximize();
57
    }
58
59
    /**
60
     * Test for truncating a table
61
     *
62
     * @return void
63
     *
64
     * @group large
65
     */
66
    public function testTruncateTable()
67
    {
68
        $this->byXPath("(//a[contains(., 'Empty')])[1]")->click();
69
70
        $this->waitForElement(
71
            'cssSelector',
72
            "button.submitOK"
73
        )->click();
74
75
        $this->assertNotNull(
76
            $this->waitForElement(
77
                'xpath',
78
                "//div[@class='success' and contains(., "
79
                . "'MySQL returned an empty result')]"
80
            )
81
        );
82
83
        $result = $this->dbQuery("SELECT count(*) as c FROM test_table");
84
        $row = $result->fetch_assoc();
85
        $this->assertEquals(0, $row['c']);
86
    }
87
88
    /**
89
     * Tests for dropping multiple tables
90
     *
91
     * @return void
92
     *
93
     * @group large
94
     */
95
    public function testDropMultipleTables()
96
    {
97
        $this->byCssSelector("label[for='tablesForm_checkall']")->click();
98
99
        $this->selectByLabel(
100
            $this->byName("submit_mult"),
101
            'Drop'
102
        );
103
104
        $this->waitForElement('id', "buttonYes")
105
            ->click();
106
107
        $this->waitForElement(
108
            'xpath',
109
            "//*[contains(., 'No tables found in database')]"
110
        );
111
112
        $result = $this->dbQuery("SHOW TABLES;");
113
        $this->assertEquals(0, $result->num_rows);
114
    }
115
}
116