[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/report/outline/tests/ -> lib_test.php (source)

   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   * Tests for report library functions.
  19   *
  20   * @package    report_outline
  21   * @copyright  2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  global $CFG;
  28  
  29  /**
  30   * Class report_outline_lib_testcase
  31   *
  32   * @package    report_outline
  33   * @copyright  2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
  35   */
  36  class report_outline_lib_testcase extends advanced_testcase {
  37  
  38      /**
  39       * @var stdClass The user.
  40       */
  41      private $user;
  42  
  43      /**
  44       * @var stdClass The course.
  45       */
  46      private $course;
  47  
  48      /**
  49       * @var \core_user\output\myprofile\tree The navigation tree.
  50       */
  51      private $tree;
  52  
  53      public function setUp() {
  54          $this->user = $this->getDataGenerator()->create_user();
  55          $this->user2 = $this->getDataGenerator()->create_user();
  56          $this->course = $this->getDataGenerator()->create_course();
  57          $this->tree = new \core_user\output\myprofile\tree();
  58          $this->resetAfterTest();
  59      }
  60  
  61      /**
  62       * Test report_log_supports_logstore.
  63       */
  64      public function test_report_participation_supports_logstore() {
  65          $logmanager = get_log_manager();
  66          $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store');
  67  
  68          $supportedstores = array(
  69              'logstore_legacy' => '\logstore_legacy\log\store',
  70              'logstore_standard' => '\logstore_standard\log\store'
  71          );
  72  
  73          // Make sure all supported stores are installed.
  74          $expectedstores = array_keys(array_intersect($allstores, $supportedstores));
  75          $stores = $logmanager->get_supported_logstores('report_outline');
  76          $stores = array_keys($stores);
  77          foreach ($expectedstores as $expectedstore) {
  78              $this->assertContains($expectedstore, $stores);
  79          }
  80      }
  81  
  82      /**
  83       * Tests the report_outline_myprofile_navigation() function as an admin user.
  84       */
  85      public function test_report_outline_myprofile_navigation() {
  86          $this->setAdminUser();
  87          $iscurrentuser = false;
  88  
  89          report_outline_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
  90          $reflector = new ReflectionObject($this->tree);
  91          $nodes = $reflector->getProperty('nodes');
  92          $nodes->setAccessible(true);
  93          $this->assertArrayHasKey('outline', $nodes->getValue($this->tree));
  94          $this->assertArrayHasKey('complete', $nodes->getValue($this->tree));
  95      }
  96  
  97      /**
  98       * Tests the report_outline_myprofile_navigation() function as a user without permission.
  99       */
 100      public function test_report_outline_myprofile_navigation_without_permission() {
 101          $this->setUser($this->user);
 102          $iscurrentuser = true;
 103  
 104          report_outline_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
 105          $reflector = new ReflectionObject($this->tree);
 106          $nodes = $reflector->getProperty('nodes');
 107          $nodes->setAccessible(true);
 108          $this->assertArrayNotHasKey('outline', $nodes->getValue($this->tree));
 109          $this->assertArrayNotHasKey('complete', $nodes->getValue($this->tree));
 110      }
 111  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1