first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,92 @@
@report @report_themeusage
Feature: Navigate to a theme usage report
In order to see a theme usage report
As an admin
I need to set a theme for user/course/category/cohort and view the report
Background:
Given the following config values are set as admin:
| allowuserthemes | 1 |
| allowcoursethemes | 1 |
| allowcategorythemes | 1 |
| allowcohortthemes | 1 |
And I log in as "admin"
Scenario: I am able to see theme usage report for all contexts overriding the default theme
Given the following "courses" exist:
| fullname | shortname | theme |
| Course 1 | course1 | boost |
| Course 2 | course2 | boost |
And the following "user" exists:
| username | student1 |
| firstname | Student |
| lastname | One |
| theme | boost |
And I navigate to "Reports > Theme usage" in site administration
And I set the field "Theme name" to "boost"
And I set the field "Usage type" to "all"
When I press "Get report"
Then the following should exist in the "reportbuilder-table" table:
| Usage type | Force theme |
| Course (2) | Boost |
| User (1) | Boost |
Scenario: I am able to see theme usage report for courses overriding the default theme
Given the following "course" exists:
| fullname | Course 1 |
| shortname | course1 |
| theme | boost |
And I navigate to "Reports > Theme usage" in site administration
And I set the field "Theme name" to "boost"
And I set the field "Usage type" to "course"
When I press "Get report"
Then the following should exist in the "reportbuilder-table" table:
| Course full name | Course short name | Force theme |
| Course 1 | course1 | Boost |
Scenario: I am able to see theme usage report for users overriding the default theme
Given the following "user" exists:
| username | student1 |
| firstname | Student |
| lastname | One |
| theme | boost |
And I navigate to "Reports > Theme usage" in site administration
And I set the field "Theme name" to "boost"
And I set the field "Usage type" to "user"
When I press "Get report"
Then the following should exist in the "reportbuilder-table" table:
| First name | Last name | Force theme |
| Student | One | Boost |
Scenario: I am able to see theme usage report for cohorts overriding the default theme
Given the following "cohort" exists:
| name | Cohort 1 |
| idnumber | cohort1 |
| context | system |
And I navigate to "Users > Accounts > Cohorts" in site administration
And I press "Edit" action in the "cohort1" report row
And I set the field "theme" to "boost"
And I press "Save changes"
And I navigate to "Reports > Theme usage" in site administration
And I set the field "Theme name" to "boost"
And I set the field "Usage type" to "cohort"
When I press "Get report"
Then the following should exist in the "reportbuilder-table" table:
| Name | Category | Force theme |
| Cohort 1 | System | Boost |
Scenario: I am able to see theme usage report for categories overriding the default theme
Given the following "categories" exist:
| name | category | idnumber |
| Category 1 | 0 | category1 |
And I navigate to "Courses > Manage courses and categories" in site administration
And I click on "edit" action for "Category 1" in management category listing
And I set the field "theme" to "boost"
And I press "Save changes"
And I navigate to "Reports > Theme usage" in site administration
And I set the field "Theme name" to "boost"
And I set the field "Usage type" to "category"
When I press "Get report"
Then the following should exist in the "reportbuilder-table" table:
| Category name | Course count | Force theme |
| Category 1 | 0 | Boost |
@@ -0,0 +1,101 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace report_themeusage;
use testing_data_generator;
use core\output\theme_usage;
/**
* Unit tests for theme usage.
*
* @package report_themeusage
* @copyright 2023 David Woloszyn <david.woloszyn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class theme_usage_test extends \advanced_testcase {
/** @var testing_data_generator Data generator. */
private testing_data_generator $generator;
/**
* Set up function for tests.
*/
protected function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->generator = $this->getDataGenerator();
}
/**
* Test is_theme_used_in_any_context method.
*
* @covers ::is_theme_used_in_any_context
* @covers ::theme_purge_used_in_context_caches
*/
public function test_is_theme_used_in_any_context(): void {
// Enable theme overrides.
set_config('allowuserthemes', 1);
set_config('allowcoursethemes', 1);
set_config('allowcohortthemes', 1);
set_config('allowcategorythemes', 1);
$theme = 'boost';
// Check there are no contexts using 'boost' as their preferred theme yet.
$usedinanycontext = theme_usage::is_theme_used_in_any_context($theme);
$this->assertEquals(theme_usage::THEME_IS_NOT_USED, $usedinanycontext);
// Create a user and set its theme preference to 'boost'.
// The outcome of this test should be the same if we use a cohort/course/category.
$this->generator->create_user(['theme' => $theme]);
// Because we have already checked and cached a response, purge this cache.
theme_purge_used_in_context_caches();
$usedinanycontext = theme_usage::is_theme_used_in_any_context($theme);
$this->assertEquals(theme_usage::THEME_IS_USED, $usedinanycontext);
// Double-check the the cache is set for the theme.
$cache = \cache::make('core', 'theme_usedincontext')->get($theme);
$this->assertEquals(theme_usage::THEME_IS_USED, $cache);
}
/**
* Test the deleting of cache using theme_delete_used_in_context_cache.
*
* @covers ::theme_delete_used_in_context_cache
*/
public function test_theme_delete_used_in_context_cache(): void {
// Enable theme override.
set_config('allowuserthemes', 1);
// Create a user and set its theme preference to 'boost'.
$theme = 'boost';
$user = $this->generator->create_user(['theme' => $theme]);
// Check for theme usage. This will create a cached result.
theme_usage::is_theme_used_in_any_context($theme);
$cache = \cache::make('core', 'theme_usedincontext')->get($theme);
$this->assertEquals(theme_usage::THEME_IS_USED, $cache);
// Delete the cache by switching themes.
theme_delete_used_in_context_cache('classic', $user->theme);
$cache = \cache::make('core', 'theme_usedincontext')->get($theme);
$this->assertFalse($cache);
}
}