Skip to content

Commit

Permalink
MDL-72143 airnotifier: Additional configuration check
Browse files Browse the repository at this point in the history
Additional check for $CFG->noemailever
  • Loading branch information
jleyva committed Jul 28, 2021
1 parent 8c0853d commit 1f5ceda
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
9 changes: 9 additions & 0 deletions message/output/airnotifier/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ public function check_configuration(): array {
$results[] = new core\check\result(core\check\result::OK, $summary, get_string('enabled', 'admin'));
}

// Check message outputs are not disabled in config.php.
$summary = get_string('noemailevernotset', 'message_airnotifier');
if (!empty($CFG->noemailever)) {
$results[] = new core\check\result(core\check\result::CRITICAL, $summary,
get_string('noemaileverset', 'message_airnotifier'));
} else {
$results[] = new core\check\result(core\check\result::OK, $summary, get_string('disabled', 'admin'));
}

// Check Mobile notifications enabled.
require_once($CFG->dirroot . '/message/lib.php');
$processors = get_message_processors();
Expand Down
2 changes: 2 additions & 0 deletions message/output/airnotifier/lang/en/message_airnotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
$string['messageproviderslow'] = 'Only a few mobile notifications are enabled in default notification preferences.';
$string['moodleappsportallimitswarning'] = 'Please note that the number of user devices allowed to receive notifications depends on your Moodle app subscription. For details, visit the <a href="{$a}" target="_blank">Moodle Apps Portal</a>.';
$string['nodevices'] = 'No registered devices. Devices will automatically appear after you install the Moodle app and add this site.';
$string['noemailevernotset'] = '$CFG->noemailever disabled';
$string['noemaileverset'] = '$CFG->noemailever is enabled in config.php. You need to set this setting to false or remove it.';
$string['nopermissiontomanagedevices'] = 'You don\'t have permission to manage devices.';
$string['notconfigured'] = 'The Airnotifier server has not been configured so push notifications cannot be sent.';
$string['notificationsserverconfiguration'] = 'Notifications server (Airnotifier) configuration';
Expand Down
39 changes: 22 additions & 17 deletions message/output/airnotifier/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ public function test_check_configuration_default() {
$checks = $manager->check_configuration();

$this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::ERROR, $checks[2]->get_status()); // Airnotifier NOT configured, missing key.
$this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier URL available.
$this->assertEquals(core\check\result::ERROR, $checks[4]->get_status()); // Missing access key.
$this->assertEquals(core\check\result::WARNING, $checks[5]->get_status()); // Only a few of default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[6]->get_status()); // No registered devices yet.
$this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Message output not disabled in config.php.
$this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::ERROR, $checks[3]->get_status()); // Airnotifier NOT configured, missing key.
$this->assertEquals(core\check\result::OK, $checks[4]->get_status()); // Airnotifier URL available.
$this->assertEquals(core\check\result::ERROR, $checks[5]->get_status()); // Missing access key.
$this->assertEquals(core\check\result::WARNING, $checks[6]->get_status()); // Only a few of default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[7]->get_status()); // No registered devices yet.
}

/** Test check_configuration with token **/
Expand All @@ -61,12 +62,13 @@ public function test_check_configuration_with_token() {
$checks = $manager->check_configuration();

$this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Airnotifier configured.
$this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier URL available.
$this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Message output not disabled in config.php.
$this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier configured.
$this->assertEquals(core\check\result::OK, $checks[4]->get_status()); // Airnotifier URL available.
// The original function fourth check (access key valid in the remote Airnotifier server) is not mockable.
$this->assertEquals(core\check\result::WARNING, $checks[4]->get_status()); // Only a few of default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[5]->get_status()); // No registered devices yet.
$this->assertEquals(core\check\result::WARNING, $checks[5]->get_status()); // Only a few of default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[6]->get_status()); // No registered devices yet.
}

/** Test check_configuration bad settings **/
Expand All @@ -82,16 +84,19 @@ public function test_check_configuration_incorrect_settings() {
curl::mock_response(json_encode(['error' => 'Invalid access key'])); // Mock second request to check acces key.
$CFG->airnotifieraccesskey = 'test'; // For enabling Airnotifier.
$CFG->airnotifierappname .= ' ';

$CFG->noemailever = true;
$checks = $manager->check_configuration();

$this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Airnotifier configured.
$this->assertEquals(core\check\result::ERROR, $checks[3]->get_status()); // Airnotifier URL available.
$this->assertEquals(core\check\result::OK, $checks[4]->get_status()); // Invalid setting (empty space).
$this->assertEquals(core\check\result::CRITICAL, $checks[1]->get_status()); // Message output disabled in config.php.
$this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier configured.
$this->assertEquals(core\check\result::ERROR, $checks[4]->get_status()); // Airnotifier URL available.
$this->assertEquals(core\check\result::OK, $checks[5]->get_status()); // Invalid setting (empty space).
// The original function fifth check (access key valid in the remote Airnotifier server) is not mockable.
$this->assertEquals(core\check\result::WARNING, $checks[5]->get_status()); // Only a few of default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[6]->get_status()); // No registered devices yet.
$this->assertEquals(core\check\result::WARNING, $checks[6]->get_status()); // Only a few of default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[7]->get_status()); // No registered devices yet.
}

/** Test has_enabled_devices **/
Expand Down

0 comments on commit 1f5ceda

Please sign in to comment.