MDL-53700 competency: Migrating tests to core
authorFrederic Massart <fred@moodle.com>
Tue, 5 Apr 2016 06:26:47 +0000 (14:26 +0800)
committerFrederic Massart <fred@moodle.com>
Mon, 18 Apr 2016 03:05:59 +0000 (11:05 +0800)
12 files changed:
admin/tool/lp/tests/lib_test.php
admin/tool/lp/tests/plan_persistent_test.php [deleted file]
competency/tests/api_test.php [moved from admin/tool/lp/tests/api_test.php with 99% similarity]
competency/tests/competency_rule_test.php [moved from admin/tool/lp/tests/competency_rule_test.php with 99% similarity]
competency/tests/course_competency_settings_test.php [moved from admin/tool/lp/tests/course_competency_settings_test.php with 97% similarity]
competency/tests/course_competency_test.php [moved from admin/tool/lp/tests/course_competency_test.php with 97% similarity]
competency/tests/exporter_test.php [moved from admin/tool/lp/tests/exporter_test.php with 86% similarity]
competency/tests/persistent_test.php [moved from admin/tool/lp/tests/persistent_test.php with 83% similarity]
competency/tests/plan_test.php [moved from admin/tool/lp/tests/plan_test.php with 57% similarity]
competency/tests/task_test.php [moved from admin/tool/lp/tests/task_test.php with 99% similarity]
competency/tests/template_test.php [moved from admin/tool/lp/tests/template_test.php with 96% similarity]
competency/tests/user_evidence_competency_test.php [moved from admin/tool/lp/tests/user_evidence_competency_test.php with 96% similarity]

