Merge branch 'MDL-52974-master' of git://github.com/jleyva/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 1 Mar 2016 03:48:16 +0000 (11:48 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 1 Mar 2016 03:48:16 +0000 (11:48 +0800)
1  2 
lib/db/services.php
mod/assign/externallib.php
mod/assign/tests/externallib_test.php
version.php

Simple merge
Simple merge
@@@ -1557,47 -1555,74 +1557,116 @@@ class mod_assign_external_testcase exte
  
      }
  
 -
 +    /**
 +     * Test subplugins availability
 +     */
 +    public function test_subplugins_availability() {
 +        global $CFG;
 +
 +        require_once($CFG->dirroot . '/mod/assign/adminlib.php');
 +        $this->resetAfterTest(true);
 +
 +        // Hide assignment file submissiong plugin.
 +        $pluginmanager = new assign_plugin_manager('assignsubmission');
 +        $pluginmanager->hide_plugin('file');
 +        $parameters = mod_assign_external::save_submission_parameters();
 +
 +        $this->assertTrue(!isset($parameters->keys['plugindata']->keys['files_filemanager']));
 +
 +        // Show it again and check that the value is returned as optional.
 +        $pluginmanager->show_plugin('file');
 +        $parameters = mod_assign_external::save_submission_parameters();
 +        $this->assertTrue(isset($parameters->keys['plugindata']->keys['files_filemanager']));
 +        $this->assertEquals(VALUE_OPTIONAL, $parameters->keys['plugindata']->keys['files_filemanager']->required);
 +
 +        // Hide feedback file submissiong plugin.
 +        $pluginmanager = new assign_plugin_manager('assignfeedback');
 +        $pluginmanager->hide_plugin('file');
 +
 +        $parameters = mod_assign_external::save_grade_parameters();
 +
 +        $this->assertTrue(!isset($parameters->keys['plugindata']->keys['files_filemanager']));
 +
 +        // Show it again and check that the value is returned as optional.
 +        $pluginmanager->show_plugin('file');
 +        $parameters = mod_assign_external::save_grade_parameters();
 +
 +        $this->assertTrue(isset($parameters->keys['plugindata']->keys['files_filemanager']));
 +        $this->assertEquals(VALUE_OPTIONAL, $parameters->keys['plugindata']->keys['files_filemanager']->required);
 +
 +        // Check a different one.
 +        $pluginmanager->show_plugin('comments');
 +        $this->assertTrue(isset($parameters->keys['plugindata']->keys['assignfeedbackcomments_editor']));
 +        $this->assertEquals(VALUE_OPTIONAL, $parameters->keys['plugindata']->keys['assignfeedbackcomments_editor']->required);
 +    }
 +
+     /**
+      * Test test_view_submission_status
+      */
+     public function test_view_submission_status() {
+         global $DB;
+         $this->resetAfterTest(true);
+         $this->setAdminUser();
+         // Setup test data.
+         $course = $this->getDataGenerator()->create_course();
+         $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
+         $context = context_module::instance($assign->cmid);
+         $cm = get_coursemodule_from_instance('assign', $assign->id);
+         // Test invalid instance id.
+         try {
+             mod_assign_external::view_submission_status(0);
+             $this->fail('Exception expected due to invalid mod_assign instance id.');
+         } catch (moodle_exception $e) {
+             $this->assertEquals('invalidrecord', $e->errorcode);
+         }
+         // Test not-enrolled user.
+         $user = self::getDataGenerator()->create_user();
+         $this->setUser($user);
+         try {
+             mod_assign_external::view_submission_status($assign->id);
+             $this->fail('Exception expected due to not enrolled user.');
+         } catch (moodle_exception $e) {
+             $this->assertEquals('requireloginerror', $e->errorcode);
+         }
+         // Test user with full capabilities.
+         $studentrole = $DB->get_record('role', array('shortname' => 'student'));
+         $this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
+         // Trigger and capture the event.
+         $sink = $this->redirectEvents();
+         $result = mod_assign_external::view_submission_status($assign->id);
+         $result = external_api::clean_returnvalue(mod_assign_external::view_submission_status_returns(), $result);
+         $events = $sink->get_events();
+         $this->assertCount(1, $events);
+         $event = array_shift($events);
+         // Checking that the event contains the expected values.
+         $this->assertInstanceOf('\mod_assign\event\submission_status_viewed', $event);
+         $this->assertEquals($context, $event->get_context());
+         $moodleurl = new \moodle_url('/mod/assign/view.php', array('id' => $cm->id));
+         $this->assertEquals($moodleurl, $event->get_url());
+         $this->assertEventContextNotUsed($event);
+         $this->assertNotEmpty($event->get_name());
+         // Test user with no capabilities.
+         // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
+         assign_capability('mod/assign:view', CAP_PROHIBIT, $studentrole->id, $context->id);
+         accesslib_clear_all_caches_for_unit_testing();
+         course_modinfo::clear_instance_cache();
+         try {
+             mod_assign_external::view_submission_status($assign->id);
+             $this->fail('Exception expected due to missing capability.');
+         } catch (moodle_exception $e) {
+             $this->assertEquals('requireloginerror', $e->errorcode);
+         }
+     }
  }
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2016030100.00;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2016012900.01;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2016030101.00;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.