PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/question/behaviour/informationitem/tests/walkthrough_test.php

https://bitbucket.org/moodle/moodle
PHP | 90 lines | 44 code | 16 blank | 30 comment | 1 complexity | e0c42eb5bfcb46d6ee21c06f1ce663f0 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  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. namespace qbehaviour_informationitem;
  17. use question_state;
  18. defined('MOODLE_INTERNAL') || die();
  19. global $CFG;
  20. require_once(__DIR__ . '/../../../engine/lib.php');
  21. require_once(__DIR__ . '/../../../engine/tests/helpers.php');
  22. /**
  23. * Unit tests for the information item behaviour.
  24. *
  25. * @package qbehaviour_informationitem
  26. * @category test
  27. * @copyright 2009 The Open University
  28. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29. */
  30. class walkthrough_test extends \qbehaviour_walkthrough_test_base {
  31. public function test_informationitem_feedback_description() {
  32. // Create a true-false question with correct answer true.
  33. $description = \test_question_maker::make_question('description');
  34. $this->start_attempt_at_question($description, 'deferredfeedback');
  35. // Check the initial state.
  36. $this->check_current_state(question_state::$todo);
  37. $this->check_current_mark(null);
  38. $this->check_current_output($this->get_contains_question_text_expectation($description),
  39. $this->get_contains_hidden_expectation(
  40. $this->quba->get_field_prefix($this->slot) . '-seen', 1),
  41. $this->get_does_not_contain_feedback_expectation());
  42. // Check no hidden input when read-only.
  43. $this->displayoptions->readonly = true;
  44. $this->check_current_output($this->get_contains_question_text_expectation($description),
  45. $this->get_does_not_contain_hidden_expectation(
  46. $this->quba->get_field_prefix($this->slot) . '-seen', 1));
  47. $this->displayoptions->readonly = false;
  48. // Process a submission indicating this question has been seen.
  49. $this->process_submission(array('-seen' => 1));
  50. $this->check_current_state(question_state::$complete);
  51. $this->check_current_mark(null);
  52. $this->check_current_output($this->get_does_not_contain_correctness_expectation(),
  53. new \question_no_pattern_expectation(
  54. '/type=\"hidden\"[^>]*name=\"[^"]*seen\"|name=\"[^"]*seen\"[^>]*type=\"hidden\"/'),
  55. $this->get_does_not_contain_feedback_expectation());
  56. // Finish the attempt.
  57. $this->quba->finish_all_questions();
  58. // Verify.
  59. $this->check_current_state(question_state::$finished);
  60. $this->check_current_mark(null);
  61. $this->check_current_output(
  62. $this->get_contains_question_text_expectation($description),
  63. $this->get_contains_general_feedback_expectation($description));
  64. // Process a manual comment.
  65. $this->manual_grade('Not good enough!', null, FORMAT_HTML);
  66. $this->check_current_state(question_state::$manfinished);
  67. $this->check_current_mark(null);
  68. $this->check_current_output(
  69. new \question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
  70. // Check that trying to process a manual comment with a grade causes an exception.
  71. $this->expectException('moodle_exception');
  72. $this->manual_grade('Not good enough!', 1, FORMAT_HTML);
  73. }
  74. }