Skip to content

Commit 3e7376f

Browse files
authored
Adding setSiteOffline, setSiteSearchEngineFriendly and createModule (#229)
1 parent 20b859d commit 3e7376f

File tree

2 files changed

+274
-1
lines changed

2 files changed

+274
-1
lines changed

src/JoomlaBrowser.php

Lines changed: 195 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public function setErrorReportingToDevelopment()
379379

380380
// TODO improve
381381
$this->wait(1);
382-
$this->click(array('xpath' => "//div[@role='tablist']/button[@aria-controls='page-server']"));
382+
$this->click($this->locator->adminConfigurationServerTab);
383383
$this->debug('I wait for error reporting dropdown');
384384
$this->selectOption('Error Reporting', 'Maximum');
385385
$this->debug('I click on save');
@@ -564,6 +564,29 @@ public function selectOptionInRadioField($label, $option)
564564
$this->click("//fieldset[@id='$radioId']/label[contains(normalize-space(string(.)), '$option')]");
565565
}
566566

567+
/**
568+
* Selects an option of a switcher radio field with check if the field is already selected
569+
*
570+
* @param string $selector Selector of the <input type="radio"/> field
571+
*
572+
* @return void
573+
*
574+
* @since 4.0.0
575+
*/
576+
public function selectOptionInSwitcherRadioField($selector)
577+
{
578+
$isChecked = $this->grabAttributeFrom($selector, 'checked');
579+
580+
if ($isChecked == 'true')
581+
{
582+
$this->debug('The value seems to already be checked.');
583+
}
584+
else
585+
{
586+
$this->click($selector);
587+
}
588+
}
589+
567590
/**
568591
* Selects an option in a Chosen Selector based on its label
569592
*
@@ -1240,4 +1263,175 @@ public function createUser($name, $username, $password, $email, $userGroup = 'Su
12401263
$this->see('User saved', '#system-message-container');
12411264
$this->checkForPhpNoticesOrWarnings();
12421265
}
1266+
1267+
/**
1268+
* Site Offline
1269+
*
1270+
* @param boolean $enable To set Site Online/Offline
1271+
*
1272+
* @return void
1273+
*
1274+
* @since 4.0.0
1275+
*/
1276+
public function setSiteOffline($enable = true)
1277+
{
1278+
$this->debug($enable ? 'I set the site to be offline' : 'I set the site to be online');
1279+
$this->amOnPage(Locators::$globalConfigurationUrl);
1280+
$this->click($this->locator->adminConfigurationSiteTab);
1281+
$this->selectOptionInSwitcherRadioField($enable ? '#jform_offline1' : '#jform_offline0');
1282+
1283+
$this->click("Save");
1284+
$this->see('Configuration saved', '#system-message-container');
1285+
}
1286+
1287+
/**
1288+
* Search Engine Optimization
1289+
*
1290+
* @param boolean $enable To set SEO true/false
1291+
*
1292+
* @return void
1293+
*
1294+
* @since 4.0.0
1295+
*/
1296+
public function setSiteSearchEngineFriendly($enable = true)
1297+
{
1298+
$this->debug($enable ? 'I set SEF URLs to Yes' : 'I set SEF URLs to No');
1299+
$this->amOnPage(Locators::$globalConfigurationUrl);
1300+
$this->click($this->locator->adminConfigurationSiteTab);
1301+
$this->scrollTo('#jform_sef');
1302+
$this->selectOptionInSwitcherRadioField($enable ? '#jform_sef1' : '#jform_sef0');
1303+
1304+
$this->click("Save");
1305+
$this->see('Configuration saved', '#system-message-container');
1306+
}
1307+
1308+
/**
1309+
* Create Module
1310+
*
1311+
* @param string $moduleType Type of module
1312+
* @param string $moduleName Name of module
1313+
* @param string $category category of module
1314+
*
1315+
* @return void
1316+
*
1317+
* @since 4.0.0
1318+
*/
1319+
public function createModule($moduleType, $moduleName, $category)
1320+
{
1321+
$this->amOnPage(Locators::$moduleUrl);
1322+
1323+
// New Module
1324+
$this->click('New');
1325+
1326+
// Select Module Type
1327+
$this->see('Select a Module Type');
1328+
1329+
// Module Type
1330+
$this->click($moduleType, '.new-modules');
1331+
1332+
// Title
1333+
$this->fillField(Locators::$moduleTitle, $moduleName);
1334+
1335+
$this->click('#jform_position-lbl');
1336+
$this->type('Main-top');
1337+
$this->pressKey('.choices__input.choices__input--cloned', \Facebook\WebDriver\WebDriverKeys::ENTER);
1338+
1339+
/**
1340+
* Module Types
1341+
* Articles - Archived
1342+
* Articles - Categories
1343+
* Articles - Category
1344+
* Banners
1345+
* Breadcrumbs
1346+
* Articles - Most Read
1347+
* Articles - Newsflash
1348+
* Articles - Related
1349+
* Custom
1350+
* Feed Display
1351+
* Latest Users
1352+
* Login
1353+
* Search
1354+
* Smart Search
1355+
* Language Switcher
1356+
* Menu
1357+
* Statistics
1358+
* Syndication Feeds
1359+
* Tags - Popular
1360+
*/
1361+
switch ($moduleType)
1362+
{
1363+
case 'Articles - Archived' :
1364+
break;
1365+
case 'Articles - Categories' :
1366+
// Select category as 'Google Summer Of Codes'
1367+
$this->click(['id' => 'jform_params_parent_select']);
1368+
$this->switchToIFrame('Select or Change Category');
1369+
$this->wait(1);
1370+
$this->searchForItem($category);
1371+
$this->wait(1);
1372+
$this->see($category);
1373+
$this->click(['link' => $category]);
1374+
$this->switchToPreviousTab();
1375+
$this->wait(1);
1376+
break;
1377+
1378+
case 'Articles - Category' :
1379+
// Filter Options
1380+
$this->click(['link' => 'Filtering Options']);
1381+
$this->selectOption(Locators::$selectModuleCategory, $category);
1382+
break;
1383+
case 'Articles - Latest' :
1384+
$this->scrollTo(Locators::$selectModuleCategory, $category);
1385+
$this->selectOption(Locators::$selectModuleCategory, $category);
1386+
break;
1387+
case 'Articles - Most Read' :
1388+
$this->scrollTo(Locators::$selectModuleCategory, $category);
1389+
$this->selectOption(Locators::$selectModuleCategory, $category);
1390+
break;
1391+
case 'Articles - Newsflash' :
1392+
$this->click(Locators::$moduleCategory);
1393+
$this->fillField(Locators::$fillModuleCategory, $category);
1394+
$this->pressKey(Locators::$fillModuleCategory, \Facebook\WebDriver\WebDriverKeys::ENTER);
1395+
break;
1396+
case 'Articles - Related' :
1397+
break;
1398+
case 'Banners' :
1399+
// Select category 'Uncategorised'
1400+
$this->scrollTo(['id' => 'jform_params_catid'], 'Uncategorised');
1401+
$this->selectOption(['id' => 'jform_params_catid'], 'Uncategorised');
1402+
$this->scrollTo(['id' => 'jform_params_header_text']);
1403+
$this->fillField(['id' => 'jform_params_header_text'], 'This is text header for Module of Banners');
1404+
$this->scrollTo(['id' => 'jform_params_footer_text']);
1405+
$this->fillField(['id' => 'jform_params_footer_text'], 'This is text footer for Module of Banners');
1406+
break;
1407+
case 'Breadcrumbs' :
1408+
$this->fillField(['id' => 'jform_params_homeText'], 'Home entry for Module of breadcrumbs');
1409+
break;
1410+
case 'Custom' :
1411+
break;
1412+
case 'Feed Display' :
1413+
$this->fillField(['id' => 'jform_params_rssurl'], 'https://www.joomla.org');
1414+
break;
1415+
case 'Language Switcher' :
1416+
$this->fillField(['id' => 'jform_params_header_text'], 'This is pre-text for Module');
1417+
$this->fillField(['id' => 'jform_params_footer_text'], 'This is post-text for Module');
1418+
$this->click(['id' => 'jform_params_dropdown1']);
1419+
break;
1420+
case 'Latest Users' :
1421+
break;
1422+
case 'Login' :
1423+
$this->fillField(['id' => 'jform_params_pretext'], 'This is pre-text for Module');
1424+
$this->fillField(['id' => 'jform_params_posttext'], 'This is post-text for Module');
1425+
$this->fillField(['id' => 'jform_params_login'], 'http://localhost/joomlaMain/test-install/');
1426+
$this->fillField(['id' => 'jform_params_logout'], 'https://www.joomla.org');
1427+
$this->scrollTo(['id' => 'jform_params_name1']);
1428+
$this->click(['id' => 'jform_params_name1']);
1429+
break;
1430+
}
1431+
1432+
// Save It
1433+
$this->clickToolbarButton('save & close');
1434+
$this->see('Module saved', ['id' => 'system-message-container']);
1435+
$this->searchForItem($moduleName);
1436+
}
12431437
}

