Skip to content

Commit

Permalink
MDL-53140 behat: Allow language customisation in behat
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Apr 29, 2019
1 parent 13230ed commit 4d0ac71
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions lib/tests/behat/behat_data_generators.php
Expand Up @@ -208,6 +208,10 @@ class behat_data_generators extends behat_base {
'required' => array('user', 'contact'),
'switchids' => array('user' => 'userid', 'contact' => 'contactid')
),
'language customisations' => array(
'datagenerator' => 'customlang',
'required' => array('component', 'stringid', 'value'),
),
);

/**
Expand Down Expand Up @@ -415,6 +419,61 @@ protected function process_block_instance($data) {
$this->datagenerator->create_block($data['blockname'], $data, $data);
}

/**
* Creates language customisation.
*
* @throws Exception
* @throws dml_exception
* @param array $data
* @return void
*/
protected function process_customlang($data) {
global $CFG, $DB, $USER;

require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/customlang/locallib.php');
require_once($CFG->libdir . '/adminlib.php');

if (empty($data['component'])) {
throw new Exception('\'customlang\' requires the field \'component\' type to be specified');
}

if (empty($data['stringid'])) {
throw new Exception('\'customlang\' requires the field \'stringid\' to be specified');
}

if (!isset($data['value'])) {
throw new Exception('\'customlang\' requires the field \'value\' to be specified');
}

$now = time();

tool_customlang_utils::checkout($USER->lang);

$record = $DB->get_record_sql("SELECT s.*
FROM {tool_customlang} s
JOIN {tool_customlang_components} c ON s.componentid = c.id
WHERE c.name = ? AND s.lang = ? AND s.stringid = ?",
array($data['component'], $USER->lang, $data['stringid']));

if (empty($data['value']) && !is_null($record->local)) {
$record->local = null;
$record->modified = 1;
$record->outdated = 0;
$record->timecustomized = null;
$DB->update_record('tool_customlang', $record);
tool_customlang_utils::checkin($USER->lang);
}

if (!empty($data['value']) && $data['value'] != $record->local) {
$record->local = $data['value'];
$record->modified = 1;
$record->outdated = 0;
$record->timecustomized = $now;
$DB->update_record('tool_customlang', $record);
tool_customlang_utils::checkin($USER->lang);
}
}

/**
* Adapter to enrol_user() data generator.
* @throws Exception
Expand Down

0 comments on commit 4d0ac71

Please sign in to comment.