summaryrefslogtreecommitdiff
path: root/tests/selenium/suites/UserPreferencesTestCase.php
blob: 3ceb3a99592e569fbc332f083416b70a1000dc43 (plain)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php

/**
 * Selenium server manager
 *
 * @file
 * @ingroup Testing
 * Copyright (C) 2010 Nadeesha Weerasinghe <nadeesha@calcey.com>
 * http://www.calcey.com/ 
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @addtogroup Testing
 *
 */

class UserPreferencesTestCase extends SeleniumTestCase {

    // Verify user information
    public function testUserInfoDisplay() {

        $this->open( $this->getUrl() .
                '/index.php?title=Main_Page&action=edit' );
        $this->click( SeleniumTestConstants::LINK_START."My preferences" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        // Verify correct username displayed in User Preferences
        $this->assertEquals( $this->getText( "//li[@id='pt-userpage']/a" ),
                $this->getText( "//table[@id='mw-htmlform-info']/tbody/tr[1]/td[2]" ));

        // Verify existing Signature Displayed correctly
        $this->assertEquals( $this->selenium->getUser(),
                $this->getTable( "mw-htmlform-signature.0.1" ) );
    }

    // Verify change password
    public function testChangePassword() {

        $this->open( $this->getUrl() .
                '/index.php?title=Main_Page&action=edit' );
        $this->click( SeleniumTestConstants::LINK_START."My preferences" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        $this->click( SeleniumTestConstants::LINK_START."Change password" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        $this->type( "wpPassword", "12345" );
        $this->type( "wpNewPassword", "54321" );
        $this->type( "wpRetype", "54321" );
        $this->click( "//input[@value='Change password']" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        $this->assertEquals( "Preferences", $this->getText( "firstHeading" ));

        $this->click( SeleniumTestConstants::LINK_START."Change password" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        $this->type( "wpPassword", "54321" );
        $this->type( "wpNewPassword", "12345" );
        $this->type( "wpRetype", "12345" );
        $this->click( "//input[@value='Change password']" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
        $this->assertEquals( "Preferences", $this->getText( "firstHeading" ));

        $this->click( SeleniumTestConstants::LINK_START."Change password" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        $this->type( "wpPassword", "54321" );
        $this->type( "wpNewPassword", "12345" );
        $this->type( "wpRetype", "12345" );
        $this->click( "//input[@value='Change password']" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
    }

    // Verify successful preferences save
    public function testSuccessfullSave() {

        $this->open( $this->getUrl() .
                '/index.php?title=Main_Page&action=edit' );
        $this->click( SeleniumTestConstants::LINK_START."My preferences" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        $this->type( "mw-input-realname", "Test User" );
        $this->click( "prefcontrol" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        // Verify  "Your preferences have been saved." message
        $this->assertEquals( "Your preferences have been saved.",
                $this->getText( "//div[@id='bodyContent']/div[4]/strong/p" ));
        $this->type( "mw-input-realname", "" );
        $this->click( "prefcontrol" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

    }

    // Verify change signature
    public function testChangeSignature() {

        $this->open( $this->getUrl() .
                '/index.php?title=Main_Page&action=edit' );
        $this->click( SeleniumTestConstants::LINK_START."My preferences" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        $this->type( "mw-input-nickname", "TestSignature" );
        $this->click( "prefcontrol" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        // Verify change user signature
        $this->assertEquals( "TestSignature", $this->getText( SeleniumTestConstants::LINK_START."TestSignature" ));
        $this->type( "mw-input-nickname", "Test" );
        $this->click( "prefcontrol" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
    }

    // Verify change date format
    public function testChangeDateFormatTimeZone() {

        $this->open( $this->getUrl() .
                '/index.php?title=Main_Page&action=edit' );

        $this->click( SeleniumTestConstants::LINK_START."My preferences" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
        $this->click( SeleniumTestConstants::LINK_START."Date and time" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        $this->click( "mw-input-date-dmy" );
        $this->select( "mw-input-timecorrection", "label=Asia/Colombo" );
        $this->click( "prefcontrol" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        // Verify Date format and time zome saved
        $this->assertEquals( "Your preferences have been saved.",
                $this->getText( "//div[@id='bodyContent']/div[4]/strong/p" ));
    }

    // Verify restoring all default settings
    public function testSetAllDefault() {

        $this->open( $this->getUrl() .
                '/index.php?title=Main_Page&action=edit' );
        $this->click( SeleniumTestConstants::LINK_START."My preferences" );
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        // Verify restoring all default settings
        $this->assertEquals( "Restore all default settings",
                $this->getText( SeleniumTestConstants::LINK_START."Restore all default settings" ));

        $this->click("//*[@id='preferences']/div/a");
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );

        // Verify 'This can not be undone' warning message displayed
        $this->assertTrue($this->isElementPresent("//input[@value='Restore all default settings']"));

        // Verify 'Restore all default settings' button available
        $this->assertEquals("You can use this page to reset your preferences to the site defaults. This cannot be undone.",
                $this->getText("//div[@id='bodyContent']/p"));

        $this->click("//input[@value='Restore all default settings']");
        $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME  );

        // Verify preferences saved successfully
        $this->assertEquals("Your preferences have been saved.",
                $this->getText("//div[@id='bodyContent']/div[4]/strong/p"));
    }
}