Skip to content

Instantly share code, notes, and snippets.

@prateeksachan
Last active December 17, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prateeksachan/5559789 to your computer and use it in GitHub Desktop.
Save prateeksachan/5559789 to your computer and use it in GitHub Desktop.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for (some of) mod/assign/locallib.php.
*
* @package mod_assign
* @category phpunit
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
/**
* Unit tests for (some of) mod/assign/locallib.php.
*
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assign_locallib_testcase extends mod_assign_base_testcase {
public function test_disable_submit_after_cutoff_date() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$now = time();
$tomorrow = $now + 24*60*60;
$lastweek = $now - 7*24*60*60;
$yesterday = $now - 24*60*60;
$assign = $this->create_instance(array('duedate'=>$yesterday,
'cutoffdate'=>$tomorrow,
'assignsubmission_onlinetext_enabled'=>1));
$PAGE->set_url(new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id)));
// Student should be able to see an add submission button.
$this->setUser($this->students[0]);
$output = $assign->view_student_summary($this->students[0], true);
$this->assertNotEquals(false, strpos($output, get_string('addsubmission', 'assign')));
// Add a submission but don't submit now.
$submission = $assign->get_user_submission($this->students[0]->id, true);
$data = new stdClass();
$data->onlinetext_editor = array('itemid'=>file_get_unused_draft_itemid(),
'text'=>'Submission text',
'format'=>FORMAT_MOODLE);
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$plugin->save($submission, $data);
//create another instance with cut-off and due-date already passed
$this->setUser($this->editingteachers[0]);
$now = time();
$assign = $this->create_instance(array('duedate'=>$lastweek,
'cutoffdate'=>$yesterday,
'assignsubmission_onlinetext_enabled'=>1));
$this->setUser($this->students[0]);
$output = $assign->view_student_summary($this->students[0], true);
$this->assertEquals(false, strpos($output, get_string('editsubmission', 'assign')));//success
$this->assertEquals(false, strpos($output, get_string('submitassignment', 'assign')));//success
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment