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   * Steps definitions related to workshopallocation_manual.
  19   *
  20   * @package    workshopallocation_manual
  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  require_once (__DIR__ . '/../../../../../../lib/behat/behat_field_manager.php');
  30  
  31  use Behat\Gherkin\Node\TableNode as TableNode,
  32      Behat\Mink\Exception\ElementTextException as ElementTextException;
  33  
  34  /**
  35   * Steps definitions related to workshopallocation_manual.
  36   *
  37   * @package    workshopallocation_manual
  38   * @category   test
  39   * @copyright  2014 Marina Glancy
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class behat_workshopallocation_manual extends behat_base {
  43      /**
  44       * Manually adds a reviewer for workshop participant.
  45       *
  46       * This step should start on manual allocation page.
  47       *
  48       * @When /^I add a reviewer "(?P<reviewer_name_string>(?:[^"]|\\")*)" for workshop participant "(?P<participant_name_string>(?:[^"]|\\")*)"$/
  49       * @param string $reviewername
  50       * @param string $participantname
  51       */
  52      public function i_add_a_reviewer_for_workshop_participant($reviewername, $participantname) {
  53          $participantnameliteral = behat_context_helper::escape($participantname);
  54          $xpathtd = "//table[contains(concat(' ', normalize-space(@class), ' '), ' allocations ')]/".
  55                  "tbody/tr[./td[contains(concat(' ', normalize-space(@class), ' '), ' peer ')]".
  56                  "[contains(.,$participantnameliteral)]]/".
  57                  "td[contains(concat(' ', normalize-space(@class), ' '), ' reviewedby ')]";
  58          $xpathselect = $xpathtd . "/descendant::select";
  59          try {
  60              $selectnode = $this->find('xpath', $xpathselect);
  61          } catch (Exception $ex) {
  62              $this->find_button(get_string('showallparticipants', 'workshopallocation_manual'))->press();
  63              $selectnode = $this->find('xpath', $xpathselect);
  64          }
  65  
  66          $this->execute('behat_forms::set_field_node_value', [
  67              $selectnode,
  68              $reviewername,
  69          ]);
  70  
  71          if (!$this->running_javascript()) {
  72              // Without Javascript we need to press the "Go" button.
  73              $go = behat_context_helper::escape(get_string('go'));
  74              $this->find('xpath', $xpathtd."/descendant::input[@value=$go]")->click();
  75          }
  76  
  77          // Check the success string to appear.
  78          $allocatedtext = behat_context_helper::escape(get_string('allocationadded', 'workshopallocation_manual'));
  79          $this->find('xpath', "//*[contains(.,$allocatedtext)]");
  80      }
  81  
  82      /**
  83       * Manually allocates multiple reviewers in workshop.
  84       *
  85       * @When /^I allocate submissions in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:$/
  86       * @When /^I allocate submissions in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
  87       * @param string $workshopname
  88       * @param TableNode $table should have one column with title 'Reviewer' and another with title 'Participant' (or 'Reviewee')
  89       */
  90      public function i_allocate_submissions_in_workshop_as($workshopname, TableNode $table) {
  91          $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname);
  92          $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
  93              get_string('submissionsallocation', 'workshop'));
  94          $rows = $table->getRows();
  95          $reviewer = $participant = null;
  96          for ($i = 0; $i < count($rows[0]); $i++) {
  97              if (strtolower($rows[0][$i]) === 'reviewer') {
  98                  $reviewer = $i;
  99              } else if (strtolower($rows[0][$i]) === 'reviewee' || strtolower($rows[0][$i]) === 'participant') {
 100                  $participant = $i;
 101              } else {
 102                  throw new ElementTextException('Unrecognised column "'.$rows[0][$i].'"', $this->getSession());
 103              }
 104          }
 105          if ($reviewer === null) {
 106              throw new ElementTextException('Column "Reviewer" could not be located', $this->getSession());
 107          }
 108          if ($participant === null) {
 109              throw new ElementTextException('Neither "Participant" nor "Reviewee" column could be located', $this->getSession());
 110          }
 111  
 112          for ($i = 1; $i < count($rows); $i++) {
 113              $this->execute(
 114                  'behat_workshopallocation_manual::i_add_a_reviewer_for_workshop_participant',
 115                  [
 116                      $rows[$i][$reviewer],
 117                      $rows[$i][$participant],
 118                  ]
 119              );
 120          }
 121      }
 122  }