From 12bf1da9e5577a5f08c04df605584c169ccfb422 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 20 Feb 2025 11:22:18 +0800 Subject: [PATCH] MDL-84424 behat: add template_competencies generator and improve test --- .../lp/tests/behat/link_unlink_lp.feature | 25 ++++++------------- .../behat_core_competency_generator.php | 22 ++++++++++++++++ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/admin/tool/lp/tests/behat/link_unlink_lp.feature b/admin/tool/lp/tests/behat/link_unlink_lp.feature index 80ef97ced9d..b0219f19a5a 100644 --- a/admin/tool/lp/tests/behat/link_unlink_lp.feature +++ b/admin/tool/lp/tests/behat/link_unlink_lp.feature @@ -8,31 +8,27 @@ Feature: Admin can create learning plans from template Given the following "users" exist: | username | firstname | lastname | email | | student1 | Student | One | student1@email.com | - # Create competency frameworks. And the following "core_competency > frameworks" exist: | shortname | idnumber | | CF1 | CF1 | | CF2 | CF2 | - # Add competency to each competency frameworks. And the following "core_competency > competencies" exist: | shortname | competencyframework | idnumber | | CF1 Competency 1 | CF1 | CF1C1 | | CF2 Competency 1 | CF2 | CF2C1 | - # Create a learning plan template. And the following "core_competency > templates" exist: | shortname | description | | LPT1 | LPT 1 description | - And I log in as "admin" + And the following "core_competency > template_competencies" exist: + | template | competency | + | LPT1 | CF1C1 | @javascript Scenario: Admin can assign competencies from different frameworks to a learning plan - Given I navigate to "Competencies > Learning plan templates" in site administration - And I click on "LPT1" "link" - # Add a competency in learning plan template. + Given I log in as "admin" + And I navigate to "Competencies > Learning plan templates" in site administration + And I follow "LPT1" When I press "Add competencies to learning plan template" - And I select "CF1 Competency 1" of the competency tree - And I click on "Add" "button" in the "Competency picker" "dialogue" - And I press "Add competencies to learning plan template" # Add another competency from a different framework in the learning plan template. And I set the field with xpath "//select[@data-action='chooseframework']" to "CF2 CF2" And I select "CF2 Competency 1" of the competency tree @@ -45,12 +41,7 @@ Feature: Admin can create learning plans from template @javascript Scenario: Admin can link and unlink learning plans created from template - Given I navigate to "Competencies > Learning plan templates" in site administration - And I click on "LPT1" "link" - # Add a competency in learning plan template. - And I press "Add competencies to learning plan template" - And I select "CF1 Competency 1" of the competency tree - And I click on "Add" "button" in the "Competency picker" "dialogue" + Given I log in as "admin" And I navigate to "Competencies > Learning plan templates" in site administration # Initially, the number of learning plans is 0. And the following should exist in the "generaltable" table: @@ -72,7 +63,7 @@ Feature: Admin can create learning plans from template # Unlink the template. And I click on "Unlink from learning plan template" "link" And I press "Unlink from learning plan template" - # Learning plan stil exists but Template name and Unlink from learning plan template link no longer exist. + # Learning plan still exists but Template name and Unlink from learning plan template link no longer exist. And "LPT1" "text" should exist And "Learning plan template" "text" should not exist And "Unlink from learning plan template" "link" should not exist diff --git a/competency/tests/generator/behat_core_competency_generator.php b/competency/tests/generator/behat_core_competency_generator.php index 2d2f9cb1ad5..bb77d9c3ff8 100644 --- a/competency/tests/generator/behat_core_competency_generator.php +++ b/competency/tests/generator/behat_core_competency_generator.php @@ -107,6 +107,12 @@ class behat_core_competency_generator extends behat_generator_base { 'required' => ['shortname'], 'switchids' => ['context' => 'contextid'], ], + 'template_competencies' => [ + 'singular' => 'template_competency', + 'datagenerator' => 'template_competency', + 'required' => ['template', 'competency'], + 'switchids' => ['template' => 'templateid', 'competency' => 'competencyid'], + ], ]; } @@ -168,6 +174,22 @@ class behat_core_competency_generator extends behat_generator_base { return $this->get_competency_id($idnumber); } + /** + * Get the template id by shortname. + * + * @param string $shortname The template name. + * @return int + */ + protected function get_template_id(string $shortname): int { + global $DB; + + if (!$id = $DB->get_field('competency_template', 'id', ['shortname' => $shortname])) { + throw new Exception('The specified template with name "' . $shortname . '" could not be found.'); + } + + return $id; + } + /** * Add a plan. *