Merge branch 'MDL-77037-401' of https://github.com/laurentdavid/moodle into MOODLE_401_STABLE

This commit is contained in:
Andrew Nicols 2023-03-09 21:59:37 +08:00
commit 3c1c543c53
4 changed files with 64 additions and 0 deletions
course/format
lib

@ -225,6 +225,18 @@ abstract class base {
self::$instances = array();
}
}
/**
* Reset the current user for all courses.
*
* The course format cache resets every time the course cache resets but
* also when the user changes their language, all course editors
*
* @return void
*/
public static function session_cache_reset_all(): void {
$statecache = cache::make('core', 'courseeditorstate');
$statecache->purge();
}
/**
* Reset the current user course format cache.

@ -0,0 +1,36 @@
@core @core_course @core_courseformat
Feature: The course index language should change according to user preferences.
As a user in a course
I should see the same language in the course index and the course content when I switch languages.
Background:
Given remote langimport tests are enabled
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| category | 0 |
| enablecompletion | 1 |
| numsections | 4 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
And the following "language pack" exists:
| language | fr |
And I change window size to "large"
@javascript
Scenario Outline: Course index is refreshed when we change language.
Given I am on the "C1" "Course" page logged in as "<user>"
When I follow "Language" in the user menu
Then I should see "Language selector" user submenu
And I follow "Français (fr)"
Then I should see "Généralités" in the "courseindex-content" "region"
Examples:
| user |
| student1 |
| teacher1 |

@ -259,6 +259,11 @@ class behat_core_generator extends behat_generator_base {
'datagenerator' => 'customlang',
'required' => ['component', 'stringid', 'value'],
],
'language packs' => [
'singular' => 'language pack',
'datagenerator' => 'langpack',
'required' => ['language'],
],
'analytics models' => [
'singular' => 'analytics model',
'datagenerator' => 'analytics_model',
@ -549,6 +554,16 @@ class behat_core_generator extends behat_generator_base {
tool_customlang_utils::checkin($USER->lang);
}
}
/**
* Imports a langpack.
*
* @param array $data
*/
protected function process_langpack($data) {
$controller = new \tool_langimport\controller();
$controller->install_languagepacks($data['language']);
get_string_manager()->reset_caches();
}
/**
* Adapter to enrol_user() data generator.

@ -937,6 +937,7 @@ if (!isset($CFG->theme)) {
if (isset($_GET['lang']) and ($lang = optional_param('lang', '', PARAM_SAFEDIR))) {
if (get_string_manager()->translation_exists($lang, false)) {
$SESSION->lang = $lang;
\core_courseformat\base::session_cache_reset_all();
}
}
unset($lang);