Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Grading methods steps definitions.
  19   *
  20   * @package   core_grading
  21   * @category  test
  22   * @copyright 2013 David MonllaĆ³
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  27  
  28  require_once (__DIR__ . '/../../../../lib/behat/behat_base.php');
  29  
  30  use Behat\Gherkin\Node\TableNode as TableNode;
  31  
  32  /**
  33   * Generic grading methods step definitions.
  34   *
  35   * @package   core_grading
  36   * @category  test
  37   * @copyright 2013 David MonllaĆ³
  38   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class behat_grading extends behat_base {
  41  
  42      /**
  43       * Goes to the selected advanced grading page. You should be in the course page when this step begins.
  44       *
  45       * @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading page$/
  46       * @param string $activityname
  47       */
  48      public function i_go_to_advanced_grading_page($activityname) {
  49  
  50          $this->execute('behat_general::click_link', $this->escape($activityname));
  51  
  52          $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
  53              get_string('gradingmanagement', 'grading'));
  54      }
  55  
  56      /**
  57       * Goes to the selected advanced grading definition page. You should be in the course page when this step begins.
  58       *
  59       * @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading definition page$/
  60       * @param string $activityname
  61       */
  62      public function i_go_to_advanced_grading_definition_page($activityname) {
  63  
  64          // Transforming to literals, probably not necessary, just in case.
  65          $newactionliteral = behat_context_helper::escape(get_string("manageactionnew", "grading"));
  66          $editactionliteral = behat_context_helper::escape(get_string("manageactionedit", "grading"));
  67  
  68          // Working both when adding and editing.
  69          $definitionxpath = "//a[@class='action btn btn-lg']" .
  70              "[./descendant::*[contains(., $newactionliteral) or contains(., $editactionliteral)]]";
  71  
  72          $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
  73  
  74          $this->execute("behat_general::i_click_on", array($this->escape($definitionxpath), "xpath_element"));
  75      }
  76      /**
  77       * Goes to the student's advanced grading page.
  78       *
  79       * @Given /^I go to "(?P<user_fullname_string>(?:[^"]|\\")*)" "(?P<activity_name_string>(?:[^"]|\\")*)" activity advanced grading page$/
  80       * @param string $userfullname The user full name including firstname and lastname.
  81       * @param string $activityname The activity name
  82       */
  83      public function i_go_to_activity_advanced_grading_page($userfullname, $activityname) {
  84  
  85          // Step to access the user grade page from the grading page.
  86          $gradetext = get_string('gradeverb');
  87  
  88          $this->execute('behat_general::click_link', $this->escape($activityname));
  89  
  90          $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
  91              get_string('viewgrading', 'mod_assign'));
  92  
  93          $this->execute('behat_general::i_click_on_in_the',
  94                         array(
  95                             $this->escape($gradetext),
  96                             'link',
  97                             $this->escape($userfullname),
  98                             'table_row'
  99                         ));
 100      }
 101  
 102      /**
 103       * Publishes current activity grading defined form as a public template.
 104       *
 105       * @Given /^I publish "(?P<activity_name_string>(?:[^"]|\\")*)" grading form definition as a public template$/
 106       * @param string $activityname
 107       */
 108      public function i_publish_grading_form_definition_as_a_public_template($activityname) {
 109  
 110          $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
 111  
 112          $this->execute("behat_general::i_click_on", array($this->escape(get_string("manageactionshare", "grading")), "link"));
 113  
 114          $this->execute('behat_forms::press_button', get_string('continue'));
 115      }
 116  
 117      /**
 118       * Sets a previously created grading form as the activity grading form.
 119       *
 120       * @Given /^I set "(?P<activity_name_string>(?:[^"]|\\")*)" activity to use "(?P<grading_form_template_string>(?:[^"]|\\")*)" grading form$/
 121       * @param string $activityname
 122       * @param string $templatename
 123       */
 124      public function i_set_activity_to_use_grading_form($activityname, $templatename) {
 125  
 126          $templateliteral = behat_context_helper::escape($templatename);
 127  
 128          $templatexpath = "//h2[@class='template-name'][contains(., $templateliteral)]/" .
 129              "following-sibling::div[contains(concat(' ', normalize-space(@class), ' '), ' template-actions ')]";
 130  
 131          // Should work with both templates and own forms.
 132          $literaltemplate = behat_context_helper::escape(get_string('templatepick', 'grading'));
 133          $literalownform = behat_context_helper::escape(get_string('templatepickownform', 'grading'));
 134          $usetemplatexpath = "/a[./descendant::div[text()=$literaltemplate]]|" .
 135              "/a[./descendant::div[text()=$literalownform]]";
 136  
 137          $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
 138  
 139          $this->execute('behat_general::click_link', $this->escape(get_string('manageactionclone', 'grading')));
 140          $this->execute('behat_forms::i_set_the_field_to', array(get_string('searchownforms', 'grading'), 1));
 141          $this->execute('behat_general::i_click_on_in_the',
 142              array(get_string('search'), "button", "region-main", "region")
 143          );
 144          $this->execute('behat_general::i_click_on_in_the',
 145              array($this->escape($usetemplatexpath), "xpath_element", $this->escape($templatexpath), "xpath_element")
 146          );
 147          $this->execute('behat_forms::press_button', get_string('continue'));
 148  
 149      }
 150  
 151      /**
 152       * Saves the current page advanced grading form.
 153       *
 154       * @When /^I save the advanced grading form$/
 155       */
 156      public function i_save_the_advanced_grading_form() {
 157  
 158          $this->execute('behat_forms::press_button', get_string('savechanges'));
 159          $this->execute('behat_general::i_click_on', array($this->escape(get_string('editsettings')), 'link'));
 160          $this->execute('behat_forms::press_button', get_string('cancel'));
 161          $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
 162              get_string('viewgrading', 'mod_assign'));
 163      }
 164  
 165      /**
 166       * Grades an activity using advanced grading. Note the grade is set by other steps, depending on the grading method.
 167       *
 168       * @Given /^I complete the advanced grading form with these values:$/
 169       * @param TableNode $data
 170       */
 171      public function i_complete_the_advanced_grading_form_with_these_values(TableNode $data) {
 172          $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
 173          $this->execute('behat_grading::i_save_the_advanced_grading_form');
 174      }
 175  }