Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning - undefined property behat_prefix #208

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion classes/jobesandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function __construct() {
global $CFG;
qtype_coderunner_sandbox::__construct();
$this->jobeserver = get_config('qtype_coderunner', 'jobe_host');
if ($this->jobeserver === 'jobe2.cosc.canterbury.ac.nz' && $CFG->prefix === $CFG->behat_prefix) {
if (qtype_coderunner_sandbox::is_canterbury_server($this->jobeserver)
&& qtype_coderunner_sandbox::is_using_test_sandbox()) {
throw new Exception("Please don't use the Canterbury jobe server for test runs");
}
$this->apikey = get_config('qtype_coderunner', 'jobe_apikey');
Expand Down
22 changes: 21 additions & 1 deletion classes/sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@

defined('MOODLE_INTERNAL') || die();

use qtype_coderunner\constants;

global $CFG;

if ($CFG->prefix == $CFG->behat_prefix) {
if (qtype_coderunner_sandbox::is_using_test_sandbox()) {
require_once($CFG->dirroot .'/question/type/coderunner/tests/fixtures/test-sandbox-config.php');
}

Expand Down Expand Up @@ -209,6 +211,24 @@ public static function enabled_sandboxes() {
return $enabled;
}

/**
* Returns true if sandbox is being used for tests.
* @return bool
*/
public static function is_using_test_sandbox(): bool {
global $CFG;
return !empty($CFG->behat_prefix) && $CFG->prefix === $CFG->behat_prefix;
}

/**
* Returns true if canterbury jobe server is being used.
* @param string jobeserver being used.
* @return bool
*/
public static function is_canterbury_server(string $jobeserver): bool {
return $jobeserver === constants::JOBE_HOST_DEFAULT;
}

/**
* Get the filename containing the given external sandbox name.
* @param string $externalsandboxname
Expand Down
2 changes: 1 addition & 1 deletion edit_coderunner_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected function add_sample_answer_field($mform) {
$mform->addHelpButton('sampleanswerattachments', 'sampleanswerattachments', 'qtype_coderunner');
// Unless behat is running, hide the attachments file picker.
// behat barfs if it's hidden.
if ($CFG->prefix !== $CFG->behat_prefix) {
if (!qtype_coderunner_sandbox::is_using_test_sandbox()) {
$method = method_exists($mform, 'hideIf') ? 'hideIf' : 'disabledIf';
$mform->$method('sampleanswerattachments', 'attachments', 'eq', 0);
}
Expand Down
3 changes: 2 additions & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ protected function build_results_table($outcome, qtype_coderunner_question $ques
if (isset($sandboxinfo['jobeserver'])) {
$jobeserver = $sandboxinfo['jobeserver'];
$apikey = $sandboxinfo['jobeapikey'];
if ($jobeserver == constants::JOBE_HOST_DEFAULT && $CFG->prefix !== $CFG->behat_prefix) {
if (qtype_coderunner_sandbox::is_canterbury_server($jobeserver)
&& (!qtype_coderunner_sandbox::is_using_test_sandbox())) {
if ($apikey == constants::JOBE_HOST_DEFAULT_API_KEY) {
$fb .= get_string('jobe_warning_html', 'qtype_coderunner');
} else {
Expand Down
Loading