Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 311 and 403]

   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 {@see workshopform_comments\privacy\provider_test} class.
  19   *
  20   * @package     workshopform_comments
  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  namespace workshopform_comments\privacy;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  global $CFG;
  30  
  31  use core_privacy\local\request\writer;
  32  use core_privacy\tests\provider_testcase;
  33  
  34  /**
  35   * Unit tests for the privacy API implementation.
  36   *
  37   * @copyright 2018 David Mudrák <david@moodle.com>
  38   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class provider_test extends provider_testcase {
  41  
  42      /**
  43       * Test {@link workshopform_comments\privacy\provider::export_assessment_form()} implementation.
  44       */
  45      public function test_export_assessment_form() {
  46          global $DB;
  47          $this->resetAfterTest();
  48          $this->setAdminUser();
  49  
  50          $this->generator = $this->getDataGenerator();
  51          $this->workshopgenerator = $this->generator->get_plugin_generator('mod_workshop');
  52  
  53          $this->course1 = $this->generator->create_course();
  54  
  55          $this->workshop11 = $this->generator->create_module('workshop', [
  56              'course' => $this->course1,
  57              'name' => 'Workshop11',
  58          ]);
  59          $DB->set_field('workshop', 'phase', 100, ['id' => $this->workshop11->id]);
  60  
  61          $this->dim1 = $DB->insert_record('workshopform_comments', [
  62              'workshopid' => $this->workshop11->id,
  63              'sort' => 1,
  64              'description' => 'Aspect 1 description',
  65              'descriptionformat' => FORMAT_MARKDOWN,
  66          ]);
  67  
  68          $this->dim2 = $DB->insert_record('workshopform_comments', [
  69              'workshopid' => $this->workshop11->id,
  70              'sort' => 2,
  71              'description' => 'Aspect 2 description',
  72              'descriptionformat' => FORMAT_MARKDOWN,
  73          ]);
  74  
  75          $this->student1 = $this->generator->create_user();
  76          $this->student2 = $this->generator->create_user();
  77  
  78          $this->submission111 = $this->workshopgenerator->create_submission($this->workshop11->id, $this->student1->id);
  79  
  80          $this->assessment1112 = $this->workshopgenerator->create_assessment($this->submission111, $this->student2->id, [
  81              'grade' => 92,
  82          ]);
  83  
  84          $DB->insert_record('workshop_grades', [
  85              'assessmentid' => $this->assessment1112,
  86              'strategy' => 'comments',
  87              'dimensionid' => $this->dim1,
  88              'grade' => 100,
  89              'peercomment' => 'Not awesome',
  90              'peercommentformat' => FORMAT_PLAIN,
  91          ]);
  92  
  93          $DB->insert_record('workshop_grades', [
  94              'assessmentid' => $this->assessment1112,
  95              'strategy' => 'comments',
  96              'dimensionid' => $this->dim2,
  97              'grade' => 100,
  98              'peercomment' => 'All good',
  99              'peercommentformat' => FORMAT_PLAIN,
 100          ]);
 101  
 102          $contextlist = new \core_privacy\local\request\approved_contextlist($this->student2, 'mod_workshop', [
 103              \context_module::instance($this->workshop11->cmid)->id,
 104          ]);
 105  
 106          \mod_workshop\privacy\provider::export_user_data($contextlist);
 107  
 108          $writer = writer::with_context(\context_module::instance($this->workshop11->cmid));
 109  
 110          $form = $writer->get_data([
 111              get_string('myassessments', 'mod_workshop'),
 112              $this->assessment1112,
 113              get_string('assessmentform', 'mod_workshop'),
 114              get_string('pluginname', 'workshopform_comments'),
 115          ]);
 116  
 117          $this->assertEquals('Aspect 1 description', $form->aspects[0]->description);
 118          $this->assertEquals('All good', $form->aspects[1]->peercomment);
 119      }
 120  }