Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310]

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