/question/type/calculatedsimple/simpletest/testwalkthrough.php

https://github.com/nigeldaley/moodle · PHP · 104 lines · 54 code · 14 blank · 36 comment · 1 complexity · d093b0e3dd60b800719848a36c3a6def MD5 · raw file

  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This file contains overall tests of simple calculated questions.
  18. *
  19. * @package qtype
  20. * @subpackage calculatedsimple
  21. * @copyright 2011 The Open University
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
  26. /**
  27. * Unit tests for the simple calculated question type.
  28. *
  29. * @copyright 2011 The Open University
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. class qtype_calculatedsimple_walkthrough_test extends qbehaviour_walkthrough_test_base {
  33. public function test_interactive() {
  34. // Create a gapselect question.
  35. $q = test_question_maker::make_question('calculatedsimple');
  36. $q->hints = array(
  37. new question_hint(1, 'This is the first hint.', FORMAT_HTML),
  38. new question_hint(2, 'This is the second hint.', FORMAT_HTML),
  39. );
  40. $this->start_attempt_at_question($q, 'interactive', 3);
  41. $values = $q->vs->get_values();
  42. // Check the initial state.
  43. $this->check_current_state(question_state::$todo);
  44. $this->check_current_mark(null);
  45. $this->check_current_output(
  46. $this->get_contains_marked_out_of_summary(),
  47. $this->get_contains_submit_button_expectation(true),
  48. $this->get_does_not_contain_feedback_expectation(),
  49. $this->get_does_not_contain_validation_error_expectation(),
  50. $this->get_does_not_contain_try_again_button_expectation(),
  51. $this->get_no_hint_visible_expectation());
  52. // Submit blank.
  53. $this->process_submission(array('-submit' => 1, 'answer' => ''));
  54. // Verify.
  55. $this->check_current_state(question_state::$invalid);
  56. $this->check_current_mark(null);
  57. $this->check_current_output(
  58. $this->get_contains_marked_out_of_summary(),
  59. $this->get_contains_submit_button_expectation(true),
  60. $this->get_does_not_contain_feedback_expectation(),
  61. $this->get_contains_validation_error_expectation(),
  62. $this->get_does_not_contain_try_again_button_expectation(),
  63. $this->get_no_hint_visible_expectation());
  64. // Sumit something that does not look like a number.
  65. $this->process_submission(array('-submit' => 1, 'answer' => 'newt'));
  66. // Verify.
  67. $this->check_current_state(question_state::$invalid);
  68. $this->check_current_mark(null);
  69. $this->check_current_output(
  70. $this->get_contains_marked_out_of_summary(),
  71. $this->get_contains_submit_button_expectation(true),
  72. $this->get_does_not_contain_feedback_expectation(),
  73. $this->get_contains_validation_error_expectation(),
  74. new PatternExpectation('/' .
  75. preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
  76. $this->get_does_not_contain_try_again_button_expectation(),
  77. $this->get_no_hint_visible_expectation());
  78. // Now get it right.
  79. $this->process_submission(array('-submit' => 1, 'answer' => $values['a'] + $values['b']));
  80. // Verify.
  81. $this->check_current_state(question_state::$gradedright);
  82. $this->check_current_mark(3);
  83. $this->check_current_output(
  84. $this->get_contains_mark_summary(3),
  85. $this->get_contains_submit_button_expectation(false),
  86. $this->get_contains_correct_expectation(),
  87. $this->get_does_not_contain_validation_error_expectation(),
  88. $this->get_no_hint_visible_expectation());
  89. }
  90. }