Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   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   * Privacy tests for repository_flickr.
  18   *
  19   * @package    repository_flickr
  20   * @category   test
  21   * @copyright  2018 Zig Tan <zig@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace repository_flickr\privacy;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  use repository_flickr\privacy\provider;
  29  use core_privacy\local\request\approved_contextlist;
  30  use core_privacy\local\request\writer;
  31  use core_privacy\tests\provider_testcase;
  32  
  33  /**
  34   * Unit tests for repository/flickr/privacy/provider
  35   *
  36   * @copyright  2018 Zig Tan <zig@moodle.com>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class provider_test extends provider_testcase {
  40      /**
  41       * Overriding setUp() function to always reset after tests.
  42       */
  43      public function setUp(): void {
  44          $this->resetAfterTest(true);
  45      }
  46  
  47      /**
  48       * Test for provider::export_user_preferences().
  49       */
  50      public function test_export_user_preferences() {
  51          global $DB;
  52  
  53          // Test setup.
  54          $user = $this->getDataGenerator()->create_user();
  55          $this->setUser($user);
  56          $contextlist = provider::get_contexts_for_userid($user->id);
  57          $approvedcontextlist = new approved_contextlist($user, 'repository_flickr', $contextlist->get_contextids());
  58          $user = $approvedcontextlist->get_user();
  59          $contextuser = \context_user::instance($user->id);
  60  
  61          // Test exporting of Flickr repository user preferences *without* OAuth token/secret preference configured.
  62          provider::export_user_preferences($user->id);
  63          $writer = writer::with_context($contextuser);
  64  
  65          // Verify there is no user preferences data exported.
  66          $this->assertFalse($writer->has_any_data());
  67  
  68          // Test exporting of Flickr repository user preferences *with* OAuth token/secret preference configured.
  69          set_user_preferences([
  70              'repository_flickr_access_token' => 'dummy flickr oauth access token',
  71              'repository_flickr_access_token_secret' => 'dummy flickr oauth access token secret',
  72          ], $user->id);
  73  
  74          provider::export_user_preferences($user->id);
  75          $writer = writer::with_context($contextuser);
  76  
  77          // Verify there is user preferences data exported.
  78          $this->assertTrue($writer->has_any_data());
  79          $userpreferences = $writer->get_user_preferences('repository_flickr');
  80  
  81          // Verify the OAuth token is not an empty string value and the OAuth secret is an empty string value.
  82          $accesstoken = $userpreferences->repository_flickr_access_token;
  83          $this->assertFalse(empty($accesstoken->value));
  84          $accesstokensecret = $userpreferences->repository_flickr_access_token_secret;
  85          $this->assertTrue(empty($accesstokensecret->value));
  86      }
  87  }