Skip to content

Commit

Permalink
Update behat testing to always use test config in test-sandbox-config…
Browse files Browse the repository at this point in the history
….php.
  • Loading branch information
trampgeek committed Mar 15, 2024
1 parent 73d0e3c commit fb2f72e
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 19 deletions.
10 changes: 3 additions & 7 deletions classes/jobesandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,10 @@ class qtype_coderunner_jobesandbox extends qtype_coderunner_sandbox {
public function __construct() {
global $CFG;
qtype_coderunner_sandbox::__construct();

// Hack to force use of a local jobe host when behat testing.
if ($CFG->prefix == "bht_") {
$this->jobeserver = "localhost";
} else {
$this->jobeserver = get_config('qtype_coderunner', 'jobe_host');
$this->jobeserver = get_config('qtype_coderunner', 'jobe_host');
if ($this->jobeserver === 'jobe2.cosc.canterbury.ac.nz' && $CFG->prefix === $CFG->behat_prefix) {
throw new Exception("Please don't use the Canterbury jobe server for test runs");
}

$this->apikey = get_config('qtype_coderunner', 'jobe_apikey');
$this->languages = null;
}
Expand Down
4 changes: 4 additions & 0 deletions classes/sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

global $CFG;

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

abstract class qtype_coderunner_sandbox {
protected $user; // Username supplied when constructing.
protected $password; // Password supplied when constructing.
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 !== "b_") {
if ($CFG->prefix !== $CFG->behat_prefix) {
$method = method_exists($mform, 'hideIf') ? 'hideIf' : 'disabledIf';
$mform->$method('sampleanswerattachments', 'attachments', 'eq', 0);
}
Expand Down
2 changes: 1 addition & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ 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 !== 'b_') {
if ($jobeserver == constants::JOBE_HOST_DEFAULT && $CFG->prefix !== $CFG->behat_prefix) {
if ($apikey == constants::JOBE_HOST_DEFAULT_API_KEY) {
$fb .= get_string('jobe_warning_html', 'qtype_coderunner');
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/ace_scratchpad_compatibility.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Ace UI convert to Scratchpad UI questions with one click
And the following "questions" exist:
| questioncategory | qtype | name |
| Test questions | coderunner | Square function |
And the CodeRunner sandbox is enabled
And the CodeRunner webservice is enabled

When I am on the "Square function" "core_question > edit" page logged in as teacher1
And I set the following fields to these values:
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/attachmentimportexport.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Test importing and exporting of question with attachments
And the following "questions" exist:
| questioncategory | qtype | name |
| Test questions | coderunner | Square function |
And the CodeRunner sandbox is enabled
And the CodeRunner webservice is enabled
And I am on the "Square function" "core_question > edit" page logged in as teacher
And I click on "a[aria-controls='id_attachmentoptionscontainer']" "css_element"
And I set the field "Answer" to "from sqrmodule import sqr"
Expand Down
6 changes: 2 additions & 4 deletions tests/behat/behat_coderunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ class behat_coderunner extends behat_base {
/**
* Sets the webserver sandbox to enabled for testing purposes.
*
* @Given /^the CodeRunner sandbox is enabled/
* @Given /^the CodeRunner webservice is enabled/
*/
public function the_coderunner_sandbox_is_enabled() {
public function the_coderunner_webservice_is_enabled() {
set_config('wsenabled', 1, 'qtype_coderunner');
set_config('jobesandbox_enabled', 1, 'qtype_coderunner');
set_config('jobe_host', '172.17.0.1:4000', 'qtype_coderunner');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/scratchpad_ui.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Test the Scratchpad UI
And the following "questions" exist:
| questioncategory | qtype | name | template |
| Test questions | coderunner | Print answer | printans |
And the CodeRunner sandbox is enabled
And the CodeRunner webservice is enabled

Scenario: Edit a CodeRunner question into a Scratchpad UI question
When I am on the "Print answer" "core_question > edit" page logged in as teacher1
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/scratchpad_ui_params.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Test the Scratchpad UI, UI Params
And the following "questions" exist:
| questioncategory | qtype | name | template |
| Test questions | coderunner | Print answer | printans |
And the CodeRunner sandbox is enabled
And the CodeRunner webservice is enabled

And I am on the "Print answer" "core_question > edit" page logged in as teacher1
And I set the field "id_validateonsave" to ""
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

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

$plugin->version = 2024022800;
$plugin->version = 2024031500;
$plugin->requires = 2022041900;
$plugin->cron = 0;
$plugin->component = 'qtype_coderunner';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '5.3.0';
$plugin->release = '5.3.1';

$plugin->dependencies = [
'qbehaviour_adaptive_adapted_for_coderunner' => 2021112300,
Expand Down

0 comments on commit fb2f72e

Please sign in to comment.