Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 23... Línea 23...
23
 * @copyright  2015 Frédéric Massart - FMCorz.net
23
 * @copyright  2015 Frédéric Massart - FMCorz.net
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
25
 */
26
class api_test extends \advanced_testcase {
26
class api_test extends \advanced_testcase {
Línea 27... Línea 27...
27
 
27
 
28
    public function test_get_framework_related_contexts() {
28
    public function test_get_framework_related_contexts(): void {
29
        $this->resetAfterTest(true);
29
        $this->resetAfterTest(true);
30
        $dg = $this->getDataGenerator();
30
        $dg = $this->getDataGenerator();
31
        $cat1 = $dg->create_category();
31
        $cat1 = $dg->create_category();
32
        $cat2 = $dg->create_category(array('parent' => $cat1->id));
32
        $cat2 = $dg->create_category(array('parent' => $cat1->id));
Línea 46... Línea 46...
46
 
46
 
47
        $expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx, $cat2ctx->id => $cat2ctx);
47
        $expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx, $cat2ctx->id => $cat2ctx);
48
        $this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents'));
48
        $this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents'));
Línea 49... Línea 49...
49
    }
49
    }
50
 
50
 
51
    public function test_get_framework_related_contexts_with_capabilities() {
51
    public function test_get_framework_related_contexts_with_capabilities(): void {
52
        $this->resetAfterTest(true);
52
        $this->resetAfterTest(true);
53
        $dg = $this->getDataGenerator();
53
        $dg = $this->getDataGenerator();
54
        $user = $dg->create_user();
54
        $user = $dg->create_user();
Línea 84... Línea 84...
84
 
84
 
85
        $expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx);
85
        $expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx);
86
        $this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents', $requiredcap));
86
        $this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents', $requiredcap));
Línea 87... Línea 87...
87
    }
87
    }
88
 
88
 
89
    public function test_get_template_related_contexts() {
89
    public function test_get_template_related_contexts(): void {
90
        $this->resetAfterTest(true);
90
        $this->resetAfterTest(true);
91
        $dg = $this->getDataGenerator();
91
        $dg = $this->getDataGenerator();
92
        $cat1 = $dg->create_category();
92
        $cat1 = $dg->create_category();
Línea 107... Línea 107...
107
 
107
 
108
        $expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx, $cat2ctx->id => $cat2ctx);
108
        $expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx, $cat2ctx->id => $cat2ctx);
109
        $this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents'));
109
        $this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents'));
Línea 110... Línea 110...
110
    }
110
    }
111
 
111
 
112
    public function test_get_template_related_contexts_with_capabilities() {
112
    public function test_get_template_related_contexts_with_capabilities(): void {
113
        $this->resetAfterTest(true);
113
        $this->resetAfterTest(true);
114
        $dg = $this->getDataGenerator();
114
        $dg = $this->getDataGenerator();
115
        $user = $dg->create_user();
115
        $user = $dg->create_user();
Línea 148... Línea 148...
148
    }
148
    }
Línea 149... Línea 149...
149
 
149
 
150
    /**
150
    /**
151
     * Test updating a template.
151
     * Test updating a template.
152
     */
152
     */
153
    public function test_update_template() {
153
    public function test_update_template(): void {
154
        $cat = $this->getDataGenerator()->create_category();
154
        $cat = $this->getDataGenerator()->create_category();
155
        $this->resetAfterTest(true);
155
        $this->resetAfterTest(true);
Línea 156... Línea 156...
156
        $this->setAdminUser();
156
        $this->setAdminUser();
Línea 172... Línea 172...
172
    }
172
    }
Línea 173... Línea 173...
173
 
173
 
174
    /**
174
    /**
175
     * Test listing framework with order param.
175
     * Test listing framework with order param.
176
     */
176
     */
177
    public function test_list_frameworks() {
177
    public function test_list_frameworks(): void {
178
        $this->resetAfterTest(true);
178
        $this->resetAfterTest(true);
179
        $this->setAdminUser();
179
        $this->setAdminUser();
Línea 180... Línea 180...
180
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
180
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
Línea 261... Línea 261...
261
    }
261
    }
Línea 262... Línea 262...
262
 
262
 
263
    /**
263
    /**
264
     * Test duplicate a framework.
264
     * Test duplicate a framework.
265
     */
265
     */
266
    public function test_duplicate_framework() {
266
    public function test_duplicate_framework(): void {
267
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
267
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
268
        $this->resetAfterTest(true);
268
        $this->resetAfterTest(true);
Línea 269... Línea 269...
269
        $this->setAdminUser();
269
        $this->setAdminUser();
Línea 370... Línea 370...
370
    }
370
    }
Línea 371... Línea 371...
371
 
371
 
372
    /**
372
    /**
373
     * Test update plan.
373
     * Test update plan.
374
     */
374
     */
375
    public function test_update_plan() {
375
    public function test_update_plan(): void {
376
        $this->resetAfterTest(true);
376
        $this->resetAfterTest(true);
377
        $dg = $this->getDataGenerator();
377
        $dg = $this->getDataGenerator();
378
        $usermanageowndraft = $dg->create_user();
378
        $usermanageowndraft = $dg->create_user();
379
        $usermanageown = $dg->create_user();
379
        $usermanageown = $dg->create_user();
Línea 492... Línea 492...
492
        } catch (\coding_exception $e) {
492
        } catch (\coding_exception $e) {
493
            $this->assertTrue(true);
493
            $this->assertTrue(true);
494
        }
494
        }
495
    }
495
    }
Línea 496... Línea 496...
496
 
496
 
497
    public function test_create_plan_from_template() {
497
    public function test_create_plan_from_template(): void {
498
        $this->resetAfterTest(true);
498
        $this->resetAfterTest(true);
Línea 499... Línea 499...
499
        $this->setAdminUser();
499
        $this->setAdminUser();
500
 
500
 
Línea 518... Línea 518...
518
        unset($record->id);
518
        unset($record->id);
519
        $this->expectException(\coding_exception::class);
519
        $this->expectException(\coding_exception::class);
520
        $plan = api::create_plan($record);
520
        $plan = api::create_plan($record);
521
    }
521
    }
Línea 522... Línea 522...
522
 
522
 
523
    public function test_update_plan_based_on_template() {
523
    public function test_update_plan_based_on_template(): void {
524
        $this->resetAfterTest(true);
524
        $this->resetAfterTest(true);
525
        $dg = $this->getDataGenerator();
525
        $dg = $this->getDataGenerator();
526
        $lpg = $dg->get_plugin_generator('core_competency');
526
        $lpg = $dg->get_plugin_generator('core_competency');
527
        $u1 = $dg->create_user();
527
        $u1 = $dg->create_user();
Línea 562... Línea 562...
562
        } catch (\coding_exception $e) {
562
        } catch (\coding_exception $e) {
563
            // All good.
563
            // All good.
564
        }
564
        }
565
    }
565
    }
Línea 566... Línea 566...
566
 
566
 
