Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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   * Types unit tests for the Subsystem Link.
  19   *
  20   * @package     core_privacy
  21   * @category    test
  22   * @copyright   2018 Andrew Nicols <andrew@nicols.co.uk>
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  
  30  use \core_privacy\local\metadata\types\subsystem_link;
  31  
  32  /**
  33   * Tests for the \core_privacy API's types\subsystem_link functionality.
  34   *
  35   * @copyright   2018 Andrew Nicols <andrew@nicols.co.uk>
  36   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   * @coversDefaultClass \core_privacy\local\metadata\types\subsystem_link
  38   */
  39  class core_privacy_metadata_types_subsystem_link extends advanced_testcase {
  40  
  41      /**
  42       * Ensure that warnings are thrown if string identifiers contain invalid characters.
  43       *
  44       * @dataProvider invalid_string_provider
  45       * @param   string  $name Name
  46       * @param   string  $summary Summary
  47       * @covers ::__construct
  48       */
  49      public function test_invalid_configs($name, $privacyfields, $summary) {
  50          $record = new subsystem_link($name, $privacyfields, $summary);
  51          $this->assertDebuggingCalled();
  52      }
  53  
  54      /**
  55       * Ensure that warnings are not thrown if debugging is not enabled, even if string identifiers contain invalid characters.
  56       *
  57       * @dataProvider invalid_string_provider
  58       * @param   string  $name Name
  59       * @param   string  $summary Summary
  60       * @covers ::__construct
  61       */
  62      public function test_invalid_configs_debug_normal($name, $privacyfields, $summary) {
  63          global $CFG;
  64          $this->resetAfterTest();
  65  
  66          $CFG->debug = DEBUG_NORMAL;
  67          $record = new subsystem_link($name, $privacyfields, $summary);
  68          $this->assertDebuggingNotCalled();
  69      }
  70  
  71      /**
  72       * Ensure that no warnings are shown for valid combinations.
  73       *
  74       * @dataProvider valid_string_provider
  75       * @param   string  $name Name
  76       * @param   string  $summary Summary
  77       * @covers ::__construct
  78       */
  79      public function test_valid_configs($name, $privacyfields, $summary) {
  80          $record = new subsystem_link($name, $privacyfields, $summary);
  81          $this->assertDebuggingNotCalled();
  82      }
  83  
  84      /**
  85       * Data provider with a list of invalid string identifiers.
  86       *
  87       * @return  array
  88       */
  89      public function invalid_string_provider() {
  90          return [
  91              'Space in summary' => [
  92                  'example',
  93                  [],
  94                  'This table is used for purposes.',
  95              ],
  96              'Comma in summary' => [
  97                  'example',
  98                  [],
  99                  'privacy,foo',
 100              ],
 101          ];
 102      }
 103  
 104      /**
 105       * Data provider with a list of valid string identifiers.
 106       *
 107       * @return  array
 108       */
 109      public function valid_string_provider() {
 110          return [
 111              'Valid combination' => [
 112                  'example',
 113                  [],
 114                  'privacy:example:valid',
 115              ],
 116          ];
 117      }
 118  }