Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

Utils to set Behat config

Copyright: 2016 Rajesh Taneja
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1585 lines (59 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 3 files
 lib/testing/classes/tests_finder.php
 lib/behat/lib.php
 lib/behat/classes/behat_command.php

Defines 1 class


Class: behat_config_util  - X-Ref

Behat configuration manager

Creates/updates Behat config files getting tests
and steps from Moodle codebase

set_theme_suite_to_include_core_features($themetoset)   X-Ref
Set value for theme suite to include all core features. This should be used if your want all core features to be
run with theme.

param: bool $themetoset

set_tag_for_feature_filter($tags)   X-Ref
Set the value for tags, so features which are returned will be using filtered by this.

param: string $tags

set_parallel_run($parallelruns, $currentrun)   X-Ref
Set parallel run to be used for generating config.

param: int $parallelruns number of parallel runs.
param: int $currentrun current run

get_number_of_parallel_run()   X-Ref
Return parallel runs

return: int number of parallel runs.

get_current_run()   X-Ref
Return current run

return: int current run.

get_components_features($tags = '')   X-Ref
Return list of features.

return: array
param: string $tags tags.

get_clean_feature_key_and_path($featurepath)   X-Ref
Return feature key for featurepath

return: array key and featurepath.
param: string $featurepath

get_component_contexts($component)   X-Ref
Get component contexts.

return: array
param: string $component component name.

get_components_contexts($component = '')   X-Ref
Gets the list of Moodle behat contexts

Class name as a key and the filepath as value

Externalized from update_config_file() to use
it from the steps definitions web interface

return: array
param: string $component Restricts the obtained steps definitions to the specified component

sort_component_contexts(array $contexts)   X-Ref
Sort the list of components contexts.

This ensures that contexts are sorted consistently.
Core hooks defined in the behat_hooks class _must_ be defined first.

return: array The sorted context list
param: array $contexts

get_config_file_contents($features = '', $contexts = '', $tags = '', $parallelruns = 0, $currentrun = 0)   X-Ref
Behat config file specifing the main context class,
the required Behat extensions and Moodle test wwwroot.

return: string
param: array $features The system feature files
param: array $contexts The system steps definitions
param: string $tags filter features with specified tags.
param: int $parallelruns number of parallel runs.
param: int $currentrun current run for which config file is needed.

filtered_features_with_tags($features = '', $tags = '')   X-Ref
Search feature files for set of tags.

return: array filtered list of feature files with tags.
param: array $features set of feature files.
param: string $tags list of tags (currently support && only.)

build_config($parallelruns = 0, $currentrun = 0)   X-Ref
Build config for behat.yml.

return: array
param: int $parallelruns how many parallel runs feature needs to be divided.
param: int $currentrun current run for which features should be returned.

get_features_for_the_run($features, $parallelruns, $currentrun)   X-Ref
Divide features between the runs and return list.

return: array
param: array $features list of features to be divided.
param: int $parallelruns how many parallel runs feature needs to be divided.
param: int $currentrun current run for which features should be returned.

get_behat_profile($profile, $values)   X-Ref
Parse $CFG->behat_profile and return the array with required config structure for behat.yml.

$CFG->behat_profiles = array(
'profile' = array(
'browser' => 'firefox',
'tags' => '@javascript',
'wd_host' => 'http://127.0.0.1:4444/wd/hub',
'capabilities' => array(
'platform' => 'Linux',
'version' => 44
)
)
);

return: array
param: string $profile profile name
param: array $values values for profile.

get_mobile_version_tags($verbose = true)   X-Ref
Gets version tags to use for the mobile app.

This is based on the current mobile app version (from its package.json) and all known
mobile app versions (based on the list appversions.json in the lib/behat directory).

return: string List of tags or '' if not supporting mobile
param: bool $verbose If true, outputs information about installed app version

profile_guided_allocate($features, $nbuckets, $instance)   X-Ref
Attempt to split feature list into fairish buckets using timing information, if available.
Simply add each one to lightest buckets until all files allocated.
PGA = Profile Guided Allocation. I made it up just now.
CAUTION: workers must agree on allocation, do not be random anywhere!

return: array|bool Feature files array, sorted into allocations
param: array $features Behat feature files array
param: int $nbuckets Number of buckets to divide into
param: int $instance Index number of this instance

merge_config($config, $localconfig)   X-Ref
Overrides default config with local config values

array_merge does not merge completely the array's values

return: mixed The merge result
param: mixed $config The node of the default config
param: mixed $localconfig The node of the local config

merge_behat_config($config)   X-Ref
Merges $CFG->behat_config with the one passed.

return: array merged config with $CFG->behat_config
param: array $config existing config.

get_behat_config_for_profile($profile, $values)   X-Ref
Parse $CFG->behat_config and return the array with required config structure for behat.yml

return: array
param: string $profile profile name
param: array $values values for profile

merge_behat_profiles($config)   X-Ref
Merges $CFG->behat_profiles with the one passed.

return: array merged config with $CFG->behat_profiles
param: array $config existing config.

fix_legacy_profile_data(string $profilename, array $data)   X-Ref
Check for and attempt to fix legacy profile data.

The Mink Driver used for W3C no longer uses the `selenium2` naming but otherwise is backwards compatibly.

Emit a warning that users should update their configuration.

return: array Th eamended profile data
param: string $profilename The name of this profile
param: array $data The profile data for this profile

clean_path($path)   X-Ref
Cleans the path returned by get_components_with_tests() to standarize it

return: string The string without the last /tests part
param: string $path

get_behat_tests_path()   X-Ref
The relative path where components stores their behat tests

return: string

get_behat_theme_selector_override_classname($themename, $selectortype, $includeclass = false)   X-Ref
Return context name of behat_theme selector to use.

return: string
param: string $themename name of the theme.
param: string $selectortype The type of selector (partial or exact at this stage)
param: bool $includeclass if class should be included.

get_components_with_tests()   X-Ref
List of components which contain behat context or features.

return: array

remove_blacklisted_features_from_list($features, $blacklist)   X-Ref
Remove list of blacklisted features from the feature list.

return: array features - blacklisted features.
param: array $features list of original features.
param: array|string $blacklist list of features which needs to be removed.

get_behat_suites($parallelruns = 0, $currentrun = 0)   X-Ref
Return list of behat suites. Multiple suites are returned if theme
overrides default step definitions/features.

return: array list of suites.
param: int $parallelruns number of parallel runs
param: int $currentrun current run.

get_default_theme()   X-Ref
Return name of default theme.

return: string

get_list_of_themes()   X-Ref
Return list of themes which can be set in moodle.

return: array list of themes with tests.

get_theme_config($themename)   X-Ref
Return the theme config for a given theme name.
This is done so we can mock it in PHPUnit.

return: theme_config
param: string $themename name of theme

get_theme_test_directory($themename)   X-Ref
Return theme directory.

return: string theme directory
param: string $themename name of theme

get_test_directories_overridden_for_theme($theme, $testtype)   X-Ref
Returns all the directories having overridden tests.

return: array all directories having tests
param: string $theme name of theme
param: string $testtype The kind of test we are looking for

get_blacklisted_tests_for_theme($theme, $testtype)   X-Ref
Return blacklisted contexts or features for a theme, as defined in blacklist.json.

return: array list of blacklisted contexts or features
param: string $theme themename
param: string $testtype test type (contexts|features)

get_tests_for_theme($theme, $testtype)   X-Ref
Return list of features and step definitions in theme.

return: array list of contexts $contexts or $features
param: string $theme theme name
param: string $testtype test type, either features or contexts

get_behat_features_for_theme($theme)   X-Ref
Return list of blacklisted behat features for theme and features defined by theme only.

return: array ($blacklistfeatures, $blacklisttags, $features)
param: string $theme theme name.

get_behat_contexts_for_theme($theme)   X-Ref
Return list of behat contexts for theme and update $this->stepdefinitions list.

return: List of contexts
param: string $theme theme name.