567
    public function test_unlink_plan_from_template() {
567
    public function test_unlink_plan_from_template(): void {
568
        $this->resetAfterTest(true);
568
        $this->resetAfterTest(true);
569
        $dg = $this->getDataGenerator();
569
        $dg = $this->getDataGenerator();
570
        $lpg = $dg->get_plugin_generator('core_competency');
570
        $lpg = $dg->get_plugin_generator('core_competency');
571
        $u1 = $dg->create_user();
571
        $u1 = $dg->create_user();
Línea 643... Línea 643...
643
        $after = next($plan1comps);
643
        $after = next($plan1comps);
644
        $this->assertEquals($before->get('id'), $after->get('id'));
644
        $this->assertEquals($before->get('id'), $after->get('id'));
645
        $this->assertEquals($before->get('sortorder'), $after->get('sortorder'));
645
        $this->assertEquals($before->get('sortorder'), $after->get('sortorder'));
646
    }
646
    }
Línea 647... Línea 647...
647
 
647
 
648
    public function test_update_template_updates_plans() {
648
    public function test_update_template_updates_plans(): void {
649
        $this->resetAfterTest(true);
649
        $this->resetAfterTest(true);
Línea 650... Línea 650...
650
        $this->setAdminUser();
650
        $this->setAdminUser();
651
 
651
 
Línea 736... Línea 736...
736
    }
736
    }
Línea 737... Línea 737...
737
 
737
 
738
    /**
738
    /**
739
     * Test that the method to complete a plan.
739
     * Test that the method to complete a plan.
740
     */
740
     */
741
    public function test_complete_plan() {
741
    public function test_complete_plan(): void {
Línea 742... Línea 742...
742
        global $DB;
742
        global $DB;
743
 
743
 
744
        $this->resetAfterTest(true);
744
        $this->resetAfterTest(true);
Línea 863... Línea 863...
863
    }
863
    }
Línea 864... Línea 864...
864
 
864
 
865
    /**
865
    /**
866
     * Testing requesting the review of a plan.
866
     * Testing requesting the review of a plan.
867
     */
867
     */
868
    public function test_plan_request_review() {
868
    public function test_plan_request_review(): void {
869
        $data = $this->setup_workflow_data();
869
        $data = $this->setup_workflow_data();
870
        $dg = $data['dg'];
870
        $dg = $data['dg'];
871
        $lpg = $data['lpg'];
871
        $lpg = $data['lpg'];
872
        $user = $data['user'];
872
        $user = $data['user'];
Línea 961... Línea 961...
961
    }
961
    }
Línea 962... Línea 962...
962
 
962
 
963
    /**
963
    /**
964
     * Testing cancelling the review request.
964
     * Testing cancelling the review request.
965
     */
965
     */
966
    public function test_plan_cancel_review_request() {
966
    public function test_plan_cancel_review_request(): void {
967
        $data = $this->setup_workflow_data();
967
        $data = $this->setup_workflow_data();
968
        $dg = $data['dg'];
968
        $dg = $data['dg'];
969
        $lpg = $data['lpg'];
969
        $lpg = $data['lpg'];
970
        $user = $data['user'];
970
        $user = $data['user'];
Línea 1062... Línea 1062...
1062
    }
1062
    }
Línea 1063... Línea 1063...
1063
 
1063
 
1064
    /**
1064
    /**
1065
     * Testing starting the review.
1065
     * Testing starting the review.
1066
     */
1066
     */
1067
    public function test_plan_start_review() {
1067
    public function test_plan_start_review(): void {
1068
        $data = $this->setup_workflow_data();
1068
        $data = $this->setup_workflow_data();
1069
        $dg = $data['dg'];
1069
        $dg = $data['dg'];
1070
        $lpg = $data['lpg'];
1070
        $lpg = $data['lpg'];
1071
        $user = $data['user'];
1071
        $user = $data['user'];
Línea 1166... Línea 1166...
1166
    }
1166
    }
Línea 1167... Línea 1167...
1167
 
1167
 
1168
    /**
1168
    /**
1169
     * Testing stopping the review.
1169
     * Testing stopping the review.
1170
     */
1170
     */
1171
    public function test_plan_stop_review() {
1171
    public function test_plan_stop_review(): void {
1172
        $data = $this->setup_workflow_data();
1172
        $data = $this->setup_workflow_data();
1173
        $dg = $data['dg'];
1173
        $dg = $data['dg'];
1174
        $lpg = $data['lpg'];
1174
        $lpg = $data['lpg'];
1175
        $user = $data['user'];
1175
        $user = $data['user'];
Línea 1267... Línea 1267...
1267
    }
1267
    }
Línea 1268... Línea 1268...
1268
 
1268
 
1269
    /**
1269
    /**
1270
     * Testing approving the plan.
1270
     * Testing approving the plan.
1271
     */
1271
     */
1272
    public function test_approve_plan() {
1272
    public function test_approve_plan(): void {
1273
        $data = $this->setup_workflow_data();
1273
        $data = $this->setup_workflow_data();
1274
        $dg = $data['dg'];
1274
        $dg = $data['dg'];
1275
        $lpg = $data['lpg'];
1275
        $lpg = $data['lpg'];
1276
        $user = $data['user'];
1276
        $user = $data['user'];
Línea 1362... Línea 1362...
1362
    }
1362
    }
Línea 1363... Línea 1363...
1363
 
1363
 
1364
    /**
1364
    /**
1365
     * Testing stopping the review.
1365
     * Testing stopping the review.
1366
     */
1366
     */
1367
    public function test_unapprove_plan() {
1367
    public function test_unapprove_plan(): void {
1368
        $data = $this->setup_workflow_data();
1368
        $data = $this->setup_workflow_data();
1369
        $dg = $data['dg'];
1369
        $dg = $data['dg'];
1370
        $lpg = $data['lpg'];
1370
        $lpg = $data['lpg'];
1371
        $user = $data['user'];
1371
        $user = $data['user'];
Línea 1463... Línea 1463...
1463
    }
1463
    }
Línea 1464... Línea 1464...
1464
 
1464
 
1465
    /**
1465
    /**
1466
     * Test update plan and the managing of archived user competencies.
1466
     * Test update plan and the managing of archived user competencies.
1467
     */
1467
     */
1468
    public function test_update_plan_manage_archived_competencies() {
1468
    public function test_update_plan_manage_archived_competencies(): void {
Línea 1469... Línea 1469...
1469
        global $DB;
1469
        global $DB;
1470
 
1470
 
1471
        $this->resetAfterTest(true);
1471
        $this->resetAfterTest(true);
Línea 1571... Línea 1571...
1571
    }
1571
    }
Línea 1572... Línea 1572...
1572
 
1572
 
1573
    /**
1573
    /**
1574
     * Test completing plan does not change the order of competencies.
1574
     * Test completing plan does not change the order of competencies.
1575
     */
1575
     */
1576
    public function test_complete_plan_doesnot_change_order() {
1576
    public function test_complete_plan_doesnot_change_order(): void {
Línea 1577... Línea 1577...
1577
        global $DB;
1577
        global $DB;
1578
 
1578
 
1579
        $this->resetAfterTest(true);
1579
        $this->resetAfterTest(true);
Línea 1661... Línea 1661...
1661
    }
1661
    }
Línea 1662... Línea 1662...
1662
 
1662
 
1663
    /**
1663
    /**
1664
     * Test remove plan and the managing of archived user competencies.
1664
     * Test remove plan and the managing of archived user competencies.
1665
     */
1665
     */
1666
    public function test_delete_plan_manage_archived_competencies() {
1666
    public function test_delete_plan_manage_archived_competencies(): void {
1667
        $this->resetAfterTest(true);
1667
        $this->resetAfterTest(true);
1668
        $dg = $this->getDataGenerator();
1668
        $dg = $this->getDataGenerator();
Línea 1669... Línea 1669...
1669
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
1669
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
Línea 1710... Línea 1710...
1710
    }
1710
    }
