Changeset 34222

Show
Ignore:
Timestamp:
03/09/08 20:55:23 (2 months ago)
Author:
Quandary
Message:

Add support for enabling/disabling widgets.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • in-series/branches/maintenance/3.x/3.1/in-series-test/WordPressTestCase.php

    r23344 r34222  
    22/* 
    33 
    4 Copyright 2007 Travis Snoozy (ai2097@users.sourceforge.net) 
     4Copyright 2007,2008 Travis Snoozy (ai2097@users.sourceforge.net) 
    55Released under the terms of the GNU GPL v2 
    66 
     
    2323    var $m_WPLoggedIn; 
    2424    var $m_WPVersion; 
     25    var $m_WPWidgets; 
    2526     
    2627    function WordPressTestCase($label = false, $rootUrl = false, $username = false, $password = false, $version = null) { 
     
    4243        $this->m_WPLoggedIn = false; 
    4344        $this->m_WPVersion = $version; 
     45        $this->m_WPWidgets = array(); 
    4446    } 
    4547 
     
    275277        return $this->m_WPRootUrl."?p=$pid"; 
    276278    } 
     279 
     280    function wpSetWidget($id, $set = true) { 
     281        $html = $this->get($this->m_WPRootUrl."wp-admin/widgets.php"); 
     282        $this->assertResponse(200); 
     283        $this->assertTrue($html); 
     284 
     285        $new_widgets = array(); 
     286        $widget_string = ''; 
     287 
     288        foreach($this->m_WPWidgets as $widget) { 
     289            if($widget == $id) { 
     290                $found = true; 
     291                if(!$set) { // Unset the widget by omitting it from the new list 
     292                    continue; 
     293                } 
     294                else { // The widget is already set; bail (nothing to do) 
     295                    return; 
     296                } 
     297            } 
     298            $new_widgets[] = $widget; 
     299            $widget_string .= $sep . "sidebar-1[]=" . $widget; 
     300            $sep = '&'; 
     301        } 
     302 
     303        if($set) { 
     304            $widget_string .= $sep . 'sidebar-1[]=' . $id; 
     305            $new_widgets[] = $id; 
     306        } 
     307        else if(!$found) { 
     308            return; // The widget is already unset; bail (nothing to do) 
     309        } 
     310 
     311        $this->m_WPWidgets = $new_widgets; 
     312        $this->assertTrue($this->setFieldById("sidebar-1order", $widget_string)); 
     313        $this->assertTrue($this->clickSubmit("Save Changes »")); 
     314    } 
     315 
     316    function wpClearWidgets() { 
     317        $html = $this->get($this->m_WPRootUrl."wp-admin/widgets.php"); 
     318        $this->assertResponse(200); 
     319        $this->assertTrue($html); 
     320        $this->assertTrue($this->setFieldById("sidebar-1order", "")); 
     321        $this->assertTrue($this->clickSubmit("Save Changes »")); 
     322    } 
    277323} 
    278324