| 1 | 
           efrain | 
           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 | 
            * Unit Tests for the approved contextlist Class
  | 
        
        
            | 
            | 
           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\request\approved_contextlist;
  | 
        
        
            | 
            | 
           31 | 
              | 
        
        
            | 
            | 
           32 | 
           /**
  | 
        
        
            | 
            | 
           33 | 
            * Tests for the \core_privacy API's approved contextlist 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\request\approved_contextlist
  | 
        
        
            | 
            | 
           38 | 
            */
  | 
        
        
           | 1441 | 
           ariadna | 
           39 | 
           final class approved_contextlist_test extends advanced_testcase {
  | 
        
        
           | 1 | 
           efrain | 
           40 | 
              | 
        
        
            | 
            | 
           41 | 
               /**
  | 
        
        
            | 
            | 
           42 | 
                * The approved contextlist should not be modifiable once set.
  | 
        
        
            | 
            | 
           43 | 
                *
  | 
        
        
            | 
            | 
           44 | 
                * @covers ::__construct
  | 
        
        
            | 
            | 
           45 | 
                * @covers \core_privacy\local\request\approved_contextlist<extended>
  | 
        
        
            | 
            | 
           46 | 
                */
  | 
        
        
           | 11 | 
           efrain | 
           47 | 
               public function test_default_values_set(): void {
  | 
        
        
           | 1 | 
           efrain | 
           48 | 
                   $testuser = \core_user::get_user_by_username('admin');
  | 
        
        
            | 
            | 
           49 | 
                   $contextids = [3, 2, 1];
  | 
        
        
            | 
            | 
           50 | 
                   $component = 'core_privacy';
  | 
        
        
            | 
            | 
           51 | 
              | 
        
        
            | 
            | 
           52 | 
                   $uit = new approved_contextlist($testuser, $component, $contextids);
  | 
        
        
            | 
            | 
           53 | 
              | 
        
        
            | 
            | 
           54 | 
                   $this->assertEquals($testuser, $uit->get_user());
  | 
        
        
            | 
            | 
           55 | 
                   $this->assertEquals($component, $uit->get_component());
  | 
        
        
            | 
            | 
           56 | 
                   $result = $uit->get_contextids();
  | 
        
        
            | 
            | 
           57 | 
              | 
        
        
            | 
            | 
           58 | 
                   // Note: Array order is not guaranteed and should not matter.
  | 
        
        
            | 
            | 
           59 | 
                   foreach ($contextids as $contextid) {
  | 
        
        
            | 
            | 
           60 | 
                       $this->assertNotFalse(array_search($contextid, $result));
  | 
        
        
            | 
            | 
           61 | 
                   }
  | 
        
        
            | 
            | 
           62 | 
               }
  | 
        
        
            | 
            | 
           63 | 
           }
  |