Línea 1711... Línea 1711...
1711
 
1711
 
1712
    /**
1712
    /**
1713
     * Test listing of plan competencies.
1713
     * Test listing of plan competencies.
1714
     */
1714
     */
1715
    public function test_list_plan_competencies_manage_archived_competencies() {
1715
    public function test_list_plan_competencies_manage_archived_competencies(): void {
1716
        $this->resetAfterTest(true);
1716
        $this->resetAfterTest(true);
1717
        $dg = $this->getDataGenerator();
1717
        $dg = $this->getDataGenerator();
Línea 1718... Línea 1718...
1718
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
1718
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
Línea 1789... Línea 1789...
1789
        $this->assertInstanceOf('\core_competency\user_competency_plan', $plancompetencies[2]->usercompetencyplan);
1789
        $this->assertInstanceOf('\core_competency\user_competency_plan', $plancompetencies[2]->usercompetencyplan);
1790
        $this->assertEquals($ucp3->get('id'), $plancompetencies[2]->usercompetencyplan->get('id'));
1790
        $this->assertEquals($ucp3->get('id'), $plancompetencies[2]->usercompetencyplan->get('id'));
1791
        $this->assertNull($plancompetencies[2]->usercompetency);
1791
        $this->assertNull($plancompetencies[2]->usercompetency);
1792
    }
1792
    }
Línea 1793... Línea 1793...
1793
 
1793
 
1794
    public function test_create_template_cohort() {
1794
    public function test_create_template_cohort(): void {
1795
        $this->resetAfterTest(true);
1795
        $this->resetAfterTest(true);
Línea 1796... Línea 1796...
1796
        $this->setAdminUser();
1796
        $this->setAdminUser();
1797
 
1797
 
Línea 1817... Línea 1817...
1817
            array('id' => $t1->get('id'))));
1817
            array('id' => $t1->get('id'))));
1818
        $this->assertEquals(0, \core_competency\template_cohort::count_records_select('templateid = :id',
1818
        $this->assertEquals(0, \core_competency\template_cohort::count_records_select('templateid = :id',
1819
            array('id' => $t2->get('id'))));
1819
            array('id' => $t2->get('id'))));
1820
    }
1820
    }
Línea 1821... Línea 1821...
1821
 
1821
 
1822
    public function test_create_template_cohort_permissions() {
1822
    public function test_create_template_cohort_permissions(): void {
Línea 1823... Línea 1823...
1823
        $this->resetAfterTest(true);
1823
        $this->resetAfterTest(true);
1824
 
1824
 
1825
        $dg = $this->getDataGenerator();
1825
        $dg = $this->getDataGenerator();
Línea 1861... Línea 1861...
1861
 
1861
 
1862
        $result = api::create_template_cohort($t1, $c2);
1862
        $result = api::create_template_cohort($t1, $c2);
1863
        $this->assertInstanceOf('core_competency\\template_cohort', $result);
1863
        $this->assertInstanceOf('core_competency\\template_cohort', $result);
Línea 1864... Línea 1864...
1864
    }
1864
    }
1865
 
1865
 
Línea 1866... Línea 1866...
1866
    public function test_reorder_template_competencies_permissions() {
1866
    public function test_reorder_template_competencies_permissions(): void {
1867
        $this->resetAfterTest(true);
1867
        $this->resetAfterTest(true);
1868
 
1868
 
Línea 1926... Línea 1926...
1926
        } catch (\required_capability_exception $e) {
1926
        } catch (\required_capability_exception $e) {
1927
            $this->assertEquals('nopermissions', $e->errorcode);
1927
            $this->assertEquals('nopermissions', $e->errorcode);
1928
        }
1928
        }
1929
    }
1929
    }
Línea 1930... Línea 1930...
1930
 
1930
 
1931
    public function test_delete_template() {
1931
    public function test_delete_template(): void {
1932
        $this->resetAfterTest(true);
1932
        $this->resetAfterTest(true);
Línea 1933... Línea 1933...
1933
        $this->setAdminUser();
1933
        $this->setAdminUser();
1934
 
1934
 
Línea 1956... Línea 1956...
1956
 
1956
 
1957
        // Test if associated cohorts are also deleted.
1957
        // Test if associated cohorts are also deleted.
1958
        $this->assertEquals(0, \core_competency\template_cohort::count_records(array('templateid' => $id)));
1958
        $this->assertEquals(0, \core_competency\template_cohort::count_records(array('templateid' => $id)));
Línea 1959... Línea 1959...
1959
    }
1959
    }
1960
 
1960
 
1961
    public function test_delete_template_cohort() {
1961
    public function test_delete_template_cohort(): void {
Línea 1962... Línea 1962...
1962
        $this->resetAfterTest(true);
1962
        $this->resetAfterTest(true);
1963
        $this->setAdminUser();
1963
        $this->setAdminUser();
Línea 1995... Línea 1995...
1995
            array('id' => $t1->get('id'))));
1995
            array('id' => $t1->get('id'))));
1996
        $this->assertEquals(1, \core_competency\template_cohort::count_records_select('templateid = :id',
1996
        $this->assertEquals(1, \core_competency\template_cohort::count_records_select('templateid = :id',
1997
            array('id' => $t2->get('id'))));
1997
            array('id' => $t2->get('id'))));
1998
    }
1998
    }
Línea 1999... Línea 1999...
1999
 
1999
 
2000
    public function test_add_evidence_log() {
2000
    public function test_add_evidence_log(): void {
2001
        $this->resetAfterTest(true);
2001
        $this->resetAfterTest(true);
2002
        $dg = $this->getDataGenerator();
2002
        $dg = $this->getDataGenerator();
Línea 2003... Línea 2003...
2003
        $lpg = $dg->get_plugin_generator('core_competency');
2003
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 2060... Línea 2060...
2060
        } catch (\coding_exception $e) {
2060
        } catch (\coding_exception $e) {
2061
            $this->assertMatchesRegularExpression('/grade MUST NOT be set/', $e->getMessage());
2061
            $this->assertMatchesRegularExpression('/grade MUST NOT be set/', $e->getMessage());
2062
        }
2062
        }
2063
    }
2063
    }
Línea 2064... Línea 2064...
2064
 
2064
 
2065
    public function test_add_evidence_complete() {
2065
    public function test_add_evidence_complete(): void {
2066
        $this->resetAfterTest(true);
2066
        $this->resetAfterTest(true);
2067
        $dg = $this->getDataGenerator();
2067
        $dg = $this->getDataGenerator();
Línea 2068... Línea 2068...
2068
        $lpg = $dg->get_plugin_generator('core_competency');
2068
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 2156... Línea 2156...
2156
        } catch (\coding_exception $e) {
2156
        } catch (\coding_exception $e) {
2157
            $this->assertMatchesRegularExpression('/grade MUST NOT be set/', $e->getMessage());
2157
            $this->assertMatchesRegularExpression('/grade MUST NOT be set/', $e->getMessage());
2158
        }
2158
        }
2159
    }
2159
    }
Línea 2160... Línea 2160...
2160
 
2160
 
