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 310 and 311] [Versions 39 and 311]

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