Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 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_accumulative\provider_test} class.
  19   *
  20   * @package     workshopform_accumulative
  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_accumulative\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_accumulative\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', 50, ['id' => $this->workshop11->id]);
  60  
  61          $this->dim1 = $DB->insert_record('workshopform_accumulative', [
  62              'workshopid' => $this->workshop11->id,
  63              'sort' => 1,
  64              'description' => 'Aspect 1 description',
  65              'descriptionformat' => FORMAT_MARKDOWN,
  66              'grade' => 6,
  67              'weight' => 1,
  68          ]);
  69  
  70          $this->dim2 = $DB->insert_record('workshopform_accumulative', [
  71              'workshopid' => $this->workshop11->id,
  72              'sort' => 2,
  73              'description' => 'Aspect 2 description',
  74              'descriptionformat' => FORMAT_MARKDOWN,
  75              'grade' => 4,
  76              'weight' => 1,
  77          ]);
  78  
  79          $this->student1 = $this->generator->create_user();
  80          $this->student2 = $this->generator->create_user();
  81  
  82          $this->submission111 = $this->workshopgenerator->create_submission($this->workshop11->id, $this->student1->id);
  83  
  84          $this->assessment1112 = $this->workshopgenerator->create_assessment($this->submission111, $this->student2->id, [
  85              'grade' => 92,
  86          ]);
  87  
  88          $DB->insert_record('workshop_grades', [
  89              'assessmentid' => $this->assessment1112,
  90              'strategy' => 'accumulative',
  91              'dimensionid' => $this->dim1,
  92              'grade' => 3,
  93              'peercomment' => 'Not awesome',
  94              'peercommentformat' => FORMAT_PLAIN,
  95          ]);
  96  
  97          $DB->insert_record('workshop_grades', [
  98              'assessmentid' => $this->assessment1112,
  99              'strategy' => 'accumulative',
 100              'dimensionid' => $this->dim2,
 101              'grade' => 4,
 102              'peercomment' => 'All good',
 103              'peercommentformat' => FORMAT_PLAIN,
 104          ]);
 105  
 106          $contextlist = new \core_privacy\local\request\approved_contextlist($this->student2, 'mod_workshop', [
 107              \context_module::instance($this->workshop11->cmid)->id,
 108          ]);
 109  
 110          \mod_workshop\privacy\provider::export_user_data($contextlist);
 111  
 112          $writer = writer::with_context(\context_module::instance($this->workshop11->cmid));
 113  
 114          $form = $writer->get_data([
 115              get_string('myassessments', 'mod_workshop'),
 116              $this->assessment1112,
 117              get_string('assessmentform', 'mod_workshop'),
 118              get_string('pluginname', 'workshopform_accumulative'),
 119          ]);
 120  
 121          $this->assertEquals('Aspect 1 description', $form->aspects[0]->description);
 122          $this->assertEquals(4, $form->aspects[1]->grade);
 123      }
 124  }