[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/self/tests/ -> externallib_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   * Self enrol external PHPunit tests
  19   *
  20   * @package   enrol_self
  21   * @copyright 2013 Rajesh Taneja <[email protected]>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   * @since     Moodle 2.6
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  
  30  require_once($CFG->dirroot . '/webservice/tests/helpers.php');
  31  require_once($CFG->dirroot . '/enrol/self/externallib.php');
  32  
  33  class enrol_self_external_testcase extends externallib_advanced_testcase {
  34  
  35      /**
  36       * Test get_instance_info
  37       */
  38      public function test_get_instance_info() {
  39          global $DB;
  40  
  41          $this->resetAfterTest(true);
  42  
  43          // Check if self enrolment plugin is enabled.
  44          $selfplugin = enrol_get_plugin('self');
  45          $this->assertNotEmpty($selfplugin);
  46  
  47          $studentrole = $DB->get_record('role', array('shortname'=>'student'));
  48          $this->assertNotEmpty($studentrole);
  49  
  50          $course = self::getDataGenerator()->create_course();
  51  
  52          // Add enrolment methods for course.
  53          $instanceid1 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_ENABLED,
  54                                                                  'name' => 'Test instance 1',
  55                                                                  'customint6' => 1,
  56                                                                  'roleid' => $studentrole->id));
  57          $instanceid2 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_DISABLED,
  58                                                                  'customint6' => 1,
  59                                                                  'name' => 'Test instance 2',
  60                                                                  'roleid' => $studentrole->id));
  61  
  62          $instanceid3 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_ENABLED,
  63                                                                  'roleid' => $studentrole->id,
  64                                                                  'customint6' => 1,
  65                                                                  'name' => 'Test instance 3',
  66                                                                  'password' => 'test'));
  67  
  68          $enrolmentmethods = $DB->get_records('enrol', array('courseid' => $course->id, 'status' => ENROL_INSTANCE_ENABLED));
  69          $this->assertCount(3, $enrolmentmethods);
  70  
  71          $instanceinfo1 = enrol_self_external::get_instance_info($instanceid1);
  72  
  73          $this->assertEquals($instanceid1, $instanceinfo1['id']);
  74          $this->assertEquals($course->id, $instanceinfo1['courseid']);
  75          $this->assertEquals('self', $instanceinfo1['type']);
  76          $this->assertEquals('Test instance 1', $instanceinfo1['name']);
  77          $this->assertTrue($instanceinfo1['status']);
  78          $this->assertFalse(isset($instanceinfo1['enrolpassword']));
  79  
  80          $instanceinfo2 = enrol_self_external::get_instance_info($instanceid2);
  81          $this->assertEquals($instanceid2, $instanceinfo2['id']);
  82          $this->assertEquals($course->id, $instanceinfo2['courseid']);
  83          $this->assertEquals('self', $instanceinfo2['type']);
  84          $this->assertEquals('Test instance 2', $instanceinfo2['name']);
  85          $this->assertEquals(get_string('canntenrol', 'enrol_self'), $instanceinfo2['status']);
  86          $this->assertFalse(isset($instanceinfo2['enrolpassword']));
  87  
  88          $instanceinfo3 = enrol_self_external::get_instance_info($instanceid3);
  89          $this->assertEquals($instanceid3, $instanceinfo3['id']);
  90          $this->assertEquals($course->id, $instanceinfo3['courseid']);
  91          $this->assertEquals('self', $instanceinfo3['type']);
  92          $this->assertEquals('Test instance 3', $instanceinfo3['name']);
  93          $this->assertTrue($instanceinfo3['status']);
  94          $this->assertEquals(get_string('password', 'enrol_self'), $instanceinfo3['enrolpassword']);
  95      }
  96  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1