2161
    public function test_add_evidence_override() {
2161
    public function test_add_evidence_override(): void {
2162
        $this->resetAfterTest(true);
2162
        $this->resetAfterTest(true);
2163
        $dg = $this->getDataGenerator();
2163
        $dg = $this->getDataGenerator();
Línea 2164... Línea 2164...
2164
        $lpg = $dg->get_plugin_generator('core_competency');
2164
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 2231... Línea 2231...
2231
        $this->assertSame(null, $uc->get('proficiency'));
2231
        $this->assertSame(null, $uc->get('proficiency'));
2232
        $this->assertEquals(\core_competency\user_competency::STATUS_WAITING_FOR_REVIEW, $uc->get('status'));
2232
        $this->assertEquals(\core_competency\user_competency::STATUS_WAITING_FOR_REVIEW, $uc->get('status'));
2233
        $this->assertSame(null, $evidence->get('grade'));
2233
        $this->assertSame(null, $evidence->get('grade'));
2234
    }
2234
    }
Línea 2235... Línea 2235...
2235
 
2235
 
2236
    public function test_add_evidence_and_send_for_review() {
2236
    public function test_add_evidence_and_send_for_review(): void {
2237
        $this->resetAfterTest(true);
2237
        $this->resetAfterTest(true);
2238
        $dg = $this->getDataGenerator();
2238
        $dg = $this->getDataGenerator();
Línea 2239... Línea 2239...
2239
        $lpg = $dg->get_plugin_generator('core_competency');
2239
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 2265... Línea 2265...
2265
    }
2265
    }
Línea 2266... Línea 2266...
2266
 
2266
 
2267
    /**
2267
    /**
2268
     * Test add evidence for existing user_competency.
2268
     * Test add evidence for existing user_competency.
2269
     */
2269
     */
2270
    public function test_add_evidence_existing_user_competency() {
2270
    public function test_add_evidence_existing_user_competency(): void {
2271
        $this->resetAfterTest(true);
2271
        $this->resetAfterTest(true);
2272
        $dg = $this->getDataGenerator();
2272
        $dg = $this->getDataGenerator();
Línea 2273... Línea 2273...
2273
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
2273
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
Línea 2307... Línea 2307...
2307
    }
2307
    }
Línea 2308... Línea 2308...
2308
 
2308
 
2309
    /**
2309
    /**
2310
     * Test add evidence for non-existing user_competency.
2310
     * Test add evidence for non-existing user_competency.
2311
     */
2311
     */
2312
    public function test_add_evidence_no_existing_user_competency() {
2312
    public function test_add_evidence_no_existing_user_competency(): void {
2313
        $this->resetAfterTest(true);
2313
        $this->resetAfterTest(true);
2314
        $dg = $this->getDataGenerator();
2314
        $dg = $this->getDataGenerator();
Línea 2315... Línea 2315...
2315
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
2315
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
Línea 2344... Línea 2344...
2344
        $this->assertEquals(1, $evidence->get('grade'));
2344
        $this->assertEquals(1, $evidence->get('grade'));
2345
        $this->assertEquals(1, $uc->get('grade'));
2345
        $this->assertEquals(1, $uc->get('grade'));
2346
        $this->assertEquals(0, $uc->get('proficiency'));
2346
        $this->assertEquals(0, $uc->get('proficiency'));
2347
    }
2347
    }
Línea 2348... Línea 2348...
2348
 
2348
 
