Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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   * User evidence competency persistent class tests.
  19   *
  20   * @package    core_competency
  21   * @copyright  2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  global $CFG;
  27  
  28  use core_competency\user_evidence_competency;
  29  
  30  /**
  31   * User evidence competency persistent testcase.
  32   *
  33   * @package    core_competency
  34   * @copyright  2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class core_competency_user_evidence_competency_testcase extends advanced_testcase {
  38  
  39      public function test_get_user_competencies_by_userevidenceid() {
  40          global $CFG, $DB;
  41  
  42          $this->resetAfterTest(true);
  43          $dg = $this->getDataGenerator();
  44          $lpg = $dg->get_plugin_generator('core_competency');
  45  
  46          $u1 = $dg->create_user();
  47  
  48          // Create framework with competencies.
  49          $fw = $lpg->create_framework();
  50          $c1 = $lpg->create_competency(array('competencyframeworkid' => $fw->get('id')));
  51          $c2 = $lpg->create_competency(array('competencyframeworkid' => $fw->get('id')));
  52          $c3 = $lpg->create_competency(array('competencyframeworkid' => $fw->get('id')));
  53          $c4 = $lpg->create_competency(array('competencyframeworkid' => $fw->get('id')));
  54  
  55          // Create a plan with competencies.
  56          $p1 = $lpg->create_plan(array('userid' => $u1->id));
  57          $lpg->create_plan_competency(array('planid' => $p1->get('id'), 'competencyid' => $c1->get('id')));
  58          $lpg->create_plan_competency(array('planid' => $p1->get('id'), 'competencyid' => $c2->get('id')));
  59          $lpg->create_plan_competency(array('planid' => $p1->get('id'), 'competencyid' => $c3->get('id')));
  60          $lpg->create_plan_competency(array('planid' => $p1->get('id'), 'competencyid' => $c4->get('id')));
  61  
  62          // Create a prior learning evidence and link competencies.
  63          $ue1 = $lpg->create_user_evidence(array('userid' => $u1->id));
  64          $uec11 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get('id'), 'competencyid' => $c1->get('id')));
  65          $uec12 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get('id'), 'competencyid' => $c2->get('id')));
  66          $uec13 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get('id'), 'competencyid' => $c3->get('id')));
  67          $uc11 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c1->get('id')));
  68          $uc12 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c2->get('id')));
  69          $uc13 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c3->get('id')));
  70  
  71          // Create an other prior learning evidence and link competencies.
  72          $ue2 = $lpg->create_user_evidence(array('userid' => $u1->id));
  73          $uec22 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue2->get('id'), 'competencyid' => $c4->get('id')));
  74          $uc22 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c4->get('id')));
  75  
  76          // Check the user competencies associated to the first prior learning evidence.
  77          $ucs = user_evidence_competency::get_user_competencies_by_userevidenceid($ue1->get('id'));
  78          $this->assertCount(3, $ucs);
  79          $uc = array_shift($ucs);
  80          $this->assertEquals($uc->get('id'), $uc11->get('id'));
  81          $uc = array_shift($ucs);
  82          $this->assertEquals($uc->get('id'), $uc12->get('id'));
  83          $uc = array_shift($ucs);
  84          $this->assertEquals($uc->get('id'), $uc13->get('id'));
  85  
  86          // Check the user competencies associated to the second prior learning evidence.
  87          $ucs = user_evidence_competency::get_user_competencies_by_userevidenceid($ue2->get('id'));
  88          $this->assertCount(1, $ucs);
  89          $uc = array_shift($ucs);
  90          $this->assertEquals($uc->get('id'), $uc22->get('id'));
  91      }
  92  }