Skip to content

Commit

Permalink
Merge branch 'MDL-81932-main' of https://github.com/safatshahin/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jul 18, 2024
2 parents 920dbc2 + efc7c6d commit d96e781
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 42 deletions.
12 changes: 7 additions & 5 deletions communication/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ public function form_definition_for_provider(\MoodleQuickForm $mform, string $pr
$mform->insertElementBefore(
$mform->createElement(
'text',
'communicationroomname',
$provider . 'roomname',
get_string('communicationroomname', 'communication'),
'maxlength="100" size="20"'
),
'addcommunicationoptionshere'
);
$mform->setType('communicationroomname', PARAM_TEXT);
$mform->setType($provider . 'roomname', PARAM_TEXT);

$mform->insertElementBefore(
$mform->createElement(
Expand Down Expand Up @@ -376,6 +376,9 @@ public function set_avatar(?\stored_file $avatar): bool {
* @return string
*/
public function get_room_name(): string {
if (!$this->communication) {
return '';
}
return $this->communication->get_room_name();
}

Expand All @@ -387,7 +390,8 @@ public function get_room_name(): string {
public function set_data(\stdClass $instance): void {
if (!empty($instance->id) && $this->communication) {
$instance->selectedcommunication = $this->communication->get_provider();
$instance->communicationroomname = $this->communication->get_room_name();
$roomnameidentifier = $this->get_provider() . 'roomname';
$instance->$roomnameidentifier = $this->communication->get_room_name();

$this->communication->get_form_provider()->set_form_data($instance);
}
Expand Down Expand Up @@ -474,8 +478,6 @@ public function configure_room_and_membership_by_provider(
// Now deactivate the previous provider.
$this->update_room(
active: processor::PROVIDER_INACTIVE,
communicationroomname: $communicationroomname,
avatar: $instanceimage,
instance: $instance,
queue: $queue,
);
Expand Down
15 changes: 10 additions & 5 deletions communication/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,14 @@ public static function update_course_communication_instance(
if (empty($provider)) {
$provider = $coursecommunication->get_provider();
}
$roomnameidenfier = $provider . 'roomname';

// Determine the communication room name if none was provided and add it to the course data.
if (empty($course->communicationroomname)) {
$course->communicationroomname = $course->fullname ?? get_course($course->id)->fullname;
if (empty($course->$roomnameidenfier)) {
$course->$roomnameidenfier = $coursecommunication->get_room_name();
if (empty($course->$roomnameidenfier)) {
$course->$roomnameidenfier = $course->fullname ?? get_course($course->id)->fullname;
}
}

// List of enrolled users for course communication.
Expand Down Expand Up @@ -465,7 +469,7 @@ public static function update_course_communication_instance(
$communication->configure_room_and_membership_by_provider(
provider: $provider,
instance: $course,
communicationroomname: $course->communicationroomname,
communicationroomname: $course->$roomnameidenfier,
users: $enrolledusers,
instanceimage: $courseimage,
);
Expand All @@ -486,7 +490,7 @@ public static function update_course_communication_instance(
$communication->configure_room_and_membership_by_provider(
provider: $provider,
instance: $course,
communicationroomname: $course->communicationroomname,
communicationroomname: $course->$roomnameidenfier,
users: $enrolledusers,
instanceimage: $courseimage,
queue: false,
Expand Down Expand Up @@ -533,8 +537,9 @@ public static function update_group_communication_instances_for_course(
context: $coursecontext,
);

$roomnameidenfier = $provider . 'roomname';
$communicationroomname = self::format_group_room_name(
baseroomname: $course->communicationroomname,
baseroomname: $course->$roomnameidenfier,
groupname: $coursegroup->name,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Feature: Communication custom link
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:
| communicationroomname | Test URL |
| customlinkurl | #wwwroot#/communication/provider/customlink/tests/behat/fixtures/custom_link_test_page.php |
| 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"
Expand Down Expand Up @@ -59,8 +59,8 @@ Feature: Communication custom link
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:
| communicationroomname | Test URL |
| customlinkurl | #wwwroot#/communication/provider/customlink/tests/behat/fixtures/custom_link_test_page.php |
| 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
Expand All @@ -74,8 +74,8 @@ Feature: Communication custom link
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:
| communicationroomname | Test URL |
| customlinkurl | #wwwroot#/communication/provider/customlink/tests/behat/fixtures/custom_link_test_page.php |
| 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@communication @communication_matrix @javascript
@communication @communication_matrix
Feature: Communication matrix form field
In order to create a new communication room in matrix
As a teacher
Expand All @@ -15,34 +15,20 @@ Feature: Communication matrix form field
| user | course | role |
| teacher1 | Test course | editingteacher |

Scenario: I can add room name for matrix room
@javascript
Scenario: I can add room name and topic for matrix room
Given a Matrix mock server is configured
And I log in as "teacher1"
And I am on "Test course" course homepage
And I am on the "Test course" "Course" page logged in as "teacher1"
When I navigate to "Communication" in current page administration
And I set the field "id_selectedcommunication" to "Matrix"
And I wait to be redirected
And I should see "Room name"
And I set the field "id_communicationroomname" to "Sampleroomname"
And I press "Save changes"
And I navigate to "Communication" in current page administration
Then the field "id_communicationroomname" matches value "Sampleroomname"

Scenario: I can add room topic for matrix room
Given a Matrix mock server is configured
And I log in as "teacher1"
And I am on "Test course" course homepage
When I navigate to "Communication" in current page administration
And I set the field "id_selectedcommunication" to "Matrix"
And I set the following fields to these values:
| selectedcommunication | communication_matrix |
And I wait to be redirected
And I set the following fields to these values:
| communication_matrixroomname | Sampleroomname |
| matrixroomtopic | Sampleroomtopic |
And I should see "Room name"
And I should see "Room topic"
And I set the field "id_communicationroomname" to "Sampleroomname"
And I set the field "id_matrixroomtopic" to "Sampleroomtopic"
And I press "Save changes"
And I navigate to "Communication" in current page administration
Then the field "id_communicationroomname" matches value "Sampleroomname"
And I press "Cancel"
And I run all adhoc tasks
And I navigate to "Communication" in current page administration
And the field "id_matrixroomtopic" matches value "Sampleroomtopic"
Then the field "Room name" matches value "Sampleroomname"
And the field "Room topic" matches value "Sampleroomtopic"
4 changes: 3 additions & 1 deletion communication/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ public function test_set_data(): void {
// Set the data.
$communication->set_data($course);

$roomnameidenfier = $communication->get_provider() . 'roomname';

// Test the set data.
$this->assertEquals($roomname, $course->communicationroomname);
$this->assertEquals($roomname, $course->$roomnameidenfier);
$this->assertEquals($provider, $course->selectedcommunication);
}

Expand Down
67 changes: 67 additions & 0 deletions communication/tests/behat/communication_configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,72 @@ Feature: Access the communication configuration page
When I navigate to "Communication" in current page administration
And I set the following fields to these values:
| selectedcommunication | communication_matrix |
And I wait to be redirected
Then I should see "Room name"
And I should see "Room topic"

@javascript
Scenario: Changing the communication provider in the form fetches the correct data
Given a Matrix mock server is configured
And I am on the "Test course" "Course" page logged in as "teacher1"
When I navigate to "Communication" in current page administration
And I set the following fields to these values:
| selectedcommunication | communication_matrix |
And I wait to be redirected
And I should see "Room name"
And I should see "Room topic"
And I set the following fields to these values:
| communication_matrixroomname | Matrix room |
| matrixroomtopic | Matrix topic |
And I click on "Save changes" "button"
And I navigate to "Communication" in current page administration
Then the field "Room name" matches value "Matrix room"
And the field "Room topic" matches value "Matrix topic"
And I set the following fields to these values:
| selectedcommunication | communication_customlink |
And I wait to be redirected
And I should see "Room name"
And I should not see "Room topic"
And I should see "Custom link URL"
And I set the following fields to these values:
| communication_customlinkroomname | Custom link room |
| customlinkurl | https://moodle.org |
And I click on "Save changes" "button"
And I navigate to "Communication" in current page administration
And the field "Room name" matches value "Custom link room"
And the field "Custom link URL" matches value "https://moodle.org"
And I set the following fields to these values:
| selectedcommunication | communication_matrix |
And I wait to be redirected
And I should see "Room name"
And I should see "Room topic"
And the field "Room name" matches value "Matrix room"
And the field "Room topic" matches value "Matrix topic"
And I should not see "Custom link URL"
And I set the following fields to these values:
| selectedcommunication | communication_customlink |
And I wait to be redirected
And I should see "Room name"
And I should see "Custom link URL"
And the field "Room name" matches value "Custom link room"
And the field "Custom link URL" matches value "https://moodle.org"
And I should not see "Room topic"
And I set the following fields to these values:
| selectedcommunication | communication_matrix |
And I wait to be redirected
And I click on "Save changes" "button"
And I am on "Test course" course homepage with editing mode on
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Group mode | Separate groups |
And I press "Save and display"
And I navigate to "Communication" in current page administration
And the field "Room name" matches value "Matrix room"
And the field "Room topic" matches value "Matrix topic"
And I press "Cancel"
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Group mode | Visible groups |
And I navigate to "Communication" in current page administration
And the field "Room name" matches value "Matrix room"
And the field "Room topic" matches value "Matrix topic"

0 comments on commit d96e781

Please sign in to comment.