first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,86 @@
@communication @communication_customlink @javascript
Feature: Communication custom link
In order to facilitate easy access to an existing communication platform
As a teacher
I need to be able to make a custom communication link available in my course
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following config values are set as admin:
| enablecommunicationsubsystem | 1 |
Scenario: As a teacher I can configure a custom communication provider for my course
Given I am on the "Course 1" "Course" page logged in as "teacher1"
And "Chat to course participants" "button" should not be visible
When I navigate to "Communication" in current page administration
And the "Provider" select box should contain "Custom link"
And I should not see "Custom link URL"
And I select "Custom link" from the "Provider" singleselect
And I should see "Custom link URL"
And I set the following fields to these values:
| communication_customlinkroomname | Test URL |
| customlinkurl | #wwwroot#/communication/provider/customlink/tests/behat/fixtures/custom_link_test_page.php |
And I press "Save changes"
Then "Chat to course participants" "button" should be visible
And I click on "Chat to course participants" "button"
# Check the link hits the expected destination.
And I switch to a second window
And I should see "Example messaging service - teacher1" in the "region-main" "region"
And I close all opened windows
# Ensure any communication subsystem tasks have no impact on availability.
And I run all adhoc tasks
And I am on the "Course 1" course page
And "Chat to course participants" "button" should be visible
And I click on "Chat to course participants" "button"
And I switch to a second window
And I should see "Example messaging service - teacher1" in the "region-main" "region"
And I close all opened windows
And I log out
# Confirm student also has access to the custom link.
And I am on the "Course 1" "Course" page logged in as "student1"
And "Chat to course participants" "button" should be visible
And I click on "Chat to course participants" "button"
And I switch to a second window
And I should see "Example messaging service - student1" in the "region-main" "region"
Scenario: As a teacher I can disable and re-enable a custom communication provider for my course
Given I am on the "Course 1" "Course" page logged in as "teacher1"
And "Chat to course participants" "button" should not be visible
When I navigate to "Communication" in current page administration
And I select "Custom link" from the "Provider" singleselect
And I set the following fields to these values:
| communication_customlinkroomname | Test URL |
| customlinkurl | #wwwroot#/communication/provider/customlink/tests/behat/fixtures/custom_link_test_page.php |
And I press "Save changes"
And "Chat to course participants" "button" should be visible
And I run all adhoc tasks
And I navigate to "Communication" in current page administration
And I select "None" from the "Provider" singleselect
And I press "Save changes"
And "Chat to course participants" "button" should not be visible
And I run all adhoc tasks
And I am on the "Course 1" course page
And "Chat to course participants" "button" should not be visible
And I navigate to "Communication" in current page administration
And I select "Custom link" from the "Provider" singleselect
And I set the following fields to these values:
| communication_customlinkroomname | Test URL |
| customlinkurl | #wwwroot#/communication/provider/customlink/tests/behat/fixtures/custom_link_test_page.php |
And I press "Save changes"
And "Chat to course participants" "button" should be visible
And I run all adhoc tasks
And I am on the "Course 1" course page
And "Chat to course participants" "button" should be visible
And I click on "Chat to course participants" "button"
And I switch to a second window
And I should see "Example messaging service - teacher1" in the "region-main" "region"
@@ -0,0 +1,40 @@
<?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/>.
/**
* A page which can be used to represent a messaging service while testing the custom link communication provider.
*
* The current Moodle user's username is listed in the heading to make it easier to confirm the page has been
* opened by the expected user.
*
* @package communication_customlink
* @copyright 2023 Michael Hawkins <michaelh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../../../../config.php');
defined('BEHAT_SITE_RUNNING') || die();
global $OUTPUT, $PAGE, $USER;
$PAGE->set_url('/communication/provider/customlink/tests/behat/fixtures/custom_link_test_page.php');
require_login();
$PAGE->set_context(core\context\system::instance());
echo $OUTPUT->header();
echo "<h2>Example messaging service - {$USER->username}</h2>";
echo "<p>Imagine this is a wonderful messaging service being accessed directly from a link in Moodle!</p>";
echo $OUTPUT->footer();
@@ -0,0 +1,144 @@
<?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 communication_customlink;
use core_communication\processor;
use core_communication\communication_test_helper_trait;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/../../../tests/communication_test_helper_trait.php');
/**
* Class communication_feature_test to test the custom link features implemented using the core interfaces.
*
* @package communication_customlink
* @category test
* @copyright 2023 Michael Hawkins <michaelh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \communication_customlink\communication_feature
*/
class communication_feature_test extends \advanced_testcase {
use communication_test_helper_trait;
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->setup_communication_configs();
}
/**
* Test create, update and delete chat room.
*
* @covers ::load_for_instance
*/
public function test_load_for_instance(): void {
$communicationprocessor = $this->get_test_communication_processor();
$instance = communication_feature::load_for_instance($communicationprocessor);
$this->assertInstanceOf('communication_customlink\communication_feature', $instance);
}
/**
* Test create, update and delete chat room.
*
* @covers ::create_chat_room
* @covers ::update_chat_room
* @covers ::delete_chat_room
*/
public function test_create_update_delete_chat_room(): void {
$communicationprocessor = $this->get_test_communication_processor();
// Create, update and delete room should always return true because this provider contains
// a link to a room, but does not manage the existence of the room.
$createroomresult = $communicationprocessor->get_room_provider()->create_chat_room();
$updateroomresult = $communicationprocessor->get_room_provider()->update_chat_room();
$deleteroomresult = $communicationprocessor->get_room_provider()->delete_chat_room();
$this->assertTrue($createroomresult);
$this->assertTrue($updateroomresult);
$this->assertTrue($deleteroomresult);
}
/**
* Test save form data with provider's custom field and fetching with get_chat_room_url().
*
* @covers ::save_form_data
* @covers ::get_chat_room_url
*/
public function test_save_form_data(): void {
$communicationprocessor = $this->get_test_communication_processor();
$customlinkurl = 'https://moodle.org/message/index.php';
$formdatainstance = (object) ['customlinkurl' => $customlinkurl];
// Test the custom link URL is saved and can be retrieved as expected.
$communicationprocessor->get_form_provider()->save_form_data($formdatainstance);
$fetchedurl = $communicationprocessor->get_room_provider()->get_chat_room_url();
$this->assertEquals($customlinkurl, $fetchedurl);
// Test with empty customlinkurl.
$customlinkurlempty = '';
$formdatainstance = (object) ['customlinkurl' => $customlinkurlempty];
$communicationprocessor->get_form_provider()->save_form_data($formdatainstance);
$fetchedurl = $communicationprocessor->get_room_provider()->get_chat_room_url();
// It should not update the url to an empty one.
$this->assertEquals($customlinkurl, $fetchedurl);
// Test with null customlinkurl.
$customlinkurlempty = null;
$formdatainstance = (object) ['customlinkurl' => $customlinkurlempty];
$communicationprocessor->get_form_provider()->save_form_data($formdatainstance);
$fetchedurl = $communicationprocessor->get_room_provider()->get_chat_room_url();
// It should not update the url to a null one.
$this->assertEquals($customlinkurl, $fetchedurl);
}
/**
* Create a test custom link communication processor object.
*
* @return processor
*/
protected function get_test_communication_processor(): processor {
$course = $this->getDataGenerator()->create_course();
$instanceid = $course->id;
$context = \core\context\system::instance();
$component = 'core_course';
$instancetype = 'coursecommunication';
$selectedcommunication = 'communication_customlink';
$communicationroomname = 'communicationroom';
$communicationprocessor = processor::create_instance(
$context,
$selectedcommunication,
$instanceid,
$component,
$instancetype,
$communicationroomname,
);
return $communicationprocessor;
}
/**
* Test if the selected provider is configured.
*
* @covers ::is_configured
*/
public function test_is_configured(): void {
$communicationprocessor = $this->get_test_communication_processor();
$this->assertTrue($communicationprocessor->get_form_provider()->is_configured());
}
}