[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/course/tests/ -> courseformat_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   * Course related unit tests
  19   *
  20   * @package    core_course
  21   * @copyright  2014 Marina Glancy
  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  require_once($CFG->dirroot . '/course/lib.php');
  29  require_once($CFG->dirroot . '/course/tests/fixtures/format_theunittest.php');
  30  
  31  class core_course_courseformat_testcase extends advanced_testcase {
  32      public function test_available_hook() {
  33          global $DB;
  34          $this->resetAfterTest();
  35  
  36          // Generate a course with two sections (0 and 1) and two modules. Course format is set to 'theunittest'.
  37          $generator = $this->getDataGenerator();
  38          $course1 = $generator->create_course(array('format' => 'theunittest'));
  39          $this->assertEquals('theunittest', $course1->format);
  40          course_create_sections_if_missing($course1, array(0, 1));
  41          $assign0 = $generator->create_module('assign', array('course' => $course1, 'section' => 0));
  42          $assign1 = $generator->create_module('assign', array('course' => $course1, 'section' => 1));
  43  
  44          // Enrol student and teacher.
  45          $roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
  46          $student = $generator->create_user();
  47          $generator->enrol_user($student->id, $course1->id, $roleids['student']);
  48          $teacher = $generator->create_user();
  49          $generator->enrol_user($teacher->id, $course1->id, $roleids['editingteacher']);
  50  
  51          // Make sure that initially both sections and both modules are available and visible for a student.
  52          $modinfostudent = get_fast_modinfo($course1, $student->id);
  53          $this->assertTrue($modinfostudent->get_section_info(1)->available);
  54          $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->available);
  55          $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->uservisible);
  56          $this->assertTrue($modinfostudent->get_cm($assign1->cmid)->available);
  57          $this->assertTrue($modinfostudent->get_cm($assign1->cmid)->uservisible);
  58  
  59          // Set 'hideoddsections' for the course to 1.
  60          // Section1 and assign1 will be unavailable, uservisible will be false for student and true for teacher.
  61          $data = (object)array('id' => $course1->id, 'hideoddsections' => 1);
  62          course_get_format($course1)->update_course_format_options($data);
  63          $modinfostudent = get_fast_modinfo($course1, $student->id);
  64          $this->assertFalse($modinfostudent->get_section_info(1)->available);
  65          $this->assertEmpty($modinfostudent->get_section_info(1)->availableinfo);
  66          $this->assertFalse($modinfostudent->get_section_info(1)->uservisible);
  67          $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->available);
  68          $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->uservisible);
  69          $this->assertFalse($modinfostudent->get_cm($assign1->cmid)->available);
  70          $this->assertFalse($modinfostudent->get_cm($assign1->cmid)->uservisible);
  71  
  72          $modinfoteacher = get_fast_modinfo($course1, $teacher->id);
  73          $this->assertFalse($modinfoteacher->get_section_info(1)->available);
  74          $this->assertEmpty($modinfoteacher->get_section_info(1)->availableinfo);
  75          $this->assertTrue($modinfoteacher->get_section_info(1)->uservisible);
  76          $this->assertTrue($modinfoteacher->get_cm($assign0->cmid)->available);
  77          $this->assertTrue($modinfoteacher->get_cm($assign0->cmid)->uservisible);
  78          $this->assertFalse($modinfoteacher->get_cm($assign1->cmid)->available);
  79          $this->assertTrue($modinfoteacher->get_cm($assign1->cmid)->uservisible);
  80  
  81          // Set 'hideoddsections' for the course to 2.
  82          // Section1 and assign1 will be unavailable, uservisible will be false for student and true for teacher.
  83          // Property availableinfo will be not empty.
  84          $data = (object)array('id' => $course1->id, 'hideoddsections' => 2);
  85          course_get_format($course1)->update_course_format_options($data);
  86          $modinfostudent = get_fast_modinfo($course1, $student->id);
  87          $this->assertFalse($modinfostudent->get_section_info(1)->available);
  88          $this->assertNotEmpty($modinfostudent->get_section_info(1)->availableinfo);
  89          $this->assertFalse($modinfostudent->get_section_info(1)->uservisible);
  90          $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->available);
  91          $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->uservisible);
  92          $this->assertFalse($modinfostudent->get_cm($assign1->cmid)->available);
  93          $this->assertFalse($modinfostudent->get_cm($assign1->cmid)->uservisible);
  94  
  95          $modinfoteacher = get_fast_modinfo($course1, $teacher->id);
  96          $this->assertFalse($modinfoteacher->get_section_info(1)->available);
  97          $this->assertNotEmpty($modinfoteacher->get_section_info(1)->availableinfo);
  98          $this->assertTrue($modinfoteacher->get_section_info(1)->uservisible);
  99          $this->assertTrue($modinfoteacher->get_cm($assign0->cmid)->available);
 100          $this->assertTrue($modinfoteacher->get_cm($assign0->cmid)->uservisible);
 101          $this->assertFalse($modinfoteacher->get_cm($assign1->cmid)->available);
 102          $this->assertTrue($modinfoteacher->get_cm($assign1->cmid)->uservisible);
 103      }
 104  }


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