Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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  // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  18  
  19  use Behat\Gherkin\Node\TableNode;
  20  
  21  require_once (__DIR__ . '/../../../../../lib/behat/behat_deprecated_base.php');
  22  
  23  /**
  24   * Steps definitions that are now deprecated and will be removed in the next releases.
  25   *
  26   * This file only contains the steps that previously were in the behat_*.php files in the SAME DIRECTORY.
  27   * When deprecating steps from other components or plugins, create a behat_COMPONENT_deprecated.php
  28   * file in the same directory where the steps were defined.
  29   *
  30   * @package    gradereport_grader
  31   * @category   test
  32   * @copyright  2023 Ilya Tregubov
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class behat_gradereport_grader_deprecated extends behat_deprecated_base {
  36  
  37      /**
  38       * Remove focus for a grade value cell.
  39       *
  40       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
  41       * @todo MDL-77107 This will be deleted in Moodle 4.6.
  42       * @Given /^I click away from student "([^"]*)" and grade item "([^"]*)" feedback$/
  43       * @param string $student
  44       * @param string $itemname
  45       */
  46      public function i_click_away_from_student_and_grade_feedback($student, $itemname) {
  47          $this->deprecated_message(['behat_gradereport_grader::i_click_away_from_student_and_grade_feedback']);
  48          $xpath = $this->get_student_and_grade_feedback_selector($student, $itemname);
  49  
  50          $this->execute('behat_general::i_take_focus_off_field', array($this->escape($xpath), 'xpath_element'));
  51      }
  52  
  53      /**
  54       * Look for a feedback editing field.
  55       *
  56       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
  57       * @todo MDL-77107 This will be deleted in Moodle 4.6.
  58       * @Then /^I should see a feedback field for "([^"]*)" and grade item "([^"]*)"$/
  59       * @param string $student
  60       * @param string $itemname
  61       */
  62      public function i_should_see_feedback_field($student, $itemname) {
  63          $this->deprecated_message(['behat_gradereport_grader::i_should_see_feedback_field']);
  64          $xpath = $this->get_student_and_grade_feedback_selector($student, $itemname);
  65  
  66          $this->execute('behat_general::should_be_visible', array($this->escape($xpath), 'xpath_element'));
  67      }
  68  
  69      /**
  70       * Look for a lack of the feedback editing field.
  71       *
  72       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
  73       * @todo MDL-77107 This will be deleted in Moodle 4.6.
  74       * @Then /^I should not see a feedback field for "([^"]*)" and grade item "([^"]*)"$/
  75       * @param string $student
  76       * @param string $itemname
  77       */
  78      public function i_should_not_see_feedback_field($student, $itemname) {
  79          $this->deprecated_message(['behat_gradereport_grader::i_should_not_see_feedback_field']);
  80          $xpath = $this->get_student_and_grade_feedback_selector($student, $itemname);
  81  
  82          $this->execute('behat_general::should_not_exist', array($this->escape($xpath), 'xpath_element'));
  83      }
  84  
  85      /**
  86       * Gets xpath for a particular student/grade item feedback cell.
  87       *
  88       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
  89       * @todo MDL-77107 This will be deleted in Moodle 4.6.
  90       * @throws Exception
  91       * @param string $student
  92       * @param string $itemname
  93       * @return string
  94       */
  95      protected function get_student_and_grade_feedback_selector($student, $itemname) {
  96          $this->deprecated_message(['behat_gradereport_grader::get_student_and_grade_feedback_selector']);
  97  
  98          $cell = $this->get_student_and_grade_cell_selector($student, $itemname);
  99          return $cell . "//input[contains(@id, 'feedback_') or @name='ajaxfeedback']";
 100      }
 101  
 102      /**
 103       * Click a given user grade cell.
 104       *
 105       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
 106       * @todo MDL-77107 This will be deleted in Moodle 4.6.
 107       * @Given /^I click on student "([^"]*)" for grade item "([^"]*)"$/
 108       * @param string $student
 109       * @param string $itemname
 110       */
 111      public function i_click_on_student_and_grade_item($student, $itemname) {
 112          $this->deprecated_message(['behat_gradereport_grader::i_click_on_student_and_grade_item']);
 113  
 114          $xpath = $this->get_student_and_grade_cell_selector($student, $itemname);
 115  
 116          $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
 117      }
 118  
 119      /**
 120       * Remove focus for a grade value cell.
 121       *
 122       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
 123       * @todo MDL-77107 This will be deleted in Moodle 4.6.
 124       * @Given /^I click away from student "([^"]*)" and grade item "([^"]*)" value$/
 125       * @param string $student
 126       * @param string $itemname
 127       */
 128      public function i_click_away_from_student_and_grade_value($student, $itemname) {
 129          $this->deprecated_message(['behat_gradereport_grader::i_click_away_from_student_and_grade_value']);
 130  
 131          $xpath = $this->get_student_and_grade_value_selector($student, $itemname);
 132  
 133          $this->execute('behat_general::i_take_focus_off_field', array($this->escape($xpath), 'xpath_element'));
 134      }
 135  
 136      /**
 137       * Checks grade values with or without a edit box.
 138       *
 139       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
 140       * @todo MDL-77107 This will be deleted in Moodle 4.6.
 141       * @Then /^the grade for "([^"]*)" in grade item "([^"]*)" should match "([^"]*)"$/
 142       * @throws Exception
 143       * @throws ElementNotFoundException
 144       * @param string $student
 145       * @param string $itemname
 146       * @param string $value
 147       */
 148      public function the_grade_should_match($student, $itemname, $value) {
 149          $this->deprecated_message(['behat_gradereport_grader::the_grade_should_match']);
 150  
 151          $xpath = $this->get_student_and_grade_value_selector($student, $itemname);
 152  
 153          $gradefield = $this->getSession()->getPage()->find('xpath', $xpath);
 154          if (!empty($gradefield)) {
 155              // Get the field.
 156              $fieldtype = behat_field_manager::guess_field_type($gradefield, $this->getSession());
 157              if (!$fieldtype) {
 158                  throw new Exception('Could not get field type for grade field "' . $itemname . '"');
 159              }
 160              $field = behat_field_manager::get_field_instance($fieldtype, $gradefield, $this->getSession());
 161              if (!$field->matches($value)) {
 162                  $fieldvalue = $field->get_value();
 163                  throw new ExpectationException(
 164                      'The "' . $student . '" and "' . $itemname . '" grade is "' . $fieldvalue . '", "' . $value . '" expected' ,
 165                      $this->getSession()
 166                  );
 167              }
 168          } else {
 169              // If there isn't a form field, just search for contents.
 170              $valueliteral = behat_context_helper::escape($value);
 171  
 172              $xpath = $this->get_student_and_grade_cell_selector($student, $itemname);
 173              $xpath .= "[contains(normalize-space(.)," . $valueliteral . ")]";
 174  
 175              $node = $this->getSession()->getDriver()->find($xpath);
 176              if (empty($node)) {
 177                  $locatorexceptionmsg = 'Cell for "' . $student . '" and "' . $itemname . '" with value "' . $value . '"';
 178                  throw new ElementNotFoundException($this->getSession(), $locatorexceptionmsg, null, $xpath);
 179              }
 180          }
 181      }
 182  
 183      /**
 184       * Look for a grade editing field.
 185       *
 186       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
 187       * @todo MDL-77107 This will be deleted in Moodle 4.6.
 188       * @Then /^I should see a grade field for "([^"]*)" and grade item "([^"]*)"$/
 189       * @param string $student
 190       * @param string $itemname
 191       */
 192      public function i_should_see_grade_field($student, $itemname) {
 193          $this->deprecated_message(['behat_gradereport_grader::i_should_see_grade_field']);
 194  
 195          $xpath = $this->get_student_and_grade_value_selector($student, $itemname);
 196  
 197          $this->execute('behat_general::should_be_visible', array($this->escape($xpath), 'xpath_element'));
 198      }
 199  
 200      /**
 201       * Look for a lack of the grade editing field.
 202       *
 203       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
 204       * @todo MDL-77107 This will be deleted in Moodle 4.6.
 205       * @Then /^I should not see a grade field for "([^"]*)" and grade item "([^"]*)"$/
 206       * @param string $student
 207       * @param string $itemname
 208       */
 209      public function i_should_not_see_grade_field($student, $itemname) {
 210          $this->deprecated_message(['behat_gradereport_grader::i_should_not_see_grade_field']);
 211          $xpath = $this->get_student_and_grade_value_selector($student, $itemname);
 212  
 213          $this->execute('behat_general::should_not_exist', array($this->escape($xpath), 'xpath_element'));
 214      }
 215  
 216      /**
 217       * Gets unique xpath selector for a student/grade item combo.
 218       *
 219       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
 220       * @todo MDL-77107 This will be deleted in Moodle 4.6.
 221       * @throws Exception
 222       * @param string $student
 223       * @param string $itemname
 224       * @return string
 225       */
 226      protected function get_student_and_grade_cell_selector($student, $itemname) {
 227          $this->deprecated_message(['behat_gradereport_grader::get_student_and_grade_cell_selector']);
 228  
 229          $itemid = 'u' . $this->get_user_id($student) . 'i' . $this->get_grade_item_id($itemname);
 230          return "//table[@id='user-grades']//td[@id='" . $itemid . "']";
 231      }
 232  
 233      /**
 234       * Gets xpath for a particular student/grade item grade value cell.
 235       *
 236       * @deprecated since 4.2 - we don't allow ajax edit on grader report anymore.
 237       * @todo MDL-77107 This will be deleted in Moodle 4.6.
 238       * @throws Exception
 239       * @param string $student
 240       * @param string $itemname
 241       * @return string
 242       */
 243      protected function get_student_and_grade_value_selector($student, $itemname) {
 244          $this->deprecated_message(['behat_gradereport_grader::get_student_and_grade_value_selector']);
 245  
 246          $cell = $this->get_student_and_grade_cell_selector($student, $itemname);
 247          return $cell . "//*[contains(@id, 'grade_') or @name='ajaxgrade']";
 248      }
 249  
 250  }