From e995df7f7fdf95114f60e25b36c7028051f7818d Mon Sep 17 00:00:00 2001 From: Yves Hoppe Date: Sun, 27 Sep 2015 12:08:16 +0200 Subject: [PATCH 1/2] [add] createMenuItem Creates a Joomla menu link item, for example: $I->createMenuItem($title, 'Weblinks', 'List All Web Link Categories', 'Main Menu'); --- src/JoomlaBrowser.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/JoomlaBrowser.php b/src/JoomlaBrowser.php index 815d4c0..298d73c 100644 --- a/src/JoomlaBrowser.php +++ b/src/JoomlaBrowser.php @@ -670,4 +670,47 @@ public function displayModuleOnAllPages($module) $I->click(['xpath' => "//div[@id='toolbar-apply']/button"]); $I->waitForText('Module successfully saved',30,['id' => 'system-message-container']); } + + /** + * Creates a menu item with the Joomla menu manager, only working for menu items without additional required fields + * + * @param string $menuTitle - The menu title + * @param string $menuCategory - The category of the menu type (for example Weblinks) + * @param string $menuItem - The menu item type / link text (for example List all Web Link Categories) + * @param string $menu - The menu where the item should be created + */ + public function createMenuItem($menuTitle, $menuCategory, $menuItem, $menu = "Main Menu") + { + $I = $this; + $I->amOnPage('administrator/index.php?option=com_menus&view=menus'); + $I->waitForText('Menus', '30', ['css' => 'H1']); + $I->wait(1); + + // Choose the right menu + $I->click(['xpath' => "//*[@id=\"menuList\"]/tbody/tr/td[2]/a[contains(text(), '" . $menu . "')]"]);; + $I->waitForText('Menus: Items', '30', ['css' => 'H1']); + + $I->click(['xpath' => "//button[@onclick=\"Joomla.submitbutton('item.add')\"]"]); + $I->waitForText('Menus: New Item','30', ['css' => 'h1']); + $I->fillField(['id' => 'jform_title'], $menuTitle); + + // Menu type (modal) + $I->click(['xpath' => "//a[@href=\"#menuTypeModal\"]"]); + $I->waitForElement('.iframe','30'); + $I->switchToIFrame("Menu Item Type"); + + // Open the category + $I->waitForElementVisible(['link' => $menuCategory], '30'); + $I->click(['link' => $menuCategory]); + $I->wait(1); + + // Choose the menu item + $I->waitForElementVisible(['xpath' => "//a[contains(text(), '" . $menuItem . "')]"], 60); + $I->click(['xpath' => "//a[contains(text(), '" . $menuItem . "')]"]); + + $I->waitForText('Menus: New Item','30', ['css' => 'h1']); + $I->click(['xpath' => "//button[@onclick=\"Joomla.submitbutton('item.apply')\"]"]); + + $I->waitForText('Menu item successfully saved', 30, ['id' => 'system-message-container']); + } } From ff805604e2e6dd3fd35ed4756d1a4218852a25bc Mon Sep 17 00:00:00 2001 From: Yves Hoppe Date: Mon, 28 Sep 2015 07:24:21 +0200 Subject: [PATCH 2/2] [imp] Removed $I->wait(1) --- src/JoomlaBrowser.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/JoomlaBrowser.php b/src/JoomlaBrowser.php index 298d73c..a5ebd08 100644 --- a/src/JoomlaBrowser.php +++ b/src/JoomlaBrowser.php @@ -674,35 +674,33 @@ public function displayModuleOnAllPages($module) /** * Creates a menu item with the Joomla menu manager, only working for menu items without additional required fields * - * @param string $menuTitle - The menu title - * @param string $menuCategory - The category of the menu type (for example Weblinks) - * @param string $menuItem - The menu item type / link text (for example List all Web Link Categories) - * @param string $menu - The menu where the item should be created + * @param string $menuTitle The menu item title + * @param string $menuCategory The category of the menu type (for example Weblinks) + * @param string $menuItem The menu item type / link text (for example List all Web Link Categories) + * @param string $menu The menu where the item should be created */ public function createMenuItem($menuTitle, $menuCategory, $menuItem, $menu = "Main Menu") { $I = $this; $I->amOnPage('administrator/index.php?option=com_menus&view=menus'); $I->waitForText('Menus', '30', ['css' => 'H1']); - $I->wait(1); // Choose the right menu $I->click(['xpath' => "//*[@id=\"menuList\"]/tbody/tr/td[2]/a[contains(text(), '" . $menu . "')]"]);; $I->waitForText('Menus: Items', '30', ['css' => 'H1']); $I->click(['xpath' => "//button[@onclick=\"Joomla.submitbutton('item.add')\"]"]); - $I->waitForText('Menus: New Item','30', ['css' => 'h1']); + $I->waitForText('Menus: New Item', '30', ['css' => 'h1']); $I->fillField(['id' => 'jform_title'], $menuTitle); // Menu type (modal) $I->click(['xpath' => "//a[@href=\"#menuTypeModal\"]"]); - $I->waitForElement('.iframe','30'); + $I->waitForElement('.iframe', '30'); $I->switchToIFrame("Menu Item Type"); // Open the category $I->waitForElementVisible(['link' => $menuCategory], '30'); $I->click(['link' => $menuCategory]); - $I->wait(1); // Choose the menu item $I->waitForElementVisible(['xpath' => "//a[contains(text(), '" . $menuItem . "')]"], 60);