Skip to content

Commit e995df7

Browse files
committed
[add] createMenuItem
Creates a Joomla menu link item, for example: $I->createMenuItem($title, 'Weblinks', 'List All Web Link Categories', 'Main Menu');
1 parent 6070485 commit e995df7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/JoomlaBrowser.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,4 +670,47 @@ 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 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+
$I->wait(1);
688+
689+
// Choose the right menu
690+
$I->click(['xpath' => "//*[@id=\"menuList\"]/tbody/tr/td[2]/a[contains(text(), '" . $menu . "')]"]);;
691+
$I->waitForText('Menus: Items', '30', ['css' => 'H1']);
692+
693+
$I->click(['xpath' => "//button[@onclick=\"Joomla.submitbutton('item.add')\"]"]);
694+
$I->waitForText('Menus: New Item','30', ['css' => 'h1']);
695+
$I->fillField(['id' => 'jform_title'], $menuTitle);
696+
697+
// Menu type (modal)
698+
$I->click(['xpath' => "//a[@href=\"#menuTypeModal\"]"]);
699+
$I->waitForElement('.iframe','30');
700+
$I->switchToIFrame("Menu Item Type");
701+
702+
// Open the category
703+
$I->waitForElementVisible(['link' => $menuCategory], '30');
704+
$I->click(['link' => $menuCategory]);
705+
$I->wait(1);
706+
707+
// Choose the menu item
708+
$I->waitForElementVisible(['xpath' => "//a[contains(text(), '" . $menuItem . "')]"], 60);
709+
$I->click(['xpath' => "//a[contains(text(), '" . $menuItem . "')]"]);
710+
711+
$I->waitForText('Menus: New Item','30', ['css' => 'h1']);
712+
$I->click(['xpath' => "//button[@onclick=\"Joomla.submitbutton('item.apply')\"]"]);
713+
714+
$I->waitForText('Menu item successfully saved', 30, ['id' => 'system-message-container']);
715+
}
673716
}

0 commit comments

Comments
 (0)