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   * Privacy provider tests.
  19   *
  20   * @package    core_editor
  21   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core_editor\privacy;
  25  
  26  use core_privacy\local\metadata\collection;
  27  use core_privacy\local\request\writer;
  28  use core_editor\privacy\provider;
  29  
  30  defined('MOODLE_INTERNAL') || die();
  31  
  32  /**
  33   * Privacy provider tests class.
  34   *
  35   * @package    core_editor
  36   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class provider_test extends \core_privacy\tests\provider_testcase {
  40  
  41      /**
  42       * When no preference exists, there should be no export.
  43       */
  44      public function test_no_preference() {
  45          global $USER;
  46          $this->resetAfterTest();
  47          $this->setAdminUser();
  48  
  49          provider::export_user_preferences($USER->id);
  50          $this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
  51      }
  52  
  53      /**
  54       * When preference exists but is empty, there should be no export.
  55       */
  56      public function test_empty_preference() {
  57          $this->resetAfterTest();
  58  
  59          // Create test user, add some preferences.
  60          $user = $this->getDataGenerator()->create_user();
  61          $this->setUser($user);
  62  
  63          set_user_preference('htmleditor', '', $user);
  64  
  65          // Switch to admin user (so we can validate preferences of the correct user are being exported).
  66          $this->setAdminUser();
  67  
  68          // Export test users preferences.
  69          provider::export_user_preferences($user->id);
  70          $this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
  71      }
  72  
  73      /**
  74       * When an editor is set, the name of that editor will be reported.
  75       */
  76      public function test_editor_atto() {
  77          $this->resetAfterTest();
  78  
  79          // Create test user, add some preferences.
  80          $user = $this->getDataGenerator()->create_user();
  81          $this->setUser($user);
  82  
  83          set_user_preference('htmleditor', 'atto');
  84  
  85          // Switch to admin user (so we can validate preferences of the correct user are being exported).
  86          $this->setAdminUser();
  87  
  88          // Export test users preferences.
  89          provider::export_user_preferences($user->id);
  90          $this->assertTrue(writer::with_context(\context_system::instance())->has_any_data());
  91  
  92          $prefs = writer::with_context(\context_system::instance())->get_user_preferences('core_editor');
  93          $this->assertNotEmpty($prefs->htmleditor);
  94          $this->assertNotEmpty($prefs->htmleditor->value);
  95          $this->assertNotEmpty($prefs->htmleditor->description);
  96          $this->assertEquals('atto', $prefs->htmleditor->value);
  97  
  98          $this->assertEquals(
  99              get_string(
 100                  'privacy:preference:htmleditor',
 101                  'core_editor',
 102                  get_string('pluginname', "editor_atto")
 103              ),
 104              $prefs->htmleditor->description
 105          );
 106      }
 107  }