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

InsertTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 72
dl 0
loc 148
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddData() 0 60 2
A setUp() 0 14 1
A _assertDataPresent() 0 50 1
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\Table;
12
13
use PhpMyAdmin\Tests\Selenium\TestBase;
14
15
/**
16
 * InsertTest class
17
 *
18
 * @package    PhpMyAdmin-test
19
 * @subpackage Selenium
20
 * @group      selenium
21
 */
22
class InsertTest extends TestBase
23
{
24
    /**
25
     * Setup the browser environment to run the selenium t
26
     * est case
27
     *
28
     * @return void
29
     */
30
    protected function setUp()
31
    {
32
        parent::setUp();
33
        $this->dbQuery(
34
            "CREATE TABLE `test_table` ("
35
            . " `id` int(11) NOT NULL AUTO_INCREMENT,"
36
            . " `name` varchar(20) NOT NULL,"
37
            . " `datetimefield` datetime NOT NULL,"
38
            . " PRIMARY KEY (`id`)"
39
            . ")"
40
        );
41
42
        $this->login();
43
        $this->navigateTable('test_table');
44
    }
45
46
    /**
47
     * Insert data into table
48
     *
49
     * @return void
50
     *
51
     * @group large
52
     */
53
    public function testAddData()
54
    {
55
        if ($this->isSafari()) {
56
            /* TODO: this should be fixed, but the cause is unclear to me */
57
            $this->markTestIncomplete('Fails with Safari');
58
        }
59
        $this->waitAjax();
60
        $this->expandMore();
61
        $this->maximize();
62
63
        $this->byPartialLinkText("Insert")->click();
64
        $this->waitAjax();
65
        $this->waitForElement('id', "insertForm");
66
67
        // shorter date to prevent error,
68
        // automatically gets appended with 00:00:00
69
        $this->byId("field_3_3")->click()->sendKeys("2011-01-2");
70
71
        $this->byId("field_1_3")->sendKeys("1");
72
        $this->byId("field_2_3")->sendKeys("abcd");
73
74
        // shorter date to prevent error,
75
        // automatically gets appended with 00:00:00
76
        $this->byId("field_6_3")->click()->sendKeys("2012-01-2");
77
78
        $this->byId("field_5_3")->sendKeys("foo");
79
80
        $this->selectByLabel(
81
            $this->byName("after_insert"),
82
            'Insert another new row'
83
        );
84
85
        // post
86
        $this->byId("buttonYes")->click();
87
        $this->waitAjax();
88
89
        $ele = $this->waitForElement('className', "success");
90
        $this->assertContains("2 rows inserted", $ele->getText());
91
92
        // shorter date to prevent error,
93
        // automatically gets appended with 00:00:00
94
        $this->byId("field_3_3")->click()->sendKeys("2013-01-2");
95
96
        $this->byId("field_2_3")->sendKeys("Abcd");
97
98
        // post
99
        $this->byCssSelector(
100
            "input[value=Go]"
101
        )->click();
102
103
        $this->waitAjax();
104
105
        // New message
106
        $ele = $this->waitForElement(
107
            'xpath',
108
            "//div[contains(@class, 'success') and not(contains(@class, 'message'))]"
109
        );
110
        $this->assertContains("1 row inserted", $ele->getText());
111
112
        $this->_assertDataPresent();
113
    }
114
115
    /**
116
     * Assert various data present in results table
117
     *
118
     * @return void
119
     */
120
    private function _assertDataPresent()
121
    {
122
        $this->byPartialLinkText("Browse")->click();
123
124
        $this->waitAjax();
125
        $this->waitForElement('cssSelector', "table.table_results");
126
127
        $this->assertEquals(
128
            "1",
129
            $this->getCellByTableClass('table_results', 1, 5)
130
        );
131
132
        $this->assertEquals(
133
            "abcd",
134
            $this->getCellByTableClass('table_results', 1, 6)
135
        );
136
137
        $this->assertEquals(
138
            "2011-01-02 00:00:00",
139
            $this->getCellByTableClass('table_results', 1, 7)
140
        );
141
142
        $this->assertEquals(
143
            "2",
144
            $this->getCellByTableClass('table_results', 2, 5)
145
        );
146
147
        $this->assertEquals(
148
            "foo",
149
            $this->getCellByTableClass('table_results', 2, 6)
150
        );
151
152
        $this->assertEquals(
153
            "2012-01-02 00:00:00",
154
            $this->getCellByTableClass('table_results', 2, 7)
155
        );
156
157
        $this->assertEquals(
158
            "4",
159
            $this->getCellByTableClass('table_results', 3, 5)
160
        );
161
162
        $this->assertEquals(
163
            "Abcd",
164
            $this->getCellByTableClass('table_results', 3, 6)
165
        );
166
167
        $this->assertEquals(
168
            "2013-01-02 00:00:00",
169
            $this->getCellByTableClass('table_results', 3, 7)
170
        );
171
    }
172
}
173