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 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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  namespace block_accessreview;
  18  
  19  use ReflectionClass;
  20  use advanced_testcase;
  21  use block_accessreview;
  22  use context_course;
  23  
  24  /**
  25   * PHPUnit block_accessibility_review tests
  26   *
  27   * @package   block_accessreview
  28   * @copyright  2020 onward: Learning Technology Services, www.lts.ie
  29   * @author     Jay Churchward (jay.churchward@poetopensource.org)
  30   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class accessibility_review_test extends advanced_testcase {
  33      public static function setUpBeforeClass(): void {
  34          require_once (__DIR__ . '/../../moodleblock.class.php');
  35          require_once (__DIR__ . '/../block_accessreview.php');
  36      }
  37  
  38      public function test_get_toggle_link() {
  39          $rc = new ReflectionClass(block_accessreview::class);
  40          $rm = $rc->getMethod('get_toggle_link');
  41          $rm->setAccessible(true);
  42  
  43          $block = new block_accessreview();
  44          $output = $rm->invoke($block);
  45          $this->assertNotEmpty($output);
  46      }
  47  
  48      public function test_get_download_link() {
  49          $this->resetAfterTest();
  50  
  51          $user1 = $this->getDataGenerator()->create_user();
  52          $user2 = $this->getDataGenerator()->create_user();
  53  
  54          $course = $this->getDataGenerator()->create_course();
  55  
  56          // Enrol users in the course.
  57          $this->getDataGenerator()->enrol_user($user1->id, $course->id, 'teacher');
  58          $this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
  59  
  60          $rc = new ReflectionClass(block_accessreview::class);
  61          $rm = $rc->getMethod('get_download_link');
  62          $rm->setAccessible(true);
  63          $block = new block_accessreview();
  64  
  65          $this->setUser($user1);
  66          $result = $rm->invoke($block, context_course::instance($course->id));
  67          $this->assertNotEmpty($result);
  68  
  69          $this->setUser($user2);
  70          $result = $rm->invoke($block, context_course::instance($course->id));
  71          $this->assertEmpty($result);
  72      }
  73  
  74      public function test_get_report_link() {
  75          $this->resetAfterTest();
  76  
  77          $user1 = $this->getDataGenerator()->create_user();
  78          $user2 = $this->getDataGenerator()->create_user();
  79  
  80          $course = $this->getDataGenerator()->create_course();
  81  
  82          // Enrol users in the course.
  83          $this->getDataGenerator()->enrol_user($user1->id, $course->id, 'teacher');
  84          $this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
  85  
  86          $rc = new ReflectionClass(block_accessreview::class);
  87          $rm = $rc->getMethod('get_report_link');
  88          $rm->setAccessible(true);
  89          $block = new block_accessreview();
  90  
  91          $this->setUser($user1);
  92          $result = $rm->invoke($block, context_course::instance($course->id));
  93          $this->assertNotEmpty($result);
  94  
  95          $this->setUser($user2);
  96          $result = $rm->invoke($block, context_course::instance($course->id));
  97          $this->assertEmpty($result);
  98      }
  99  }