Skip to content

Commit

Permalink
MDL-78337 tool_brickfield: Attempt immediate validation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlkin committed Aug 16, 2024
1 parent a75365f commit a68496f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
13 changes: 12 additions & 1 deletion admin/tool/brickfield/classes/brickfieldconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
require_once("{$CFG->libdir}/filelib.php");

use curl;
use ErrorException;
use moodle_url;

/**
Expand Down Expand Up @@ -122,7 +123,12 @@ protected function get_url_for_command(array $command): string {
protected function call(array $command, $params = ''): string {
$url = $this->get_url_for_command($command);
if ($command['method'] === 'get') {
return $this->get($url, $params);
try {
return $this->get($url, $params);
} catch (ErrorException $e) {
// URL blocked or otherwise inaccessible.
return '';
}
}

if ($command['method'] === 'post') {
Expand Down Expand Up @@ -210,6 +216,11 @@ protected function get_registration_id_for_credentials(string $apikey = null, st
$this->set_headers($headers);
$response = $this->call(self::ACTION_CHECK_REGISTRATION);

if (empty($this->info['http_code'])) {
// The response was blocked.
return '';
}

if ((int)$this->info['http_code'] !== 200) {
// The response was unsuccessful.
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ class i_is_not_used extends brickfield_accessibility_tag_test {

/** @var string The tag this test will fire on. */
public $tag = 'i';

}
7 changes: 7 additions & 0 deletions admin/tool/brickfield/classes/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ public function set_keys_for_registration(string $apikey, string $secretkey): bo
$this->set_api_key($apikey);
$this->set_secret_key($secretkey);
$this->set_not_validated();
// Attempt to validate the registration.
$this->validate();
if (!$this->status_is_validated()) {
// If the validation failed here, start the grace period.
$this->set_not_validated();
$this->set_summary_time();
}
if ($this->summarytime <= 0) {
$this->set_summary_time();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ public function test_check(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}

/**
* Test for font awesome icon
*/
public function test_fa_icon(): void {
$html = "<div><i class=\"fa fa-user\"></i><i>Hello there</i><i class=\"fa fa-address-book\" aria-hidden=\"true\"></i></div>";
$results = $this->get_checker_results($html);
$this->assertCount(2, $results);
}
}
3 changes: 2 additions & 1 deletion admin/tool/brickfield/tests/registration_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function test_set_keys_for_registration(): void {
// State when valid format keys are sent.
$this->assertTrue($regobj->set_keys_for_registration(mock_brickfieldconnect::VALIDAPIKEY,
mock_brickfieldconnect::VALIDSECRETKEY));
$this->assertTrue($regobj->validation_pending());
$this->assertTrue($regobj->toolkit_is_active());
$this->assertFalse($regobj->validation_pending());
$this->assertEquals($regobj->get_api_key(), mock_brickfieldconnect::VALIDAPIKEY);
$this->assertEquals($regobj->get_secret_key(), mock_brickfieldconnect::VALIDSECRETKEY);
}
Expand Down

0 comments on commit a68496f

Please sign in to comment.