| | 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 | } |
|---|