Merge branch 'wip-mdl-40126' of git://github.com/rajeshtaneja/moodle
authorMarina Glancy <marina@moodle.com>
Tue, 6 Aug 2013 12:53:19 +0000 (22:53 +1000)
committerMarina Glancy <marina@moodle.com>
Tue, 6 Aug 2013 12:53:19 +0000 (22:53 +1000)
1  2 
enrol/tests/externallib_test.php

@@@ -30,7 -30,7 +30,7 @@@ require_once($CFG->dirroot . '/enrol/ex
   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
   * @since Moodle 2.4
   */
 -class core_enrol_external_testcase extends externallib_advanced_testcase {
 +class core_enrol_externallib_testcase extends externallib_advanced_testcase {
  
      /**
       * Test get_enrolled_users
          $this->assertEquals(1, count($expecteduserlist['users']));
  
      }
+     /**
+      * Test get_course_enrolment_methods
+      */
+     public function test_get_course_enrolment_methods() {
+         global $DB;
+         $this->resetAfterTest(true);
+         // Get enrolment plugins.
+         $selfplugin = enrol_get_plugin('self');
+         $this->assertNotEmpty($selfplugin);
+         $manualplugin = enrol_get_plugin('manual');
+         $this->assertNotEmpty($manualplugin);
+         $studentrole = $DB->get_record('role', array('shortname'=>'student'));
+         $this->assertNotEmpty($studentrole);
+         $course1 = self::getDataGenerator()->create_course();
+         $course2 = self::getDataGenerator()->create_course();
+         // Add enrolment methods for course.
+         $instanceid1 = $selfplugin->add_instance($course1, array('status' => ENROL_INSTANCE_ENABLED,
+                                                                 'name' => 'Test instance 1',
+                                                                 'customint6' => 1,
+                                                                 'roleid' => $studentrole->id));
+         $instanceid2 = $selfplugin->add_instance($course1, array('status' => ENROL_INSTANCE_DISABLED,
+                                                                 'name' => 'Test instance 2',
+                                                                 'roleid' => $studentrole->id));
+         $instanceid3 = $manualplugin->add_instance($course1, array('status' => ENROL_INSTANCE_ENABLED,
+                                                                 'name' => 'Test instance 3'));
+         $enrolmentmethods = $DB->get_records('enrol', array('courseid' => $course1->id, 'status' => ENROL_INSTANCE_ENABLED));
+         $this->assertCount(2, $enrolmentmethods);
+         // Check if information is returned.
+         $enrolmentmethods = core_enrol_external::get_course_enrolment_methods($course1->id);
+         // Enrolment information is currently returned by self enrolment plugin, so count == 1.
+         // This should be changed as we implement get_enrol_info() for other enrolment plugins.
+         $this->assertCount(1, $enrolmentmethods);
+         $enrolmentmethod = $enrolmentmethods[0];
+         $this->assertEquals($course1->id, $enrolmentmethod['courseid']);
+         $this->assertEquals('self', $enrolmentmethod['type']);
+         $this->assertTrue($enrolmentmethod['status']);
+         $this->assertFalse(isset($enrolmentmethod['wsfunction']));
+         $instanceid4 = $selfplugin->add_instance($course2, array('status' => ENROL_INSTANCE_ENABLED,
+                                                                 'name' => 'Test instance 4',
+                                                                 'roleid' => $studentrole->id,
+                                                                 'customint6' => 1,
+                                                                 'password' => 'test'));
+         $enrolmentmethods = core_enrol_external::get_course_enrolment_methods($course2->id);
+         $this->assertCount(1, $enrolmentmethods);
+         $enrolmentmethod = $enrolmentmethods[0];
+         $this->assertEquals($course2->id, $enrolmentmethod['courseid']);
+         $this->assertEquals('self', $enrolmentmethod['type']);
+         $this->assertTrue($enrolmentmethod['status']);
+         $this->assertEquals('enrol_self_get_instance_info', $enrolmentmethod['wsfunction']);
+     }
  }