[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/workshop/tests/behat/ -> behat_mod_workshop.php (source)

   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          $switchphase = behat_context_helper::escape(get_string('switchphase', 'workshop'));
  52  
  53          $xpath = "//*[@class='userplan']/descendant::div[./span[contains(.,$phaseliteral)]]/".
  54                  "descendant-or-self::a[./img[@alt=$switchphase]]";
  55          $continue = $this->escape(get_string('continue'));
  56  
  57          $this->execute('behat_general::click_link', $workshopname);
  58  
  59          $this->execute("behat_general::i_click_on", array($xpath, "xpath_element"));
  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::input[@type='submit']";
  75  
  76          $this->execute('behat_general::click_link', $workshopname);
  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          $workshopname = $this->escape($workshopname);
  94          $editassessmentform = $this->escape(get_string('editassessmentform', 'workshop'));
  95          $saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
  96  
  97          $this->execute('behat_general::click_link', $workshopname);
  98  
  99          $this->execute('behat_general::click_link', $editassessmentform);
 100  
 101          $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
 102  
 103          $this->execute("behat_forms::press_button", $saveandclose);
 104      }
 105  
 106      /**
 107       * Peer-assesses a workshop submission.
 108       *
 109       * @When /^I assess submission "(?P<submission_string>(?:[^"]|\\")*)" in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
 110       * @param string $submission
 111       * @param string $workshopname
 112       * @param TableNode $table
 113       */
 114      public function i_assess_submission_in_workshop_as($submission, $workshopname, TableNode $table) {
 115          $workshopname = $this->escape($workshopname);
 116          $submissionliteral = behat_context_helper::escape($submission);
 117          $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' assessment-summary ') ".
 118                  "and contains(.,$submissionliteral)]";
 119          $assess = $this->escape(get_string('assess', 'workshop'));
 120          $saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
 121  
 122          $this->execute('behat_general::click_link', $workshopname);
 123  
 124          $this->execute('behat_general::i_click_on_in_the',
 125              array($assess, "button", $xpath, "xpath_element")
 126          );
 127  
 128          $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
 129  
 130          $this->execute("behat_forms::press_button", $saveandclose);
 131      }
 132  
 133      /**
 134       * Checks that the user has particular grade set by his reviewing peer in workshop
 135       *
 136       * @Then /^I should see grade "(?P<grade_string>[^"]*)" for workshop participant "(?P<participant_name_string>(?:[^"]|\\")*)" set by peer "(?P<reviewer_name_string>(?:[^"]|\\")*)"$/
 137       * @param string $grade
 138       * @param string $participant
 139       * @param string $reviewer
 140       */
 141      public function i_should_see_grade_for_workshop_participant_set_by_peer($grade, $participant, $reviewer) {
 142          $participantliteral = behat_context_helper::escape($participant);
 143          $reviewerliteral = behat_context_helper::escape($reviewer);
 144          $gradeliteral = behat_context_helper::escape($grade);
 145          $participantselector = "contains(concat(' ', normalize-space(@class), ' '), ' participant ') ".
 146                  "and contains(.,$participantliteral)";
 147          $trxpath = "//table/tbody/tr[td[$participantselector]]";
 148          $tdparticipantxpath = "//table/tbody/tr/td[$participantselector]";
 149          $tdxpath = "/td[contains(concat(' ', normalize-space(@class), ' '), ' receivedgrade ') and contains(.,$reviewerliteral)]/".
 150                  "descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' grade ') and .=$gradeliteral]";
 151  
 152          $tr = $this->find('xpath', $trxpath);
 153          $rowspan = $this->find('xpath', $tdparticipantxpath)->getAttribute('rowspan');
 154  
 155          $xpath = $trxpath.$tdxpath;
 156          if (!empty($rowspan)) {
 157              for ($i = 1; $i < $rowspan; $i++) {
 158                  $xpath .= ' | '.$trxpath."/following-sibling::tr[$i]".$tdxpath;
 159              }
 160          }
 161          $this->find('xpath', $xpath);
 162      }
 163  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1