Merge "Retrieve rev_len for sizediff in usercontributions API"
[lhc/web/wiklou.git] / tests / selenium / SeleniumTestCase.php
1 <?php
2 include("SeleniumTestConstants.php");
3
4 class SeleniumTestCase extends PHPUnit_Framework_TestCase { // PHPUnit_Extensions_SeleniumTestCase
5 protected $selenium;
6
7 public function setUp() {
8 set_time_limit( 60 );
9 $this->selenium = Selenium::getInstance();
10 }
11
12 public function tearDown() {
13
14 }
15
16 public function __call( $method, $args ) {
17 return call_user_func_array( array( $this->selenium, $method ), $args );
18 }
19
20 public function assertSeleniumAttributeEquals( $attribute, $value ) {
21 $attr = $this->getAttribute( $attribute );
22 $this->assertEquals( $attr, $value );
23 }
24
25 public function assertSeleniumHTMLContains( $element, $text ) {
26 $innerHTML = $this->getText( $element );
27 // or assertContains
28 $this->assertRegExp( "/$text/", $innerHTML );
29 }
30
31
32 /**
33 * Create a test fixture page if one does not exist
34 * @param $pageName The fixture page name. If none is supplied, it uses SeleniumTestConstants::WIKI_INTERNAL_LINK
35 */
36 function createTestPageIfMissing( $pageName = null ) {
37 if ( $pageName == null ) {
38 $pageName = SeleniumTestConstants::WIKI_INTERNAL_LINK;
39 }
40 $this->type( SeleniumTestConstants::INPUT_SEARCH_BOX, $pageName );
41 $this->click( SeleniumTestConstants::BUTTON_SEARCH );
42 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
43 $this->click( SeleniumTestConstants::LINK_START . $pageName );
44 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
45 $location = $this->getLocation() . "\n";
46 if ( strpos( $location, '&redlink=1') !== false ) {
47 $this->type( SeleniumTestConstants::TEXT_EDITOR, "Test fixture page. No real content here" );
48 $this->click( SeleniumTestConstants::BUTTON_SAVE );
49 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
50 $this->assertTrue( $this->isTextPresent( $pageName ),
51 $this->getText( SeleniumTestConstants::TEXT_PAGE_HEADING ) );
52 }
53 }
54
55 /**
56 * Create a test page using date as part of the name so that it is unique
57 * @param $pagePrefix The prefix to use for the page name. The current date will be appended to this to make it unique
58 * @param $watchThis Whether to add the page to my watchlist. Defaults to false.
59 */
60 function createNewTestPage( $pagePrefix, $watchThis = false ) {
61 $pageName = $pagePrefix . date("Ymd-His");
62 $this->type( SeleniumTestConstants::INPUT_SEARCH_BOX, $pageName );
63 $this->click( SeleniumTestConstants::BUTTON_SEARCH );
64 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
65 $this->click( SeleniumTestConstants::LINK_START . $pageName );
66 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
67 $location = $this->getLocation() . "\n";
68 $this->assertContains( '&redlink=1', $location ).
69 $this->type( SeleniumTestConstants::TEXT_EDITOR, "Test fixture page. No real content here" );
70 if ( $watchThis ) {
71 $this->click( "wpWatchthis" );
72 }
73 $this->click( SeleniumTestConstants::BUTTON_SAVE );
74 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
75 $this->assertTrue( $this->isTextPresent( $pageName ),
76 $this->getText( SeleniumTestConstants::TEXT_PAGE_HEADING ) );
77 return $pageName;
78 }
79
80 public function getExistingPage(){
81 $this->open( $this->getUrl() .
82 '/index.php?title=Main_Page&action=edit' );
83 $this->type("searchInput", "new" );
84 $this->click("searchGoButton");
85 $this->waitForPageToLoad("30000");
86 }
87
88 public function getNewPage($pageName){
89
90 $this->open( $this->getUrl() .
91 '/index.php?title=Main_Page&action=edit' );
92 $this->type("searchInput", $pageName );
93 $this->click("searchGoButton");
94 $this->waitForPageToLoad("30000");
95 $this->click("link=".$pageName);
96 $this->waitForPageToLoad("600000");
97
98
99 }
100 // Loading the mediawiki editor
101 public function loadWikiEditor(){
102 $this->open( $this->getUrl() .
103 '/index.php?title=Main_Page&action=edit' );
104 }
105
106 // Clear the content of the mediawiki editor
107 public function clearWikiEditor(){
108 $this->type("wpTextbox1", "");
109 }
110
111 // Click on the 'Show preview' button of the mediawiki editor
112 public function clickShowPreviewBtn(){
113 $this->click("wpPreview");
114 }
115
116 // Click on the 'Save Page' button of the mediawiki editor
117 public function clickSavePageBtn(){
118 $this->click("wpSave");
119 }
120
121 // Click on the 'Edit' link
122 public function clickEditLink(){
123 $this->click("link=Edit");
124 $this->waitForPageToLoad("30000");
125 }
126
127 }