Example #1
0
/**
 * Returns an array of quoras that the current user is subscribed to and is allowed to unsubscribe from
 *
 * @return array An array of unsubscribable quoras
 * @deprecated since Moodle 2.8 use \mod_quora\subscriptions::get_unsubscribable_quoras() instead
 */
function quora_get_optional_subscribed_quoras()
{
    debugging("quora_get_optional_subscribed_quoras() has been deprecated, please use \\mod_quora\\subscriptions::get_unsubscribable_quoras() instead.", DEBUG_DEVELOPER);
    return \mod_quora\subscriptions::get_unsubscribable_quoras();
}
 /**
  * Test fetching unsubscribable quoras.
  */
 public function test_unsubscribable_quoras()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Create a course, with a quora.
     $course = $this->getDataGenerator()->create_course();
     // Create a user enrolled in the course as a student.
     list($user) = $this->helper_create_users($course, 1);
     // Must be logged in as the current user.
     $this->setUser($user);
     // Without any subscriptions, there should be nothing returned.
     $result = \mod_quora\subscriptions::get_unsubscribable_quoras();
     $this->assertEquals(0, count($result));
     // Create the quoras.
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE);
     $forcequora = $this->getDataGenerator()->create_module('quora', $options);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_DISALLOWSUBSCRIBE);
     $disallowquora = $this->getDataGenerator()->create_module('quora', $options);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE);
     $choosequora = $this->getDataGenerator()->create_module('quora', $options);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
     $initialquora = $this->getDataGenerator()->create_module('quora', $options);
     // At present the user is only subscribed to the initial quora.
     $result = \mod_quora\subscriptions::get_unsubscribable_quoras();
     $this->assertEquals(1, count($result));
     // Ensure that the user is enrolled in all of the quoras except force subscribed.
     \mod_quora\subscriptions::subscribe_user($user->id, $disallowquora);
     \mod_quora\subscriptions::subscribe_user($user->id, $choosequora);
     $result = \mod_quora\subscriptions::get_unsubscribable_quoras();
     $this->assertEquals(3, count($result));
     // Hide the quoras.
     set_coursemodule_visible($forcequora->cmid, 0);
     set_coursemodule_visible($disallowquora->cmid, 0);
     set_coursemodule_visible($choosequora->cmid, 0);
     set_coursemodule_visible($initialquora->cmid, 0);
     $result = \mod_quora\subscriptions::get_unsubscribable_quoras();
     $this->assertEquals(0, count($result));
     // Add the moodle/course:viewhiddenactivities capability to the student user.
     $roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
     $context = \context_course::instance($course->id);
     assign_capability('moodle/course:viewhiddenactivities', CAP_ALLOW, $roleids['student'], $context);
     $context->mark_dirty();
     // All of the unsubscribable quoras should now be listed.
     $result = \mod_quora\subscriptions::get_unsubscribable_quoras();
     $this->assertEquals(3, count($result));
 }