[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/question/tests/ -> events_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   * Events tests.
  19   *
  20   * @package core_question
  21   * @copyright 2014 Mark Nelson <markn@moodle.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  require_once($CFG->dirroot . '/question/editlib.php');
  30  require_once($CFG->dirroot . '/question/category_class.php');
  31  
  32  class core_question_events_testcase extends advanced_testcase {
  33  
  34      /**
  35       * Tests set up.
  36       */
  37      public function setUp() {
  38          $this->resetAfterTest();
  39      }
  40  
  41      /**
  42       * Test the question category created event.
  43       */
  44      public function test_question_category_created() {
  45          $this->setAdminUser();
  46          $course = $this->getDataGenerator()->create_course();
  47          $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id));
  48  
  49          $contexts = new question_edit_contexts(context_module::instance($quiz->cmid));
  50  
  51          $defaultcategoryobj = question_make_default_categories(array($contexts->lowest()));
  52          $defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
  53  
  54          $qcobject = new question_category_object(
  55              1,
  56              new moodle_url('/mod/quiz/edit.php', array('cmid' => $quiz->cmid)),
  57              $contexts->having_one_edit_tab_cap('categories'),
  58              $defaultcategoryobj->id,
  59              $defaultcategory,
  60              null,
  61              $contexts->having_cap('moodle/question:add'));
  62  
  63          // Trigger and capture the event.
  64          $sink = $this->redirectEvents();
  65          $categoryid = $qcobject->add_category($defaultcategory, 'newcategory', '', true);
  66          $events = $sink->get_events();
  67          $event = reset($events);
  68  
  69          // Check that the event data is valid.
  70          $this->assertInstanceOf('\core\event\question_category_created', $event);
  71          $this->assertEquals(context_module::instance($quiz->cmid), $event->get_context());
  72          $expected = array($course->id, 'quiz', 'addcategory', 'view.php?id=' . $quiz->cmid , $categoryid, $quiz->cmid);
  73          $this->assertEventLegacyLogData($expected, $event);
  74          $this->assertEventContextNotUsed($event);
  75      }
  76  }


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