diff --git a/course/format/classes/base.php b/course/format/classes/base.php index 644a8b5d72f..6b658fa32fd 100644 --- a/course/format/classes/base.php +++ b/course/format/classes/base.php @@ -226,6 +226,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. diff --git a/course/format/tests/behat/courseindex_language.feature b/course/format/tests/behat/courseindex_language.feature new file mode 100644 index 00000000000..1f8af0ef955 --- /dev/null +++ b/course/format/tests/behat/courseindex_language.feature @@ -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 "" + 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 | diff --git a/lib/behat/classes/behat_core_generator.php b/lib/behat/classes/behat_core_generator.php index 75e7860ef2c..2a81c598de1 100644 --- a/lib/behat/classes/behat_core_generator.php +++ b/lib/behat/classes/behat_core_generator.php @@ -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. diff --git a/lib/setup.php b/lib/setup.php index ccbba5281d5..6c300f5ecc2 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -947,6 +947,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);