Skip to content

Commit bae3c18

Browse files
[auto-generated] Update plugin files
Check out the commits that caused these changes: moodlehq/moodleapp@3dd5acc...ee2e785
1 parent 5fadd6e commit bae3c18

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

tests/behat/behat_app_helper.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ public function parse_element_locator(string $text): string {
275275
);
276276

277277
$locator = [
278-
'text' => str_replace('\\"', '"', $matches[1]),
278+
'text' => $this->transform_time_to_string(str_replace('\\"', '"', $matches[1])),
279279
'selector' => $matches[2] ?? null,
280280
];
281281

282282
if (!empty($matches[3])) {
283283
$locator[$matches[3]] = (object) [
284-
'text' => str_replace('\\"', '"', $matches[4]),
284+
'text' => $this->transform_time_to_string(str_replace('\\"', '"', $matches[4])),
285285
'selector' => $matches[5] ?? null,
286286
];
287287
}
@@ -608,4 +608,37 @@ protected function resize_app_window(int $width = 500, int $height = 720) {
608608

609609
$this->getSession()->getDriver()->resizeWindow($width + $offset['x'], $height + $offset['y']);
610610
}
611+
612+
/**
613+
* Given a string, search if it contains a time with the ## format and convert it to a timestamp or readable time.
614+
* Only allows 1 occurence, if the text contains more than one time sub-string it won't work as expected.
615+
* This function is similar to the arg_time_to_string transformation, but it allows the time to be a sub-text of the string.
616+
*
617+
* @param string $text
618+
* @return string Transformed text.
619+
*/
620+
protected function transform_time_to_string(string $text): string {
621+
if (!preg_match('/##(.*)##/', $text, $matches)) {
622+
// No time found, return the original text.
623+
return $text;
624+
}
625+
626+
$timepassed = explode('##', $matches[1]);
627+
628+
// If not a valid time string, then just return what was passed.
629+
if ((($timestamp = strtotime($timepassed[0])) === false)) {
630+
return $text;
631+
}
632+
633+
$count = count($timepassed);
634+
if ($count === 2) {
635+
// If timestamp with specified strftime format, then return formatted date string.
636+
return str_replace($matches[0], userdate($timestamp, $timepassed[1]), $text);
637+
} else if ($count === 1) {
638+
return str_replace($matches[0], $timestamp, $text);
639+
} else {
640+
// If not a valid time string, then just return what was passed.
641+
return $text;
642+
}
643+
}
611644
}

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
defined('MOODLE_INTERNAL') || die;
88

9-
$plugin->version = 2023092100;
9+
$plugin->version = 2023100900;
1010
$plugin->requires = 2016052300;
1111
$plugin->maturity = MATURITY_STABLE;
1212
$plugin->release = '4.3.0';

0 commit comments

Comments
 (0)