Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   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   * Steps definitions related to mod_workshop.
  19   *
  20   * @package    mod_workshop
  21   * @category   test
  22   * @copyright  2014 Marina Glancy
  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   * Steps definitions related to mod_workshop.
  34   *
  35   * @package    mod_workshop
  36   * @category   test
  37   * @copyright  2014 Marina Glancy
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class behat_mod_workshop extends behat_base {
  41      /**
  42       * Changes the submission phase for the workshop.
  43       *
  44       * @When /^I change phase in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" to "(?P<phase_name_string>(?:[^"]|\\")*)"$/
  45       * @param string $questiontype
  46       * @param string $workshopname
  47       */
  48      public function i_change_phase_in_workshop_to($workshopname, $phase) {
  49          $workshopname = $this->escape($workshopname);
  50          $phaseliteral = behat_context_helper::escape($phase);
  51  
  52          $xpath = "//*[@class='userplan']/descendant::div[./span[contains(.,$phaseliteral)]]";
  53          $continue = $this->escape(get_string('continue'));
  54  
  55          $this->execute("behat_general::i_click_on_in_the", [$this->escape($workshopname), 'link', 'page', 'region']);
  56  
  57          $this->execute('behat_general::i_click_on_in_the',
  58              array('a.action-icon', "css_element", $this->escape($xpath), "xpath_element")
  59          );
  60  
  61          $this->execute("behat_forms::press_button", $continue);
  62      }
  63  
  64      /**
  65       * Adds or edits a student workshop submission.
  66       *
  67       * @When /^I add a submission in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
  68       * @param string $workshopname
  69       * @param TableNode $table data to fill the submission form with, must contain 'Title'
  70       */
  71      public function i_add_a_submission_in_workshop_as($workshopname, $table) {
  72          $workshopname = $this->escape($workshopname);
  73          $savechanges = $this->escape(get_string('savechanges'));
  74          $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ownsubmission ')]/descendant::*[@type='submit']";
  75  
  76          $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($workshopname), 'workshop activity']);
  77  
  78          $this->execute("behat_general::i_click_on", array($xpath, "xpath_element"));
  79  
  80          $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
  81  
  82          $this->execute("behat_forms::press_button", $savechanges);
  83      }
  84  
  85      /**
  86       * Sets the workshop assessment form.
  87       *
  88       * @When /^I edit assessment form in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
  89       * @param string $workshopname
  90       * @param TableNode $table data to fill the submission form with, must contain 'Title'
  91       */
  92      public function i_edit_assessment_form_in_workshop_as($workshopname, $table) {
  93          $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($workshopname), 'workshop activity']);
  94  
  95          $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
  96              get_string('editassessmentform', 'workshop'));
  97  
  98          $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
  99  
 100          $this->execute("behat_forms::press_button", get_string('saveandclose', 'workshop'));
 101      }
 102  
 103      /**
 104       * Peer-assesses a workshop submission.
 105       *
 106       * @When /^I assess submission "(?P<submission_string>(?:[^"]|\\")*)" in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
 107       * @param string $submission
 108       * @param string $workshopname
 109       * @param TableNode $table
 110       */
 111      public function i_assess_submission_in_workshop_as($submission, $workshopname, TableNode $table) {
 112          $workshopname = $this->escape($workshopname);
 113          $submissionliteral = behat_context_helper::escape($submission);
 114          $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' assessment-summary ') ".
 115                  "and contains(.,$submissionliteral)]";
 116          $assess = $this->escape(get_string('assess', 'workshop'));
 117          $saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
 118  
 119          $this->execute("behat_navigation::i_am_on_page_instance", [$workshopname, 'workshop activity']);
 120  
 121          $this->execute('behat_general::i_click_on_in_the',
 122              array($assess, "button", $xpath, "xpath_element")
 123          );
 124  
 125          $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
 126  
 127          $this->execute("behat_forms::press_button", $saveandclose);
 128      }
 129  
 130      /**
 131       * Checks that the user has particular grade set by his reviewing peer in workshop
 132       *
 133       * @Then /^I should see grade "(?P<grade_string>[^"]*)" for workshop participant "(?P<participant_name_string>(?:[^"]|\\")*)" set by peer "(?P<reviewer_name_string>(?:[^"]|\\")*)"$/
 134       * @param string $grade
 135       * @param string $participant
 136       * @param string $reviewer
 137       */
 138      public function i_should_see_grade_for_workshop_participant_set_by_peer($grade, $participant, $reviewer) {
 139          $participantliteral = behat_context_helper::escape($participant);
 140          $reviewerliteral = behat_context_helper::escape($reviewer);
 141          $gradeliteral = behat_context_helper::escape($grade);
 142          $participantselector = "contains(concat(' ', normalize-space(@class), ' '), ' participant ') ".
 143                  "and contains(.,$participantliteral)";
 144          $trxpath = "//table/tbody/tr[td[$participantselector]]";
 145          $tdparticipantxpath = "//table/tbody/tr/td[$participantselector]";
 146          $tdxpath = "/td[contains(concat(' ', normalize-space(@class), ' '), ' receivedgrade ') and contains(.,$reviewerliteral)]/".
 147                  "descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' grade ') and .=$gradeliteral]";
 148  
 149          $tr = $this->find('xpath', $trxpath);
 150          $rowspan = $this->find('xpath', $tdparticipantxpath)->getAttribute('rowspan');
 151  
 152          $xpath = $trxpath.$tdxpath;
 153          if (!empty($rowspan)) {
 154              for ($i = 1; $i < $rowspan; $i++) {
 155                  $xpath .= ' | '.$trxpath."/following-sibling::tr[$i]".$tdxpath;
 156              }
 157          }
 158          $this->find('xpath', $xpath);
 159      }
 160  
 161      /**
 162       * Configure portfolio plugin, set value for portfolio instance
 163       *
 164       * @When /^I set portfolio instance "(?P<portfolioinstance_string>(?:[^"]|\\")*)" to "(?P<value_string>(?:[^"]|\\")*)"$/
 165       * @param string $portfolioinstance
 166       * @param string $value
 167       */
 168      public function i_set_portfolio_instance_to($portfolioinstance, $value) {
 169  
 170          $rowxpath = "//table[contains(@class, 'generaltable')]//tr//td[contains(text(), '"
 171              . $portfolioinstance . "')]/following-sibling::td";
 172  
 173          $selectxpath = $rowxpath.'//select';
 174          $select = $this->find('xpath', $selectxpath);
 175          $select->selectOption($value);
 176  
 177          if (!$this->running_javascript()) {
 178              $this->execute('behat_general::i_click_on_in_the',
 179                  array(get_string('go'), "button", $rowxpath, "xpath_element")
 180              );
 181          }
 182      }
 183  }