Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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_numerrors_privacy_provider_testcase} class.
  19   *
  20   * @package     workshopform_numerrors
  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  use core_privacy\tests\provider_testcase;
  32  
  33  /**
  34   * Unit tests for the privacy API implementation.
  35   *
  36   * @copyright 2018 David Mudrák <david@moodle.com>
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class workshopform_numerrors_privacy_provider_testcase extends provider_testcase {
  40  
  41      /**
  42       * Test {@link workshopform_numerrors\privacy\provider::export_assessment_form()} implementation.
  43       */
  44      public function test_export_assessment_form() {
  45          global $DB;
  46          $this->resetAfterTest();
  47          $this->setAdminUser();
  48  
  49          $this->generator = $this->getDataGenerator();
  50          $this->workshopgenerator = $this->generator->get_plugin_generator('mod_workshop');
  51  
  52          $this->course1 = $this->generator->create_course();
  53  
  54          $this->workshop11 = $this->generator->create_module('workshop', [
  55              'course' => $this->course1,
  56              'name' => 'Workshop11',
  57          ]);
  58          $DB->set_field('workshop', 'phase', 50, ['id' => $this->workshop11->id]);
  59  
  60          $this->dim1 = $DB->insert_record('workshopform_numerrors', [
  61              'workshopid' => $this->workshop11->id,
  62              'sort' => 1,
  63              'description' => 'Assertion 1 description',
  64              'descriptionformat' => FORMAT_MARKDOWN,
  65              'descriptiontrust' => 0,
  66              'grade0' => 'No',
  67              'grade1' => 'Yes',
  68              'weight' => 1,
  69          ]);
  70  
  71          $this->dim2 = $DB->insert_record('workshopform_numerrors', [
  72              'workshopid' => $this->workshop11->id,
  73              'sort' => 2,
  74              'description' => 'Assertion 2 description',
  75              'descriptionformat' => FORMAT_MARKDOWN,
  76              'descriptiontrust' => 0,
  77              'grade0' => 'Missing',
  78              'grade1' => 'Present',
  79              'weight' => 1,
  80          ]);
  81  
  82          $this->student1 = $this->generator->create_user();
  83          $this->student2 = $this->generator->create_user();
  84  
  85          $this->submission111 = $this->workshopgenerator->create_submission($this->workshop11->id, $this->student1->id);
  86  
  87          $this->assessment1112 = $this->workshopgenerator->create_assessment($this->submission111, $this->student2->id, [
  88              'grade' => 92,
  89          ]);
  90  
  91          $DB->insert_record('workshop_grades', [
  92              'assessmentid' => $this->assessment1112,
  93              'strategy' => 'numerrors',
  94              'dimensionid' => $this->dim1,
  95              'grade' => 1,
  96              'peercomment' => 'Awesome',
  97              'peercommentformat' => FORMAT_PLAIN,
  98          ]);
  99  
 100          $DB->insert_record('workshop_grades', [
 101              'assessmentid' => $this->assessment1112,
 102              'strategy' => 'numerrors',
 103              'dimensionid' => $this->dim2,
 104              'grade' => 0,
 105              'peercomment' => 'Missing',
 106              'peercommentformat' => FORMAT_PLAIN,
 107          ]);
 108  
 109          $contextlist = new \core_privacy\local\request\approved_contextlist($this->student2, 'mod_workshop', [
 110              \context_module::instance($this->workshop11->cmid)->id,
 111          ]);
 112  
 113          \mod_workshop\privacy\provider::export_user_data($contextlist);
 114  
 115          $writer = writer::with_context(\context_module::instance($this->workshop11->cmid));
 116  
 117          $form = $writer->get_data([
 118              get_string('myassessments', 'mod_workshop'),
 119              $this->assessment1112,
 120              get_string('assessmentform', 'mod_workshop'),
 121              get_string('pluginname', 'workshopform_numerrors'),
 122          ]);
 123  
 124          $this->assertEquals('Assertion 1 description', $form->assertions[0]->description);
 125          $this->assertEquals(0, $form->assertions[1]->grade);
 126          $this->assertEquals('Missing', $form->assertions[1]->peercomment);
 127      }
 128  }