MediaWiki  REL1_19
SeleniumTestCase.php
Go to the documentation of this file.
00001 <?php
00002 include("SeleniumTestConstants.php");
00003 
00004 class SeleniumTestCase extends PHPUnit_Framework_TestCase { // PHPUnit_Extensions_SeleniumTestCase
00005         protected $selenium;
00006 
00007         public function setUp() {
00008                 set_time_limit( 60 );
00009                 $this->selenium = Selenium::getInstance();
00010         }
00011 
00012         public function tearDown() {
00013 
00014         }
00015 
00016         public function __call( $method, $args ) {
00017                 return call_user_func_array( array( $this->selenium, $method ), $args );
00018         }
00019 
00020         public function assertSeleniumAttributeEquals( $attribute, $value ) {
00021                 $attr = $this->getAttribute( $attribute );
00022                 $this->assertEquals( $attr, $value );
00023         }
00024 
00025         public function assertSeleniumHTMLContains( $element, $text ) {
00026                 $innerHTML = $this->getText( $element );
00027                 // or assertContains
00028                 $this->assertRegExp( "/$text/", $innerHTML );
00029         }
00030 
00031 
00036         function createTestPageIfMissing( $pageName = null ) {
00037                 if ( $pageName == null ) {
00038                         $pageName = SeleniumTestConstants::WIKI_INTERNAL_LINK;          
00039                 }
00040                 $this->type( SeleniumTestConstants::INPUT_SEARCH_BOX, $pageName  );
00041                 $this->click( SeleniumTestConstants::BUTTON_SEARCH );
00042                 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
00043                 $this->click( SeleniumTestConstants::LINK_START . $pageName );
00044                 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
00045                 $location =  $this->getLocation() . "\n";
00046                 if ( strpos( $location, '&redlink=1') !== false  ) {
00047                         $this->type( SeleniumTestConstants::TEXT_EDITOR,  "Test fixture page. No real content here" );
00048                         $this->click( SeleniumTestConstants::BUTTON_SAVE );
00049                         $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
00050                         $this->assertTrue( $this->isTextPresent( $pageName ),
00051                         $this->getText( SeleniumTestConstants::TEXT_PAGE_HEADING ) );
00052                 }
00053         }
00054         
00060         function createNewTestPage( $pagePrefix, $watchThis = false ) {
00061                 $pageName = $pagePrefix . date("Ymd-His");
00062                 $this->type( SeleniumTestConstants::INPUT_SEARCH_BOX, $pageName  );
00063                 $this->click( SeleniumTestConstants::BUTTON_SEARCH );
00064                 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
00065                 $this->click( SeleniumTestConstants::LINK_START . $pageName );
00066                 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
00067                 $location =  $this->getLocation() . "\n";
00068                 $this->assertContains( '&redlink=1', $location ).
00069                 $this->type( SeleniumTestConstants::TEXT_EDITOR,  "Test fixture page. No real content here" );
00070                 if ( $watchThis ) {
00071                         $this->click( "wpWatchthis" );
00072                 }
00073                 $this->click( SeleniumTestConstants::BUTTON_SAVE );
00074                 $this->waitForPageToLoad( SeleniumTestConstants::WIKI_TEST_WAIT_TIME );
00075                 $this->assertTrue( $this->isTextPresent( $pageName ),
00076                 $this->getText( SeleniumTestConstants::TEXT_PAGE_HEADING ) );
00077                 return $pageName;
00078         }
00079 
00080         public function getExistingPage(){
00081                 $this->open( $this->getUrl() .
00082                         '/index.php?title=Main_Page&action=edit' );
00083                 $this->type("searchInput", "new" );
00084                 $this->click("searchGoButton");
00085                 $this->waitForPageToLoad("30000");
00086         }
00087 
00088         public function getNewPage($pageName){
00089 
00090                 $this->open( $this->getUrl() .
00091                         '/index.php?title=Main_Page&action=edit' );
00092                 $this->type("searchInput", $pageName );
00093                 $this->click("searchGoButton");
00094                 $this->waitForPageToLoad("30000");
00095                 $this->click("link=".$pageName);
00096                 $this->waitForPageToLoad("600000");
00097 
00098 
00099         }
00100         // Loading the mediawiki editor
00101         public function loadWikiEditor(){
00102                 $this->open( $this->getUrl() .
00103                         '/index.php?title=Main_Page&action=edit' );
00104         }
00105 
00106         // Clear the content of the mediawiki editor
00107         public function clearWikiEditor(){
00108                 $this->type("wpTextbox1", "");
00109         }
00110 
00111         // Click on the 'Show preview' button of the mediawiki editor
00112         public function clickShowPreviewBtn(){
00113                 $this->click("wpPreview");
00114         }
00115 
00116         // Click on the 'Save Page' button of the mediawiki editor
00117         public function clickSavePageBtn(){
00118                 $this->click("wpSave");
00119         }
00120 
00121         // Click on the 'Edit' link
00122         public function clickEditLink(){
00123                 $this->click("link=Edit");
00124                 $this->waitForPageToLoad("30000");
00125         }
00126 
00127 }