Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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 39 and 310] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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_general::i_click_on_in_the", [$this->escape($workshopname), 'link', 'page', 'region']);
  92          $this->execute('behat_navigation::i_navigate_to_in_current_page_administration', get_string('allocate', 'workshop'));
  93          $rows = $table->getRows();
  94          $reviewer = $participant = null;
  95          for ($i = 0; $i < count($rows[0]); $i++) {
  96              if (strtolower($rows[0][$i]) === 'reviewer') {
  97                  $reviewer = $i;
  98              } else if (strtolower($rows[0][$i]) === 'reviewee' || strtolower($rows[0][$i]) === 'participant') {
  99                  $participant = $i;
 100              } else {
 101                  throw new ElementTextException('Unrecognised column "'.$rows[0][$i].'"', $this->getSession());
 102              }
 103          }
 104          if ($reviewer === null) {
 105              throw new ElementTextException('Column "Reviewer" could not be located', $this->getSession());
 106          }
 107          if ($participant === null) {
 108              throw new ElementTextException('Neither "Participant" nor "Reviewee" column could be located', $this->getSession());
 109          }
 110  
 111          for ($i = 1; $i < count($rows); $i++) {
 112              $this->execute(
 113                  'behat_workshopallocation_manual::i_add_a_reviewer_for_workshop_participant',
 114                  [
 115                      $rows[$i][$reviewer],
 116                      $rows[$i][$participant],
 117                  ]
 118              );
 119          }
 120      }
 121  }