__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?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/>.
declare(strict_types=1);
namespace core_reportbuilder;
use advanced_testcase;
use core_reportbuilder_generator;
use core_tag_tag;
use core_user\reportbuilder\datasource\users;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/lib.php");
/**
* Unit tests for the component callbacks
*
* @package core_reportbuilder
* @copyright 2023 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class lib_test extends advanced_testcase {
/**
* Test getting tagged reports
*
* @covers ::core_reportbuilder_get_tagged_reports
*/
public function test_core_reportbuilder_get_tagged_reports(): void {
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
// Create three tagged reports.
$reportone = $generator->create_report(['name' => 'Report 1', 'source' => users::class, 'tags' => ['cat']]);
$reporttwo = $generator->create_report(['name' => 'Report 2', 'source' => users::class, 'tags' => ['dog']]);
$reportthree = $generator->create_report(['name' => 'Report 3', 'source' => users::class, 'tags' => ['cat']]);
// Add all users audience to report one and two.
$generator->create_audience(['reportid' => $reportone->get('id'), 'configdata' => []]);
$generator->create_audience(['reportid' => $reporttwo->get('id'), 'configdata' => []]);
$tag = core_tag_tag::get_by_name(0, 'cat');
// Current user can only access report one with "cat" tag.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$tagindex = core_reportbuilder_get_tagged_reports($tag);
$this->assertStringContainsString($reportone->get_formatted_name(), $tagindex->content);
$this->assertStringNotContainsString($reporttwo->get_formatted_name(), $tagindex->content);
$this->assertStringNotContainsString($reportthree->get_formatted_name(), $tagindex->content);
// Admin can access both reports with "cat" tag.
$this->setAdminUser();
$tagindex = core_reportbuilder_get_tagged_reports($tag);
$this->assertStringContainsString($reportone->get_formatted_name(), $tagindex->content);
$this->assertStringNotContainsString($reporttwo->get_formatted_name(), $tagindex->content);
$this->assertStringContainsString($reportthree->get_formatted_name(), $tagindex->content);
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| behat | Folder | 0777 |
|
|
| classes | Folder | 0777 |
|
|
| external | Folder | 0777 |
|
|
| fixtures | Folder | 0777 |
|
|
| generator | Folder | 0777 |
|
|
| local | Folder | 0777 |
|
|
| output | Folder | 0777 |
|
|
| privacy | Folder | 0777 |
|
|
| reportbuilder | Folder | 0777 |
|
|
| task | Folder | 0777 |
|
|
| datasource_test.php | File | 12.6 KB | 0777 |
|
| generator_test.php | File | 7.11 KB | 0777 |
|
| helpers.php | File | 1.03 KB | 0777 |
|
| lib_test.php | File | 3.21 KB | 0777 |
|
| manager_test.php | File | 7.84 KB | 0777 |
|
| permission_test.php | File | 16.31 KB | 0777 |
|
| system_report_factory_test.php | File | 3.13 KB | 0777 |
|
| system_report_test.php | File | 3.5 KB | 0777 |
|