[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/submission/comments/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    assignsubmission_comments
  21   * @category   test
  22   * @copyright  2013 Rajesh Taneja <rajesh@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  require_once($CFG->dirroot . '/mod/assign/lib.php');
  30  require_once($CFG->dirroot . '/mod/assign/locallib.php');
  31  require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
  32  
  33  /**
  34   * Events tests class.
  35   *
  36   * @package    assignsubmission_comments
  37   * @category   test
  38   * @copyright  2013 Rajesh Taneja <rajesh@moodle.com>
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class assignsubmission_comments_events_testcase extends mod_assign_base_testcase {
  42  
  43      /**
  44       * Test comment_created event.
  45       */
  46      public function test_comment_created() {
  47          global $CFG;
  48          require_once($CFG->dirroot . '/comment/lib.php');
  49  
  50          $this->setUser($this->editingteachers[0]);
  51          $assign = $this->create_instance();
  52          $submission = $assign->get_user_submission($this->students[0]->id, true);
  53  
  54          $context = $assign->get_context();
  55          $options = new stdClass();
  56          $options->area = 'submission_comments';
  57          $options->course = $assign->get_course();
  58          $options->context = $context;
  59          $options->itemid = $submission->id;
  60          $options->component = 'assignsubmission_comments';
  61          $options->showcount = true;
  62          $options->displaycancel = true;
  63  
  64          $comment = new comment($options);
  65  
  66          // Triggering and capturing the event.
  67          $sink = $this->redirectEvents();
  68          $comment->add('New comment');
  69          $events = $sink->get_events();
  70          $this->assertCount(1, $events);
  71          $event = reset($events);
  72  
  73          // Checking that the event contains the expected values.
  74          $this->assertInstanceOf('\assignsubmission_comments\event\comment_created', $event);
  75          $this->assertEquals($context, $event->get_context());
  76          $url = new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id));
  77          $this->assertEquals($url, $event->get_url());
  78          $this->assertEventContextNotUsed($event);
  79      }
  80  
  81      /**
  82       * Test comment_deleted event.
  83       */
  84      public function test_comment_deleted() {
  85          global $CFG;
  86          require_once($CFG->dirroot . '/comment/lib.php');
  87  
  88          $this->setUser($this->editingteachers[0]);
  89          $assign = $this->create_instance();
  90          $submission = $assign->get_user_submission($this->students[0]->id, true);
  91  
  92          $context = $assign->get_context();
  93          $options = new stdClass();
  94          $options->area    = 'submission_comments';
  95          $options->course    = $assign->get_course();
  96          $options->context = $context;
  97          $options->itemid  = $submission->id;
  98          $options->component = 'assignsubmission_comments';
  99          $options->showcount = true;
 100          $options->displaycancel = true;
 101          $comment = new comment($options);
 102          $newcomment = $comment->add('New comment 1');
 103  
 104          // Triggering and capturing the event.
 105          $sink = $this->redirectEvents();
 106          $comment->delete($newcomment->id);
 107          $events = $sink->get_events();
 108          $this->assertCount(1, $events);
 109          $event = reset($events);
 110  
 111          // Checking that the event contains the expected values.
 112          $this->assertInstanceOf('\assignsubmission_comments\event\comment_deleted', $event);
 113          $this->assertEquals($context, $event->get_context());
 114          $url = new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id));
 115          $this->assertEquals($url, $event->get_url());
 116          $this->assertEventContextNotUsed($event);
 117      }
 118  }


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