diff --git a/admin/tool/behat/cli/util_single_run.php b/admin/tool/behat/cli/util_single_run.php index 967fde33358..f0a3650f540 100644 --- a/admin/tool/behat/cli/util_single_run.php +++ b/admin/tool/behat/cli/util_single_run.php @@ -164,6 +164,8 @@ if ($options['install']) { mtrace("Acceptance tests site installed"); } + // Note: Do not build the themes here. This is done during the 'enable' stage. + } else if ($options['drop']) { // Ensure no tests are running. test_lock::acquire('behat'); @@ -182,6 +184,10 @@ if ($options['install']) { // Enable test mode. behat_util::start_test_mode($options['add-core-features-to-theme'], $options['optimize-runs'], $parallel, $run); + // Themes are only built in the 'enable' command. + behat_util::build_themes(); + mtrace("Testing environment themes built"); + // This is only displayed once for parallel install. if (empty($run)) { // Notify user that 2.5 profile has been converted to 3.5. diff --git a/lib/behat/classes/util.php b/lib/behat/classes/util.php index 267406bb5bf..fda4f1c1321 100644 --- a/lib/behat/classes/util.php +++ b/lib/behat/classes/util.php @@ -32,6 +32,7 @@ require_once(__DIR__ . '/behat_config_manager.php'); require_once(__DIR__ . '/../../filelib.php'); require_once(__DIR__ . '/../../clilib.php'); +require_once(__DIR__ . '/../../csslib.php'); use Behat\Mink\Session; use Behat\Mink\Exception\ExpectationException; @@ -131,6 +132,35 @@ class behat_util extends testing_util { self::store_database_state(); } + /** + * Build theme CSS. + */ + public static function build_themes() { + global $CFG; + require_once("{$CFG->libdir}/outputlib.php"); + + $themenames = array_keys(\core_component::get_plugin_list('theme')); + + // Load the theme configs. + $themeconfigs = array_map(function($themename) { + return \theme_config::load($themename); + }, $themenames); + + // Build the list of themes and cache them in local cache. + $themes = theme_build_css_for_themes($themeconfigs, ['ltr'], true); + + $framework = self::get_framework(); + $storageroot = self::get_dataroot() . "/{$framework}/themedata"; + + foreach ($themes as $themename => $themedata) { + $dirname = "{$storageroot}/{$themename}"; + check_dir_exists($dirname); + foreach ($themedata as $direction => $css) { + file_put_contents("{$dirname}/{$direction}.css", $css); + } + } + } + /** * Drops dataroot and remove test database tables * @throws coding_exception