Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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 tool_brickfield;
  18  
  19  use tool_brickfield\local\tool\filter;
  20  
  21  /**
  22   * Unit tests for {@accessibility tool_brickfield\accessibility.php}.
  23   *
  24   * @package   tool_brickfield
  25   * @copyright  2020 onward: Brickfield Education Labs, www.brickfield.ie
  26   * @author     Jay Churchward (jay@brickfieldlabs.ie)
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  class accessibility_test extends \advanced_testcase {
  30  
  31      /**
  32       * Test get_title().
  33       *
  34       * @throws \coding_exception
  35       * @throws \dml_exception
  36       * @throws \moodle_exception
  37       */
  38      public function test_get_title() {
  39          $this->resetAfterTest();
  40          $object = new accessibility();
  41          $filter = new filter();
  42  
  43          // Testing the else statement.
  44          $output = $object->get_title($filter, 0);
  45          $this->assertEquals($output, 'Error details: all reviewed courses (0 courses)');
  46          $output = $object->get_title($filter, 5);
  47          $this->assertEquals($output, 'Error details: all reviewed courses (5 courses)');
  48  
  49          // Testing the if statement.
  50          $filter->courseid = 1;
  51          $output = $object->get_title($filter, 0);
  52          $this->assertEquals($output, 'Error details: course PHPUnit test site');
  53      }
  54  
  55      /**
  56       * Test check_ids().
  57       *
  58       * @throws \dml_exception
  59       */
  60      public function test_check_ids() {
  61          $this->resetAfterTest();
  62          $object = new accessibility();
  63  
  64          $output = $object->checkids();
  65          $this->assertEquals($output[1], 'a_links_dont_open_new_window');
  66          $this->assertEquals($output[10], 'css_text_has_contrast');
  67  
  68          $output = $object->checkids(2);
  69          $this->assertEmpty($output);
  70      }
  71  
  72      /**
  73       * Test get_translations().
  74       *
  75       * @throws \dml_exception
  76       */
  77      public function test_get_translations() {
  78          $this->resetAfterTest();
  79          $object = new accessibility();
  80  
  81          $output = $object->get_translations();
  82          $this->assertEquals($output['a_must_contain_text']['title'], 'Links should contain text');
  83          $this->assertStringContainsString('<p>Because many users of screen readers use links to ' .
  84              'navigate the page, providing links with no text (or with images that have empty \'alt\' attributes and no other ' .
  85              'readable text) hinders these users.</p>', $output['a_must_contain_text']['description']);
  86      }
  87  
  88      /**
  89       * Test get_category_courseids().
  90       *
  91       * @throws \dml_exception
  92       */
  93      public function test_get_category_courseids() {
  94          $this->resetAfterTest();
  95          $object = new accessibility();
  96          $category = $this->getDataGenerator()->create_category();
  97          $course = $this->getDataGenerator()->create_course((object)['category' => $category->id]);
  98  
  99          $output = $object->get_category_courseids($category->id);
 100          $this->assertEquals($output[0], $course->id);
 101      }
 102  }