2349
    public function test_add_evidence_applies_competency_rules() {
2349
    public function test_add_evidence_applies_competency_rules(): void {
2350
        $this->resetAfterTest(true);
2350
        $this->resetAfterTest(true);
2351
        $dg = $this->getDataGenerator();
2351
        $dg = $this->getDataGenerator();
2352
        $lpg = $dg->get_plugin_generator('core_competency');
2352
        $lpg = $dg->get_plugin_generator('core_competency');
2353
        $syscontext = \context_system::instance();
2353
        $syscontext = \context_system::instance();
Línea 2444... Línea 2444...
2444
 
2444
 
2445
    /**
2445
    /**
2446
     * Tests for the user_competency_course data when api::add_evidence() is invoked when
2446
     * Tests for the user_competency_course data when api::add_evidence() is invoked when
2447
     * grading a user competency in the system context.
2447
     * grading a user competency in the system context.
2448
     */
2448
     */
2449
    public function test_add_evidence_for_user_competency_course_grade_outside_course() {
2449
    public function test_add_evidence_for_user_competency_course_grade_outside_course(): void {
2450
        $this->resetAfterTest(true);
2450
        $this->resetAfterTest(true);
2451
        $dg = $this->getDataGenerator();
2451
        $dg = $this->getDataGenerator();
Línea 2452... Línea 2452...
2452
        $syscontext = \context_system::instance();
2452
        $syscontext = \context_system::instance();
Línea 2475... Línea 2475...
2475
 
2475
 
2476
    /**
2476
    /**
2477
     * Tests for the user_competency_course data when api::add_evidence() is invoked when
2477
     * Tests for the user_competency_course data when api::add_evidence() is invoked when
2478
     * grading a user competency in a course.
2478
     * grading a user competency in a course.
2479
     */
2479
     */
2480
    public function test_add_evidence_user_competency_course_grade_in_course() {
2480
    public function test_add_evidence_user_competency_course_grade_in_course(): void {
Línea 2481... Línea 2481...
2481
        global $USER;
2481
        global $USER;
2482
 
2482
 
Línea 2537... Línea 2537...
2537
        $this->assertNotEmpty($usercompetency);
2537
        $this->assertNotEmpty($usercompetency);
2538
        $this->assertNotEquals($usercompcourse->get('grade'), $usercompetency->get('grade'));
2538
        $this->assertNotEquals($usercompcourse->get('grade'), $usercompetency->get('grade'));
2539
        $this->assertNotEquals($usercompcourse->get('proficiency'), $usercompetency->get('proficiency'));
2539
        $this->assertNotEquals($usercompcourse->get('proficiency'), $usercompetency->get('proficiency'));
2540
    }
2540
    }
Línea 2541... Línea 2541...
2541
 
2541
 
2542
    public function test_observe_course_completed() {
2542
    public function test_observe_course_completed(): void {
2543
        $this->resetAfterTest(true);
2543
        $this->resetAfterTest(true);
2544
        $dg = $this->getDataGenerator();
2544
        $dg = $this->getDataGenerator();
Línea 2545... Línea 2545...
2545
        $lpg = $dg->get_plugin_generator('core_competency');
2545
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 2632... Línea 2632...
2632
        $this->assertEquals($coursectx->id, $ev4->get('contextid'));
2632
        $this->assertEquals($coursectx->id, $ev4->get('contextid'));
2633
        $this->assertEquals(\core_competency\evidence::ACTION_COMPLETE, $ev4->get('action'));
2633
        $this->assertEquals(\core_competency\evidence::ACTION_COMPLETE, $ev4->get('action'));
2634
        $this->assertEquals(null, $ev4->get('actionuserid'));
2634
        $this->assertEquals(null, $ev4->get('actionuserid'));
2635
    }
2635
    }
Línea 2636... Línea 2636...
2636
 
2636
 
2637
    public function test_list_evidence_in_course() {
2637
    public function test_list_evidence_in_course(): void {
Línea 2638... Línea 2638...
2638
        global $SITE;
2638
        global $SITE;
2639
 
2639
 
2640
        $this->resetAfterTest(true);
2640
        $this->resetAfterTest(true);
Línea 2673... Línea 2673...
2673
        $result = api::list_evidence_in_course($u1->id, $course->id, $c->get('id'), 'timecreated', 'ASC');
2673
        $result = api::list_evidence_in_course($u1->id, $course->id, $c->get('id'), 'timecreated', 'ASC');
2674
        $this->assertEquals($evidence1->get('id'), $result[0]->get('id'));
2674
        $this->assertEquals($evidence1->get('id'), $result[0]->get('id'));
2675
        $this->assertEquals($evidence2->get('id'), $result[1]->get('id'));
2675
        $this->assertEquals($evidence2->get('id'), $result[1]->get('id'));
2676
    }
2676
    }
Línea 2677... Línea 2677...
2677
 
2677
 
2678
    public function test_list_course_modules_using_competency() {
2678
    public function test_list_course_modules_using_competency(): void {
Línea 2679... Línea 2679...
2679
        global $SITE;
2679
        global $SITE;
2680
 
2680
 
2681
        $this->resetAfterTest(true);
2681
        $this->resetAfterTest(true);
Línea 2752... Línea 2752...
2752
    }
2752
    }
Línea 2753... Línea 2753...
2753
 
2753
 
2754
    /**
2754
    /**
2755
     * Test update ruleoutcome for course_competency.
2755
     * Test update ruleoutcome for course_competency.
2756
     */
2756
     */
2757
    public function test_set_ruleoutcome_course_competency() {
2757
    public function test_set_ruleoutcome_course_competency(): void {
2758
        $this->resetAfterTest(true);
2758
        $this->resetAfterTest(true);
2759
        $dg = $this->getDataGenerator();
2759
        $dg = $this->getDataGenerator();
2760
        $lpg = $dg->get_plugin_generator('core_competency');
2760
        $lpg = $dg->get_plugin_generator('core_competency');
2761
        $u1 = $dg->create_user();
2761
        $u1 = $dg->create_user();
Línea 2782... Línea 2782...
2782
    }
2782
    }
Línea 2783... Línea 2783...
2783
 
2783
 
2784
    /**
2784
    /**
2785
     * Test validation on grade on user_competency.
2785
     * Test validation on grade on user_competency.
2786
     */
2786
     */
2787
    public function test_validate_grade_in_user_competency() {
2787
    public function test_validate_grade_in_user_competency(): void {
Línea 2788... Línea 2788...
2788
        global $DB;
2788
        global $DB;
2789
 
2789
 
2790
        $this->resetAfterTest(true);
2790
        $this->resetAfterTest(true);
Línea 2857... Línea 2857...
2857
    }
2857
    }
Línea 2858... Línea 2858...
2858
 
2858
 
2859
    /**
2859
    /**
2860
     * Test when adding competency that belong to hidden framework to plan/template/course.
2860
     * Test when adding competency that belong to hidden framework to plan/template/course.
2861
     */
2861
     */
2862
    public function test_hidden_framework() {
2862
    public function test_hidden_framework(): void {
2863
        $this->resetAfterTest(true);
2863
        $this->resetAfterTest(true);
2864
        $this->setAdminUser();
2864
        $this->setAdminUser();
2865
        $dg = $this->getDataGenerator();
2865
        $dg = $this->getDataGenerator();
2866
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
2866
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
Línea 2907... Línea 2907...
2907
    }
2907
    }
Línea 2908... Línea 2908...
2908
 
2908
 
2909
    /**
2909
    /**
2910
     * Test when using hidden template in plan/cohort.
2910
     * Test when using hidden template in plan/cohort.
2911
     */
2911
     */
2912
    public function test_hidden_template() {
2912
    public function test_hidden_template(): void {
2913
        $this->resetAfterTest(true);
2913
        $this->resetAfterTest(true);
2914
        $this->setAdminUser();
2914
        $this->setAdminUser();
2915
        $dg = $this->getDataGenerator();
2915
        $dg = $this->getDataGenerator();
2916
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
2916
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
Línea 2935... Línea 2935...
2935
    }
2935
    }
Línea 2936... Línea 2936...
2936
 
2936
 
2937
    /**
2937
    /**
2938
     * Test that completed plan created form a template does not change when template is modified.
2938
     * Test that completed plan created form a template does not change when template is modified.
2939
     */
2939
     */
2940
    public function test_completed_plan_doesnot_change() {
2940
    public function test_completed_plan_doesnot_change(): void {
Línea 2941... Línea 2941...
2941
        global $DB;
2941
        global $DB;
2942
 
2942
 
2943
        $this->resetAfterTest(true);
2943
        $this->resetAfterTest(true);
Línea 3030... Línea 3030...
3030
            'c2' => $c2,
3030
            'c2' => $c2,
3031
            'c2a' => $c2a,
3031
            'c2a' => $c2a,
3032
        );
3032
        );
3033
    }
3033
    }
Línea 3034... Línea 3034...
3034
 
3034
 
3035
    public function test_moving_competency_reset_rules_updown() {
3035
    public function test_moving_competency_reset_rules_updown(): void {
3036
        $data = $this->setup_framework_for_reset_rules_tests();
3036
        $data = $this->setup_framework_for_reset_rules_tests();
3037
        $f1 = $data['f1'];
3037
        $f1 = $data['f1'];
3038
        $c1 = $data['c1'];
3038
        $c1 = $data['c1'];
3039
        $c1a = $data['c1a'];
3039
        $c1a = $data['c1a'];
Línea 3060... Línea 3060...
3060
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1->get('ruleoutcome'));
3060
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1->get('ruleoutcome'));
3061
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a->get('ruleoutcome'));
3061
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a->get('ruleoutcome'));
3062
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get('ruleoutcome'));
3062
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get('ruleoutcome'));
3063
    }
3063
    }
Línea 3064... Línea 3064...
3064
 
3064
 
3065
    public function test_moving_competency_reset_rules_parent() {
3065
    public function test_moving_competency_reset_rules_parent(): void {
3066
        $data = $this->setup_framework_for_reset_rules_tests();
3066
        $data = $this->setup_framework_for_reset_rules_tests();
3067
        $f1 = $data['f1'];
3067
        $f1 = $data['f1'];
3068
        $c1 = $data['c1'];
3068
        $c1 = $data['c1'];
3069
        $c1a = $data['c1a'];
3069
        $c1a = $data['c1a'];
Línea 3087... Línea 3087...
3087
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get('ruleoutcome'));
3087
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get('ruleoutcome'));
3088
        $this->assertEquals(competency::OUTCOME_NONE, $c1b->get('ruleoutcome'));
3088
        $this->assertEquals(competency::OUTCOME_NONE, $c1b->get('ruleoutcome'));
3089
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3089
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3090
    }
3090
    }
Línea 3091... Línea 3091...
3091
 
3091
 
3092
    public function test_moving_competency_reset_rules_totoplevel() {
3092
    public function test_moving_competency_reset_rules_totoplevel(): void {
3093
        $data = $this->setup_framework_for_reset_rules_tests();
3093
        $data = $this->setup_framework_for_reset_rules_tests();
3094
        $f1 = $data['f1'];
3094
        $f1 = $data['f1'];
3095
        $c1 = $data['c1'];
3095
        $c1 = $data['c1'];
3096
        $c1a = $data['c1a'];
3096
        $c1a = $data['c1a'];
Línea 3114... Línea 3114...
3114
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get('ruleoutcome'));
3114
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get('ruleoutcome'));
3115
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3115
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3116
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3116
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3117
    }
3117
    }
Línea 3118... Línea 3118...
3118
 
3118
 
