Skip to content

Commit 650962e

Browse files
committed
Merge pull request #61 from yvesh/develop
[add] createMenuItem
2 parents 6070485 + ff80560 commit 650962e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/JoomlaBrowser.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,4 +670,45 @@ public function displayModuleOnAllPages($module)
670670
$I->click(['xpath' => "//div[@id='toolbar-apply']/button"]);
671671
$I->waitForText('Module successfully saved',30,['id' => 'system-message-container']);
672672
}
673+
674+
/**
675+
* Creates a menu item with the Joomla menu manager, only working for menu items without additional required fields
676+
*
677+
* @param string $menuTitle The menu item title
678+
* @param string $menuCategory The category of the menu type (for example Weblinks)
679+
* @param string $menuItem The menu item type / link text (for example List all Web Link Categories)
680+
* @param string $menu The menu where the item should be created
681+
*/
682+
public function createMenuItem($menuTitle, $menuCategory, $menuItem, $menu = "Main Menu")
683+
{
684+
$I = $this;
685+
$I->amOnPage('administrator/index.php?option=com_menus&view=menus');
686+
$I->waitForText('Menus', '30', ['css' => 'H1']);
687+
688+
// Choose the right menu
689+
$I->click(['xpath' => "//*[@id=\"menuList\"]/tbody/tr/td[2]/a[contains(text(), '" . $menu . "')]"]);;
690+
$I->waitForText('Menus: Items', '30', ['css' => 'H1']);
691+
692+
$I->click(['xpath' => "//button[@onclick=\"Joomla.submitbutton('item.add')\"]"]);
693+
$I->waitForText('Menus: New Item', '30', ['css' => 'h1']);
694+
$I->fillField(['id' => 'jform_title'], $menuTitle);
695+
696+
// Menu type (modal)
697+
$I->click(['xpath' => "//a[@href=\"#menuTypeModal\"]"]);
698+
$I->waitForElement('.iframe', '30');
699+
$I->switchToIFrame("Menu Item Type");
700+
701+
// Open the category
702+
$I->waitForElementVisible(['link' => $menuCategory], '30');
703+
$I->click(['link' => $menuCategory]);
704+
705+
// Choose the menu item
706+
$I->waitForElementVisible(['xpath' => "//a[contains(text(), '" . $menuItem . "')]"], 60);
707+
$I->click(['xpath' => "//a[contains(text(), '" . $menuItem . "')]"]);
708+
709+
$I->waitForText('Menus: New Item','30', ['css' => 'h1']);
710+
$I->click(['xpath' => "//button[@onclick=\"Joomla.submitbutton('item.apply')\"]"]);
711+
712+
$I->waitForText('Menu item successfully saved', 30, ['id' => 'system-message-container']);
713+
}
673714
}

0 commit comments

Comments
 (0)