diff --git a/css/admin-toolbar-tools.css b/css/admin-toolbar-tools.css index 7151b95a992a79266d0603ec7121166d97e20969..a2c79542d2aa546fca878dc89898cf7a2ad6ffec 100644 --- a/css/admin-toolbar-tools.css +++ b/css/admin-toolbar-tools.css @@ -15,4 +15,4 @@ span .cke_button__embed_icon { span .cke_button__media_icon { background-image: url('../images/embed-media.png') !important; -} \ No newline at end of file +} diff --git a/src/Config/ConfigBit.php b/src/Config/ConfigBit.php index da02b6c79d463c8f463c605aa49336fc82d339b2..61aaf50ea5939596adbd30c75cc7fba52e9b4027 100644 --- a/src/Config/ConfigBit.php +++ b/src/Config/ConfigBit.php @@ -67,13 +67,17 @@ class ConfigBit { * Get a list of sub list of config. * * @param string $config_bit_file_name - * Config bit file name in the root configbit folder. + * The Config bit file name in the root configbit folder. * @param string $condition_name - * Condition name in the config bit file. + * The Condition name in the config bit file. * @param string|bool $condition_value - * Condition value for the condition name in the config bit file. + * The Condition value for the condition name in the config bit file. * @param string $sublist - * Sub list item name to get a sub list of data. not all the list. + * The Sub list item name to get a sub list of data. not all the list. + * @param string $type + * The type of profile. + * @param string $project + * The project. * * @return array * Get List config as an array. @@ -101,14 +105,18 @@ class ConfigBit { } /** - * Applay the action of archive files to the given config bit file. + * Apply the action of archive files to the given config bit file. * * @param string $config_bit_file_name - * Config bit file name in the root configbit folder. + * The Config bit file name in the root configbit folder. * @param string $condition_name - * Condition name in the config bit file. + * The Condition name in the config bit file. * @param string|bool $condition_value - * Condition value for the condition name in the config bit file. + * The Condition value for the condition name in the config bit file. + * @param string $type + * The type of profile. + * @param string $project + * The project. */ public static function actionArchiveFiles($config_bit_file_name, $condition_name, $condition_value, $type = 'profile', $project = 'varbase') { $config_bit_data = ConfigBit::getConfigBit($config_bit_file_name, $type, $project); @@ -133,7 +141,7 @@ class ConfigBit { } /** - * Applay the action of Un archive files to the given config bit file. + * Apply the action of Un archive files to the given config bit file. * * @param string $config_bit_file_name * Config bit file name in the root configbit folder. @@ -141,6 +149,10 @@ class ConfigBit { * Condition name in the config bit file. * @param string|bool $condition_value * Condition value for the condition name in the config bit file. + * @param string $type + * The type of profile. + * @param string $project + * The project. */ public static function actionUnArchiveFiles($config_bit_file_name, $condition_name, $condition_value, $type = 'profile', $project = 'varbase') { $config_bit_data = ConfigBit::getConfigBit($config_bit_file_name, $type, $project); @@ -164,16 +176,20 @@ class ConfigBit { } /** - * Applay the action of adding config bit in to the parent file. + * Apply the action of adding config bit in to the parent file. * * @param string $config_bit_file_name - * Config bit file name in the root configbit folder. + * The Config bit file name in the root configbit folder. * @param string $condition_name - * Condition name in the config bit file. + * The Condition name in the config bit file. * @param string|bool $condition_value - * Condition value for the condition name in the config bit file. + * The Condition value for the condition name in the config bit file. * @param string $target - * Targent item in the parent config file. + * The Target item in the parent config file. + * @param string $type + * The type of profile. + * @param string $project + * The project. */ public static function actionAdd($config_bit_file_name, $condition_name, $condition_value, $target, $type = 'profile', $project = 'varbase') { $config_bit_data = ConfigBit::getConfigBit($config_bit_file_name, $type, $project); @@ -211,16 +227,20 @@ class ConfigBit { } /** - * Applay the action of removing config bit from the parent file. + * Apply the action of removing config bit from the parent file. * * @param string $config_bit_file_name - * Config bit file name in the root configbit folder. + * The Config bit file name in the root configbit folder. * @param string $condition_name - * Condition name in the config bit file. + * The Condition name in the config bit file. * @param string|bool $condition_value - * Condition value for the condition name in the config bit file. + * The Condition value for the condition name in the config bit file. * @param string $target - * Targent item in the parent config file. + * The Target item in the parent config file. + * @param string $type + * The type of profile. + * @param string $project + * The project. */ public static function actionRemove($config_bit_file_name, $condition_name, $condition_value, $target, $type = 'profile', $project = 'varbase') { $config_bit_data = ConfigBit::getConfigBit($config_bit_file_name, $type, $project); diff --git a/src/Entity/VarbaseEntityDefinitionUpdateManager.php b/src/Entity/VarbaseEntityDefinitionUpdateManager.php index b1c449e55faf8285b5e33b1e67210cf678eef005..ca0edd543b10a4a1a274e0f2cdf4b74d8b825b4a 100644 --- a/src/Entity/VarbaseEntityDefinitionUpdateManager.php +++ b/src/Entity/VarbaseEntityDefinitionUpdateManager.php @@ -68,14 +68,14 @@ final class VarbaseEntityDefinitionUpdateManager implements ContainerInjectionIn * * @param \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $entity_definition_update_manager * The entity definition update manager. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager service. * @param \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository * The last installed schema repository service. - * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager - * The entity field manager service. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager service. * @param \Drupal\Core\Entity\EntityTypeListenerInterface $entity_type_listener * The entity type listener interface. + * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager + * The entity field manager service. * @param \Drupal\Core\Field\FieldStorageDefinitionListenerInterface $field_storage_definition_listener * The field storage definition listener service. */ @@ -99,7 +99,7 @@ final class VarbaseEntityDefinitionUpdateManager implements ContainerInjectionIn * {@inheritdoc} */ public static function create(ContainerInterface $container) { - /** @noinspection PhpParamsInspection */ + // @noinspection PhpParamsInspection. return new static( $container->get('entity.definition_update_manager'), $container->get('entity.last_installed_schema.repository'), diff --git a/src/Form/ConfigureMultilingualForm.php b/src/Form/ConfigureMultilingualForm.php index d609ca54099df2e5e3d6a1b95ae29718f837e5ab..8caec1791a5d1d4362236cc9942c45abd9e4ccda 100644 --- a/src/Form/ConfigureMultilingualForm.php +++ b/src/Form/ConfigureMultilingualForm.php @@ -8,11 +8,16 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Language\LanguageManager; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Defines form for selecting Varbase's Multiligual configuration options form. */ -class ConfigureMultilingualForm extends FormBase { +class ConfigureMultilingualForm extends FormBase implements ContainerInjectionInterface { + + use StringTranslationTrait; /** * The Drupal application root. @@ -35,6 +40,13 @@ class ConfigureMultilingualForm extends FormBase { */ protected $formHelper; + /** + * The config factory service. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + /** * Configure Multilingual Form constructor. * @@ -46,12 +58,15 @@ class ConfigureMultilingualForm extends FormBase { * The string translation service. * @param \Drupal\varbase\Form\FormHelper $form_helper * The form helper. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. */ - public function __construct($root, InfoParserInterface $info_parser, TranslationInterface $translator, FormHelper $form_helper) { + public function __construct($root, InfoParserInterface $info_parser, TranslationInterface $translator, FormHelper $form_helper, ConfigFactoryInterface $config_factory) { $this->root = $root; $this->infoParser = $info_parser; $this->stringTranslation = $translator; $this->formHelper = $form_helper; + $this->configFactory = $config_factory; } /** @@ -59,10 +74,11 @@ class ConfigureMultilingualForm extends FormBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('app.root'), - $container->get('info_parser'), - $container->get('string_translation'), - $container->get('varbase.form_helper') + $container->get('app.root'), + $container->get('info_parser'), + $container->get('string_translation'), + $container->get('varbase.form_helper'), + $container->get('config.factory') ); } @@ -88,7 +104,7 @@ class ConfigureMultilingualForm extends FormBase { } asort($select_options); - $default_langcode = \Drupal::configFactory()->getEditable('system.site')->get('default_langcode'); + $default_langcode = $this->configFactory->getEditable('system.site')->get('default_langcode'); // Save the default language name. $default_language_name = $select_options[$default_langcode]; diff --git a/src/FormBit/varbase_auth.formbit.php b/src/FormBit/varbase_auth.formbit.php index f19ae32d1e45500c0dab1819fa6160372066576a..5dd09f4d948b7bb5e4703f4ebfef100ad54314c7 100644 --- a/src/FormBit/varbase_auth.formbit.php +++ b/src/FormBit/varbase_auth.formbit.php @@ -66,7 +66,7 @@ function varbase_auth_submit_formbit(array $editable_config_values) { if (isset($auth_modules) && is_array($auth_modules) && count($auth_modules) > 0) { $modules_to_install = []; - foreach ($auth_modules as $auth_module_index => $auth_module) { + foreach ($auth_modules as $auth_module) { if (is_string($auth_module)) { array_push($modules_to_install, $auth_module); } diff --git a/src/composer/ScriptHandler.php b/src/composer/ScriptHandler.php index cd66669739e3531bc837ea6d6a4895868f667338..d7ad431381ab8f94004eefb8126956568e8c049c 100644 --- a/src/composer/ScriptHandler.php +++ b/src/composer/ScriptHandler.php @@ -174,6 +174,7 @@ class ScriptHandler { * Find and return the path to .git repository in root folder. * * @param string $root + * The Drupal root directory. */ private static function removeWindowsGitDirectories($root) { foreach (scandir($root) as $dirOrFile) { @@ -194,6 +195,7 @@ class ScriptHandler { * Remove a directory on Windows. * * @param string $dirname + * The directory name. */ private static function rmdirWindows($dirname) { if (is_file($dirname)) { diff --git a/tests/features/bootstrap/SelectorsContext.php b/tests/features/bootstrap/SelectorsContext.php index c9e7f14256d8162185cbe9883ad12cadd30eb732..53d41695aca4bd2aa2fa7f7c23b6fe7b3156427c 100644 --- a/tests/features/bootstrap/SelectorsContext.php +++ b/tests/features/bootstrap/SelectorsContext.php @@ -1,20 +1,10 @@ <?php -/** - * @file - */ +namespace Drupal\varbase\tests\features\bootstrap\SelectorsContext; use Drupal\DrupalExtension\Context\RawDrupalContext; use Behat\Behat\Context\SnippetAcceptingContext; -use Behat\Gherkin\Node\PyStringNode; -use Behat\Gherkin\Node\TableNode; - use Behat\Mink\Selector\CssSelector; -use Behat\Mink\Selector\NamedSelector; -use Behat\Mink\Exception\ExpectationException; - -use Behat\Behat\Hook\Scope\BeforeScenarioScope; - use Symfony\Component\Yaml\Yaml; /** @@ -27,14 +17,14 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte * * @var array */ - protected $cssSelectors = array(); + protected $cssSelectors = []; /** * Holed a list of XPaht Selectors. * * @var array */ - protected $xpathSelectors = array(); + protected $xpathSelectors = []; /** * Holed the file path for where we could have selector files. @@ -111,6 +101,8 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte } /** + * Register Selectors. + * * @BeforeStep @javascript */ public function registerSelectors() { @@ -130,9 +122,9 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte } /** - * #Selector : To add a new selector name with a css selector. + * Selector : To add a new selector name with a css selector. * - * Exmaple 1: When I add "mobile logo" selector for "header img#logo" css selector + * Example 1: When I add "mobile logo" selector for "header img#logo" css selector * Example 2: And I add "breadcrumb" selector for ".breadcrumb" css selector * Example 3: And I add "breadcrumb first link" selector for ".breadcrumb li:nth-child(1) a" css selector. * @@ -172,7 +164,7 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte } /** - * #Selector : To add a new selector name with a XPath selector. + * Selector : To add a new selector name with a XPath selector. * * Exmaple 1: When I add "page title" selector for "//h1[contains(@class, 'page-header')" xpath selector * Example 2: And I add "Dashboard" selector for "//*[@id='navbar-link-admin-dashboard']" xpath selector @@ -195,7 +187,7 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte * * @When /^I add "(?P<selectorName>[^"]*)" selector for "(?P<xpathSelector>[^"]*)" xpath selector$/ */ - public function addSelectorNameForXPathSelector($selectorName, $xpathSelector) { + public function addSelectorNameForXpathSelector($selectorName, $xpathSelector) { if (!empty($selectorName) && $selectorName != '' && !empty($xpathSelector) && $xpathSelector != '') { // Add the selector name for the XPath selector to the selectors array. $this->xpathSelectors[$selectorName] = $xpathSelector; @@ -210,15 +202,15 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte } /** - * #Selector : To add a new selector name with a css selector. + * Selector : To add a new selector name with a css selector. * - * Exmaple 1: When I load selectors from "" file + * Example 1: When I load selectors from "" file * Example 2: And I add "breadcrumb" selector for ".breadcrumb" css selector * Example 3: And I add "breadcrumb first link" selector for ".breadcrumb li:nth-child(1) a" css selector. * * @When /^I add selectors from "(?P<fileName>[^"]*)" file$/ */ - public function IAddSelectorsFromFile($fileName) { + public function iAddSelectorsFromFile($fileName) { if (!empty($fileName) && $fileName != '' && isset($this->filesPath) && $this->filesPath != '') { @@ -268,9 +260,9 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte } /** - * #Selector : To print list of CSS selectors which has been registered. + * Selector: To print list of CSS selectors which has been registered. * - * Exmaple : When I print css selectors. + * Example: When I print css selectors. * * @Then /^(?:|I )print css selectors$/ */ @@ -279,53 +271,53 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte } /** - * #Selector : To print list of XPath selectors which has been registered. + * Selector: To print list of XPath selectors which has been registered. * - * Exmaple : When I print xpath selectors. + * Example: When I print xpath selectors. * * @Then /^(?:|I )print xpath selectors$/ */ - public function printXPathSelectors() { + public function printXpathSelectors() { echo Yaml::dump($this->xpathSelectors); } /** - * #vardot : Move the focus to selected field input element. + * Move the focus to selected field input element. * * Example #1: When I move focus to "Title" field * Example #2: And I move focus to "Body" field. * * @When /^(?:|I )move focus to "(?P<selectedField>[^"]*)" field$/ */ - function moveFocusToField($selectedField) { + public function moveFocusToField($selectedField) { $field = $this->getSession()->getPage()->findField($selectedField); $fieldid = $field->getAttribute('id'); $this->getSession()->getDriver()->evaluateScript("jQuery('#{$fieldid}').focus();"); } /** - * #vardot : Select all text in selected field input element. + * Select all text in selected field input element. * * Example #1: When I select all text in "Title" field * Example #2: And I select all text in "Description" field. * * @When /^(?:|I )select all text in "(?P<selectedField>[^"]*)" field$/ */ - function selectAllTextInField($selectedField) { + public function selectAllTextInField($selectedField) { $field = $this->getSession()->getPage()->findField($selectedField); $fieldid = $field->getAttribute('id'); $this->getSession()->getDriver()->evaluateScript('document.getElementById("' . $fieldid . '").select();'); } /** - * #vardot : Select part of the text in selected field input element. + * Select part of the text in selected field input element. * * Example #1: When I select from 0 to 5 text in "Title" field * Example #2: And I select from 0 to 5 text in "Description" field. * * @When /^(?:|I )select from (?P<from>\d+) to (?P<to>\d+) text in "(?P<selectedField>[^"]*)" field$/ */ - function setSelectionRangeFromField($from, $to, $selectedField) { + public function setSelectionRangeFromField($from, $to, $selectedField) { $field = $this->getSession()->getPage()->findField($selectedField); $fieldid = $field->getAttribute('id'); @@ -341,14 +333,14 @@ class SelectorsContext extends RawDrupalContext implements SnippetAcceptingConte } /** - * #vardot : Select a part text in selected field input element. + * Select a part text in selected field input element. * * Example #1: When I select "title name" text in "Title" field * Example #2: And I select "some content" text in "Description" field. * * @When /^(?:|I )select "(?P<selectedText>[^"]*)" text in "(?P<selectedField>[^"]*)" field$/ */ - function selectTextInField($selectedText, $selectedField) { + public function selectTextInField($selectedText, $selectedField) { $field = $this->getSession()->getPage()->findField($selectedField); $fieldid = $field->getAttribute('id'); diff --git a/tests/features/bootstrap/VarbaseContext.php b/tests/features/bootstrap/VarbaseContext.php index 5aabe2b70954ca924440c743a2d26aa052d11b5a..a3b928d1cbc90396b00067e660494c4fb0051616 100644 --- a/tests/features/bootstrap/VarbaseContext.php +++ b/tests/features/bootstrap/VarbaseContext.php @@ -1,10 +1,10 @@ <?php -use Behat\Behat\Tester\Exception\PendingException; +namespace Drupal\varbase\tests\features\bootstrap\VarbaseContext; + +use WebDriver\Exception; use Drupal\DrupalExtension\Context\RawDrupalContext; use Behat\Behat\Context\SnippetAcceptingContext; -use Behat\Gherkin\Node\PyStringNode; -use Behat\Gherkin\Node\TableNode; /** * Defines application features from the specific context. @@ -12,24 +12,30 @@ use Behat\Gherkin\Node\TableNode; class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext { /** - * Hold the user name and password from drupal_users parameters. - */ - protected $users = array(); + * Hold the user name and password from drupal_users parameters. + * + * @var array + */ + protected $users = []; /** - * Hold the user name and password from varbase_users parameters. - */ - protected $varbase_users = array(); + * Hold the user name and password from varbase_users parameters. + * + * @var array + */ + protected $varbaseUsers = []; /** - * Hold all passed parameters. - */ - protected $parameters = array(); + * Hold all passed parameters. + * + * @var array + */ + protected $parameters = []; /** * Initializes context. * - * @param array $parameters . + * @param array $parameters * Context parameters (set them up through behat.yml or behat.local.yml). */ public function __construct(array $parameters) { @@ -38,9 +44,9 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $this->parameters = $parameters; if (isset($parameters['varbase_users'])) { - $this->varbase_users = $parameters['varbase_users']; - foreach ($parameters['varbase_users'] as $varbase_username => $varbase_user) { - $this->users[$varbase_username] = $varbase_user['password']; + $this->varbaseUsers = $parameters['varbase_users']; + foreach ($parameters['varbase_users'] as $varbaseUsername => $varbaseUser) { + $this->users[$varbaseUsername] = $varbaseUser['password']; } } else { @@ -49,9 +55,17 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase : To authenticate a user with password from varbase configuration. - * If you want to see the list of users or add yours you can go and - * edit the behat.varbase.yml file under the varbase_users list. + * Clean users. + */ + public function cleanUsers() { + + } + + /** + * Authenticate a user with password from varbase configuration. + * + * Varbase Context #varbase. If you want to see the list of users or add yours you can go and + * edit the behat.varbase.yml file under the varbase_users list. * * Example: I am a logged in user with the username "test_content_admin" * @@ -78,7 +92,9 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase : To authenticate a user with a gavin username and password on the spot. + * Authenticate a user with a given username and password on the spot. + * + * Varbase Context #varbase. * * Example: I am a logged in user with the username "testing" and password "testing user password" * @@ -90,7 +106,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $this->logout(); } - // Login with the + // Login with the. $element = $this->getSession()->getPage(); $this->getSession()->visit($this->locatePath('/user')); $element->fillField('edit-name', $username); @@ -100,23 +116,27 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase : To logout from the current session. + * Logout from the current session. * - * Example: When I logout + * Varbase Context #varbase. + * + * Example: When I logout. * * @When /^I logout$/ */ - public function iLogout() { - // Logout if I am logged in. - if ($this->loggedIn()) { - $this->logout(); - } - } + public function iLogout() { + // Logout if I am logged in. + if ($this->loggedIn()) { + $this->logout(); + } + } /** - * #varbase: To go directly to an external website. + * Navigate directly to an external web site. + * + * Varbase Context #varbase. * - * Example: When I go to "https://www.google.com" website + * Example: When I go to "https://www.google.com" website. * * @When /^I go to "(?P<domain>[^"]*)" website$/ */ @@ -125,14 +145,16 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase: To wait for seconds before going to the next step. + * Wait for seconds before going to the next step. + * + * Varbase Context #varbase. * * Example 1: And wait for "1" second * Example 2: When I wait for "5" seconds * Example 3: And wait 1 second * Example 4: When I wait for 60 seconds * Example 5: And wait 1s - * Example 6: When I wait for 60s + * Example 6: When I wait for 60s. * * @When /^(?:|I )wait (?:|for )"(?P<seconds>\d+)" second(?:|s)$/ * @When /^(?:|I )wait (?:|for )(?P<seconds>\d+) second(?:|s)$/ @@ -143,14 +165,16 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase: To wait for minutes before going to the next step + * Wait for minutes before going to the next step. + * + * Varbase Context #varbase. * * Example 1: And I wait for "1" minute * Example 2: When I wait for "2" minutes * Example 3: And wait 1 minute * Example 4: When I wait for 3 minutes * Example 5: And wait 1m - * Example 6: When I wait for 3m + * Example 6: When I wait for 3m. * * @When /^(?:|I )wait (?:|for )"(?P<minutes>\d+)" minute(?:|s)$/ * @When /^(?:|I )wait (?:|for )(?P<minutes>\d+) minute(?:|s)$/ @@ -161,62 +185,74 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase : I wait max of seconds for the page to be ready and loaded. + * Wait max of seconds for the page to be ready and loaded. * - * Exmaple 1: And wait - * Exmaple 2: And I wait + * Varbase Context #varbase. + * + * Example 1: And wait + * Example 2: And I wait * Example 3: And wait for the page * Example 4: And I wait for the page * Example 5: And wait max of 5 seconds * Example 6: And wait max of 5s * Example 7: And I wait max of 5s * Example 8: And I wait max of "5" seconds - * Example 9: And I wait max of "5" seconds for the page to be ready and loaded + * Example 9: And I wait max of "5" seconds for the page to be ready and loaded. * * @Given /^(?:|I )wait max of "(?P<time>\d+)" second(?:|s)(?:| for the page to be ready and loaded)$/ * @Given /^(?:|I )wait max of (?P<time>\d+) second(?:|s)(?:| for the page to be ready and loaded)$/ * @Given /^(?:|I )wait max of (?P<time>\d+)s(?:| for the page to be ready and loaded)$/ * @Given /^(?:|I )wait(?:| for the page)$/ * - * @throws BehaviorException If timeout is reached + * @throws BehaviorException + * If timeout is reached. */ public function iWaitMaxOfSecondsForThePageToBeReadyAndLoaded($time = 10000) { - if (!$this->getSession()->getDriver() instanceof Selenium2Driver) { - return; - } - $start = microtime(true); - $end = $start + $time / 1000.0; - $defaultCondition = true; - $conditions = [ - "document.readyState == 'complete'", // Page is ready - "typeof $ != 'undefined'", // jQuery is loaded - "!$.active", // No ajax request is active - "$('#page').css('display') == 'block'", // Page is displayed (no progress bar) - "$('.loading-mask').css('display') == 'none'", // Page is not loading (no black mask loading page) - "$('.jstree-loading').length == 0", // Jstree has finished loading - ]; - $condition = implode(' && ', $conditions); - // Make sure the AJAX calls are fired up before checking the condition - $this->getSession()->wait(100, false); - $this->getSession()->wait($time, $condition); - // Check if we reached the timeout unless the condition is false to explicitly wait the specified time - if ($condition !== false && microtime(true) > $end) { - throw new BehaviorException(sprintf('Timeout of %d reached when checking on %s', $time, $condition)); - } + if (!$this->getSession()->getDriver() instanceof Selenium2Driver) { + return; + } + $start = microtime(TRUE); + $end = $start + $time / 1000.0; + $conditions = [ + // Page is ready. + "document.readyState == 'complete'", + // jQuery is loaded. + "typeof $ != 'undefined'", + // No ajax request is active. + "!$.active", + // Page is displayed (no progress bar) + "$('#page').css('display') == 'block'", + // Page is not loading (no black mask loading page) + "$('.loading-mask').css('display') == 'none'", + // Jstree has finished loading. + "$('.jstree-loading').length == 0", + ]; + $condition = implode(' && ', $conditions); + // Make sure the AJAX calls are fired up before checking the condition. + $this->getSession()->wait(100, FALSE); + $this->getSession()->wait($time, $condition); + // Check if we reached the timeout unless the condition is false to explicitly wait the specified time. + if ($condition !== FALSE && microtime(TRUE) > $end) { + throw new BehaviorException(sprintf('Timeout of %d reached when checking on %s', $time, $condition)); + } } - // Editor Media Browser functions - // =========================================================================== + /** + * Editor Media Browser functions. + * + * ==========================================================================. + */ /** - * #varbase : Click the editor media browser command button + * Click the editor media browser command button. + * + * Varbase Context #varbase. * - * Example 1: When I click the editor media browser command button + * Example 1: When I click the editor media browser command button. * * @When /^I click the editor media browser command button$/ */ public function iClickTheEditorMediaBrowserCommandButton() { - $element = $this->getSession()->getPage(); $editorMediaBrowserButton = $this->getSession()->getPage()->find('css', '.cke_button.cke_button__media'); @@ -228,19 +264,27 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** + * Check if the editor media browser is open. + * + * Varbase Context #varbase. + * * @Then /^the editor media browser should be open$/ */ public function theEitorMediaBrowserIsOpen() { - if (!$elem = $this->getSession()->getPage()->find('css', '.ui-dialog.media-wrapper') || !$this->getSession()->getPage()->find('css', '.ui-dialog.media-wrapper .media-browser-panes')) { + + if (!$this->getSession()->getPage()->find('css', '.ui-dialog.media-wrapper') + || !$this->getSession()->getPage()->find('css', '.ui-dialog.media-wrapper .media-browser-panes')) { throw new Exception('The editor media browser failed to open.'); } } /** - * #varbase : To press a button in the filter form under the editor media browser. + * Press a button in the filter form under the editor media browser. + * + * Varbase Context #varbase. * * Example 1: When I press the "Apply" button under the editor media browser - * Example 2: When I press the "Submit" button under the editor media browser + * Example 2: When I press the "Submit" button under the editor media browser. * * @When /^I press (?:|the )"([^"]*)" button under the editor media browser$/ */ @@ -248,26 +292,27 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext // Switch to the "entity_browser_iframe_editor_media_browser" iframe. $this->getSession()->switchToIFrame('entity_browser_iframe_editor_media_browser'); + try { + $this->getSession()->wait(1000, 'typeof(jQuery)=="undefined" || jQuery("#autocomplete").length === 0'); + } + catch (UnsupportedDriverActionException $e) { - try { - $this->getSession()->wait(1000, 'typeof(jQuery)=="undefined" || jQuery("#autocomplete").length === 0'); - } - catch (UnsupportedDriverActionException $e) { - - } + } $this->getSession()->getPage()->pressButton($button); // Switch back too the page from the "entity_browser_iframe_editor_media_browser" iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } /** - * #varbase : To click on a link or button under the editor media browser + * Click on a link or button under the editor media browser. + * + * Varbase Context #varbase. * * Example 1: When I click "Submit" button under the media browser * Example 2: When I click "Submit" under media browser - * Example 3: When I click "Upload" under the media browser + * Example 3: When I click "Upload" under the media browser. * * @When /^I click "([^"]*)" (?:|button )under (?:|the )editor media browser$/ */ @@ -275,7 +320,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext // Switch to the "mediaBrowser" iframe. $this->getSession()->switchToIFrame('entity_browser_iframe_editor_media_browser'); - // Find the Tab by txt + // Find the Tab by txt. $element = $this->getSession()->getPage()->find('xpath', "//*[contains(@class, 'button') and text() = '{$text}']"); if (empty($element)) { @@ -285,14 +330,16 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $element->click(); // Switch back too the page from the "entity_browser_iframe_editor_media_browser" iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } /** - * #varbase : To click on a tab under the editor media browser. + * Click on a tab under the editor media browser. + * + * Varbase Context #varbase. * * Example 1: When I click on the "Library" tab under the editor media browser - * Example 2: When I click on the "My files" tab under the editor media browser + * Example 2: When I click on the "My files" tab under the editor media browser. * * @When /^I click on the "([^"]*)" tab under the editor media browser$/ */ @@ -300,7 +347,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext // Switch to the "entity_browser_iframe_editor_media_browser" iframe. $this->getSession()->switchToIFrame('entity_browser_iframe_editor_media_browser'); - // Find the Tab by txt + // Find the Tab by txt. $element = $this->getSession()->getPage()->find('xpath', "//*[contains(@class, 'ui-tabs-anchor') and text() = '{$text}']"); if (empty($element)) { @@ -310,13 +357,15 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $element->click(); // Switch back too the page from the "mediaBrowser" iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } /** - * #varbase : select the file under the editor media browser. + * Select the file under the editor media browser. + * + * Varbase Context #varbase. * - * Example 1: When I click on the "Flag Earth" file under the editor media browser + * Example 1: When I click on the "Flag Earth" file under the editor media browser. * * @When /^I select (?:|the )"([^"]*)" file under (?:|the )editor media browser$/ */ @@ -334,22 +383,23 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $element->click(); // Switch back too the page from the "entity_browser_iframe_editor_media_browser" iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } /** - * #varbase : To fill in a form field with id|name|title|alt|value - * under the editor media browser. - * - * Example: I fill in "flag earth" for "File name" under the editor media browser - * - * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)" under (?:|the )editor media browser$/ - * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with: under (?:|the )editor media browser$/ - * @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)" under (?:|the )editor media browser$/ - */ + * Fill in a form field with id|name|title|alt|value. + * + * Under the editor media browser. + * Varbase Context #varbase. + * + * Example: I fill in "flag earth" for "File name" under the editor media browser. + * + * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)" under (?:|the )editor media browser$/ + * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with: under (?:|the )editor media browser$/ + * @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)" under (?:|the )editor media browser$/ + */ public function iFillInFieldUnderTheEditorMediaBrowser($field, $value) { // Switch to the "entity_browser_iframe_editor_media_browser" iframe. - $this->getSession()->switchToIFrame('entity_browser_iframe_editor_media_browser'); $field = str_replace('\\"', '"', $field); @@ -357,40 +407,41 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $this->getSession()->getPage()->fillField($field, $value); // Switch back too the page from the "entity_browser_iframe_editor_media_browser" iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } - /** - * #varbase : To check if we can see a text - * under the editor media browser. - * - * Example 1: Then I should see "this text" under editor media browser - * Example 2: Then I should see "this text" under the editormedia browser modal window - * - * @Then /^I should see "([^"]*)" under (?:|the )editor media browser(?:| modal window)$/ - */ + * Check if we can see a text under the editor media browser. + * + * Varbase Context #varbase. + * + * Example 1: Then I should see "this text" under editor media browser + * Example 2: Then I should see "this text" under the editormedia browser modal window. + * + * @Then /^I should see "([^"]*)" under (?:|the )editor media browser(?:| modal window)$/ + */ public function iShouldSeeTextUnderTheEditorMediaBrowser($text) { // Switch to the "entity_browser_iframe_editor_media_browser" iframe. $this->getSession()->switchToIFrame('entity_browser_iframe_editor_media_browser'); $actual = $this->getSession()->getPage()->getText(); $actual = preg_replace('/\s+/u', ' ', $actual); - $regex = '/'.preg_quote($text, '/').'/ui'; + $regex = '/' . preg_quote($text, '/') . '/ui'; if (!preg_match($regex, $actual)) { throw new Exception(sprintf('The text "%s" was not found anywhere in the text of the current page.', $text)); } // Switch back too the page from the "entity_browser_iframe_editor_media_browser" iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } - /** - * #varbase : To Find an image with the title text attribute. + * Find an image with the title text attribute. * - * Example 1: Then I should see image with the "Flag Earth" title text + * Varbase Context #varbase. + * + * Example 1: Then I should see image with the "Flag Earth" title text. * * @Then /^I should see image with the "([^"]*)" title text under (?:|the )editor media browser(?:| modal window)$/ */ @@ -406,15 +457,16 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } // Switch back too the page from the "entity_browser_iframe_editor_media_browser" iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } - /** - * #varbase : To check if we can NOT see a text - * under the editor media browser. + /** + * Check if we can NOT see a text under the editor media browser. + * + * Varbase Context #varbase. * * Example 1: Then I should not see "this text" under editor media browser - * Example 2: Then I should not see "this text" under the editor media browser modal window + * Example 2: Then I should not see "this text" under the editor media browser modal window. * * @Then /^I should not see "([^"]*)" under (?:|the )editor media browser(?:| modal window)$/ */ @@ -424,42 +476,44 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $actual = $this->getSession()->getPage()->getText(); $actual = preg_replace('/\s+/u', ' ', $actual); - $regex = '/'.preg_quote($text, '/').'/ui'; + $regex = '/' . preg_quote($text, '/') . '/ui'; if (preg_match($regex, $actual)) { throw new Exception(sprintf('The text "%s" was not found anywhere in the text of the current page.', $text)); } // Switch back too the page from the "entity_browser_iframe_editor_media_browser" iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } - // =========================================================================== - - // Rich text editor Functions CKEditor. - // =========================================================================== + /* + * =========================================================================== + * Rich text editor Functions CKEditor. + * =========================================================================== + */ /** - * #varbase : To fill in a rich text editor field WYSIWYG with content - * using the name of the field. - * - * Example: When I fill in the rich text editor field "Body" with "Test Body text" - * - * @When /^I fill in the rich text editor field "([^"]*)" with "([^"]*)"$/ - */ + * Fill in a rich text editor field WYSIWYG with content. + * + * Using the name of the field. + * Varbase Context #varbase. + * + * Example: When I fill in the rich text editor field "Body" with "Test Body text" + * + * @When /^I fill in the rich text editor field "([^"]*)" with "([^"]*)"$/ + */ public function iFillInTheRichTextEditorField($locator, $value) { $el = $this->getSession()->getPage()->findField($locator); $fieldId = $el->getAttribute('id'); if ($fieldId == NULL) { // If the WYSIWYG is in an ifream with no id. - $iFreamID = $this->_getAttributeByOtherAttributeValue('id', 'title', "Rich Text Editor, ". $el->getAttribute('id'), 'iframe'); + $iFreamID = $this->getAttributeByOtherAttributeValue('id', 'title', "Rich Text Editor, " . $el->getAttribute('id'), 'iframe'); if (!empty($iFreamID)) { $fieldId = $iFreamID; } } - if (empty($fieldId)) { throw new Exception('Could not find an id for the rich text editor field : ' . $locator); } @@ -468,9 +522,12 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase : To click a command button in the rich text editor - * Example 1: When I click on "bold" command button in the rich text editor field "Body" - * Exmaple 2: When I click on "media" command button in the rich text editor field "Body" + * Click a command button in the rich text editor. + * + * Varbase Context #varbase. + * + * Example 1: When I click on "bold" command button in the rich text editor field "Body" + * Example 2: When I click on "media" command button in the rich text editor field "Body". * * @When /^I click on "([^"]*)" command button in the rich text editor field "([^"]*)"$/ */ @@ -488,27 +545,29 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase : To append text at the end of a rich text editor field WYSIWYG with content - * using the name of the field. - * - * Example #1: When I append after the rich text editor field "Body" with "Test Body text" - * Example #2: When I append the rich text editor field "Body" with "Test Body text" - * - * @When /^(?:|I )append(?:| after) the rich text editor field "([^"]*)" with "([^"]*)"$/ - */ + * Append text at the end of a rich text editor field WYSIWYG with content. + * + * Using the name of the field. + * + * Varbase Context #varbase. + * + * Example #1: When I append after the rich text editor field "Body" with "Test Body text" + * Example #2: When I append the rich text editor field "Body" with "Test Body text" + * + * @When /^(?:|I )append(?:| after) the rich text editor field "([^"]*)" with "([^"]*)"$/ + */ public function appendTheRichTextEditorField($locator, $value) { $el = $this->getSession()->getPage()->findField($locator); $fieldId = $el->getAttribute('id'); if ($fieldId == NULL) { // If the WYSIWYG is in an ifream with no id. - $iFreamID = $this->_getAttributeByOtherAttributeValue('id', 'title', "Rich Text Editor, ". $el->getAttribute('id'), 'iframe'); + $iFreamID = $this->getAttributeByOtherAttributeValue('id', 'title', "Rich Text Editor, " . $el->getAttribute('id'), 'iframe'); if (!empty($iFreamID)) { $fieldId = $iFreamID; } } - if (empty($fieldId)) { throw new Exception('Could not find an id for the rich text editor field : ' . $locator); } @@ -517,27 +576,28 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase : To add append text at the end of a rich text editor field WYSIWYG with content - * using the name of the field. - * - * Example #1: When I prepend before the rich text editor field "Body" with "Test Body text" - * Example #2: When I prepend the rich text editor field "Body" with "Test Body text" - * - * @When /^(?:|I )prepend(?:| before) the rich text editor field "([^"]*)" with "([^"]*)"$/ - */ + * Add append text at the end of rich text editor field WYSIWYG with content. + * + * Using the name of the field. + * Varbase Context #varbase. + * + * Example #1: When I prepend before the rich text editor field "Body" with "Test Body text" + * Example #2: When I prepend the rich text editor field "Body" with "Test Body text" + * + * @When /^(?:|I )prepend(?:| before) the rich text editor field "([^"]*)" with "([^"]*)"$/ + */ public function prependTheRichTextEditorField($locator, $value) { $el = $this->getSession()->getPage()->findField($locator); $fieldId = $el->getAttribute('id'); if ($fieldId == NULL) { // If the WYSIWYG is in an ifream with no id. - $iFreamID = $this->_getAttributeByOtherAttributeValue('id', 'title', "Rich Text Editor, ". $el->getAttribute('id'), 'iframe'); + $iFreamID = $this->getAttributeByOtherAttributeValue('id', 'title', "Rich Text Editor, " . $el->getAttribute('id'), 'iframe'); if (!empty($iFreamID)) { $fieldId = $iFreamID; } } - if (empty($fieldId)) { throw new Exception('Could not find an id for the rich text editor field : ' . $locator); } @@ -546,57 +606,62 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #vardot : Move the focus to selected rich text editor field. + * Move the focus to selected rich text editor field. + * + * Varbase Context #varbase. * * Example #1: When I move focus to "Title" rich text editor field - * Example #2: And I move focus to "Body" rich text editor field + * Example #2: And I move focus to "Body" rich text editor field. * * @When /^(?:|I )move focus to "(?P<selectedField>[^"]*)" rich text editor field$/ */ - function moveFocusToTheRichTextEditorField($selectedField) { + public function moveFocusToTheRichTextEditorField($selectedField) { $el = $this->getSession()->getPage()->findField($selectedField); $fieldid = $el->getAttribute('id'); if (empty($fieldid)) { - throw new Exception('Could not find an id for the rich text editor field : ' . $selectedField); + throw new Exception('Could not find an id for the rich text editor field : ' . $selectedField); } - $this->getSession()->getDriver()->evaluateScript("CKEDITOR.instances[\"$fieldid\"].focus();"); + $this->getSession()->getDriver()->evaluateScript("CKEDITOR.instances[\"$fieldid\"].focus();"); } /** - * #vardot : Select all text in selected field input element. - * - * Example #1: When I select all text in "Body" field - * Example #2: And I select all text in "Body" field - * - * @When /^(?:|I )select all text in "(?P<selectedField>[^"]*)" rich text editor field$/ - */ - function selectAllTextInTheRichTextEditorField($selectedField) { + * Select all text in selected field input element. + * + * Varbase Context #varbase. + * + * Example #1: When I select all text in "Body" field + * Example #2: And I select all text in "Body" field. + * + * @When /^(?:|I )select all text in "(?P<selectedField>[^"]*)" rich text editor field$/ + */ + public function selectAllTextInTheRichTextEditorField($selectedField) { $el = $this->getSession()->getPage()->findField($selectedField); $fieldid = $el->getAttribute('id'); if (empty($fieldid)) { - throw new Exception('Could not find an id for the rich text editor field : ' . $selectedField); + throw new Exception('Could not find an id for the rich text editor field : ' . $selectedField); } - $this->getSession()->getDriver()->evaluateScript("CKEDITOR.instances[\"$fieldid\"].execCommand('selectAll', false, null);"); - $this->getSession()->getDriver()->evaluateScript("CKEDITOR.instances[\"$fieldid\"].forceNextSelectionCheck();"); - $this->getSession()->getDriver()->evaluateScript("CKEDITOR.instances[\"$fieldid\"].selectionChange();"); + $this->getSession()->getDriver()->evaluateScript("CKEDITOR.instances[\"$fieldid\"].execCommand('selectAll', false, null);"); + $this->getSession()->getDriver()->evaluateScript("CKEDITOR.instances[\"$fieldid\"].forceNextSelectionCheck();"); + $this->getSession()->getDriver()->evaluateScript("CKEDITOR.instances[\"$fieldid\"].selectionChange();"); } - // =========================================================================== - - - - // Images Functions. - // =========================================================================== + /** + * Images Functions. + * + * ==========================================================================. + */ /** - * #varbase : To Find an image with the title text attribute. + * Find an image with the title text attribute. + * + * Varbase Context #varbase. * - * Example 1: Then I should see image with the "Flag Earth" title text + * Example 1: Then I should see image with the "Flag Earth" title text. * * @Then /^I should see image with the "([^"]*)" title text$/ */ @@ -610,9 +675,11 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase : To Find an image with the alt text attribute. + * Find an image with the alt text attribute. * - * Example 1: Then I should see image with the "Flag Earth" alt text + * Varbase Context #varbase. + * + * Example 1: Then I should see image with the "Flag Earth" alt text. * * @Then /^I should see image with the "([^"]*)" alt text$/ */ @@ -625,49 +692,54 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } } - /** - * #varbase: To double click on an image with the provided title. - * - * Example 1: I double on the image with the "Flag Earth image title" title text - * - * @Given /^I double click on the image with the "([^"]*)" title text$/ - */ - public function iDoubleClickOnTheImageWithTheTitleText($titleText) { - // Find an image with the title. - $element = $this->getSession()->getPage()->find('xpath', "//img[contains(@title, '{$titleText}')]"); + /** + * Double click on an image with the provided title. + * + * Varbase Context #varbase. + * + * Example 1: I double on the image with the "Flag Earth image title" title text. + * + * @Given /^I double click on the image with the "([^"]*)" title text$/ + */ + public function iDoubleClickOnTheImageWithTheTitleText($titleText) { + // Find an image with the title. + $element = $this->getSession()->getPage()->find('xpath', "//img[contains(@title, '{$titleText}')]"); - if (empty($element)) { - throw new Exception('The page dose not have an image with the [ ' . $titleText . ' ] title text.'); - } + if (empty($element)) { + throw new Exception('The page dose not have an image with the [ ' . $titleText . ' ] title text.'); + } - // Double click on the image. - $element->doubleClick(); - } + // Double click on the image. + $element->doubleClick(); + } - /** - * #varbase: To click on an image with the provided title. + /** + * Click on an image with the provided title. * - * Example 1: I click on the image with the "Flag Earth image title" title text + * Varbase Context #varbase. + * + * Example 1: I click on the image with the "Flag Earth image title" title text. * * @Given /^I click on the image with the "([^"]*)" title text$/ */ public function iClickOnTheImageWithTheTitleText($titleText) { - // Find an image with the title. - $element = $this->getSession()->getPage()->find('xpath', "//img[contains(@title, '{$titleText}')]"); + // Find an image with the title. + $element = $this->getSession()->getPage()->find('xpath', "//img[contains(@title, '{$titleText}')]"); - if (empty($element)) { - throw new Exception('The page dose not have an image with the [ ' . $titleText . ' ] title text.'); - } + if (empty($element)) { + throw new Exception('The page dose not have an image with the [ ' . $titleText . ' ] title text.'); + } // Click on the image. $element->click(); } - /** - * #varbase: To double click on an image with the provided alt Text. + * Double click on an image with the provided alt Text. + * + * Varbase Context #varbase. * - * Example 1: I double click on the image with the "Flag Earth image title" alt text + * Example 1: I double click on the image with the "Flag Earth image title" alt text. * * @Given /^I double click on the image with the "([^"]*)" alt text$/ */ @@ -683,14 +755,16 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $element->doubleClick(); } - /** - * #varbase: To click on an image with the provided alt. + /** + * Click on an image with the provided alt. * - * Example 1: I click on the image with the "Flag Earth image title" alt text + * Varbase Context #varbase. + * + * Example 1: I click on the image with the "Flag Earth image title" alt text. * * @Given /^I click on the image with the "([^"]*)" alt text$/ */ - public function iClickOnTheImageWithTheAltText($titleText) { + public function iClickOnTheImageWithTheAltText($altText) { // Find an image with the title. $element = $this->getSession()->getPage()->find('xpath', "//img[contains(@title, '{$altText}')]"); @@ -698,13 +772,14 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext throw new Exception('The page dose not have an image with the [ ' . $altText . ' ] title text.'); } - // click on the image. + // Click on the image. $element->click(); } /** - * #varbase : To Find an image with the title text attribute - * under a custom iframe. + * Find an image with the title text attribute under a custom iframe. + * + * Varbase Context #varbase. * * Example 1: Then I should see image with the "Flag Earth" title text in the rich text editor field "Body" * @@ -719,27 +794,27 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext throw new Exception('Could not find an id for the rich text editor field : ' . $locator); } - $CKEditorContent = $this->getSession()->executeScript("return CKEDITOR.instances[\"$fieldId\"].getData();"); - + $this->getSession()->executeScript("return CKEDITOR.instances[\"$fieldId\"].getData();"); // Switch to the iframe. - $iFreamID = $this->_getAttributeByOtherAttributeValue('id', 'title', $filedName, 'iframe'); + $iFreamID = $this->getAttributeByOtherAttributeValue('id', 'title', $fieldId, 'iframe'); $this->getSession()->switchToIFrame($iFreamID); // Find an image with the title. $element = $this->getSession()->getPage()->findAll('xpath', "//img[contains(@title, '{$titleText}')]"); if (empty($element)) { - throw new Exception('The page dose not have an image with the [ ' . $titleText . ' ] title text under [ '. $filedName .' ].'); + throw new Exception('The page dose not have an image with the [ ' . $titleText . ' ] title text under [ ' . $locator . ' ].'); } // Switch back too the page from the iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } /** - * #varbase : To Find an image with the alt text attribute. - * under a custom iframe. + * Find an image with the alt text attribute under a custom iframe. + * + * Varbase Context #varbase. * * Example 1: Then I should see image with the "Flag Earth" alt text in the rich text editor field "Body" * @@ -747,28 +822,33 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext */ public function iShouldSeeImageWithTheAltTextUnder($altText, $filedName) { // Switch to the iframe. - $iFreamID = $this->_getAttributeByOtherAttributeValue('id', 'title', $filedName, 'iframe'); + $iFreamID = $this->getAttributeByOtherAttributeValue('id', 'title', $filedName, 'iframe'); $this->getSession()->switchToIFrame($iFreamID); // Find an image with the title. $element = $this->getSession()->getPage()->find('xpath', "//img[contains(@alt, '{$altText}')]"); if (empty($element)) { - throw new Exception('The page dose not have an image with the [ ' . $altText . ' ] Alt Text under [ '. $filedName .' ].'); + throw new Exception('The page dose not have an image with the [ ' . $altText . ' ] Alt Text under [ ' . $filedName . ' ].'); } // Switch back too the page from the iframe. - $this->getSession()->switchToIFrame(null); + $this->getSession()->switchToIFrame(NULL); } - // =========================================================================== + /** + * Mouse Functions. + * + * ==========================================================================. + */ - // Mouse Functions. - // =========================================================================== - /** - * #varbase: To move the mouse over an element. + /** + * Move the mouse over an element. + * + * Varbase Context #varbase. * - * Example: When I move the mouse over "header#navbar #main_menu ul.nav li a" + * Example #1: When I move the mouse over "header#navbar #main_menu ul.nav li a" + * Example #2: And I move the mouse over "hero_slider" * * @When /^I move the mouse over the "([^"]*)"$/ */ @@ -783,29 +863,35 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase: To double click on an element. - * - * Example: When I move the mouse over "#select .option-switch" - * - * @When /^I double click "([^"]*)"$/ - */ + * Double click on an element. + * + * Varbase Context #varbase. + * + * Example #1 : When I double click "Earth Flag Image" + * Example #1 : And I double click "input#username" + * + * @When /^I double click "([^"]*)"$/ + */ public function iDoubleClick($selector) { $elem = $this->getSession()->getPage()->find('css', $selector); if ($elem) { - $elem->doubleClick(); + $elem->doubleClick(); } else { - throw new Exception("No element matching \"$selector\" is found."); + throw new Exception("No element matching \"$selector\" is found."); } } /** - * #varbase: To right click on an element. - * - * Example: When I move the mouse over "#right-click-to-configure a" - * - * @When /^I right click "([^"]*)"$/ - */ + * Right click on an element. + * + * Varbase Context #varbase. + * + * Example #1: When I right click "#right-click-to-configure a" + * Example #2: And I right click "Right click action box" + * + * @When /^I right click "([^"]*)"$/ + */ public function iRightClick($selector) { $elem = $this->getSession()->getPage()->find('css', $selector); if ($elem) { @@ -815,16 +901,17 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext throw new Exception("No element matching \"$selector\" is found."); } } - // =========================================================================== /** - * #varbase: To check if we do have the text in the selected element. - * - * Example 1: And I should see "your text" in the "ol" element with the "class" attribute set to "breadcrumb" - * Example 2: And I should see "your text" in the "div" element with the "id" attribute set to "right-panel" - * - * @Then /^I should see "(?P<text>[^"]*)" in the "(?P<htmlTagName>[^"]*)" element with the "(?P<attribute>[^"]*)" attribute set to "(?P<value>[^"]*)"$/ - */ + * Check if we do have the text in the selected element. + * + * Varbase Context #varbase. + * + * Example #1: Then I should see "your text" in the "ol" element with the "class" attribute set to "breadcrumb" + * Example #2: And I should see "your text" in the "div" element with the "id" attribute set to "right-panel" + * + * @Then /^I should see "(?P<text>[^"]*)" in the "(?P<htmlTagName>[^"]*)" element with the "(?P<attribute>[^"]*)" attribute set to "(?P<value>[^"]*)"$/ + */ public function ishouldSeeTextInTheHtmlTagElement($text, $htmlTagName, $attribute, $value) { $elements = $this->getSession()->getPage()->findAll('css', $htmlTagName); @@ -836,7 +923,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext foreach ($elements as $element) { $actual = $element->getText(); $actual = preg_replace('/\s+/u', ' ', $actual); - $regex = '/'.preg_quote($text, '/').'/ui'; + $regex = '/' . preg_quote($text, '/') . '/ui'; if (preg_match($regex, $actual)) { $found = TRUE; @@ -859,13 +946,15 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase: To click on the text in the selected element. - * - * Example 1: And I click "your text" in the "ol" element with the "class" attribute set to "breadcrumb" - * Example 2: And I click "your text" in the "div" element with the "id" attribute set to "right-panel" - * - * @Then /^I click "(?P<text>[^"]*)" in the "(?P<htmlTagName>[^"]*)" element with the "(?P<attribute>[^"]*)" attribute set to "(?P<value>[^"]*)"$/ - */ + * Click on the text in the selected element. + * + * Varbase Context #varbase. + * + * Example #1: Then I click "your text" in the "ol" element with the "class" attribute set to "breadcrumb" + * Example #2: And I click "your text" in the "div" element with the "id" attribute set to "right-panel" + * + * @Then /^I click "(?P<text>[^"]*)" in the "(?P<htmlTagName>[^"]*)" element with the "(?P<attribute>[^"]*)" attribute set to "(?P<value>[^"]*)"$/ + */ public function iClickTextInTheHtmlTagElement($text, $htmlTagName, $attribute, $value) { $elements = $this->getSession()->getPage()->findAll('css', $htmlTagName); @@ -877,7 +966,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext foreach ($elements as $element) { $actual = $element->getText(); $actual = preg_replace('/\s+/u', ' ', $actual); - $regex = '/'.preg_quote($text, '/').'/ui'; + $regex = '/' . preg_quote($text, '/') . '/ui'; if (preg_match($regex, $actual)) { $found = TRUE; @@ -900,14 +989,14 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } } - /** - * #varbase: To check if we do have a text in the input element. - * - * Example 1: And I should see "your text" value in the "edit-items-2-target-id" input element - * Example 2: And I should see "Location property" value in the "edit-name" input element - * - * @Then /^I should see "(?P<text>[^"]*)" value in the "(?P<selector>[^"]*)" input element$/ - */ + /** + * Check if we do have a text in the input element. + * + * Example #1: Then I should see "your text" value in the "edit-items-2-target-id" input element + * Example #2: And I should see "Location property" value in the "edit-name" input element. + * + * @Then /^I should see "(?P<text>[^"]*)" value in the "(?P<selector>[^"]*)" input element$/ + */ public function iShouldSeeValueInTheInputElement($text, $selector) { $elements = $this->getSession()->getPage()->findAll('xpath', "//input[@id='{$selector}']"); @@ -932,15 +1021,17 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } /** - * #varbase: To check if we do have the text in the selected panel region. - * using the code name of the panel region. or the html id. - * - * Example 1: Then I should see "Add new pane" in the "Center" panel region - * Example 2: Then I should see "custom pane title" in the "Right side" panel region - * Example 3: Then I should see "Add new pane" in the "panels-ipe-regionid-center" panel region - * - * @Then /^I should see "(?P<text>[^"]*)" in the "(?P<panleRegion>[^"]*)" panel region$/ - */ + * Check if we do have the text in the selected panel region. + * + * Using the code name of the panel region. or the html id. + * Varbase Context #varbase. + * + * Example #1: Then I should see "Add new pane" in the "Center" panel region + * Example #2: Then I should see "custom pane title" in the "Right side" panel region + * Example #3: And I should see "Add new pane" in the "panels-ipe-regionid-center" panel region. + * + * @Then /^I should see "(?P<text>[^"]*)" in the "(?P<panleRegion>[^"]*)" panel region$/ + */ public function iShouldSeeInThePanelRegion($text, $panleRegion) { if (strpos($panleRegion, "panels-ipe-regionid-")) { @@ -957,20 +1048,22 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $element = $this->getSession()->getPage()->find('xpath', "//*[contains(@id, '{$panleRegionId}')]//*[text()='{$text}']"); if (empty($element)) { - throw new Exception('The panle region "' . $panleRegion . '" dose not have "'. $text .'" in it.'); + throw new Exception('The panle region "' . $panleRegion . '" dose not have "' . $text . '" in it.'); } } /** - * #varbase: To check if we do not have the text in the selected panel region. - * using the code name of the panel region. or the html id. - * - * Example 1: Then I should not see "Add new pane" in the "Center" panel region - * Example 2: Then I should not see "custom pane title" in the "Right side" panel region - * Example 3: Then I should not see "Add new pane" in the "panels-ipe-regionid-center" panel region - * - * @Then /^I should not see "(?P<text>[^"]*)" in the "(?P<panleRegion>[^"]*)" panel region$/ - */ + * Check if we do not have the text in the selected panel region. + * + * Using the code name of the panel region. or the html id. + * Varbase Context #varbase. + * + * Example #1: Then I should not see "Add new pane" in the "Center" panel region + * Example #2: Then I should not see "custom pane title" in the "Right side" panel region + * Example #3: And I should not see "Add new pane" in the "panels-ipe-regionid-center" panel region. + * + * @Then /^I should not see "(?P<text>[^"]*)" in the "(?P<panleRegion>[^"]*)" panel region$/ + */ public function iShouldNotSeeInThePanelRegion($text, $panleRegion) { if (strpos($panleRegion, "panels-ipe-regionid-")) { @@ -987,21 +1080,22 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $element = $this->getSession()->getPage()->find('xpath', "//*[contains(@id, '{$panleRegionId}')]//*[text()='{$text}']"); if (!empty($element)) { - throw new Exception('The panle region "' . $panleRegion . '" dose have "'. $text .'" in it.'); + throw new Exception('The panle region "' . $panleRegion . '" dose have "' . $text . '" in it.'); } } /** - * #varbase: To click on the text in the selected panel region. - * using the code name of the panel region. or the html id. - * - * - * Example 1: When I click "Add new pane" in the "center" panel region - * Example 2: When I click "Region style" in the "left" panel region - * Example 3: When I click "Add new pane" in the "panels-ipe-regionid-center" panel region - * - * @When /^I click "(?P<text>[^"]*)" in the "(?P<panleRegion>[^"]*)" panel region$/ - */ + * Click on the text in the selected panel region. + * + * Using the code name of the panel region. or the html id. + * Varbase Context #varbase. + * + * Example #1: When I click "Add new pane" in the "center" panel region + * Example #2: When I click "Region style" in the "left" panel region + * Example #3: And I click "Add new pane" in the "panels-ipe-regionid-center" panel region. + * + * @When /^I click "(?P<text>[^"]*)" in the "(?P<panleRegion>[^"]*)" panel region$/ + */ public function iClickInThePanelRegion($text, $panleRegion) { if (strpos($panleRegion, "panels-ipe-regionid-")) { @@ -1018,175 +1112,186 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $element = $this->getSession()->getPage()->find('xpath', "//*[contains(@id, '{$panleRegionId}')]//*[text()='{$text}']"); if (empty($element)) { - throw new Exception('The panle region "' . $panleRegion . '" dose not have "'. $text .'".'); + throw new Exception('The panle region "' . $panleRegion . '" dose not have "' . $text . '".'); } $element->click(); } - // Alert Functions. - // =========================================================================== + /** + * Alert Functions. + * + * ==========================================================================. + */ /** - * #varbase: To accept alert if present. - * - * Example 1: When I accept alert - * Example 2: And accept alert - * - * @when /^(?:|I )accept alert$/ - */ + * Accept alert if present. + * + * Varbase Context #varbase. + * + * Example #1: When I accept alert + * Example #2: And accept alert. + * + * @when /^(?:|I )accept alert$/ + */ public function acceptAlert() { try { $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); - } catch(\WebDriver\Exception $e) { - // no-op, alert might not be present + } + catch (Exception $e) { + // no-op, alert might not be present. } } /** - * #varbase: To dismiss alert if present. - * - * Example 1: When I dismiss alert - * Example 2: And dismiss alert - * - * @when /^(?:|I )dismiss alert$/ - */ + * Dismiss alert if present. + * + * Varbase Context #varbase. + * + * Example #1: When I dismiss alert + * Example #2: And dismiss alert. + * + * @when /^(?:|I )dismiss alert$/ + */ public function iDismissAlert() { try { $this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert(); - } catch(\WebDriver\Exception $e) { - // no-op, alert might not be present + } + catch (Exception $e) { + // no-op, alert might not be present. } } /** - * #varbase: To print the text of the current alert message. - * - * Example 1: When I print alert text - * Example 2: And print alert text - * - * @When /^(?:|I ) print alert text$/ - */ + * Print the text of the current alert message. + * + * Varbase Context #varbase. + * + * Example #1: When I print alert text + * Example #2: And print alert text. + * + * @When /^(?:|I ) print alert text$/ + */ public function iPrintAlertText() { try { return $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text(); - } catch(\WebDriver\Exception $e) { - // no-op, alert might not be present + } + catch (Exception $e) { + // no-op, alert might not be present. } } - /** - * #varbase: To fill a text in the alert message. - * - * Example 1: When I fill "See this alert" in alert - * Example 2: And fill "See this text" in alert - * - * @When /^(?:|I )fill "(?P<text>[^"]*)" in alert$/ - */ + * Fill a text in the alert message. + * + * Varbase Context #varbase. + * + * Example #1: When I fill "See this alert" in alert + * Example #2: And fill "See this text" in alert. + * + * @When /^(?:|I )fill "(?P<text>[^"]*)" in alert$/ + */ public function iFillInAlert($message) { try { $this->getSession()->getDriver()->getWebDriverSession()->postAlert_text($message); - } catch(\WebDriver\Exception $e) { - // no-op, alert might not be present + } + catch (Exception $e) { + // no-op, alert might not be present. } } - // =========================================================================== /** - * #WIP#vardot: To press a modifier and other key - * Modifier options: { ctrl, shift, alt } - * Key options: + * Press a modifier and other key. + * + * Modifier options: { ctrl, shift, alt } key options. + * Varbase Context #varbase. * * Example #1: When I press "ctrl" and "v" * Example #2: When I press "alt" and "f" - * Example #3: When I press "ctrl" and "r" + * Example #3: And I press "ctrl" and "r" * * @When I press :modifier and :key in :field field */ public function iPressModifierAndKeys($modifier, $key, $field) { - static $keys = array( - 'backspace' => 8, - 'tab' => 9, - 'enter' => 13, - 'shift' => 16, - 'ctrl' => 17, - 'alt' => 18, - 'pause' => 19, - 'break' => 19, - 'escape' => 27, - 'esc' => 27, - 'end' => 35, - 'home' => 36, - 'left' => 37, - 'up' => 38, - 'right' =>39, - 'down' => 40, - 'insert' => 45, - 'delete' => 46, - 'pageup' => 33, - 'pagedown' => 34, - 'capslock' => 20, - ); - - static $modifiers = array( - 'shift' => 16, - 'ctrl' => 17, - 'alt' => 18, - ); - - $key = is_numeric($key) ? $key : ord($key); - $isCtrlKeyArg = ($modifier == 'ctrl') ? "true" : "false"; - $isAltKeyArg = ($modifier == 'alt') ? "true" : "false"; - $isShiftKeyArg = ($modifier == 'shift') ? "true" : "false"; - $isMetaKeyArg = ($modifier == 'meta') ? "true" : "false"; - - // Validate the modifier keys. - if (is_string($modifier)) { - if (strlen($modifier) < 1) { - throw new \Exception('Modifier parameter was empty. one of \'shift\', \'alt\', \'ctrl\''); + static $keys = [ + 'backspace' => 8, + 'tab' => 9, + 'enter' => 13, + 'shift' => 16, + 'ctrl' => 17, + 'alt' => 18, + 'pause' => 19, + 'break' => 19, + 'escape' => 27, + 'esc' => 27, + 'end' => 35, + 'home' => 36, + 'left' => 37, + 'up' => 38, + 'right' => 39, + 'down' => 40, + 'insert' => 45, + 'delete' => 46, + 'pageup' => 33, + 'pagedown' => 34, + 'capslock' => 20, + ]; + + static $modifiers = [ + 'shift' => 16, + 'ctrl' => 17, + 'alt' => 18, + ]; + + $key = is_numeric($key) ? $key : ord($key); + $isCtrlKeyArg = ($modifier == 'ctrl') ? "true" : "false"; + $isAltKeyArg = ($modifier == 'alt') ? "true" : "false"; + $isShiftKeyArg = ($modifier == 'shift') ? "true" : "false"; + + // Validate the modifier keys. + if (is_string($modifier)) { + if (strlen($modifier) < 1) { + throw new \Exception('Modifier parameter was empty. one of \'shift\', \'alt\', \'ctrl\''); + } + elseif (strlen($modifier) > 1) { + // One of 'shift', 'alt', 'ctrl'. + $filteredModifier = strtolower(str_replace(' ', '', $modifier)); + if (isset($modifiers[$filteredModifier])) { + $modifier = $modifiers[$filteredModifier]; } - elseif (strlen($modifier) > 1) { - // one of 'shift', 'alt', 'ctrl'. - $filteredModifier = strtolower(str_replace(' ', '', $modifier)); - if (isset($modifiers[$filteredModifier])) { - $modifier = $modifiers[$filteredModifier]; - } - else { - throw new \Exception('Modifier parameter must be one of \'shift\', \'alt\', \'ctrl\''); - } - + else { + throw new \Exception('Modifier parameter must be one of \'shift\', \'alt\', \'ctrl\''); } + } + } - // Validate the other key. - if (is_string($key)) { - if (strlen($key) < 1) { - throw new \Exception('Key parameter was empty.'); + // Validate the other key. + if (is_string($key)) { + if (strlen($key) < 1) { + throw new \Exception('Key parameter was empty.'); + } + elseif (strlen($key) > 1) { + // Support for all variations, e.g. ESC, Esc, page up, pageup. + $filteredKey = strtolower(str_replace(' ', '', $key)); + if (isset($keys[$filteredKey])) { + $key = $keys[$filteredKey]; } - elseif (strlen($key) > 1) { - // Support for all variations, e.g. ESC, Esc, page up, pageup. - $filteredKey = strtolower(str_replace(' ', '', $key)); - if (isset($keys[$filteredKey])) { - $key = $keys[$filteredKey]; - } - else { - throw new \Exception('Key parameter must a keyboard key'); - } + else { + throw new \Exception('Key parameter must a keyboard key'); } } + } - $elementField = $this->getSession()->getPage()->findField($field); - if (!$elementField) { - throw new \Exception("Field '{$field}' not found"); - } - - $fieldid = $elementField->getAttribute('id'); - + $elementField = $this->getSession()->getPage()->findField($field); + if (!$elementField) { + throw new \Exception("Field '{$field}' not found"); + } + $fieldid = $elementField->getAttribute('id'); - $js = <<<JS + $js = <<<JS var node = document.getElementById("{$fieldid}"); var keyEvent = document.createEvent('KeyboardEvent'); keyEvent.initKeyEvent('keypress', // typeArg, @@ -1203,76 +1308,25 @@ keyEvent.initKeyEvent('keypress', // typeArg, node.dispatchEvent(keyEvent); JS; - - - $this->getSession()->executeScript($js); - } - - /** - * Accept Alerts Before going to the next step. - * - * @BeforeStep @AcceptAlertsBeforStep - */ - public function beforeStepAcceptAlert(BeforeStepScope $scope) { - try { - $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); - } catch(\WebDriver\Exception $e) { - // no-op, alert might not be present - } - } + $this->getSession()->executeScript($js); + } /** - * Accept Alerts After going to the next step. - * - * @AftereStep @AcceptAlertsAfterStep + * Fill a text in the alert message. + * + * Varbase Context #varbase. + * + * Example #1: Given I drag and drop ".element-item" to ".target" + * Example #2: When I drag and drop "#panels-ipe-regionid-left .panels-ipe-portlet-wrapper" to "#panels-ipe-regionid-center .panels-ipe-sort-container" + * Example #3: And I drag and drop ".item-1" to ".target-2" + * + * @Given /^I drag and drop "([^"]*)" to "([^"]*)"$/ */ - public function afterStepAcceptAlert(AfterStepScope $scope) { - try { - $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); - } catch(\WebDriver\Exception $e) { - // no-op, alert might not be present - } - } - - /** - * Accept Alerts Before going to the next step. - * - * @BeforeStep @AcceptAlertsBeforStep - */ - public function beforeStepDismissAlert(BeforeStepScope $scope) { - try { - $this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert(); - } catch(\WebDriver\Exception $e) { - // no-op, alert might not be present - } - } - - /** - * Accept Alerts After going to the next step. - * - * @AftereStep @DismissAlertsAfterStep - */ - public function afterStepDismissAlert(AfterStepScope $scope) { - try { - $this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert(); - } catch(\WebDriver\Exception $e) { - // no-op, alert might not be present - } - } - - /** - * #varbase: To fill a text in the alert message. - * - * Example 1: Given I drag and drop ".element-item" to ".target" - * Example 2: When I drag and drop "#panels-ipe-regionid-left .panels-ipe-portlet-wrapper" to "#panels-ipe-regionid-center .panels-ipe-sort-container" - * - * @Given /^I drag and drop "([^"]*)" to "([^"]*)"$/ - */ public function iDragAndDropTo($draggedElement, $targetElement) { $dragged = $this->getSession()->getPage()->find('css', $draggedElement); if (empty($dragged)) { - throw new Exception('The selected dragged element [ ' . $draggedElement . ' ] is not in the page.'); + throw new Exception('The selected dragged element [ ' . $draggedElement . ' ] is not in the page.'); } $target = $this->getSession()->getPage()->find('css', $targetElement); @@ -1285,67 +1339,77 @@ JS; } /** - * #varbase: To select a radio button. - * - * Example 1: When I select the "Male" radio button - * - * @When /^I select the "([^"]*)" radio button$/ - */ + * Select a radio button. + * + * Varbase Context #varbase. + * + * Example #1: When I select the "Male" radio button + * Example #2: And I select the "Male" radio button + * + * @When /^I select the "([^"]*)" radio button$/ + */ public function iSelectTheRadioButton($labelText) { - // Find the label by its text, then use that to get the radio item's ID - $radioId = null; - - /** @var $label NodeElement */ - foreach ($this->getSession()->getPage()->findAll('css', 'label') as $label) { - if ($labelText === $label->getText()) { - if ($label->hasAttribute('for')) { - $radioId = $label->getAttribute('for'); - break; - } else { - throw new \Exception("Radio button's label needs the 'for' attribute to be set"); - } - } - } - if (!$radioId) { - throw new \InvalidArgumentException("Label '$labelText' not found."); + // Find the label by its text, then use that to get the radio item's ID. + $radioId = NULL; + + /** @var $label NodeElement */ + foreach ($this->getSession()->getPage()->findAll('css', 'label') as $label) { + if ($labelText === $label->getText()) { + if ($label->hasAttribute('for')) { + $radioId = $label->getAttribute('for'); + break; + } + else { + throw new \Exception("Radio button's label needs the 'for' attribute to be set"); + } } + } + if (!$radioId) { + throw new \InvalidArgumentException("Label '$labelText' not found."); + } - // Now use the ID to retrieve the button and click it - /** @var NodeElement $radioButton */ - $radioButton = $this->getSession()->getPage()->find('css', "#$radioId"); - if (!$radioButton) { - throw new \Exception("$labelText radio button not found."); - } + // Now use the ID to retrieve the button and click it. + // @var NodeElement $radioButton. + $radioButton = $this->getSession()->getPage()->find('css', "#$radioId"); + if (!$radioButton) { + throw new \Exception("$labelText radio button not found."); + } - $this->getSession()->getPage()->fillField($radioId, $radioButton->getAttribute('value')); + $this->getSession()->getPage()->fillField($radioId, $radioButton->getAttribute('value')); } - /** - * #varbase: To click on the label with the for attribute value linked to - * to the an ID of a radio button with a value to select the radio option - * we need to use this when we do have a list of radio buttons - * but we do have the label with extra HTML tags like images or the - * actual radio button is hidden. + /** + * Click on the label with the for attribute value. * - * Example 1: I click on the radio label for "right_sidebar_layout" value + * Linked to the an ID of a radio button with a value to select the radio + * option. we need to use this when we do have a list of radio buttons + * but we do have the label with extra HTML tags like images or the actual + * radio button is hidden. + * Varbase Context #varbase. + * + * Example #1: Given I click on the radio label for "right_sidebar_layout" value + * Example #2: When I click on the radio label for "layout-settings" value * * @Given /^I click on the radio label for "([^"]*)" value$/ */ public function iClickOnTheRadioLabelForValue($value) { $radio_label = $this->getSession()->getPage()->find('xpath', "//label[contains(@for, '{$value}')]"); if ($radio_label) { - $radio_label->click(); + $radio_label->click(); } else { - throw new \Exception("No label with the value of for='" . $value . "' radio button not found."); + throw new \Exception("No label with the value of for='" . $value . "' radio button not found."); } } - - /** - * #varbase: To expand a field group by its id attribute. + + /** + * Expand a field group by its id attribute. + * + * Varbase Context #varbase. + * + * Example #1: When I expand the field "Field Group ID" + * Example #2: And I expand the field "More options" * - * Example #1: I expand the field "Field Group ID" - * * @When I expand the field :arg1 */ public function iExpandThefield($fieldID) { @@ -1357,10 +1421,13 @@ JS; } /** - * #varbase: To expand a select list by it's class attribute. + * Expand a select list by it's class attribute. + * + * Varbase Context #varbase. + * + * Example #1: When I expand the "1" select list "dropbutton-multiple" + * Example #2: And I expand the "2" select list "Editor Styling options" * - * Example #1: I expand the "1" select list "dropbutton-multiple" - * * @When I expand the :nth select list :arg1 */ public function iExpandTheSelectList($index, $listClassName) { @@ -1372,10 +1439,13 @@ JS; } /** - * #varbase: To scroll down in the current status of the page. + * Scroll down in the current status of the page, about 350 down. + * + * Varbase Context #varbase. * * Example #1: When I scrolldown - * + * Example #2: And I scrolldown. + * * @When I scrolldown */ public function iScrolldown() { @@ -1383,10 +1453,12 @@ JS; } /** - * #varbase: To scroll up in the current status of the page, about 350 up + * Scroll up in the current status of the page, about 350 up. + * + * Varbase Context #varbase. + * + * Example #1: When I scrollup. * - * Example #1: When I scrollup - * * @When I scrollup */ public function iScrollup() { @@ -1394,42 +1466,49 @@ JS; } /** - * #varbase: To check if the Image media browser opened. - * - * Example : Then the image media browser should be open + * Check if the Image media browser opened. + * + * Varbase Context #varbase. + * + * Example #1: Then the image media browser should be open + * Example #2: And the image media browser should be open * * @Then /^the image media browser should be open$/ */ public function theImageMediaBrowserIsOpen() { - if (!$elem = $this->getSession()->getPage()->find('css', '.ui-dialog.ui-widget-content')) { + if (!$this->getSession()->getPage()->find('css', '.ui-dialog.ui-widget-content')) { throw new Exception('The image media browser failed to open.'); } } - + /** - * #varbase: To check if the media browser with the selected iframe id - * is open. - * - * Example : Then the "entity_browser_iframe_media_browser" media browser should be open + * Check if the media browser with the selected iframe id is open. + * + * Varbase Context #varbase. + * + * Example #1: Then the "editor_media_browser" media browser should be open + * Example #2: And the "multiple_image_browser" media browser should be open * * @Then /^the "([^"]*)" media browser should be open$/ */ public function theMediaBrowserIsOpen($entityBrowserIframeId) { - if (!$elem = $this->getSession()->getPage()->find('css', '.ui-dialog.ui-widget-content')) { + if (!$this->getSession()->getPage()->find('css', '.ui-dialog.ui-widget-content')) { throw new Exception('The media browser failed to open.'); } - $entityBrowserIframe = $this->getSession()->getPage()->find('css', "#$entityBrowserIframeId"); - if (!$entityBrowserIframeId) { - throw new \Exception("$entityBrowserIframeId is not found."); + if (!$this->getSession()->getPage()->find('css', "#$entityBrowserIframeId")) { + throw new \Exception("$entityBrowserIframeId is not found."); } } - + /** - * #varbase: To find an element with a selected index having the - * first attribute, and check if it's have the second one. - * + * Find an element with a selected index having the first attribute. + * + * Check if it's have the second one. + * Varbase Context #varbase. + * * Example #1: Then I should see the "1" "wrapper" with "align2right" class + * Example #2: And I should see the "2" "wrapper" with "align2right" class * * @Then I should see the :nth :arg1 with :arg2 class */ @@ -1440,79 +1519,135 @@ JS; throw new Exception("The image position is wrong"); } } - + /** - * #varbase: Resize the current window browser to a selected width and height. - * - * Example #1: And I resize the current window to width="1280" and height="600" - * + * Resize the current window browser to a selected width and height. + * + * Varbase Context #varbase. + * + * Example #1: And I resize the current window to width="1280" and height="600" + * Example #2: And I resize the current window to width="1280" and height="600" + * * @Given /^I resize the current window to width="([^"]*)" and height="([^"]*)"$/ */ public function resizeTheCurrentWindowToWidthAndHeight($width, $height) { - $this->getSession()->resizeWindow((int)$width, (int)$height, 'current'); + $this->getSession()->resizeWindow((int) $width, (int) $height, 'current'); } + /** + * Switch to an ifram by its id. + * + * Varbase Context #varbase. + * + * Example #1: When I switch to iframe "entity_browser_iframe_media_browser" + * Example #2: And I switch to iframe "remote-video-media" + * + * @When /^(?:|I )switch to iframe "([^"]*)"$/ + */ + public function iSwitchToIframe($iFrameLocator) { + $this->getSession()->getDriver()->switchToIFrame($iFrameLocator); + } - public function cleanUsers() { - + /** + * Switch to the main frame or the parent ifram. + * + * Varbase Context #varbase. + * + * Example #1: When I switch to main fram + * Example #2: When I switch to parent + * + * @When /^(?:|I )switch to main frame$/ + * @When /^(?:|I )switch to parent$/ + */ + public function iSwitchToParent() { + $this->getSession()->getDriver()->switchToIFrame(NULL); } /** - * Helper function to let you get the value of an attribute name for - * an HTML tag by other Attribute name and value + * Helper function to let you get the value of an attribute name. + * + * For an HTML tag by other Attribute name and value. + * + * @param string $attributeName + * The attribute name. + * @param string $otherAttributeName + * The other attribute name. + * @param string $otherAttributeValue + * The other attribute value. + * @param string $htmlTagName + * The HTML tag name you are filtring with. * - * @param string $attributeName The attribute name. - * @param string $otherAttributeName other attribute name. - * @param string $otherAttributeValue other attribute value. - * @param string $htmlTagName the HTML tag name you are filtring with. - * @return string Attribute value for the first matching element. + * @return string + * Attribute value for the first matching element. */ - private function _getAttributeByOtherAttributeValue($attributeName, $otherAttributeName, $otherAttributeValue, $htmlTagName = "*") { + private function getAttributeByOtherAttributeValue($attributeName, $otherAttributeName, $otherAttributeValue, $htmlTagName = "*") { $element = $this->getSession()->getPage()->find('xpath', "//{$htmlTagName}[contains(@{$otherAttributeName}, '{$otherAttributeValue}')]"); return $element->getAttribute($attributeName); } /** - * Helper function to update a selected element id attribute by css. - * @param string $htmlTagCSS - * @param string $htmlTagID - * @param string $prefix + * Accept Alerts Before going to the next step. + * + * @BeforeStep @AcceptAlertsBeforStep */ - private function _updateIDByCSS($htmlTagCSS, $htmlTagID, $prefix = '') { - $this->getSession()->getDriver()->evaluateScript('jQuery("' . $htmlTagCSS . '").attr("id", "'. $prefix . $htmlTagID. '");'); + public function beforeStepAcceptAlert(BeforeStepScope $scope) { + try { + $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); + } + catch (Exception $e) { + // no-op, alert might not be present. + } } /** - * Helper function to add an ID to an IFream. - * @param string $fieldid field id in drupal. - * @param string $prefix a prefix which needed for the id. + * Accept Alerts After going to the next step. + * + * @AftereStep @AcceptAlertsAfterStep */ - private function _addIDtoIFrame($fieldid, $prefix = "ifream-") { - // If the WYSIWYG is in an ifream with no id. - $iFreamID = $this->_getAttributeByOtherAttributeValue('id', 'title', "Rich Text Editor, ". $fieldid, 'iframe'); - if (empty($iFreamID)) { - $ifreamcss = $this->_getAttributeByOtherAttributeValue('class', 'title', "Rich Text Editor, ". $fieldid, 'iframe'); - $ifreamcss = str_replace(" ", ".", $ifreamcss); - if (strpos($ifreamcss, ".") > 1) { - $ifreamcss = '.' . $ifreamcss; - } - $this->_updateIDByCSS($ifreamcss, $fieldid, $prefix); + public function afterStepAcceptAlert(AfterStepScope $scope) { + try { + $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); + } + catch (Exception $e) { + // no-op, alert might not be present. } } /** - * @When /^(?:|I )switch to iframe "([^"]*)"$/ - */ - public function iSwitchToIframe($iFrameLocator) { - $this->getSession()->getDriver()->switchToIFrame($iFrameLocator); + * Accept Alerts Before going to the next step. + * + * @BeforeStep @AcceptAlertsBeforStep + */ + public function beforeStepDismissAlert(BeforeStepScope $scope) { + try { + $this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert(); + } + catch (Exception $e) { + // no-op, alert might not be present. + } } /** - * @When /^(?:|I )switch to main frame$/ - * @When /^(?:|I )switch to parent$/ - */ - public function iSwitchToParent() { - $this->getSession()->getDriver()->switchToIFrame(null); + * Accept Alerts After going to the next step. + * + * @AftereStep @DismissAlertsAfterStep + */ + public function afterStepDismissAlert(AfterStepScope $scope) { + try { + $this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert(); + } + catch (Exception $e) { + // no-op, alert might not be present. + } + } + + /** + * Maximize the window before scenario. + * + * @BeforeScenario @javascript + */ + public function beforeScenarioMaximizeWindow() { + $this->getSession()->getDriver()->getWebDriverSession()->maximizeWindow(); } } diff --git a/tests/features/varbase/step1-init-tests/README.md b/tests/features/varbase/step1-init-tests/README.md index 444d77942ceb57b11bc17986ba2d02ba77aabe33..c693a8642ae6ec86df4da56167bba65705e83b7d 100644 --- a/tests/features/varbase/step1-init-tests/README.md +++ b/tests/features/varbase/step1-init-tests/README.md @@ -11,4 +11,4 @@ test_seo_admin: { email: 'seo.admin.test@vardot.com', password: 'dD.123123ddd' } test_site_admin: { email: 'site.admin.test@vardot.com', password: 'dD.123123ddd' } test_super_admin: { email: 'super.admin.test@vardot.com', password: 'dD.123123ddd' } ``` -* Feature: Add Arabic language if we do not have it to languages in the system \ No newline at end of file +* Feature: Add Arabic language if we do not have it to languages in the system diff --git a/tests/features/varbase/step3-cleanup-tests/README.md b/tests/features/varbase/step3-cleanup-tests/README.md index 38a1752b50035d485de67952c87fd96c56ba62d4..5e53710bd5255a6688cd283878c72412f80ba421 100644 --- a/tests/features/varbase/step3-cleanup-tests/README.md +++ b/tests/features/varbase/step3-cleanup-tests/README.md @@ -14,4 +14,4 @@ test_super_admin * Feature: Delete Arabic language from the system * Feature: Cleanup after [entityqueue] module tests -* Feature: Cleanup leftover media from the Media Library \ No newline at end of file +* Feature: Cleanup leftover media from the Media Library diff --git a/varbase.info.yml b/varbase.info.yml index b8f12233beb5f6a3844a54d4f6449630ff807c63..43506823091f18e665749c159a87beab2151f6ac 100755 --- a/varbase.info.yml +++ b/varbase.info.yml @@ -2,6 +2,7 @@ name: Varbase type: profile description: 'Varbase is an enhanced Drupal distribution with a lot of necessities.' core: 8.x +core_version_requirement: ^8 || ^9 project: varbase distribution: name: Varbase diff --git a/varbase.install b/varbase.install index 1d3d7294aa1011559bac7a69043f03920d35f662..b3bd07cc6a2686b7c42a473c1c59fa5c88181ae7 100644 --- a/varbase.install +++ b/varbase.install @@ -70,9 +70,5 @@ function varbase_install() { $response = new RedirectResponse($homepage_with_tour); $response->send(); exit; - - include_once __DIR__ . '/../../core/includes/install.core.inc'; - include_once __DIR__ . '/../../core/includes/install.inc'; - install_goto('?tour'); } }