3119
    public function test_moving_competency_reset_rules_fromtoplevel() {
3119
    public function test_moving_competency_reset_rules_fromtoplevel(): void {
3120
        $data = $this->setup_framework_for_reset_rules_tests();
3120
        $data = $this->setup_framework_for_reset_rules_tests();
3121
        $f1 = $data['f1'];
3121
        $f1 = $data['f1'];
3122
        $c1 = $data['c1'];
3122
        $c1 = $data['c1'];
3123
        $c1a = $data['c1a'];
3123
        $c1a = $data['c1a'];
Línea 3141... Línea 3141...
3141
        $this->assertEquals(competency::OUTCOME_NONE, $c1a1->get('ruleoutcome'));
3141
        $this->assertEquals(competency::OUTCOME_NONE, $c1a1->get('ruleoutcome'));
3142
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3142
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3143
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3143
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3144
    }
3144
    }
Línea 3145... Línea 3145...
3145
 
3145
 
3146
    public function test_moving_competency_reset_rules_child() {
3146
    public function test_moving_competency_reset_rules_child(): void {
3147
        $data = $this->setup_framework_for_reset_rules_tests();
3147
        $data = $this->setup_framework_for_reset_rules_tests();
3148
        $f1 = $data['f1'];
3148
        $f1 = $data['f1'];
3149
        $c1 = $data['c1'];
3149
        $c1 = $data['c1'];
3150
        $c1a = $data['c1a'];
3150
        $c1a = $data['c1a'];
Línea 3168... Línea 3168...
3168
        $this->assertEquals(competency::OUTCOME_NONE, $c1a1->get('ruleoutcome'));
3168
        $this->assertEquals(competency::OUTCOME_NONE, $c1a1->get('ruleoutcome'));
3169
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3169
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3170
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3170
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3171
    }
3171
    }
Línea 3172... Línea 3172...
3172
 
3172
 
3173
    public function test_create_competency_reset_rules() {
3173
    public function test_create_competency_reset_rules(): void {
3174
        $data = $this->setup_framework_for_reset_rules_tests();
3174
        $data = $this->setup_framework_for_reset_rules_tests();
3175
        $f1 = $data['f1'];
3175
        $f1 = $data['f1'];
3176
        $c1 = $data['c1'];
3176
        $c1 = $data['c1'];
3177
        $c1a = $data['c1a'];
3177
        $c1a = $data['c1a'];
Línea 3196... Línea 3196...
3196
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get('ruleoutcome'));
3196
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get('ruleoutcome'));
3197
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3197
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3198
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3198
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3199
    }
3199
    }
Línea 3200... Línea 3200...
3200
 
3200
 
3201
    public function test_delete_competency_reset_rules() {
3201
    public function test_delete_competency_reset_rules(): void {
3202
        $data = $this->setup_framework_for_reset_rules_tests();
3202
        $data = $this->setup_framework_for_reset_rules_tests();
3203
        $f1 = $data['f1'];
3203
        $f1 = $data['f1'];
3204
        $c1 = $data['c1'];
3204
        $c1 = $data['c1'];
3205
        $c1a = $data['c1a'];
3205
        $c1a = $data['c1a'];
Línea 3219... Línea 3219...
3219
        $this->assertEquals(competency::OUTCOME_NONE, $c1->get('ruleoutcome'));
3219
        $this->assertEquals(competency::OUTCOME_NONE, $c1->get('ruleoutcome'));
3220
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3220
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get('ruleoutcome'));
3221
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3221
        $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get('ruleoutcome'));
3222
    }
3222
    }
Línea 3223... Línea 3223...
3223
 
3223
 
3224
    public function test_template_has_related_data() {
3224
    public function test_template_has_related_data(): void {
3225
        $this->resetAfterTest(true);
3225
        $this->resetAfterTest(true);
Línea 3226... Línea 3226...
3226
        $this->setAdminUser();
3226
        $this->setAdminUser();
3227
 
3227
 
Línea 3239... Línea 3239...
3239
        $this->assertTrue(api::template_has_related_data($tpl1->get('id')));
3239
        $this->assertTrue(api::template_has_related_data($tpl1->get('id')));
3240
        $this->assertFalse(api::template_has_related_data($tpl2->get('id')));
3240
        $this->assertFalse(api::template_has_related_data($tpl2->get('id')));
Línea 3241... Línea 3241...
3241
 
3241
 
Línea 3242... Línea 3242...
3242
    }
3242
    }
3243
 
3243
 
3244
    public function test_delete_template_delete_plans() {
3244
    public function test_delete_template_delete_plans(): void {
Línea 3245... Línea 3245...
3245
        $this->resetAfterTest(true);
3245
        $this->resetAfterTest(true);
3246
        $this->setAdminUser();
3246
        $this->setAdminUser();
Línea 3278... Línea 3278...
3278
 
3278
 
3279
        // Check that associated plan are also deleted.
3279
        // Check that associated plan are also deleted.
3280
        $this->assertEquals(0, count(\core_competency\plan::get_records(array('templateid' => $tpl->get('id')))));
3280
        $this->assertEquals(0, count(\core_competency\plan::get_records(array('templateid' => $tpl->get('id')))));
Línea 3281... Línea 3281...
3281
    }
3281
    }
3282
 
3282
 
3283
    public function test_delete_template_unlink_plans() {
3283
    public function test_delete_template_unlink_plans(): void {
Línea 3284... Línea 3284...
3284
        $this->resetAfterTest(true);
3284
        $this->resetAfterTest(true);
3285
        $this->setAdminUser();
3285
        $this->setAdminUser();
Línea 3320... Línea 3320...
3320
        $this->assertEquals(1, count($plans));
3320
        $this->assertEquals(1, count($plans));
3321
        $this->assertEquals($plans[0]->get('origtemplateid'), $tpl->get('id'));
3321
        $this->assertEquals($plans[0]->get('origtemplateid'), $tpl->get('id'));
3322
        $this->assertNull($plans[0]->get('templateid'));
3322
        $this->assertNull($plans[0]->get('templateid'));
3323
    }
3323
    }
Línea 3324... Línea 3324...
3324
 
3324
 
3325
    public function test_delete_competency() {
3325
    public function test_delete_competency(): void {
3326
        $this->resetAfterTest(true);
3326
        $this->resetAfterTest(true);
3327
        $dg = $this->getDataGenerator();
3327
        $dg = $this->getDataGenerator();
3328
        $lpg = $dg->get_plugin_generator('core_competency');
3328
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 3380... Línea 3380...
3380
        // Delete a simple competency.
3380
        // Delete a simple competency.
3381
        $this->assertTrue(api::delete_competency($c2->get('id')));
3381
        $this->assertTrue(api::delete_competency($c2->get('id')));
3382
        $this->assertFalse(competency::record_exists($c2->get('id')));
3382
        $this->assertFalse(competency::record_exists($c2->get('id')));
3383
    }
3383
    }
Línea 3384... Línea 3384...
3384
 
3384
 
3385
    public function test_delete_competency_used_in_plan() {
3385
    public function test_delete_competency_used_in_plan(): void {
3386
        $this->resetAfterTest(true);
3386
        $this->resetAfterTest(true);
3387
        $dg = $this->getDataGenerator();
3387
        $dg = $this->getDataGenerator();
3388
        $lpg = $dg->get_plugin_generator('core_competency');
3388
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 3413... Línea 3413...
3413
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3413
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3414
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3414
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3415
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3415
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3416
    }
3416
    }
Línea 3417... Línea 3417...
3417
 
3417
 
