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

use availability_date\condition;
use core_availability\tree;
use core_courseformat\formatactions;

/**
 * Tests for Subsection manager class.
 *
 * @covers     \mod_subsection\manager
 * @package    mod_subsection
 * @category   test
 * @copyright  2024 Ferran Recio <ferran@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class manager_test extends \advanced_testcase {
    /**
     * Test get_delegated_section_info.
     *
     * @covers ::get_delegated_section_info
     * @dataProvider provider_test_get_delegated_section_info
     * @param bool $hasavailability Whether the module has access restrictions.
     * @param bool $visible Whether the module is visible.
     * @return void
     */
    public function test_get_delegated_section_info(
        bool $hasavailability,
        bool $visible
    ): void {
        global $DB;

        $this->resetAfterTest();

        $pluginmanager = \core_plugin_manager::resolve_plugininfo_class('mod');
        $pluginmanager::enable_plugin('subsection', 1);

        // Set up the availability settings.
        $availabilityjson = null;
        if ($hasavailability) {
            $operation = condition::DIRECTION_FROM;
            $availabilityjson = json_encode(tree::get_root_json(
                [
                    condition::get_json($operation, time() + 3600),
                ],
                '&',
                true
            ));
        }

        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 2]);
        $module = $this->getDataGenerator()->create_module(
            'subsection',
            (object)['course' => $course->id, 'section' => 2],
            ['visible' => $visible, 'availability' => $availabilityjson]
        );

        $cm = get_coursemodule_from_id('subsection', $module->cmid, 0, false, MUST_EXIST);
        $manager = manager::create_from_coursemodule($cm);
        $sectioninfo = $manager->get_delegated_section_info();
        $this->assertInstanceOf(\section_info::class, $sectioninfo);
        $this->assertEquals($cm->instance, $sectioninfo->itemid);
        $this->assertEquals($cm->name, $sectioninfo->name);
        $this->assertEquals($cm->visible, $sectioninfo->visible);
        $this->assertEquals($cm->availability, $sectioninfo->availability);
        $initialid = $sectioninfo->id;

        // When subsections are disabled, all subsections are considered orphaned
        // and can be removed without affecting the course_module. This should regenerate
        // the delegated section once the module is re-enabled.
        $pluginmanager::enable_plugin('subsection', 0);
        formatactions::section($course)->delete($sectioninfo);
        rebuild_course_cache($course->id, true);
        $pluginmanager::enable_plugin('subsection', 1);
        rebuild_course_cache($course->id, true);

        $cm = get_coursemodule_from_id('subsection', $module->cmid, 0, false, MUST_EXIST);
        $manager = manager::create_from_coursemodule($cm);
        $sectioninfo = $manager->get_delegated_section_info();
        $this->assertInstanceOf(\section_info::class, $sectioninfo);
        $this->assertEquals($cm->instance, $sectioninfo->itemid);
        $this->assertEquals($cm->name, $sectioninfo->name);
        $this->assertEquals($cm->visible, $sectioninfo->visible);
        $this->assertEquals($cm->availability, $sectioninfo->availability);

        // The section should be different from the previous one.
        $this->assertNotEquals($initialid, $sectioninfo->id);
    }

    /**
     * Data provider for test_get_delegated_section_info.
     *
     * @return array
     */
    public static function provider_test_get_delegated_section_info(): array {
        return [
            'Module is visible with no restrictions' => [
                'hasavailability' => false,
                'visible' => true,
            ],
            'Module is visible with restrictions' => [
                'hasavailability' => true,
                'visible' => true,
            ],
            'Module is hidden with no restrictions' => [
                'hasavailability' => false,
                'visible' => false,
            ],
            'Module is hidden with restrictions' => [
                'hasavailability' => true,
                'visible' => false,
            ],

        ];
    }
}

Filemanager

Name Type Size Permission Actions
behat Folder 0777
courseformat Folder 0777
generator Folder 0777
manager_test.php File 5 KB 0777
permission_test.php File 4.96 KB 0777
Filemanager