Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310]

   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   * Provides the {@link workshopform_rubric_privacy_provider_testcase} class.
  19   *
  20   * @package     workshopform_rubric
  21   * @category    test
  22   * @copyright   2018 David Mudrák <david@moodle.com>
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  
  30  use core_privacy\local\request\writer;
  31  
  32  /**
  33   * Unit tests for the privacy API implementation.
  34   *
  35   * @copyright 2018 David Mudrák <david@moodle.com>
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class workshopform_rubric_privacy_provider_testcase extends advanced_testcase {
  39  
  40      /**
  41       * Test {@link workshopform_rubric\privacy\provider::export_assessment_form()} implementation.
  42       */
  43      public function test_export_assessment_form() {
  44          global $DB;
  45          $this->resetAfterTest();
  46          $this->setAdminUser();
  47  
  48          $this->generator = $this->getDataGenerator();
  49          $this->workshopgenerator = $this->generator->get_plugin_generator('mod_workshop');
  50  
  51          $this->course1 = $this->generator->create_course();
  52  
  53          $this->workshop11 = $this->generator->create_module('workshop', [
  54              'course' => $this->course1,
  55              'name' => 'Workshop11',
  56          ]);
  57          $DB->set_field('workshop', 'phase', 50, ['id' => $this->workshop11->id]);
  58  
  59          $this->dim1 = $DB->insert_record('workshopform_rubric', [
  60              'workshopid' => $this->workshop11->id,
  61              'sort' => 1,
  62              'description' => 'Criterion 1 description',
  63              'descriptionformat' => FORMAT_MARKDOWN,
  64          ]);
  65  
  66          $DB->insert_record('workshopform_rubric_levels', [
  67              'dimensionid' => $this->dim1,
  68              'grade' => 0,
  69              'definition' => 'Missing',
  70              'definitionformat' => FORMAT_PLAIN,
  71          ]);
  72  
  73          $DB->insert_record('workshopform_rubric_levels', [
  74              'dimensionid' => $this->dim1,
  75              'grade' => 1,
  76              'definition' => 'Poor',
  77              'definitionformat' => FORMAT_PLAIN,
  78          ]);
  79  
  80          $DB->insert_record('workshopform_rubric_levels', [
  81              'dimensionid' => $this->dim1,
  82              'grade' => 2,
  83              'definition' => 'Good',
  84              'definitionformat' => FORMAT_PLAIN,
  85          ]);
  86  
  87          $this->dim2 = $DB->insert_record('workshopform_rubric', [
  88              'workshopid' => $this->workshop11->id,
  89              'sort' => 2,
  90              'description' => 'Criterion 2 description',
  91              'descriptionformat' => FORMAT_MARKDOWN,
  92          ]);
  93  
  94          $DB->insert_record('workshopform_rubric_levels', [
  95              'dimensionid' => $this->dim2,
  96              'grade' => 0,
  97              'definition' => 'Missing',
  98              'definitionformat' => FORMAT_PLAIN,
  99          ]);
 100  
 101          $DB->insert_record('workshopform_rubric_levels', [
 102              'dimensionid' => $this->dim2,
 103              'grade' => 5,
 104              'definition' => 'Great',
 105              'definitionformat' => FORMAT_PLAIN,
 106          ]);
 107  
 108          $this->student1 = $this->generator->create_user();
 109          $this->student2 = $this->generator->create_user();
 110  
 111          $this->submission111 = $this->workshopgenerator->create_submission($this->workshop11->id, $this->student1->id);
 112  
 113          $this->assessment1112 = $this->workshopgenerator->create_assessment($this->submission111, $this->student2->id, [
 114              'grade' => 92,
 115          ]);
 116  
 117          $DB->insert_record('workshop_grades', [
 118              'assessmentid' => $this->assessment1112,
 119              'strategy' => 'rubric',
 120              'dimensionid' => $this->dim1,
 121              'grade' => 1,
 122              'peercomment' => '',
 123              'peercommentformat' => FORMAT_PLAIN,
 124          ]);
 125  
 126          $DB->insert_record('workshop_grades', [
 127              'assessmentid' => $this->assessment1112,
 128              'strategy' => 'rubric',
 129              'dimensionid' => $this->dim2,
 130              'grade' => 5,
 131              'peercomment' => '',
 132              'peercommentformat' => FORMAT_PLAIN,
 133          ]);
 134  
 135          $contextlist = new \core_privacy\local\request\approved_contextlist($this->student2, 'mod_workshop', [
 136              \context_module::instance($this->workshop11->cmid)->id,
 137          ]);
 138  
 139          \mod_workshop\privacy\provider::export_user_data($contextlist);
 140  
 141          $writer = writer::with_context(\context_module::instance($this->workshop11->cmid));
 142  
 143          $form = $writer->get_data([
 144              get_string('myassessments', 'mod_workshop'),
 145              $this->assessment1112,
 146              get_string('assessmentform', 'mod_workshop'),
 147              get_string('pluginname', 'workshopform_rubric'),
 148          ]);
 149  
 150          $this->assertEquals('Criterion 1 description', $form->criteria[0]->description);
 151          $this->assertEquals(3, count($form->criteria[0]->levels));
 152          $this->assertEquals(2, count($form->criteria[1]->levels));
 153          $this->assertEquals(5, $form->criteria[1]->grade);
 154      }
 155  }