index dd7aa3a..346f96e 100644 (file)
@@ -36,7 +36,7 @@ global $CFG;
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_lib_testcase extends advanced_testcase {
+class core_competency_lib_testcase extends advanced_testcase {
 
     public function test_comment_add_user_competency() {
         global $DB;
diff --git a/admin/tool/lp/tests/plan_persistent_test.php b/admin/tool/lp/tests/plan_persistent_test.php
deleted file mode 100644 (file)
index 96abc2c..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Plan persistent class tests.
- *
- * @package    tool_lp
- * @copyright  2015 Frédéric Massart - FMCorz.net
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
-
-use core_competency\api;
-use core_competency\plan;
-
-/**
- * Plan persistent testcase.
- *
- * @package    tool_lp
- * @copyright  2015 Frédéric Massart - FMCorz.net
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class tool_lp_plan_persistent_testcase extends advanced_testcase {
-
-    public function test_get_by_user_and_competency() {
-        $this->resetAfterTest();
-        $this->setAdminUser();
-
-        $dg = $this->getDataGenerator();
-        $lpg = $dg->get_plugin_generator('core_competency');
-
-        $u1 = $dg->create_user();
-        $u2 = $dg->create_user();
-        $u3 = $dg->create_user();
-        $u4 = $dg->create_user();
-
-        $f1 = $lpg->create_framework();
-        $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
-        $c2 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
-
-        $tpl1 = $lpg->create_template();
-        $lpg->create_template_competency(array('competencyid' => $c1->get_id(), 'templateid' => $tpl1->get_id()));
-
-        $p1 = $lpg->create_plan(array('userid' => $u1->id));
-        $lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c1->get_id()));
-        $p2 = $lpg->create_plan(array('userid' => $u2->id));
-        $lpg->create_plan_competency(array('planid' => $p2->get_id(), 'competencyid' => $c1->get_id()));
-        $p3 = $lpg->create_plan(array('userid' => $u3->id, 'templateid' => $tpl1->get_id()));
-        $p4 = $lpg->create_plan(array('userid' => $u4->id, 'templateid' => $tpl1->get_id()));
-        api::complete_plan($p2);
-        api::complete_plan($p4);
-
-        // Finding a plan, not completed.
-        $plans = plan::get_by_user_and_competency($u1->id, $c1->get_id());
-        $this->assertCount(1, $plans);
-        $plan = array_shift($plans);
-        $this->assertEquals($p1->get_id(), $plan->get_id());
-        $this->assertNotEquals(plan::STATUS_COMPLETE, $plan->get_status());
-
-        // Finding a completed plan.
-        $plans = plan::get_by_user_and_competency($u2->id, $c1->get_id());
-        $this->assertCount(1, $plans);
-        $plan = array_shift($plans);
-        $this->assertEquals($p2->get_id(), $plan->get_id());
-        $this->assertEquals(plan::STATUS_COMPLETE, $plan->get_status());
-
-        // Finding a plan based on a template, not completed.
-        $plans = plan::get_by_user_and_competency($u3->id, $c1->get_id());
-        $this->assertCount(1, $plans);
-        $plan = array_shift($plans);
-        $this->assertEquals($p3->get_id(), $plan->get_id());
-        $this->assertTrue($plan->is_based_on_template());
-        $this->assertNotEquals(plan::STATUS_COMPLETE, $plan->get_status());
-
-        // Finding a plan based on a template.
-        $plans = plan::get_by_user_and_competency($u4->id, $c1->get_id());
-        $this->assertCount(1, $plans);
-        $plan = array_shift($plans);
-        $this->assertEquals($p4->get_id(), $plan->get_id());
-        $this->assertTrue($plan->is_based_on_template());
-        $this->assertEquals(plan::STATUS_COMPLETE, $plan->get_status());
-
-        // Finding more than one plan, no template.
-        $p5 = $lpg->create_plan(array('userid' => $u1->id));
-        $lpg->create_plan_competency(array('planid' => $p5->get_id(), 'competencyid' => $c1->get_id()));
-        $plans = plan::get_by_user_and_competency($u1->id, $c1->get_id());
-        $this->assertCount(2, $plans);
-        $plan = array_shift($plans);
-        $this->assertEquals($p1->get_id(), $plan->get_id());
-        $plan = array_shift($plans);
-        $this->assertEquals($p5->get_id(), $plan->get_id());
-
-        // Finding more than one plan, with template.
-        $p6 = $lpg->create_plan(array('userid' => $u1->id, 'templateid' => $tpl1->get_id()));
-        $plans = plan::get_by_user_and_competency($u1->id, $c1->get_id());
-        $this->assertCount(3, $plans);
-        $plan = array_shift($plans);
-        $this->assertEquals($p1->get_id(), $plan->get_id());
-        $plan = array_shift($plans);
-        $this->assertEquals($p5->get_id(), $plan->get_id());
-        $plan = array_shift($plans);
-        $this->assertEquals($p6->get_id(), $plan->get_id());
-
-        // Finding no plans.
-        $plans = plan::get_by_user_and_competency($u1->id, $c2->get_id());
-        $this->assertCount(0, $plans);
-    }
-
-}
similarity index 99%
rename from admin/tool/lp/tests/api_test.php
rename to competency/tests/api_test.php
index 6209cb4..9b4c742 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * API tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -36,11 +36,11 @@ use core_competency\plan;
 /**
  * API tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_api_testcase extends advanced_testcase {
+class core_competency_api_testcase extends advanced_testcase {
 
     public function test_get_framework_related_contexts() {
         $this->resetAfterTest(true);
similarity index 99%
rename from admin/tool/lp/tests/competency_rule_test.php
rename to competency/tests/competency_rule_test.php
index 4a85895..950e255 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * Competency rule tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -35,11 +35,11 @@ use core_competency\competency_rule_points;
 /**
  * Competency rule testcase.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_competency_rule_testcase extends externallib_advanced_testcase {
+class core_competency_competency_rule_testcase extends externallib_advanced_testcase {
 
     public function test_rule_all_matching() {
         $this->resetAfterTest(true);
@@ -17,7 +17,7 @@
 /**
  * Course competency persistent class tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2016 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -32,11 +32,11 @@ use core_competency\course_competency_settings;
 /**
  * This test ensures that the course competency settings are applied and work correctly.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2016 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_course_competency_settings_testcase extends advanced_testcase {
+class core_competency_course_competency_settings_testcase extends advanced_testcase {
 
     public function test_who_can_change_settings() {
         global $CFG, $DB;
similarity index 97%
rename from admin/tool/lp/tests/course_competency_test.php
rename to competency/tests/course_competency_test.php
index 8d48d16..421c0ec 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * Course competency persistent class tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2016 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -30,11 +30,11 @@ use core_competency\course_competency;
 /**
  * Course competency persistent testcase.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2016 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_course_competency_testcase extends advanced_testcase {
+class core_competency_course_competency_testcase extends advanced_testcase {
 
     public function test_get_courses_with_competency_and_user() {
         global $CFG, $DB;
similarity index 86%
rename from admin/tool/lp/tests/exporter_test.php
rename to competency/tests/exporter_test.php
index 272b55e..eb4830b 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * Exporter class tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Damyon Wiese
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -28,11 +28,11 @@ global $CFG;
 /**
  * Exporter testcase.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Damyon Wiese
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_exporter_testcase extends advanced_testcase {
+class core_competency_exporter_testcase extends advanced_testcase {
 
     protected $validrelated = null;
     protected $invalidrelated = null;
@@ -50,7 +50,7 @@ class tool_lp_exporter_testcase extends advanced_testcase {
     }
 
     public function test_get_read_structure() {
-        $structure = tool_lp_testable_exporter::get_read_structure();
+        $structure = core_competency_testable_exporter::get_read_structure();
 
         $this->assertInstanceOf('external_single_structure', $structure);
         $this->assertInstanceOf('external_value', $structure->keys['stringA']);
@@ -61,7 +61,7 @@ class tool_lp_exporter_testcase extends advanced_testcase {
     }
 
     public function test_get_create_structure() {
-        $structure = tool_lp_testable_exporter::get_create_structure();
+        $structure = core_competency_testable_exporter::get_create_structure();
 
         $this->assertInstanceOf('external_single_structure', $structure);
         $this->assertInstanceOf('external_value', $structure->keys['stringA']);
@@ -72,7 +72,7 @@ class tool_lp_exporter_testcase extends advanced_testcase {
     }
 
     public function test_get_update_structure() {
-        $structure = tool_lp_testable_exporter::get_update_structure();
+        $structure = core_competency_testable_exporter::get_update_structure();
 
         $this->assertInstanceOf('external_single_structure', $structure);
         $this->assertInstanceOf('external_value', $structure->keys['stringA']);
@@ -85,7 +85,7 @@ class tool_lp_exporter_testcase extends advanced_testcase {
     public function test_invalid_data() {
         global $PAGE;
         $this->setExpectedException('coding_exception');
-        $exporter = new tool_lp_testable_exporter($this->invaliddata, $this->validrelated);
+        $exporter = new core_competency_testable_exporter($this->invaliddata, $this->validrelated);
         $output = $PAGE->get_renderer('tool_lp');
 
         $result = $exporter->export($output);
@@ -94,7 +94,7 @@ class tool_lp_exporter_testcase extends advanced_testcase {
     public function test_invalid_related() {
         global $PAGE;
         $this->setExpectedException('coding_exception');
-        $exporter = new tool_lp_testable_exporter($this->validdata, $this->invalidrelated);
+        $exporter = new core_competency_testable_exporter($this->validdata, $this->invalidrelated);
         $output = $PAGE->get_renderer('tool_lp');
 
         $result = $exporter->export($output);
@@ -102,7 +102,7 @@ class tool_lp_exporter_testcase extends advanced_testcase {
 
     public function test_valid_data_and_related() {
         global $PAGE;
-        $exporter = new tool_lp_testable_exporter($this->validdata, $this->validrelated);
+        $exporter = new core_competency_testable_exporter($this->validdata, $this->validrelated);
 
         $output = $PAGE->get_renderer('tool_lp');
 
@@ -113,11 +113,11 @@ class tool_lp_exporter_testcase extends advanced_testcase {
 /**
  * Example persistent class.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_testable_exporter extends \core_competency\external\exporter {
+class core_competency_testable_exporter extends \core_competency\external\exporter {
 
     protected static function define_related() {
         // We cache the context so it does not need to be retrieved from the course.
similarity index 83%
rename from admin/tool/lp/tests/persistent_test.php
rename to competency/tests/persistent_test.php
index 377ba4f..c37f06d 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * Persistent class tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -28,11 +28,11 @@ global $CFG;
 /**
  * Persistent testcase.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_persistent_testcase extends advanced_testcase {
+class core_competency_persistent_testcase extends advanced_testcase {
 
     public function setUp() {
         $this->resetAfterTest();
@@ -126,11 +126,11 @@ class tool_lp_persistent_testcase extends advanced_testcase {
                 'null' => NULL_ALLOWED
             )
         );
-        $this->assertEquals($expected, tool_lp_testable_persistent::properties_definition());
+        $this->assertEquals($expected, core_competency_testable_persistent::properties_definition());
     }
 
     public function test_to_record() {
-        $p = new tool_lp_testable_persistent();
+        $p = new core_competency_testable_persistent();
         $expected = (object) array(
             'shortname' => '',
             'idnumber' => null,
@@ -154,7 +154,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
     }
 
     public function test_from_record() {
-        $p = new tool_lp_testable_persistent();
+        $p = new core_competency_testable_persistent();
         $data = (object) array(
             'shortname' => 'ddd',
             'idnumber' => 'abc',
@@ -179,7 +179,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
     }
 
     public function test_from_record_invalid_param() {
-        $p = new tool_lp_testable_persistent();
+        $p = new core_competency_testable_persistent();
         $data = (object) array(
             'invalidparam' => 'abc'
         );
@@ -192,7 +192,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
             'idnumber' => 'abc',
             'sortorder' => 0
         );
-        $p = new tool_lp_testable_persistent(0, $data);
+        $p = new core_competency_testable_persistent(0, $data);
         $this->assertFalse(isset($p->beforevalidate));
         $this->assertTrue($p->validate());
         $this->assertTrue(isset($p->beforevalidate));
@@ -212,7 +212,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
         $data = (object) array(
             'idnumber' => 'abc'
         );
-        $p = new tool_lp_testable_persistent(0, $data);
+        $p = new core_competency_testable_persistent(0, $data);
         $expected = array(
             'sortorder' => new lang_string('requiredelement', 'form'),
         );
@@ -225,7 +225,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
             'idnumber' => 'abc',
             'sortorder' => 10,
         );
-        $p = new tool_lp_testable_persistent(0, $data);
+        $p = new core_competency_testable_persistent(0, $data);
         $expected = array(
             'sortorder' => new lang_string('invalidkey', 'error'),
         );
@@ -238,7 +238,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
             'idnumber' => 'abc',
             'sortorder' => 'abc',
         );
-        $p = new tool_lp_testable_persistent(0, $data);
+        $p = new core_competency_testable_persistent(0, $data);
         $expected = array(
             'sortorder' => new lang_string('invalidrequest', 'error'),
         );
@@ -252,7 +252,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
             'sortorder' => 0,
             'descriptionformat' => -100
         );
-        $p = new tool_lp_testable_persistent(0, $data);
+        $p = new core_competency_testable_persistent(0, $data);
         $expected = array(
             'descriptionformat' => new lang_string('invaliddata', 'error'),
         );
@@ -265,7 +265,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
             'idnumber' => 'abc',
             'sortorder' => 'NaN'
         );
-        $p = new tool_lp_testable_persistent(0, $data);
+        $p = new core_competency_testable_persistent(0, $data);
         $this->assertFalse($p->is_valid());
         $this->assertArrayHasKey('sortorder', $p->get_errors());
     }
@@ -276,7 +276,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
             'sortorder' => 0,
             'competencyframeworkid' => 'bad!'
         );
-        $p = new tool_lp_testable_persistent(0, $data);
+        $p = new core_competency_testable_persistent(0, $data);
         $this->assertFalse($p->is_valid());
         $this->assertArrayHasKey('idnumber', $p->get_errors());
         $this->assertArrayHasKey('competencyframeworkid', $p->get_errors());
@@ -291,11 +291,11 @@ class tool_lp_persistent_testcase extends advanced_testcase {
 
     public function test_create() {
         global $DB;
-        $p = new tool_lp_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
+        $p = new core_competency_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
         $this->assertFalse(isset($p->beforecreate));
         $this->assertFalse(isset($p->aftercreate));
         $p->create();
-        $record = $DB->get_record(tool_lp_testable_persistent::TABLE, array('id' => $p->get_id()), '*', MUST_EXIST);
+        $record = $DB->get_record(core_competency_testable_persistent::TABLE, array('id' => $p->get_id()), '*', MUST_EXIST);
         $expected = $p->to_record();
         $this->assertTrue(isset($p->beforecreate));
         $this->assertTrue(isset($p->aftercreate));
@@ -307,7 +307,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
 
     public function test_update() {
         global $DB;
-        $p = new tool_lp_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
+        $p = new core_competency_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
         $p->create();
         $id = $p->get_id();
         $p->set_sortorder(456);
@@ -317,7 +317,7 @@ class tool_lp_persistent_testcase extends advanced_testcase {
         $p->update();
 
         $expected = $p->to_record();
-        $record = $DB->get_record(tool_lp_testable_persistent::TABLE, array('id' => $p->get_id()), '*', MUST_EXIST);
+        $record = $DB->get_record(core_competency_testable_persistent::TABLE, array('id' => $p->get_id()), '*', MUST_EXIST);
         $this->assertTrue(isset($p->beforeupdate));
         $this->assertTrue(isset($p->afterupdate));
         $this->assertEquals($id, $record->id);
@@ -327,16 +327,16 @@ class tool_lp_persistent_testcase extends advanced_testcase {
     }
 
     public function test_read() {
-        $p = new tool_lp_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
+        $p = new core_competency_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
         $p->create();
         unset($p->beforevalidate);
         unset($p->beforecreate);
         unset($p->aftercreate);
 
-        $p2 = new tool_lp_testable_persistent($p->get_id());
+        $p2 = new core_competency_testable_persistent($p->get_id());
         $this->assertEquals($p, $p2);
 
-        $p3 = new tool_lp_testable_persistent();
+        $p3 = new core_competency_testable_persistent();
         $p3->set_id($p->get_id());
         $p3->read();
         $this->assertEquals($p, $p3);
@@ -345,23 +345,23 @@ class tool_lp_persistent_testcase extends advanced_testcase {
     public function test_delete() {
         global $DB;
 
-        $p = new tool_lp_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
+        $p = new core_competency_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
         $p->create();
         $this->assertNotEquals(0, $p->get_id());
-        $this->assertTrue($DB->record_exists_select(tool_lp_testable_persistent::TABLE, 'id = ?', array($p->get_id())));
+        $this->assertTrue($DB->record_exists_select(core_competency_testable_persistent::TABLE, 'id = ?', array($p->get_id())));
         $this->assertFalse(isset($p->beforedelete));
         $this->assertFalse(isset($p->afterdelete));
 
         $p->delete();
-        $this->assertFalse($DB->record_exists_select(tool_lp_testable_persistent::TABLE, 'id = ?', array($p->get_id())));
+        $this->assertFalse($DB->record_exists_select(core_competency_testable_persistent::TABLE, 'id = ?', array($p->get_id())));
         $this->assertEquals(0, $p->get_id());
         $this->assertEquals(true, $p->beforedelete);
         $this->assertEquals(true, $p->afterdelete);
     }
 
     public function test_has_property() {
-        $this->assertFalse(tool_lp_testable_persistent::has_property('unknown'));
-        $this->assertTrue(tool_lp_testable_persistent::has_property('idnumber'));
+        $this->assertFalse(core_competency_testable_persistent::has_property('unknown'));
+        $this->assertTrue(core_competency_testable_persistent::has_property('idnumber'));
     }
 
     public function test_custom_setter_getter() {
@@ -370,26 +370,26 @@ class tool_lp_persistent_testcase extends advanced_testcase {
         $path = array(1, 2, 3);
         $json = json_encode($path);
 
-        $p = new tool_lp_testable_persistent(0, (object) array('sortorder' => 0, 'idnumber' => 'abc'));
+        $p = new core_competency_testable_persistent(0, (object) array('sortorder' => 0, 'idnumber' => 'abc'));
         $p->set_path($path);
         $this->assertEquals($path, $p->get_path());
         $this->assertEquals($json, $p->to_record()->path);
 
         $p->create();
-        $record = $DB->get_record(tool_lp_testable_persistent::TABLE, array('id' => $p->get_id()), 'id, path', MUST_EXIST);
+        $record = $DB->get_record(core_competency_testable_persistent::TABLE, array('id' => $p->get_id()), 'id, path', MUST_EXIST);
         $this->assertEquals($json, $record->path);
     }
 
     public function test_record_exists() {
         global $DB;
-        $this->assertFalse($DB->record_exists(tool_lp_testable_persistent::TABLE, array('idnumber' => 'abc')));
-        $p = new tool_lp_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
+        $this->assertFalse($DB->record_exists(core_competency_testable_persistent::TABLE, array('idnumber' => 'abc')));
+        $p = new core_competency_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
         $p->create();
         $id = $p->get_id();
-        $this->assertTrue(tool_lp_testable_persistent::record_exists($id));
-        $this->assertTrue($DB->record_exists(tool_lp_testable_persistent::TABLE, array('idnumber' => 'abc')));
+        $this->assertTrue(core_competency_testable_persistent::record_exists($id));
+        $this->assertTrue($DB->record_exists(core_competency_testable_persistent::TABLE, array('idnumber' => 'abc')));
         $p->delete();
-        $this->assertFalse(tool_lp_testable_persistent::record_exists($id));
+        $this->assertFalse(core_competency_testable_persistent::record_exists($id));
     }
 
 }
@@ -397,11 +397,11 @@ class tool_lp_persistent_testcase extends advanced_testcase {
 /**
  * Example persistent class.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_testable_persistent extends \core_competency\persistent {
+class core_competency_testable_persistent extends \core_competency\persistent {
 
     const TABLE = 'competency';
 
similarity index 57%
rename from admin/tool/lp/tests/plan_test.php
rename to competency/tests/plan_test.php
index 54ad1ed..38e45aa 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * Plan persistent class tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 defined('MOODLE_INTERNAL') || die();
 global $CFG;
 
+use core_competency\api;
 use core_competency\plan;
 
 /**
  * Plan persistent testcase.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_plan_testcase extends advanced_testcase {
+class core_competency_plan_testcase extends advanced_testcase {
 
     public function test_can_manage_user() {
         $this->resetAfterTest(true);
@@ -60,19 +61,19 @@ class tool_lp_plan_testcase extends advanced_testcase {
         accesslib_clear_all_caches_for_unit_testing();
 
         $this->setUser($u1);
-        $this->assertTrue(\core_competency\plan::can_manage_user($u1->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user($u2->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user($u3->id));
+        $this->assertTrue(plan::can_manage_user($u1->id));
+        $this->assertTrue(plan::can_manage_user($u2->id));
+        $this->assertTrue(plan::can_manage_user($u3->id));
 
         $this->setUser($u2);
-        $this->assertFalse(\core_competency\plan::can_manage_user($u1->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user($u2->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user($u3->id));
+        $this->assertFalse(plan::can_manage_user($u1->id));
+        $this->assertTrue(plan::can_manage_user($u2->id));
+        $this->assertFalse(plan::can_manage_user($u3->id));
 
         $this->setUser($u3);
-        $this->assertFalse(\core_competency\plan::can_manage_user($u1->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user($u2->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user($u3->id));
+        $this->assertFalse(plan::can_manage_user($u1->id));
+        $this->assertTrue(plan::can_manage_user($u2->id));
+        $this->assertFalse(plan::can_manage_user($u3->id));
     }
 
     public function test_can_manage_user_draft() {
@@ -109,39 +110,39 @@ class tool_lp_plan_testcase extends advanced_testcase {
         accesslib_clear_all_caches_for_unit_testing();
 
         $this->setUser($u1);
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u1->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u2->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u3->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u4->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u5->id));
+        $this->assertFalse(plan::can_manage_user_draft($u1->id));
+        $this->assertFalse(plan::can_manage_user_draft($u2->id));
+        $this->assertFalse(plan::can_manage_user_draft($u3->id));
+        $this->assertFalse(plan::can_manage_user_draft($u4->id));
+        $this->assertFalse(plan::can_manage_user_draft($u5->id));
 
         $this->setUser($u2);
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u1->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u2->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u3->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u4->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u5->id));
+        $this->assertFalse(plan::can_manage_user_draft($u1->id));
+        $this->assertFalse(plan::can_manage_user_draft($u2->id));
+        $this->assertFalse(plan::can_manage_user_draft($u3->id));
+        $this->assertFalse(plan::can_manage_user_draft($u4->id));
+        $this->assertFalse(plan::can_manage_user_draft($u5->id));
 
         $this->setUser($u3);
-        $this->assertTrue(\core_competency\plan::can_manage_user_draft($u1->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user_draft($u2->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user_draft($u3->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user_draft($u4->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user_draft($u5->id));
+        $this->assertTrue(plan::can_manage_user_draft($u1->id));
+        $this->assertTrue(plan::can_manage_user_draft($u2->id));
+        $this->assertTrue(plan::can_manage_user_draft($u3->id));
+        $this->assertTrue(plan::can_manage_user_draft($u4->id));
+        $this->assertTrue(plan::can_manage_user_draft($u5->id));
 
         $this->setUser($u4);
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u1->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user_draft($u2->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u3->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u4->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u5->id));
+        $this->assertFalse(plan::can_manage_user_draft($u1->id));
+        $this->assertTrue(plan::can_manage_user_draft($u2->id));
+        $this->assertFalse(plan::can_manage_user_draft($u3->id));
+        $this->assertFalse(plan::can_manage_user_draft($u4->id));
+        $this->assertFalse(plan::can_manage_user_draft($u5->id));
 
         $this->setUser($u5);
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u1->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u2->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u3->id));
-        $this->assertFalse(\core_competency\plan::can_manage_user_draft($u4->id));
-        $this->assertTrue(\core_competency\plan::can_manage_user_draft($u5->id));
+        $this->assertFalse(plan::can_manage_user_draft($u1->id));
+        $this->assertFalse(plan::can_manage_user_draft($u2->id));
+        $this->assertFalse(plan::can_manage_user_draft($u3->id));
+        $this->assertFalse(plan::can_manage_user_draft($u4->id));
+        $this->assertTrue(plan::can_manage_user_draft($u5->id));
     }
 
     public function test_can_read_user() {
@@ -168,19 +169,19 @@ class tool_lp_plan_testcase extends advanced_testcase {
         accesslib_clear_all_caches_for_unit_testing();
 
         $this->setUser($u1);
-        $this->assertTrue(\core_competency\plan::can_read_user($u1->id));
-        $this->assertTrue(\core_competency\plan::can_read_user($u2->id));
-        $this->assertTrue(\core_competency\plan::can_read_user($u3->id));
+        $this->assertTrue(plan::can_read_user($u1->id));
+        $this->assertTrue(plan::can_read_user($u2->id));
+        $this->assertTrue(plan::can_read_user($u3->id));
 
         $this->setUser($u2);
-        $this->assertFalse(\core_competency\plan::can_read_user($u1->id));
-        $this->assertTrue(\core_competency\plan::can_read_user($u2->id));
-        $this->assertFalse(\core_competency\plan::can_read_user($u3->id));
+        $this->assertFalse(plan::can_read_user($u1->id));
+        $this->assertTrue(plan::can_read_user($u2->id));
+        $this->assertFalse(plan::can_read_user($u3->id));
 
         $this->setUser($u3);
-        $this->assertFalse(\core_competency\plan::can_read_user($u1->id));
-        $this->assertTrue(\core_competency\plan::can_read_user($u2->id));
-        $this->assertTrue(\core_competency\plan::can_read_user($u3->id));    // Due to the default capability.
+        $this->assertFalse(plan::can_read_user($u1->id));
+        $this->assertTrue(plan::can_read_user($u2->id));
+        $this->assertTrue(plan::can_read_user($u3->id));    // Due to the default capability.
     }
 
     public function test_can_read_user_draft() {
@@ -218,39 +219,39 @@ class tool_lp_plan_testcase extends advanced_testcase {
         accesslib_clear_all_caches_for_unit_testing();
 
         $this->setUser($u1);
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u1->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u2->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u3->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u4->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u5->id));
+        $this->assertFalse(plan::can_read_user_draft($u1->id));
+        $this->assertFalse(plan::can_read_user_draft($u2->id));
+        $this->assertFalse(plan::can_read_user_draft($u3->id));
+        $this->assertFalse(plan::can_read_user_draft($u4->id));
+        $this->assertFalse(plan::can_read_user_draft($u5->id));
 
         $this->setUser($u2);
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u1->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u2->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u3->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u4->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u5->id));
+        $this->assertFalse(plan::can_read_user_draft($u1->id));
+        $this->assertFalse(plan::can_read_user_draft($u2->id));
+        $this->assertFalse(plan::can_read_user_draft($u3->id));
+        $this->assertFalse(plan::can_read_user_draft($u4->id));
+        $this->assertFalse(plan::can_read_user_draft($u5->id));
 
         $this->setUser($u3);
-        $this->assertTrue(\core_competency\plan::can_read_user_draft($u1->id));
-        $this->assertTrue(\core_competency\plan::can_read_user_draft($u2->id));
-        $this->assertTrue(\core_competency\plan::can_read_user_draft($u3->id));
-        $this->assertTrue(\core_competency\plan::can_read_user_draft($u4->id));
-        $this->assertTrue(\core_competency\plan::can_read_user_draft($u5->id));
+        $this->assertTrue(plan::can_read_user_draft($u1->id));
+        $this->assertTrue(plan::can_read_user_draft($u2->id));
+        $this->assertTrue(plan::can_read_user_draft($u3->id));
+        $this->assertTrue(plan::can_read_user_draft($u4->id));
+        $this->assertTrue(plan::can_read_user_draft($u5->id));
 
         $this->setUser($u4);
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u1->id));
-        $this->assertTrue(\core_competency\plan::can_read_user_draft($u2->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u3->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u4->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u5->id));
+        $this->assertFalse(plan::can_read_user_draft($u1->id));
+        $this->assertTrue(plan::can_read_user_draft($u2->id));
+        $this->assertFalse(plan::can_read_user_draft($u3->id));
+        $this->assertFalse(plan::can_read_user_draft($u4->id));
+        $this->assertFalse(plan::can_read_user_draft($u5->id));
 
         $this->setUser($u5);
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u1->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u2->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u3->id));
-        $this->assertFalse(\core_competency\plan::can_read_user_draft($u4->id));
-        $this->assertTrue(\core_competency\plan::can_read_user_draft($u5->id));
+        $this->assertFalse(plan::can_read_user_draft($u1->id));
+        $this->assertFalse(plan::can_read_user_draft($u2->id));
+        $this->assertFalse(plan::can_read_user_draft($u3->id));
+        $this->assertFalse(plan::can_read_user_draft($u4->id));
+        $this->assertTrue(plan::can_read_user_draft($u5->id));
     }
 
     public function test_validate_duedate() {
@@ -262,15 +263,15 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $user = $dg->create_user();
 
         $record = array('userid' => $user->id,
-                        'status' => core_competency\plan::STATUS_DRAFT,
+                        'status' => plan::STATUS_DRAFT,
                         'duedate' => time() - 8000);
 
         // Ignore duedate validation on create/update draft plan.
         $plan = $lpg->create_plan($record);
-        $this->assertInstanceOf('\core_competency\plan', $plan);
+        $this->assertInstanceOf('core_competency\plan', $plan);
 
         // Passing from draft to active.
-        $plan->set_status(core_competency\plan::STATUS_ACTIVE);
+        $plan->set_status(plan::STATUS_ACTIVE);
 
         // Draft to active with duedate in the past.
         $expected = array(
@@ -293,7 +294,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $this->assertEquals($expected, $plan->validate());
 
         // Draft to active: past date => future date (pass).
-        $plan->set_duedate(time() + core_competency\plan::DUEDATE_THRESHOLD + 10);
+        $plan->set_duedate(time() + plan::DUEDATE_THRESHOLD + 10);
         $this->assertEquals(true, $plan->validate());
 
         // Draft to active: past date => unset date (pass).
@@ -335,7 +336,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $this->assertEquals($expected, $plan->validate());
 
         // Active to active: unset date => future date (pass).
-        $plan->set_duedate(time() + core_competency\plan::DUEDATE_THRESHOLD + 10);
+        $plan->set_duedate(time() + plan::DUEDATE_THRESHOLD + 10);
         $this->assertEquals(true, $plan->validate());
 
         // Updating active plan with future date.
@@ -364,50 +365,50 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $this->assertEquals($expected, $plan->validate());
 
         // Active to active: future date => future date (pass).
-        $plan->set_duedate(time() + core_competency\plan::DUEDATE_THRESHOLD + 10);
+        $plan->set_duedate(time() + plan::DUEDATE_THRESHOLD + 10);
         $this->assertEquals(true, $plan->validate());
 
         // Completing plan: with due date in the past.
         $record = $plan->to_record();
-        $record->status = core_competency\plan::STATUS_ACTIVE;
+        $record->status = plan::STATUS_ACTIVE;
         $record->duedate = time() - 200;
-        $DB->update_record(core_competency\plan::TABLE, $record);
+        $DB->update_record(plan::TABLE, $record);
 
         $success = core_competency\api::complete_plan($plan->get_id());
         $this->assertTrue($success);
 
         // Completing plan: with due date too soon (pass).
         $record = $plan->to_record();
-        $record->status = core_competency\plan::STATUS_ACTIVE;
+        $record->status = plan::STATUS_ACTIVE;
         $record->duedate = time() + 200;
-        $DB->update_record(core_competency\plan::TABLE, $record);
+        $DB->update_record(plan::TABLE, $record);
 
         $success = core_competency\api::complete_plan($plan->get_id());
         $this->assertTrue($success);
 
         // Completing plan: with due date in the future (pass).
         $record = $plan->to_record();
-        $record->status = core_competency\plan::STATUS_ACTIVE;
-        $record->duedate = time() + core_competency\plan::DUEDATE_THRESHOLD + 10;
-        $DB->update_record(core_competency\plan::TABLE, $record);
+        $record->status = plan::STATUS_ACTIVE;
+        $record->duedate = time() + plan::DUEDATE_THRESHOLD + 10;
+        $DB->update_record(plan::TABLE, $record);
 
         $success = core_competency\api::complete_plan($plan->get_id());
         $this->assertTrue($success);
 
         // Completing plan: with due date unset (pass).
         $record = $plan->to_record();
-        $record->status = core_competency\plan::STATUS_ACTIVE;
+        $record->status = plan::STATUS_ACTIVE;
         $record->duedate = 0;
-        $DB->update_record(core_competency\plan::TABLE, $record);
+        $DB->update_record(plan::TABLE, $record);
 
         $success = core_competency\api::complete_plan($plan->get_id());
         $this->assertTrue($success);
 
         // Reopening plan: with due date in the past => duedate unset.
         $record = $plan->to_record();
-        $record->status = core_competency\plan::STATUS_COMPLETE;
+        $record->status = plan::STATUS_COMPLETE;
         $record->duedate = time() - 200;
-        $DB->update_record(core_competency\plan::TABLE, $record);
+        $DB->update_record(plan::TABLE, $record);
 
         $success = core_competency\api::reopen_plan($plan->get_id());
         $this->assertTrue($success);
@@ -416,9 +417,9 @@ class tool_lp_plan_testcase extends advanced_testcase {
 
         // Reopening plan: with due date too soon => duedate unset.
         $record = $plan->to_record();
-        $record->status = core_competency\plan::STATUS_COMPLETE;
+        $record->status = plan::STATUS_COMPLETE;
         $record->duedate = time() + 100;
-        $DB->update_record(core_competency\plan::TABLE, $record);
+        $DB->update_record(plan::TABLE, $record);
 
         $success = core_competency\api::reopen_plan($plan->get_id());
         $this->assertTrue($success);
@@ -427,17 +428,101 @@ class tool_lp_plan_testcase extends advanced_testcase {
 
         // Reopening plan: with due date in the future => duedate unchanged.
         $record = $plan->to_record();
-        $record->status = core_competency\plan::STATUS_COMPLETE;
-        $record->duedate = time() + core_competency\plan::DUEDATE_THRESHOLD + 10;
-        $DB->update_record(core_competency\plan::TABLE, $record);
+        $record->status = plan::STATUS_COMPLETE;
+        $record->duedate = time() + plan::DUEDATE_THRESHOLD + 10;
+        $DB->update_record(plan::TABLE, $record);
 
         $success = core_competency\api::reopen_plan($plan->get_id());
         $this->assertTrue($success);
         $plan->read();
 
         // Check that the due date has not changed, but allow for PHP Unit latency.
-        $this->assertTrue($plan->get_duedate() >= time() + core_competency\plan::DUEDATE_THRESHOLD + 10);
-        $this->assertTrue($plan->get_duedate() <= time() + core_competency\plan::DUEDATE_THRESHOLD + 15);
+        $this->assertTrue($plan->get_duedate() >= time() + plan::DUEDATE_THRESHOLD + 10);
+        $this->assertTrue($plan->get_duedate() <= time() + plan::DUEDATE_THRESHOLD + 15);
+    }
+
+    public function test_get_by_user_and_competency() {
+        $this->resetAfterTest();
+        $this->setAdminUser();
 
+        $dg = $this->getDataGenerator();
+        $lpg = $dg->get_plugin_generator('core_competency');
+
+        $u1 = $dg->create_user();
+        $u2 = $dg->create_user();
+        $u3 = $dg->create_user();
+        $u4 = $dg->create_user();
+
+        $f1 = $lpg->create_framework();
+        $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
+        $c2 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
+
+        $tpl1 = $lpg->create_template();
+        $lpg->create_template_competency(array('competencyid' => $c1->get_id(), 'templateid' => $tpl1->get_id()));
+
+        $p1 = $lpg->create_plan(array('userid' => $u1->id));
+        $lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c1->get_id()));
+        $p2 = $lpg->create_plan(array('userid' => $u2->id));
+        $lpg->create_plan_competency(array('planid' => $p2->get_id(), 'competencyid' => $c1->get_id()));
+        $p3 = $lpg->create_plan(array('userid' => $u3->id, 'templateid' => $tpl1->get_id()));
+        $p4 = $lpg->create_plan(array('userid' => $u4->id, 'templateid' => $tpl1->get_id()));
+        api::complete_plan($p2);
+        api::complete_plan($p4);
+
+        // Finding a plan, not completed.
+        $plans = plan::get_by_user_and_competency($u1->id, $c1->get_id());
+        $this->assertCount(1, $plans);
+        $plan = array_shift($plans);
+        $this->assertEquals($p1->get_id(), $plan->get_id());
+        $this->assertNotEquals(plan::STATUS_COMPLETE, $plan->get_status());
+
+        // Finding a completed plan.
+        $plans = plan::get_by_user_and_competency($u2->id, $c1->get_id());
+        $this->assertCount(1, $plans);
+        $plan = array_shift($plans);
+        $this->assertEquals($p2->get_id(), $plan->get_id());
+        $this->assertEquals(plan::STATUS_COMPLETE, $plan->get_status());
+
+        // Finding a plan based on a template, not completed.
+        $plans = plan::get_by_user_and_competency($u3->id, $c1->get_id());
+        $this->assertCount(1, $plans);
+        $plan = array_shift($plans);
+        $this->assertEquals($p3->get_id(), $plan->get_id());
+        $this->assertTrue($plan->is_based_on_template());
+        $this->assertNotEquals(plan::STATUS_COMPLETE, $plan->get_status());
+
+        // Finding a plan based on a template.
+        $plans = plan::get_by_user_and_competency($u4->id, $c1->get_id());
+        $this->assertCount(1, $plans);
+        $plan = array_shift($plans);
+        $this->assertEquals($p4->get_id(), $plan->get_id());
+        $this->assertTrue($plan->is_based_on_template());
+        $this->assertEquals(plan::STATUS_COMPLETE, $plan->get_status());
+
+        // Finding more than one plan, no template.
+        $p5 = $lpg->create_plan(array('userid' => $u1->id));
+        $lpg->create_plan_competency(array('planid' => $p5->get_id(), 'competencyid' => $c1->get_id()));
+        $plans = plan::get_by_user_and_competency($u1->id, $c1->get_id());
+        $this->assertCount(2, $plans);
+        $plan = array_shift($plans);
+        $this->assertEquals($p1->get_id(), $plan->get_id());
+        $plan = array_shift($plans);
+        $this->assertEquals($p5->get_id(), $plan->get_id());
+
+        // Finding more than one plan, with template.
+        $p6 = $lpg->create_plan(array('userid' => $u1->id, 'templateid' => $tpl1->get_id()));
+        $plans = plan::get_by_user_and_competency($u1->id, $c1->get_id());
+        $this->assertCount(3, $plans);
+        $plan = array_shift($plans);
+        $this->assertEquals($p1->get_id(), $plan->get_id());
+        $plan = array_shift($plans);
+        $this->assertEquals($p5->get_id(), $plan->get_id());
+        $plan = array_shift($plans);
+        $this->assertEquals($p6->get_id(), $plan->get_id());
+
+        // Finding no plans.
+        $plans = plan::get_by_user_and_competency($u1->id, $c2->get_id());
+        $this->assertCount(0, $plans);
     }
+
 }
similarity index 99%
rename from admin/tool/lp/tests/task_test.php
rename to competency/tests/task_test.php
index 9e345f1..311a7ef 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * Task tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Issam Taboubi <issam.taboubi@umontreal.ca>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -30,11 +30,11 @@ use core_competency\plan;
 /**
  * Task tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Issam Taboubi <issam.taboubi@umontreal.ca>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_task_testcase extends advanced_testcase {
+class core_competency_task_testcase extends advanced_testcase {
 
     public function test_sync_plans_from_cohorts_task() {
         global $DB;
similarity index 96%
rename from admin/tool/lp/tests/template_test.php
rename to competency/tests/template_test.php
index bf8f421..217a68d 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * Template persistent class tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2016 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -30,11 +30,11 @@ use core_competency\template;
 /**
  * Template persistent testcase.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2016 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_template_testcase extends advanced_testcase {
+class core_competency_template_testcase extends advanced_testcase {
 
     public function test_validate_duedate() {
         global $DB;
@@ -17,7 +17,7 @@
 /**
  * User evidence competency persistent class tests.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -30,11 +30,11 @@ use core_competency\user_evidence_competency;
 /**
  * User evidence competency persistent testcase.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_lp_user_evidene_competency_testcase extends advanced_testcase {
+class core_competency_user_evidene_competency_testcase extends advanced_testcase {
 
     public function test_get_user_competencies_by_userevidenceid() {
         global $CFG, $DB;