Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 311 and 402]

   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   * @coversDefaultClass \block_accessreview
  32   */
  33  class accessibility_review_test extends advanced_testcase {
  34      public static function setUpBeforeClass(): void {
  35          require_once (__DIR__ . '/../../moodleblock.class.php');
  36          require_once (__DIR__ . '/../block_accessreview.php');
  37      }
  38  
  39      public function test_get_toggle_link() {
  40          $rc = new ReflectionClass(block_accessreview::class);
  41          $rm = $rc->getMethod('get_toggle_link');
  42          $rm->setAccessible(true);
  43  
  44          $block = new block_accessreview();
  45          $output = $rm->invoke($block);
  46          $this->assertNotEmpty($output);
  47      }
  48  
  49      public function test_get_download_link() {
  50          $this->resetAfterTest();
  51  
  52          $user1 = $this->getDataGenerator()->create_user();
  53          $user2 = $this->getDataGenerator()->create_user();
  54  
  55          $course = $this->getDataGenerator()->create_course();
  56  
  57          // Enrol users in the course.
  58          $this->getDataGenerator()->enrol_user($user1->id, $course->id, 'teacher');
  59          $this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
  60  
  61          $rc = new ReflectionClass(block_accessreview::class);
  62          $rm = $rc->getMethod('get_download_link');
  63          $rm->setAccessible(true);
  64          $block = new block_accessreview();
  65  
  66          $this->setUser($user1);
  67          $result = $rm->invoke($block, context_course::instance($course->id));
  68          $this->assertNotEmpty($result);
  69  
  70          $this->setUser($user2);
  71          $result = $rm->invoke($block, context_course::instance($course->id));
  72          $this->assertEmpty($result);
  73      }
  74  
  75      public function test_get_report_link() {
  76          $this->resetAfterTest();
  77  
  78          $user1 = $this->getDataGenerator()->create_user();
  79          $user2 = $this->getDataGenerator()->create_user();
  80  
  81          $course = $this->getDataGenerator()->create_course();
  82  
  83          // Enrol users in the course.
  84          $this->getDataGenerator()->enrol_user($user1->id, $course->id, 'teacher');
  85          $this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
  86  
  87          $rc = new ReflectionClass(block_accessreview::class);
  88          $rm = $rc->getMethod('get_report_link');
  89          $rm->setAccessible(true);
  90          $block = new block_accessreview();
  91  
  92          $this->setUser($user1);
  93          $result = $rm->invoke($block, context_course::instance($course->id));
  94          $this->assertNotEmpty($result);
  95  
  96          $this->setUser($user2);
  97          $result = $rm->invoke($block, context_course::instance($course->id));
  98          $this->assertEmpty($result);
  99      }
 100  
 101      /**
 102       * Test the behaviour of can_block_be_added() method.
 103       *
 104       * @covers ::can_block_be_added
 105       */
 106      public function test_can_block_be_added(): void {
 107          $this->resetAfterTest();
 108          $this->setAdminUser();
 109  
 110          // Create a course and prepare the page where the block will be added.
 111          $course = $this->getDataGenerator()->create_course();
 112          $page = new \moodle_page();
 113          $page->set_context(context_course::instance($course->id));
 114          $page->set_pagelayout('course');
 115  
 116          $block = new block_accessreview();
 117  
 118          // If the accessibility tools is enabled, the method should return true.
 119          set_config('enableaccessibilitytools', true);
 120          $this->assertTrue($block->can_block_be_added($page));
 121  
 122          // However, if the accessibility tools is disabled, the method should return false.
 123          set_config('enableaccessibilitytools', false);
 124          $this->assertFalse($block->can_block_be_added($page));
 125      }
 126  }