3418
    public function test_delete_competency_used_in_usercompetency() {
3418
    public function test_delete_competency_used_in_usercompetency(): void {
3419
        $this->resetAfterTest(true);
3419
        $this->resetAfterTest(true);
3420
        $dg = $this->getDataGenerator();
3420
        $dg = $this->getDataGenerator();
3421
        $lpg = $dg->get_plugin_generator('core_competency');
3421
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 3445... Línea 3445...
3445
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3445
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3446
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3446
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3447
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3447
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3448
    }
3448
    }
Línea 3449... Línea 3449...
3449
 
3449
 
3450
    public function test_delete_competency_used_in_usercompetencyplan() {
3450
    public function test_delete_competency_used_in_usercompetencyplan(): void {
3451
        $this->resetAfterTest(true);
3451
        $this->resetAfterTest(true);
3452
        $dg = $this->getDataGenerator();
3452
        $dg = $this->getDataGenerator();
3453
        $lpg = $dg->get_plugin_generator('core_competency');
3453
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 3483... Línea 3483...
3483
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3483
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3484
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3484
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3485
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3485
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3486
    }
3486
    }
Línea 3487... Línea 3487...
3487
 
3487
 
3488
    public function test_delete_competency_used_in_template() {
3488
    public function test_delete_competency_used_in_template(): void {
3489
        $this->resetAfterTest(true);
3489
        $this->resetAfterTest(true);
3490
        $dg = $this->getDataGenerator();
3490
        $dg = $this->getDataGenerator();
3491
        $lpg = $dg->get_plugin_generator('core_competency');
3491
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 3517... Línea 3517...
3517
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3517
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3518
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3518
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3519
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3519
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3520
    }
3520
    }
Línea 3521... Línea 3521...
3521
 
3521
 
3522
    public function test_delete_competency_used_in_course() {
3522
    public function test_delete_competency_used_in_course(): void {
3523
        $this->resetAfterTest(true);
3523
        $this->resetAfterTest(true);
3524
        $dg = $this->getDataGenerator();
3524
        $dg = $this->getDataGenerator();
3525
        $lpg = $dg->get_plugin_generator('core_competency');
3525
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 3554... Línea 3554...
3554
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3554
        $this->assertFalse(competency::record_exists($c1b->get('id')));
3555
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3555
        $this->assertFalse(competency::record_exists($c11b->get('id')));
3556
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3556
        $this->assertFalse(competency::record_exists($c12b->get('id')));
3557
    }
3557
    }
Línea 3558... Línea 3558...
3558
 
3558
 
3559
    public function test_delete_framework() {
3559
    public function test_delete_framework(): void {
3560
        $this->resetAfterTest(true);
3560
        $this->resetAfterTest(true);
3561
        $dg = $this->getDataGenerator();
3561
        $dg = $this->getDataGenerator();
3562
        $lpg = $dg->get_plugin_generator('core_competency');
3562
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 3608... Línea 3608...
3608
        $f2 = $lpg->create_framework();
3608
        $f2 = $lpg->create_framework();
3609
        $this->assertTrue(api::delete_framework($f2->get('id')));
3609
        $this->assertTrue(api::delete_framework($f2->get('id')));
3610
        $this->assertFalse(competency_framework::record_exists($f2->get('id')));
3610
        $this->assertFalse(competency_framework::record_exists($f2->get('id')));
3611
    }
3611
    }
Línea 3612... Línea 3612...
3612
 
3612
 
3613
    public function test_delete_framework_competency_used_in_plan() {
3613
    public function test_delete_framework_competency_used_in_plan(): void {
3614
        $this->resetAfterTest(true);
3614
        $this->resetAfterTest(true);
3615
        $dg = $this->getDataGenerator();
3615
        $dg = $this->getDataGenerator();
3616
        $lpg = $dg->get_plugin_generator('core_competency');
3616
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 3666... Línea 3666...
3666
 
3666
 
3667
        // Check if related conpetency relation is deleted.
3667
        // Check if related conpetency relation is deleted.
3668
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
3668
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
Línea 3669... Línea 3669...
3669
    }
3669
    }
3670
 
3670
 
3671
    public function test_delete_framework_competency_used_in_usercompetency() {
3671
    public function test_delete_framework_competency_used_in_usercompetency(): void {
3672
        $this->resetAfterTest(true);
3672
        $this->resetAfterTest(true);
3673
        $dg = $this->getDataGenerator();
3673
        $dg = $this->getDataGenerator();
Línea 3723... Línea 3723...
3723
 
3723
 
3724
        // Check if related conpetency relation is deleted.
3724
        // Check if related conpetency relation is deleted.
3725
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
3725
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
Línea 3726... Línea 3726...
3726
    }
3726
    }
3727
 
3727
 
3728
    public function test_delete_framework_competency_used_in_usercompetencyplan() {
3728
    public function test_delete_framework_competency_used_in_usercompetencyplan(): void {
3729
        $this->resetAfterTest(true);
3729
        $this->resetAfterTest(true);
3730
        $dg = $this->getDataGenerator();
3730
        $dg = $this->getDataGenerator();
Línea 3786... Línea 3786...
3786
 
3786
 
3787
        // Check if related conpetency relation is deleted.
3787
        // Check if related conpetency relation is deleted.
3788
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
3788
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
Línea 3789... Línea 3789...
3789
    }
3789
    }
3790
 
3790
 
3791
    public function test_delete_framework_competency_used_in_template() {
3791
    public function test_delete_framework_competency_used_in_template(): void {
3792
        $this->resetAfterTest(true);
3792
        $this->resetAfterTest(true);
3793
        $dg = $this->getDataGenerator();
3793
        $dg = $this->getDataGenerator();
Línea 3846... Línea 3846...
3846
 
3846
 
3847
        // Check if related conpetency relation is deleted.
3847
        // Check if related conpetency relation is deleted.
3848
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
3848
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
Línea 3849... Línea 3849...
3849
    }
3849
    }
3850
 
3850
 
3851
    public function test_delete_framework_competency_used_in_course() {
3851
    public function test_delete_framework_competency_used_in_course(): void {
3852
        $this->resetAfterTest(true);
3852
        $this->resetAfterTest(true);
3853
        $dg = $this->getDataGenerator();
3853
        $dg = $this->getDataGenerator();
Línea 3908... Línea 3908...
3908
 
3908
 
3909
        // Check if related conpetency relation is deleted.
3909
        // Check if related conpetency relation is deleted.
3910
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
3910
        $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
Línea 3911... Línea 3911...
3911
    }
3911
    }
3912
 
3912
 
3913
    public function test_grade_competency_in_course_permissions() {
3913
    public function test_grade_competency_in_course_permissions(): void {
Línea 3914... Línea 3914...
3914
        $this->resetAfterTest();
3914
        $this->resetAfterTest();
3915
        $dg = $this->getDataGenerator();
3915
        $dg = $this->getDataGenerator();
Línea 4059... Línea 4059...
4059
    }
4059
    }
Línea 4060... Línea 4060...
4060
 
4060
 
4061
    /**
4061
    /**
4062
     * Test list of evidences for plan completed and not completed.
4062
     * Test list of evidences for plan completed and not completed.
4063
     */
4063
     */
4064
    public function test_list_evidence() {
4064
    public function test_list_evidence(): void {
Línea 4065... Línea 4065...
4065
        global $DB;
4065
        global $DB;
4066
 
4066
 
4067
        $this->resetAfterTest(true);
4067
        $this->resetAfterTest(true);
Línea 4112... Línea 4112...
4112
    }
4112
    }
