Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 311 and 403] [Versions 400 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  namespace theme_boost\privacy;
  18  
  19  use context_user;
  20  use core_privacy\local\request\writer;
  21  
  22  /**
  23   * Privacy tests for theme_boost.
  24   *
  25   * @package    theme_boost
  26   * @category   test
  27   * @covers     \theme_boost\privacy\provider
  28   * @copyright  2018 Adrian Greeve <adriangreeve.com>
  29   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class provider_test extends \core_privacy\tests\provider_testcase {
  32  
  33      /**
  34       * Data provider for {@see test_export_user_preferences}
  35       *
  36       * @return array[]
  37       */
  38      public function export_user_preference_provider(): array {
  39          return [
  40              'Index drawer open' => [provider::DRAWER_OPEN_INDEX, true, 'privacy:drawerindexopen'],
  41              'Index drawer closed' => [provider::DRAWER_OPEN_INDEX, false, 'privacy:drawerindexclosed'],
  42              'Block drawer open' => [provider::DRAWER_OPEN_BLOCK, true, 'privacy:drawerblockopen'],
  43              'Block drawer closed' => [provider::DRAWER_OPEN_BLOCK, false, 'privacy:drawerblockclosed'],
  44          ];
  45      }
  46  
  47      /**
  48       * Test for provider::test_export_user_preferences().
  49       *
  50       * @param string $preference
  51       * @param bool $value
  52       * @param string $expectdescription
  53       *
  54       * @dataProvider export_user_preference_provider
  55       */
  56      public function test_export_user_preferences(string $preference, bool $value, string $expectdescription): void {
  57          $this->resetAfterTest();
  58  
  59          // Test setup.
  60          $user = $this->getDataGenerator()->create_user();
  61          $this->setUser($user);
  62  
  63          // Add a user home page preference for the User.
  64          set_user_preference($preference, $value, $user);
  65  
  66          // Test the user preferences export contains 1 user preference record for the User.
  67          provider::export_user_preferences($user->id);
  68          $writer = writer::with_context(context_user::instance($user->id));
  69          $this->assertTrue($writer->has_any_data());
  70  
  71          $exportedpreferences = $writer->get_user_preferences('theme_boost');
  72          $this->assertCount(1, (array) $exportedpreferences);
  73          $this->assertEquals($value, (bool) $exportedpreferences->{$preference}->value);
  74          $this->assertEquals(get_string($expectdescription, 'theme_boost'), $exportedpreferences->{$preference}->description);
  75      }
  76  }