src/Locators/Locators.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,85 @@ class Locators
187187
*/
188188
public $adminManageUsersAccountDetailsTab = array('link' => 'Account Details');
189189

190+
/**
191+
* Global Configuration - Site Tab
192+
*
193+
* @var string
194+
* @since 4.0.0
195+
*/
196+
public $adminConfigurationSiteTab = array('xpath' => "//div[@role='tablist']/button[@aria-controls='page-site']");
197+
198+
/**
199+
* Global Configuration - System Tab
200+
*
201+
* @var string
202+
* @since 4.0.0
203+
*/
204+
public $adminConfigurationSystemTab = array('xpath' => "//div[@role='tablist']/button[@aria-controls='page-system']");
205+
206+
/**
207+
* Global Configuration - Server Tab
208+
*
209+
* @var string
210+
* @since 4.0.0
211+
*/
212+
public $adminConfigurationServerTab = array('xpath' => "//div[@role='tablist']/button[@aria-controls='page-server']");
213+
214+
/**
215+
* Global Configuration URL
216+
*
217+
* @var string
218+
* @since 4.0.0
219+
*/
220+
public static $globalConfigurationUrl = '/administrator/index.php?option=com_config';
221+
222+
/**
223+
* Admin Module URL
224+
*
225+
* @var string
226+
* @since 4.0.0
227+
*/
228+
public static $moduleUrl = '/administrator/index.php?option=com_modules';
229+
230+
/**
231+
* Select Module Title
232+
*
233+
* @var string
234+
* @since 4.0.0
235+
*/
236+
public static $moduleTitle = '#jform_title';
237+
238+
/**
239+
* Select Filter Options
240+
*
241+
* @var array
242+
* @since 4.0.0
243+
*/
244+
public static $filterOptions = ['link' => 'Filtering Options'];
245+
246+
/**
247+
* Select Filter Options
248+
*
249+
* @var string
250+
* @since 4.0.0
251+
*/
252+
public static $selectModuleCategory = '#jform_params_catid';
253+
254+
/**
255+
* Fill Category
256+
*
257+
* @var string
258+
* @since 4.0.0
259+
*/
260+
public static $fillModuleCategory = '//div[@id="jform_params_catid_chzn"]/ul/li/input';
261+
262+
/**
263+
* Select Module category
264+
*
265+
* @var string
266+
* @since 4.0.0
267+
*/
268+
public static $moduleCategory = 'jform_params_catid_chzn';
190269

191270
/**
192271
* Manage User - User Group Assignment Tab - User Group checkbox

0 commit comments

Comments
 (0)