Línea 4113... Línea 4113...
4113
 
4113
 
4114
    /**
4114
    /**
4115
     * Get a user competency in a course.
4115
     * Get a user competency in a course.
4116
     */
4116
     */
4117
    public function test_get_user_competency_in_course() {
4117
    public function test_get_user_competency_in_course(): void {
4118
        $this->resetAfterTest(true);
4118
        $this->resetAfterTest(true);
4119
        $dg = $this->getDataGenerator();
4119
        $dg = $this->getDataGenerator();
4120
        $lpg = $dg->get_plugin_generator('core_competency');
4120
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 4155... Línea 4155...
4155
    }
4155
    }
Línea 4156... Línea 4156...
4156
 
4156
 
4157
    /**
4157
    /**
4158
     * Test course statistics api functions.
4158
     * Test course statistics api functions.
4159
     */
4159
     */
4160
    public function test_course_statistics() {
4160
    public function test_course_statistics(): void {
4161
        $this->resetAfterTest(true);
4161
        $this->resetAfterTest(true);
4162
        $dg = $this->getDataGenerator();
4162
        $dg = $this->getDataGenerator();
4163
        $lpg = $dg->get_plugin_generator('core_competency');
4163
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 4245... Línea 4245...
4245
    }
4245
    }
Línea 4246... Línea 4246...
4246
 
4246
 
4247
    /**
4247
    /**
4248
     * Test template statistics api functions.
4248
     * Test template statistics api functions.
4249
     */
4249
     */
4250
    public function test_template_statistics() {
4250
    public function test_template_statistics(): void {
4251
        $this->resetAfterTest(true);
4251
        $this->resetAfterTest(true);
4252
        $dg = $this->getDataGenerator();
4252
        $dg = $this->getDataGenerator();
4253
        $lpg = $dg->get_plugin_generator('core_competency');
4253
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 4384... Línea 4384...
4384
            $this->assertInstanceOf('\core_competency\competency', $one);
4384
            $this->assertInstanceOf('\core_competency\competency', $one);
4385
            $this->assertContainsEquals($one->get('id'), $leastarray);
4385
            $this->assertContainsEquals($one->get('id'), $leastarray);
4386
        }
4386
        }
4387
    }
4387
    }
Línea 4388... Línea 4388...
4388
 
4388
 
4389
    public function test_is_scale_used_anywhere() {
4389
    public function test_is_scale_used_anywhere(): void {
4390
        $this->resetAfterTest();
4390
        $this->resetAfterTest();
4391
        $dg = $this->getDataGenerator();
4391
        $dg = $this->getDataGenerator();
Línea 4392... Línea 4392...
4392
        $lpg = $dg->get_plugin_generator('core_competency');
4392
        $lpg = $dg->get_plugin_generator('core_competency');
Línea 4472... Línea 4472...
4472
        $this->assertTrue(api::is_scale_used_anywhere($scale2->id));
4472
        $this->assertTrue(api::is_scale_used_anywhere($scale2->id));
4473
        $this->assertTrue(api::is_scale_used_anywhere($scale3->id));
4473
        $this->assertTrue(api::is_scale_used_anywhere($scale3->id));
4474
        $this->assertTrue(api::is_scale_used_anywhere($scale4->id));
4474
        $this->assertTrue(api::is_scale_used_anywhere($scale4->id));
4475
    }
4475
    }
Línea 4476... Línea 4476...
4476
 
4476
 
4477
    public function test_delete_evidence() {
4477
    public function test_delete_evidence(): void {
4478
        $this->resetAfterTest();
4478
        $this->resetAfterTest();
4479
        $dg = $this->getDataGenerator();
4479
        $dg = $this->getDataGenerator();
Línea 4480... Línea 4480...
4480
        $ccg = $dg->get_plugin_generator('core_competency');
4480
        $ccg = $dg->get_plugin_generator('core_competency');
Línea 4494... Línea 4494...
4494
        $this->assertEquals(1, evidence::count_records());
4494
        $this->assertEquals(1, evidence::count_records());
4495
        $this->assertFalse(evidence::record_exists($ev1->get('id')));
4495
        $this->assertFalse(evidence::record_exists($ev1->get('id')));
4496
        $this->assertTrue(evidence::record_exists($ev2->get('id')));
4496
        $this->assertTrue(evidence::record_exists($ev2->get('id')));
4497
    }
4497
    }
Línea 4498... Línea 4498...
4498
 
4498
 
4499
    public function test_delete_evidence_without_permissions() {
4499
    public function test_delete_evidence_without_permissions(): void {
4500
        $this->resetAfterTest();
4500
        $this->resetAfterTest();
4501
        $dg = $this->getDataGenerator();
4501
        $dg = $this->getDataGenerator();
Línea 4502... Línea 4502...
4502
        $ccg = $dg->get_plugin_generator('core_competency');
4502
        $ccg = $dg->get_plugin_generator('core_competency');
Línea 4511... Línea 4511...
4511
 
4511
 
4512
        $this->expectException(\required_capability_exception::class);
4512
        $this->expectException(\required_capability_exception::class);
4513
        api::delete_evidence($ev1);
4513
        api::delete_evidence($ev1);
Línea 4514... Línea 4514...
4514
    }
4514
    }
4515
 
4515
 
4516
    public function test_list_plans_to_review() {
4516
    public function test_list_plans_to_review(): void {
4517
        $dg = $this->getDataGenerator();
4517
        $dg = $this->getDataGenerator();
4518
        $this->resetAfterTest();
4518
        $this->resetAfterTest();
4519
        $ccg = $dg->get_plugin_generator('core_competency');
4519
        $ccg = $dg->get_plugin_generator('core_competency');
Línea 4556... Línea 4556...
4556
        $this->assertEquals(2, $result['count']);
4556
        $this->assertEquals(2, $result['count']);
4557
        $this->assertEquals($p1a->get('id'), $result['plans'][0]->plan->get('id'));
4557
        $this->assertEquals($p1a->get('id'), $result['plans'][0]->plan->get('id'));
4558
        $this->assertEquals($p1b->get('id'), $result['plans'][1]->plan->get('id'));
4558
        $this->assertEquals($p1b->get('id'), $result['plans'][1]->plan->get('id'));
4559
    }
4559
    }
Línea 4560... Línea 4560...
4560
 
4560
 
4561
    public function test_list_user_competencies_to_review() {
4561
    public function test_list_user_competencies_to_review(): void {
4562
        global $CFG;
4562
        global $CFG;
Línea 4563... Línea 4563...
4563
        require_once($CFG->dirroot . '/user/lib.php');
4563
        require_once($CFG->dirroot . '/user/lib.php');
4564
 
4564
 
Línea 4624... Línea 4624...
4624
    }
4624
    }
Línea 4625... Línea 4625...
4625
 
4625
 
4626
    /**
4626
    /**
4627
     * Test we can get all of a users plans with a competency.
4627
     * Test we can get all of a users plans with a competency.
4628
     */
4628
     */
4629
    public function test_list_plans_with_competency() {
4629
    public function test_list_plans_with_competency(): void {
4630
        $this->resetAfterTest(true);
4630
        $this->resetAfterTest(true);
4631
        $this->setAdminUser();
4631
        $this->setAdminUser();
Línea 4632... Línea 4632...
4632
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
4632
        $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');