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   * Type unit tests for the External Location.
  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\external_location;
  31  
  32  /**
  33   * Tests for the \core_privacy API's types\external_location 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\external_location
  38   */
  39  class core_privacy_metadata_types_external_location 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   array   $fields List of fields
  47       * @param   string  $summary Summary
  48       * @covers ::__construct
  49       */
  50      public function test_invalid_configs($name, $fields, $summary) {
  51          $record = new external_location($name, $fields, $summary);
  52          $this->assertDebuggingCalled();
  53      }
  54  
  55      /**
  56       * Ensure that warnings are not thrown if debugging is not enabled, even if string identifiers contain invalid characters.
  57       *
  58       * @dataProvider invalid_string_provider
  59       * @param   string  $name Name
  60       * @param   array   $fields List of fields
  61       * @param   string  $summary Summary
  62       * @covers ::__construct
  63       */
  64      public function test_invalid_configs_debug_normal($name, $fields, $summary) {
  65          global $CFG;
  66          $this->resetAfterTest();
  67  
  68          $CFG->debug = DEBUG_NORMAL;
  69          $record = new external_location($name, $fields, $summary);
  70          $this->assertDebuggingNotCalled();
  71      }
  72  
  73      /**
  74       * Ensure that no warnings are shown for valid combinations.
  75       *
  76       * @dataProvider valid_string_provider
  77       * @param   string  $name Name
  78       * @param   array   $fields List of fields
  79       * @param   string  $summary Summary
  80       * @covers ::__construct
  81       */
  82      public function test_valid_configs($name, $fields, $summary) {
  83          $record = new external_location($name, $fields, $summary);
  84          $this->assertDebuggingNotCalled();
  85      }
  86  
  87      /**
  88       * Data provider with a list of invalid string identifiers.
  89       *
  90       * @return  array
  91       */
  92      public function invalid_string_provider() {
  93          return [
  94              'Space in summary' => [
  95                  'example',
  96                  [
  97                      'field' => 'privacy:valid',
  98                  ],
  99                  'This table is used for purposes.',
 100              ],
 101              'Comma in summary' => [
 102                  'example',
 103                  [
 104                      'field' => 'privacy:valid',
 105                  ],
 106                  'privacy,foo',
 107              ],
 108              'Space in field name' => [
 109                  'example',
 110                  [
 111                      'field' => 'This field is used for purposes.',
 112                  ],
 113                  'privacy:valid',
 114              ],
 115              'Comma in field name' => [
 116                  'example',
 117                  [
 118                      'field' => 'invalid,name',
 119                  ],
 120                  'privacy:valid',
 121              ],
 122              'No fields specified' => [
 123                  'example',
 124                  [],
 125                  'privacy:example:valid',
 126              ],
 127  
 128          ];
 129      }
 130  
 131      /**
 132       * Data provider with a list of valid string identifiers.
 133       *
 134       * @return  array
 135       */
 136      public function valid_string_provider() {
 137          return [
 138              'Valid combination' => [
 139                  'example',
 140                  [
 141                      'field' => 'privacy:example:valid:field',
 142                      'field2' => 'privacy:example:valid:field2',
 143                  ],
 144                  'privacy:example:valid',
 145              ],
 146          ];
 147      }
 148  }