MDL-78129 communication: Fix all phpcs isuses

This is a brand new subsystem, plugin-type, and plugin. They are written
from the ground up by us. They should not contain any coding style
violations.
This commit is contained in:
Andrew Nicols 2023-09-22 11:08:02 +08:00
parent 2a096dc5ad
commit 84cfc8beeb
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
53 changed files with 108 additions and 123 deletions

View File

@ -32,11 +32,14 @@ use moodle_url;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manage_communication_providers_page extends admin_setting {
public function __construct() {
$this->nosave = true;
parent::__construct('managecommunications',
new \lang_string('managecommunicationproviders', 'core_communication'), '', '');
parent::__construct(
'managecommunications',
new \lang_string('managecommunicationproviders', 'core_communication'),
'',
''
);
}
public function get_setting(): bool {
@ -71,20 +74,26 @@ class manage_communication_providers_page extends admin_setting {
foreach ($plugins as $plugin) {
$class = '';
$actionurl = new moodle_url('/admin/communication.php', ['sesskey' => sesskey(), 'name' => $plugin->name]);
if ($pluginmanager->get_plugin_info('communication_' . $plugin->name)->get_status() ===
core_plugin_manager::PLUGIN_STATUS_MISSING) {
if (
$pluginmanager->get_plugin_info('communication_' . $plugin->name)->get_status() ===
core_plugin_manager::PLUGIN_STATUS_MISSING
) {
$strtypename = $plugin->displayname . ' (' . get_string('missingfromdisk') . ')';
} else {
$strtypename = $plugin->displayname;
}
if ($plugin->is_enabled()) {
$hideshow = html_writer::link($actionurl->out(false, ['action' => 'disable']),
$OUTPUT->pix_icon('t/hide', get_string('disable'), 'moodle', ['class' => 'iconsmall']));
$hideshow = html_writer::link(
$actionurl->out(false, ['action' => 'disable']),
$OUTPUT->pix_icon('t/hide', get_string('disable'), 'moodle', ['class' => 'iconsmall'])
);
} else {
$class = 'dimmed_text';
$hideshow = html_writer::link($actionurl->out(false, ['action' => 'enable']),
$OUTPUT->pix_icon('t/show', get_string('enable'), 'moodle', ['class' => 'iconsmall']));
$hideshow = html_writer::link(
$actionurl->out(false, ['action' => 'enable']),
$OUTPUT->pix_icon('t/show', get_string('enable'), 'moodle', ['class' => 'iconsmall'])
);
}
$settings = '';
@ -93,8 +102,12 @@ class manage_communication_providers_page extends admin_setting {
}
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url(
'communication_' . $plugin->name, 'manage')) {
if (
$uninstallurl = core_plugin_manager::instance()->get_uninstall_url(
'communication_' . $plugin->name,
'manage'
)
) {
$uninstall = html_writer::link($uninstallurl, get_string('uninstallplugin', 'core_admin'));
}
@ -114,8 +127,10 @@ class manage_communication_providers_page extends admin_setting {
}
$types = core_plugin_manager::instance()->get_plugins_of_type('communication');
foreach ($types as $type) {
if (strpos($type->component, $query) !== false ||
strpos(core_text::strtolower($type->displayname), $query) !== false) {
if (
strpos($type->component, $query) !== false ||
strpos(core_text::strtolower($type->displayname), $query) !== false
) {
return true;
}
}

View File

@ -40,7 +40,6 @@ use stdClass;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class api {
/**
* @var null|processor $communication The communication settings object
*/
@ -167,7 +166,7 @@ class api {
$selection[processor::PROVIDER_NONE] = get_string('nocommunicationselected', 'communication');
$communicationplugins = \core\plugininfo\communication::get_enabled_plugins();
foreach ($communicationplugins as $pluginname => $notusing) {
$selection['communication_' . $pluginname] = get_string('pluginname', 'communication_'. $pluginname);
$selection['communication_' . $pluginname] = get_string('pluginname', 'communication_' . $pluginname);
}
return $selection;
}
@ -200,8 +199,7 @@ class api {
): void {
global $PAGE;
list($communicationproviders, $defaulprovider) = self::
get_enabled_providers_and_default($selectdefaultcommunication);
[$communicationproviders, $defaulprovider] = self::get_enabled_providers_and_default($selectdefaultcommunication);
$PAGE->requires->js_call_amd('core_communication/providerchooser', 'init');
@ -217,10 +215,12 @@ class api {
$mform->setDefault('selectedcommunication', $defaulprovider);
$mform->registerNoSubmitButton('updatecommunicationprovider');
$mform->addElement('submit',
$mform->addElement(
'submit',
'updatecommunicationprovider',
'update communication',
['data-communicationchooser-field' => 'updateButton', 'class' => 'd-none',]);
['data-communicationchooser-field' => 'updateButton', 'class' => 'd-none']
);
// Just a placeholder for the communication options.
$mform->addElement('hidden', 'addcommunicationoptionshere');
@ -242,7 +242,9 @@ class api {
$mform->createElement(
'text',
'communicationroomname',
get_string('communicationroomname', 'communication'), 'maxlength="100" size="20"'),
get_string('communicationroomname', 'communication'),
'maxlength="100" size="20"'
),
'addcommunicationoptionshere'
);
$mform->addHelpButton('communicationroomname', 'communicationroomname', 'communication');
@ -250,7 +252,6 @@ class api {
processor::set_proider_form_definition($provider[0], $mform);
}
}
/**
@ -613,7 +614,6 @@ class api {
switch ($roomstatus) {
case 'pending':
\core\notification::add($message, \core\notification::INFO);
break;

View File

@ -28,7 +28,6 @@ namespace core_communication;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface communication_provider {
/**
* A base communication provider.
*

View File

@ -26,13 +26,12 @@ namespace core_communication\form;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir . '/formslib.php');
/**
* Defines the configure communication form.
*/
class configure_form extends \moodleform {
/**
* @var \core_communication\api $communication The communication api object.
*/

View File

@ -26,7 +26,6 @@ namespace core_communication;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface form_provider {
/**
* Set the form data to the instance if any data is available.
*

View File

@ -29,10 +29,10 @@ use core_privacy\local\request\userlist;
* @copyright 2023 Huong Nguyen <huongnv13@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\provider,
\core_privacy\local\request\subsystem\provider,
\core_privacy\local\request\core_userlist_provider {
class provider implements
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\metadata\provider,
\core_privacy\local\request\subsystem\provider {
public static function get_metadata(collection $collection): collection {
$collection->add_database_table('communication_user', [

View File

@ -29,7 +29,6 @@ use stored_file;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class processor {
/** @var string The magic 'none' provider */
public const PROVIDER_NONE = 'none';
@ -324,7 +323,7 @@ class processor {
$DB->delete_records_select(
'communication_user',
'commid = ? AND userid IN (' . implode(',', $userids) . ') AND synced = ?' ,
'commid = ? AND userid IN (' . implode(',', $userids) . ') AND synced = ?',
[$this->instancedata->id, 0]
);
}

View File

@ -26,7 +26,6 @@ namespace core_communication;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface room_chat_provider {
/**
* Create a provider room when a instance is created.
*/

View File

@ -27,7 +27,6 @@ use core_communication\processor;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class add_members_to_room_task extends adhoc_task {
public function execute() {
// Initialize the custom data operation to be used for the action.
$data = $this->get_custom_data();
@ -55,7 +54,7 @@ class add_members_to_room_task extends adhoc_task {
// Add ad-hoc task to update the provider room.
$task = new self();
$task->set_custom_data([
'id' => $communication->get_id()
'id' => $communication->get_id(),
]);
// Queue the task for the next run.

View File

@ -29,7 +29,6 @@ use core_communication\processor;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class create_and_configure_room_task extends adhoc_task {
public function execute() {
$data = $this->get_custom_data();
@ -66,7 +65,7 @@ class create_and_configure_room_task extends adhoc_task {
// Add ad-hoc task to update the provider room.
$task = new self();
$task->set_custom_data([
'id' => $communication->get_id()
'id' => $communication->get_id(),
]);
// Queue the task for the next run.

View File

@ -29,7 +29,6 @@ use core_communication\processor;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_room_task extends adhoc_task {
public function execute() {
$data = $this->get_custom_data();
@ -63,7 +62,7 @@ class delete_room_task extends adhoc_task {
// Add ad-hoc task to update the provider room.
$task = new self();
$task->set_custom_data([
'id' => $communication->get_id()
'id' => $communication->get_id(),
]);
// Queue the task for the next run.

View File

@ -27,7 +27,6 @@ use core_communication\processor;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class remove_members_from_room extends adhoc_task {
public function execute() {
// Initialize the custom data operation to be used for the action.
$data = $this->get_custom_data();
@ -58,7 +57,7 @@ class remove_members_from_room extends adhoc_task {
// Add ad-hoc task to update the provider room.
$task = new self();
$task->set_custom_data([
'id' => $communication->get_id()
'id' => $communication->get_id(),
]);
// Queue the task for the next run.

View File

@ -27,7 +27,6 @@ use core_communication\processor;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class update_room_membership_task extends adhoc_task {
public function execute() {
// Initialize the custom data operation to be used for the action.
$data = $this->get_custom_data();
@ -55,7 +54,7 @@ class update_room_membership_task extends adhoc_task {
// Add ad-hoc task to update the provider room.
$task = new self();
$task->set_custom_data([
'id' => $communication->get_id()
'id' => $communication->get_id(),
]);
// Queue the task for the next run.

View File

@ -29,7 +29,6 @@ use core_communication\processor;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class update_room_task extends adhoc_task {
public function execute() {
$data = $this->get_custom_data();
@ -56,7 +55,7 @@ class update_room_task extends adhoc_task {
// Add ad-hoc task to update the provider room.
$task = new self();
$task->set_custom_data([
'id' => $communication->get_id()
'id' => $communication->get_id(),
]);
// Queue the task for the next run.

View File

@ -24,7 +24,6 @@ namespace core_communication;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface user_provider {
/**
* Create members.
*

View File

@ -51,7 +51,7 @@ if (!$communication) {
}
// Set variables according to the component callback and use them on the page.
list($instance, $context, $heading, $returnurl) = component_callback(
[$instance, $context, $heading, $returnurl] = component_callback(
$component,
'get_communication_instance_data',
[$instanceid]
@ -70,11 +70,8 @@ $instanceinfo['instance'] = $instance;
$form = new \core_communication\form\configure_form(null, $instanceinfo);
if ($form->is_cancelled()) {
redirect($returnurl);
} else if ($data = $form->get_data()) {
component_callback($component, 'update_communication_instance_data', [$data]);
redirect($returnurl);
}

View File

@ -27,9 +27,8 @@ use core_communication\processor;
*/
class communication_feature implements
\core_communication\communication_provider,
\core_communication\room_chat_provider,
\core_communication\form_provider {
\core_communication\form_provider,
\core_communication\room_chat_provider {
/** @var string The database table storing custom link specific data */
protected const CUSTOMLINK_TABLE = 'communication_customlink';
@ -132,7 +131,6 @@ class communication_feature implements
// Create the record if it does not exist.
$newrecord->commid = $commid;
$DB->insert_record(self::CUSTOMLINK_TABLE, $newrecord);
} else if ($newrecord->url !== $existingrecord->url) {
// Update record if the URL has changed.
$newrecord->id = $existingrecord->id;
@ -154,15 +152,22 @@ class communication_feature implements
public static function set_form_definition(\MoodleQuickForm $mform): void {
// Custom link description for the communication provider.
$mform->insertElementBefore($mform->createElement('text', 'customlinkurl',
$mform->insertElementBefore($mform->createElement(
'text',
'customlinkurl',
get_string('customlinkurl', 'communication_customlink'),
'maxlength="255" size="40"'), 'addcommunicationoptionshere');
'maxlength="255" size="40"'
), 'addcommunicationoptionshere');
$mform->addHelpButton('customlinkurl', 'customlinkurl', 'communication_customlink');
$mform->setType('customlinkurl', PARAM_URL);
$mform->addRule('customlinkurl', get_string('required'), 'required', null, 'client');
$mform->addRule('customlinkurl', get_string('maximumchars', '', 255), 'maxlength', 255);
$mform->insertElementBefore($mform->createElement('static', 'customlinkurlinfo', '',
$mform->insertElementBefore($mform->createElement(
'static',
'customlinkurlinfo',
'',
get_string('customlinkurlinfo', 'communication_customlink'),
'addcommunicationoptionshere'), 'addcommunicationoptionshere');
'addcommunicationoptionshere'
), 'addcommunicationoptionshere');
}
}

View File

@ -26,7 +26,6 @@ use core_privacy\local\metadata\null_provider;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.

View File

@ -33,7 +33,6 @@ require_once(__DIR__ . '/../../../tests/communication_test_helper_trait.php');
* @coversDefaultClass \communication_customlink\communication_feature
*/
class communication_feature_test extends \advanced_testcase {
use communication_test_helper_trait;
public function setUp(): void {

View File

@ -45,11 +45,10 @@ use GuzzleHttp\Psr7\Response;
*/
class communication_feature implements
\core_communication\communication_provider,
\core_communication\user_provider,
\core_communication\form_provider,
\core_communication\room_chat_provider,
\core_communication\room_user_provider,
\core_communication\form_provider {
\core_communication\user_provider {
/** @var ?matrix_room $room The matrix room object to update room information */
private ?matrix_room $room = null;
@ -166,7 +165,7 @@ class communication_feature implements
threepids: [(object) [
'medium' => 'email',
'address' => $user->email,
]],
], ],
externalids: [],
);
$body = json_decode($response->getBody());
@ -542,9 +541,12 @@ class communication_feature implements
public static function set_form_definition(\MoodleQuickForm $mform): void {
// Room description for the communication provider.
$mform->insertElementBefore($mform->createElement('text', 'matrixroomtopic',
$mform->insertElementBefore($mform->createElement(
'text',
'matrixroomtopic',
get_string('matrixroomtopic', 'communication_matrix'),
'maxlength="255" size="20"'), 'addcommunicationoptionshere');
'maxlength="255" size="20"'
), 'addcommunicationoptionshere');
$mform->addHelpButton('matrixroomtopic', 'matrixroomtopic', 'communication_matrix');
$mform->setType('matrixroomtopic', PARAM_TEXT);
}
@ -645,7 +647,6 @@ class communication_feature implements
}
},
);
}
/**

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait create_room_v3 {
/**
* Create a new room.
*

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait get_room_members_v3 {
/**
* Get a list of room members.
*

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait get_room_powerlevels_from_sync_v3 {
/**
* Get a list of room members.
*

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait media_create_v1 {
/**
* Create a media URI.
*

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait remove_member_from_room_v3 {
/**
* Remove a member from a room.
*

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait update_room_avatar_v3 {
/**
* Set the avatar for a room to the specified URL.
*
@ -56,5 +55,4 @@ trait update_room_avatar_v3 {
params: $params,
));
}
}

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait update_room_name_v3 {
/**
* Set the name for a room.
*

View File

@ -34,7 +34,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait update_room_power_levels_v3 {
/**
* Set the avatar for a room to the specified URL.
*
@ -75,5 +74,4 @@ trait update_room_power_levels_v3 {
params: $params,
));
}
}

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait update_room_topic_v3 {
/**
* Set the topic for a room.
*
@ -51,6 +50,5 @@ trait update_room_topic_v3 {
endpoint: '_matrix/client/v3/rooms/:roomid/state/m.room.topic',
params: $params,
));
}
}

View File

@ -32,7 +32,6 @@ use GuzzleHttp\Psr7\Utils;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait upload_content_v3 {
/**
* Upload the content in the matrix/synapse server.
*

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait create_user_v2 {
/**
* Create a new user.
*
@ -63,5 +62,4 @@ trait create_user_v2 {
params: $params,
));
}
}

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait get_room_info_v1 {
/**
* Get room info.
*

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait get_user_info_v2 {
/**
* Get user info.
*
@ -49,5 +48,4 @@ trait get_user_info_v2 {
],
));
}
}

View File

@ -31,7 +31,6 @@ use GuzzleHttp\Psr7\Response;
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
*/
trait invite_member_to_room_v1 {
/**
* Join a user to a room.
*

View File

@ -30,6 +30,5 @@ class v1p7 extends v1p6 {
// Note: A new Content Upload API was introduced.
// See details in the spec:
// https://github.com/matrix-org/matrix-spec-proposals/pull/2246.
use features\matrix\media_create_v1;
}

View File

@ -36,7 +36,6 @@ use GuzzleHttp\Psr7\Response;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class matrix_client {
/** @var string $serverurl The URL of the home server */
/** @var string $accesstoken The access token of the matrix server */

View File

@ -24,7 +24,6 @@ namespace communication_matrix;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class matrix_constants {
/**
* User default power level for matrix.
*/

View File

@ -26,7 +26,6 @@ use stdClass;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class matrix_room {
private const TABLE = 'matrix_room';
/** @var \stdClass|null $record The matrix room record from db */

View File

@ -24,7 +24,6 @@ namespace communication_matrix;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class matrix_user_manager {
/**
* Gets matrix user id from moodle.
*
@ -33,7 +32,7 @@ class matrix_user_manager {
*/
public static function get_matrixid_from_moodle(
int $userid,
) : ?string {
): ?string {
self::load_requirements();
$field = profile_user_record($userid);
$matrixprofilefield = get_config('communication_matrix', 'matrixuserid_field');
@ -141,7 +140,7 @@ class matrix_user_manager {
// Check if matrixuserid exists in user_info_field table.
$matrixuserid = $DB->count_records('user_info_field', [
'shortname' => 'matrixuserid',
'categoryid' => $categoryid
'categoryid' => $categoryid,
]);
if ($matrixuserid < 1) {
@ -158,7 +157,7 @@ class matrix_user_manager {
'visible' => 0,
'locked' => 1,
'param1' => 30,
'param2' => 2048
'param2' => 2048,
];
$profileclass->define_save($data);

View File

@ -27,7 +27,6 @@ use core_privacy\local\metadata\null_provider;
* @codeCoverageIgnore
*/
class provider implements null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.

View File

@ -34,6 +34,6 @@ $capabilities = [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
]
],
],
];

View File

@ -52,5 +52,4 @@ function xmldb_communication_matrix_upgrade($oldversion) {
}
return true;
}

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use communication_matrix\matrix_test_helper_trait;
use Moodle\BehatExtension\Exception\SkippedException;
@ -31,7 +33,6 @@ require_once(__DIR__ . '/../../../../tests/communication_test_helper_trait.php')
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_communication_matrix extends \behat_base {
use \core_communication\communication_test_helper_trait;
use matrix_test_helper_trait;

View File

@ -33,6 +33,7 @@ require_once(__DIR__ . '/../../../tests/communication_test_helper_trait.php');
* @category test
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \communication_matrix\communication_feature
* @coversDefaultClass \communication_matrix\communication_feature
*/
class communication_feature_test extends \advanced_testcase {
@ -67,6 +68,7 @@ class communication_feature_test extends \advanced_testcase {
],
);
// phpcs:ignore moodle.Commenting.InlineComment.DocBlock
/** @var communication_feature */
$provider = $communication->get_room_provider();
$this->assertInstanceOf(
@ -125,6 +127,7 @@ class communication_feature_test extends \advanced_testcase {
roomtopic: 'Our room topic',
);
// phpcs:ignore moodle.Commenting.InlineComment.DocBlock
/** @var communication_feature */
$provider = $communication->get_room_provider();
$this->assertInstanceOf(

View File

@ -266,7 +266,7 @@ class command_test extends \advanced_testcase {
mock: $mock,
);
$mock->append(function(Request $request) use ($expected): Response {
$mock->append(function (Request $request) use ($expected): Response {
$this->assertSame(
$expected,
$request->getUri()->getQuery(),

View File

@ -301,7 +301,7 @@ class matrix_client_test extends \advanced_testcase {
*/
public function require_features_provider(): array {
// We'll just add to the standard testcases.
$testcases = array_map(static function(array $testcase): array {
$testcases = array_map(static function (array $testcase): array {
$testcase[1] = [$testcase[1]];
return $testcase;
}, $this->implements_feature_provider());

View File

@ -47,7 +47,7 @@ trait matrix_client_test_trait {
mocked_matrix_client::reset_client();
}
public function tearDown():void {
public function tearDown(): void {
parent::tearDown();
// Reset the test client.

View File

@ -26,7 +26,6 @@ namespace communication_matrix;
* @coversDefaultClass \communication_matrix\matrix_room
*/
class matrix_room_test extends \advanced_testcase {
/**
* Test for load_by_processor_id with no record.
*
@ -84,7 +83,6 @@ class matrix_room_test extends \advanced_testcase {
$this->assertEquals(54321, $reloadedroom->get_processor_id());
$this->assertEquals('The topic of this room is thusly', $reloadedroom->get_topic());
$this->assertEquals('This is a roomid', $reloadedroom->get_room_id());
}
/**

View File

@ -26,7 +26,6 @@ use GuzzleHttp\Psr7\Response;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait matrix_test_helper_trait {
/**
* @var string $accesstoken The token for matrix connection
*/
@ -46,7 +45,7 @@ trait matrix_test_helper_trait {
$this->matrixhomeserverurl = TEST_COMMUNICATION_MATRIX_MOCK_SERVER;
set_config('matrixhomeserverurl', $this->matrixhomeserverurl, 'communication_matrix');
$request = $this->request();
$response = $request->post($this->matrixhomeserverurl. '/backoffice/create-admin');
$response = $request->post($this->matrixhomeserverurl . '/backoffice/create-admin');
$admindata = json_decode($response->getBody());
$json = [
'identifier' => [
@ -57,7 +56,7 @@ trait matrix_test_helper_trait {
'password' => $admindata->password,
];
$request = $this->request($json);
$response = $request->post($this->matrixhomeserverurl. '/_matrix/client/r0/login');
$response = $request->post($this->matrixhomeserverurl . '/_matrix/client/r0/login');
$response = json_decode($response->getBody());
if (empty($response->access_token)) {
$this->markTestSkipped(
@ -161,10 +160,15 @@ trait matrix_test_helper_trait {
array $rooms = [],
): Response {
$client = new \core\http_client();
return $client->put($this->get_backoffice_uri('create'), ['json' => [
'users' => $users,
'rooms' => $rooms,
]]);
return $client->put(
$this->get_backoffice_uri('create'),
[
'json' => [
'users' => $users,
'rooms' => $rooms,
],
],
);
}
/**
@ -225,7 +229,7 @@ trait matrix_test_helper_trait {
public function reset_mock(): void {
if (defined('TEST_COMMUNICATION_MATRIX_MOCK_SERVER')) {
$request = $this->request();
$response = $request->post(TEST_COMMUNICATION_MATRIX_MOCK_SERVER. '/backoffice/reset');
$response = $request->post(TEST_COMMUNICATION_MATRIX_MOCK_SERVER . '/backoffice/reset');
$response = json_decode($response->getBody());
if (empty($response->reset)) {
$this->markTestSkipped(

View File

@ -27,10 +27,9 @@ require_once(__DIR__ . '/communication_test_helper_trait.php');
* @category test
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_communication\api
* @covers \core_communication\api
*/
class api_test extends \advanced_testcase {
use communication_test_helper_trait;
public function setUp(): void {
@ -284,7 +283,7 @@ class api_test extends \advanced_testcase {
* Test the enabled communication plugin list and default.
*/
public function test_get_enabled_providers_and_default(): void {
list($communicationproviders, $defaulprovider) = \core_communication\api::get_enabled_providers_and_default();
[$communicationproviders, $defaulprovider] = \core_communication\api::get_enabled_providers_and_default();
// Get the communication plugins.
$plugins = \core_component::get_plugin_list('communication');
// Check the number of plugins matches plus 1 as we have none in the selection.

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../tests/communication_test_helper_trait.php');
@ -26,7 +28,6 @@ require_once(__DIR__ . '/../../tests/communication_test_helper_trait.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_communication extends \behat_base {
use \core_communication\communication_test_helper_trait;
/**

View File

@ -25,7 +25,6 @@ namespace core_communication;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait communication_test_helper_trait {
/**
* Setup necessary configs for communication subsystem.
*
@ -83,7 +82,7 @@ trait communication_test_helper_trait {
$records = [
'firstname' => $firstname,
'lastname' => $lastname,
'username' => $username
'username' => $username,
];
return $this->getDataGenerator()->create_user($records);

View File

@ -30,7 +30,6 @@ require_once(__DIR__ . '/communication_test_helper_trait.php');
* @coversDefaultClass \core_communication\processor
*/
class processor_test extends \advanced_testcase {
use communication_test_helper_trait;
/**
@ -61,8 +60,10 @@ class processor_test extends \advanced_testcase {
);
// Now test the record against the database.
$communicationrecord = $DB->get_record('communication',
['instanceid' => $instanceid, 'component' => $component, 'instancetype' => $instancetype]);
$communicationrecord = $DB->get_record(
'communication',
['instanceid' => $instanceid, 'component' => $component, 'instancetype' => $instancetype]
);
// Test against the set data.
$this->assertNotEmpty($communicationrecord);
@ -114,7 +115,7 @@ class processor_test extends \advanced_testcase {
$communicationrecord = $DB->get_record('communication', [
'instanceid' => $instanceid,
'component' => $component,
'instancetype' => $instancetype
'instancetype' => $instancetype,
]);
// Test against the set data.
@ -163,7 +164,7 @@ class processor_test extends \advanced_testcase {
$communicationrecord = $DB->get_record('communication', [
'instanceid' => $instanceid,
'component' => $component,
'instancetype' => $instancetype
'instancetype' => $instancetype,
]);
// Test against the set data.
@ -173,7 +174,8 @@ class processor_test extends \advanced_testcase {
$communicationprocessor = processor::load_by_instance(
$component,
$instancetype,
$instanceid);
$instanceid
);
$this->assertNull($communicationprocessor);
}