[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/feedback/comments/tests/ -> comments_test.php (source)

   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  /**
  18   * Unit tests for assignfeedback_comments
  19   *
  20   * @package    assignfeedback_comments
  21   * @copyright  2016 Adrian Greeve <adrian@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  global $CFG;
  28  require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
  29  
  30  /**
  31   * Unit tests for assignfeedback_comments
  32   *
  33   * @copyright  2016 Adrian Greeve <adrian@moodle.com>
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class assignfeedback_comments_testcase extends mod_assign_base_testcase {
  37  
  38      /**
  39       * Create an assign object and submit an online text submission.
  40       */
  41      protected function create_assign_and_submit_text() {
  42          $assign = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1,
  43                                                 'assignfeedback_comments_enabled' => 1));
  44  
  45          $user = $this->students[0];
  46          $this->setUser($user);
  47  
  48          // Create an online text submission.
  49          $submission = $assign->get_user_submission($user->id, true);
  50  
  51          $data = new stdClass();
  52          $data->onlinetext_editor = array(
  53                  'text' => '<p>This is some text.</p>',
  54                  'format' => 1,
  55                  'itemid' => file_get_unused_draft_itemid());
  56          $plugin = $assign->get_submission_plugin_by_type('onlinetext');
  57          $plugin->save($submission, $data);
  58  
  59          return $assign;
  60      }
  61  
  62      /**
  63       * Test the is_feedback_modified() method for the comments feedback.
  64       */
  65      public function test_is_feedback_modified() {
  66          $assign = $this->create_assign_and_submit_text();
  67  
  68          $this->setUser($this->teachers[0]);
  69  
  70          // Create formdata.
  71          $data = new stdClass();
  72          $data->assignfeedbackcomments_editor = array(
  73                  'text' => '<p>first comment for this test</p>',
  74                  'format' => 1
  75              );
  76          $grade = $assign->get_user_grade($this->students[0]->id, true);
  77  
  78          // This is the first time that we are submitting feedback, so it is modified.
  79          $plugin = $assign->get_feedback_plugin_by_type('comments');
  80          $this->assertTrue($plugin->is_feedback_modified($grade, $data));
  81          // Save the feedback.
  82          $plugin->save($grade, $data);
  83          // Try again with the same data.
  84          $this->assertFalse($plugin->is_feedback_modified($grade, $data));
  85          // Change the data.
  86          $data->assignfeedbackcomments_editor = array(
  87                  'text' => '<p>Altered comment for this test</p>',
  88                  'format' => 1
  89              );
  90          $this->assertTrue($plugin->is_feedback_modified($grade, $data));
  91      }
  92  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1