Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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          try {
  51              $this->execute("behat_general::i_click_on_in_the", [$this->escape($activityname), 'link', 'page', 'region']);
  52          } catch (Exception $e) {
  53              $this->execute('behat_navigation::go_to_breadcrumb_location', $this->escape($activityname));
  54          }
  55  
  56          $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
  57              get_string('gradingmanagement', 'grading'));
  58      }
  59  
  60      /**
  61       * Goes to the selected advanced grading definition page. You should be in the course page when this step begins.
  62       *
  63       * @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading definition page$/
  64       * @param string $activityname
  65       */
  66      public function i_go_to_advanced_grading_definition_page($activityname) {
  67  
  68          // Transforming to literals, probably not necessary, just in case.
  69          $newactionliteral = behat_context_helper::escape(get_string("manageactionnew", "grading"));
  70          $editactionliteral = behat_context_helper::escape(get_string("manageactionedit", "grading"));
  71  
  72          // Working both when adding and editing.
  73          $definitionxpath = "//a[@class='action btn btn-lg']" .
  74              "[./descendant::*[contains(., $newactionliteral) or contains(., $editactionliteral)]]";
  75  
  76          $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
  77  
  78          $this->execute("behat_general::i_click_on", array($this->escape($definitionxpath), "xpath_element"));
  79      }
  80      /**
  81       * Goes to the student's advanced grading page.
  82       *
  83       * @Given /^I go to "(?P<user_fullname_string>(?:[^"]|\\")*)" "(?P<activity_name_string>(?:[^"]|\\")*)" activity advanced grading page$/
  84       * @param string $userfullname The user full name including firstname and lastname.
  85       * @param string $activityname The activity name
  86       */
  87      public function i_go_to_activity_advanced_grading_page($userfullname, $activityname) {
  88  
  89          // Step to access the user grade page from the grading page.
  90          $gradetext = get_string('gradeverb');
  91  
  92          $this->execute('behat_navigation::go_to_breadcrumb_location', $this->escape($activityname));
  93  
  94          $this->execute('behat_general::click_link', get_string('viewgrading', 'mod_assign'));
  95  
  96          $this->execute('behat_general::i_click_on_in_the',
  97                         array(
  98                             $this->escape($gradetext),
  99                             'link',
 100                             $this->escape($userfullname),
 101                             'table_row'
 102                         ));
 103      }
 104  
 105      /**
 106       * Publishes current activity grading defined form as a public template.
 107       *
 108       * @Given /^I publish "(?P<activity_name_string>(?:[^"]|\\")*)" grading form definition as a public template$/
 109       * @param string $activityname
 110       */
 111      public function i_publish_grading_form_definition_as_a_public_template($activityname) {
 112  
 113          $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
 114  
 115          $this->execute("behat_general::i_click_on", array($this->escape(get_string("manageactionshare", "grading")), "link"));
 116  
 117          $this->execute('behat_forms::press_button', get_string('continue'));
 118      }
 119  
 120      /**
 121       * Sets a previously created grading form as the activity grading form.
 122       *
 123       * @Given /^I set "(?P<activity_name_string>(?:[^"]|\\")*)" activity to use "(?P<grading_form_template_string>(?:[^"]|\\")*)" grading form$/
 124       * @param string $activityname
 125       * @param string $templatename
 126       */
 127      public function i_set_activity_to_use_grading_form($activityname, $templatename) {
 128  
 129          $templateliteral = behat_context_helper::escape($templatename);
 130  
 131          $templatexpath = "//h2[@class='template-name'][contains(., $templateliteral)]/" .
 132              "following-sibling::div[contains(concat(' ', normalize-space(@class), ' '), ' template-actions ')]";
 133  
 134          // Should work with both templates and own forms.
 135          $literaltemplate = behat_context_helper::escape(get_string('templatepick', 'grading'));
 136          $literalownform = behat_context_helper::escape(get_string('templatepickownform', 'grading'));
 137          $usetemplatexpath = "/a[./descendant::div[text()=$literaltemplate]]|" .
 138              "/a[./descendant::div[text()=$literalownform]]";
 139  
 140          $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
 141  
 142          $this->execute('behat_general::click_link', $this->escape(get_string('manageactionclone', 'grading')));
 143          $this->execute('behat_forms::i_set_the_field_to', array(get_string('searchownforms', 'grading'), 1));
 144          $this->execute('behat_general::i_click_on_in_the',
 145              array(get_string('search'), "button", "region-main", "region")
 146          );
 147          $this->execute('behat_general::i_click_on_in_the',
 148              array($this->escape($usetemplatexpath), "xpath_element", $this->escape($templatexpath), "xpath_element")
 149          );
 150          $this->execute('behat_forms::press_button', get_string('continue'));
 151  
 152      }
 153  
 154      /**
 155       * Saves the current page advanced grading form.
 156       *
 157       * @When /^I save the advanced grading form$/
 158       */
 159      public function i_save_the_advanced_grading_form() {
 160  
 161          $this->execute('behat_forms::press_button', get_string('savechanges'));
 162          $this->execute('behat_general::i_click_on', array($this->escape(get_string('editsettings')), 'link'));
 163          $this->execute('behat_forms::press_button', get_string('cancel'));
 164          $this->execute('behat_general::click_link', get_string('viewgrading', 'mod_assign'));
 165      }
 166  
 167      /**
 168       * Grades an activity using advanced grading. Note the grade is set by other steps, depending on the grading method.
 169       *
 170       * @Given /^I complete the advanced grading form with these values:$/
 171       * @param TableNode $data
 172       */
 173      public function i_complete_the_advanced_grading_form_with_these_values(TableNode $data) {
 174          $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
 175          $this->execute('behat_grading::i_save_the_advanced_grading_form');
 176      }
 177  }