Skip to content

Commit

Permalink
Merge branch 'wip-MDL-44258-m25' of git://github.com/marinaglancy/moo…
Browse files Browse the repository at this point in the history
…dle into MOODLE_25_STABLE
  • Loading branch information
danpoltawski committed Mar 5, 2014
2 parents 27a3ba4 + 067c202 commit 12e33d7
Show file tree
Hide file tree
Showing 3 changed files with 427 additions and 0 deletions.
@@ -0,0 +1,114 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Steps definitions related to workshopallocation_manual.
*
* @package workshopallocation_manual
* @category test
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.

require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../../../../../lib/behat/behat_field_manager.php');

use Behat\Behat\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ElementTextException as ElementTextException;

/**
* Steps definitions related to workshopallocation_manual.
*
* @package workshopallocation_manual
* @category test
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_workshopallocation_manual extends behat_base {
/**
* Manually adds a reviewer for workshop participant.
*
* This step should start on manual allocation page.
*
* @When /^I add a reviewer "(?P<reviewer_name_string>(?:[^"]|\\")*)" for workshop participant "(?P<participant_name_string>(?:[^"]|\\")*)"$/
* @param string $reviewername
* @param string $participantname
*/
public function i_add_a_reviewer_for_workshop_participant($reviewername, $participantname) {
$participantnameliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($participantname);
$xpathtd = "//table[contains(concat(' ', normalize-space(@class), ' '), ' allocations ')]/".
"tbody/tr[./td[contains(concat(' ', normalize-space(@class), ' '), ' peer ')]".
"[contains(.,$participantnameliteral)]]/".
"td[contains(concat(' ', normalize-space(@class), ' '), ' reviewedby ')]";
$xpathselect = $xpathtd . "/descendant::select";
try {
$selectnode = $this->find('xpath', $xpathselect);
} catch (Exception $ex) {
$this->find_button(get_string('showallparticipants', 'workshopallocation_manual'))->press();
$selectnode = $this->find('xpath', $xpathselect);
}
$selectid = $selectnode->getAttribute('id');
$selectformfield = behat_field_manager::get_form_field($selectnode, $this->getSession());
$selectformfield->set_value($reviewername);

if (!$this->running_javascript()) {
// Without Javascript we need to press the "Go" button.
$go = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('go'));
$this->find('xpath', $xpathtd."/descendant::input[@value=$go]")->click();
} else {
// With Javascript we just wait for the page to reload and the success string to appear.
$allocatedtext = $this->getSession()->getSelectorsHandler()->xpathLiteral(
get_string('allocationadded', 'workshopallocation_manual'));
$this->find('xpath', "//*[contains(.,$allocatedtext)]");
}
}

/**
* Manually allocates multiple reviewers in workshop.
*
* @When /^I allocate submissions in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
* @param string $workshopname
* @param TableNode $table should have one column with title 'Reviewer' and another with title 'Participant' (or 'Reviewee')
*/
public function i_allocate_submissions_in_workshop_as($workshopname, TableNode $table) {

$this->find_link($workshopname)->click();
$this->find_link(get_string('allocate', 'workshop'))->click();
$rows = $table->getRows();
$reviewer = $participant = null;
for ($i = 0; $i < count($rows[0]); $i++) {
if (strtolower($rows[0][$i]) === 'reviewer') {
$reviewer = $i;
} else if (strtolower($rows[0][$i]) === 'reviewee' || strtolower($rows[0][$i]) === 'participant') {
$participant = $i;
} else {
throw new ElementTextException('Unrecognised column "'.$rows[0][$i].'"', $this->getSession());
}
}
if ($reviewer === null) {
throw new ElementTextException('Column "Reviewer" could not be located', $this->getSession());
}
if ($participant === null) {
throw new ElementTextException('Neither "Participant" nor "Reviewee" column could be located', $this->getSession());
}
for ($i = 1; $i < count($rows); $i++) {
$this->i_add_a_reviewer_for_workshop_participant($rows[$i][$reviewer], $rows[$i][$participant]);
}
}
}
155 changes: 155 additions & 0 deletions mod/workshop/tests/behat/behat_mod_workshop.php
@@ -0,0 +1,155 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Steps definitions related to mod_workshop.
*
* @package mod_workshop
* @category test
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.

require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;

/**
* Steps definitions related to mod_workshop.
*
* @package mod_workshop
* @category test
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_workshop extends behat_base {
/**
* Changes the submission phase for the workshop.
*
* @When /^I change phase in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" to "(?P<phase_name_string>(?:[^"]|\\")*)"$/
* @param string $questiontype
* @param string $workshopname
*/
public function i_change_phase_in_workshop_to($workshopname, $phase) {
$workshopname = $this->escape($workshopname);
$phaseliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($phase);
$switchphase = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('switchphase', 'workshop'));

$xpath = "//*[@class='userplan']/descendant::div[./span[contains(.,$phaseliteral)]]/".
"descendant-or-self::a[./img[@alt=$switchphase]]";
$continue = $this->escape(get_string('continue'));
return array(
new Given("I follow \"$workshopname\""),
new Given("I click on \"$xpath\" \"xpath_element\""),
new Given("I press \"$continue\""),
);
}

/**
* Adds or edits a student workshop submission.
*
* @When /^I add a submission in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
* @param string $workshopname
* @param TableNode $table data to fill the submission form with, must contain 'Title'
*/
public function i_add_a_submission_in_workshop_as($workshopname, $table) {
$workshopname = $this->escape($workshopname);
$savechanges = $this->escape(get_string('savechanges'));
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ownsubmission ')]/descendant::input[@type='submit']";
return array(
new Given("I follow \"$workshopname\""),
new Given("I click on \"$xpath\" \"xpath_element\""),
new Given("I fill the moodle form with:", $table),
new Given("I press \"$savechanges\""),
);
}

/**
* Sets the workshop assessment form.
*
* @When /^I edit assessment form in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
* @param string $workshopname
* @param TableNode $table data to fill the submission form with, must contain 'Title'
*/
public function i_edit_assessment_form_in_workshop_as($workshopname, $table) {
$workshopname = $this->escape($workshopname);
$editassessmentform = $this->escape(get_string('editassessmentform', 'workshop'));
$saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
return array(
new Given("I follow \"$workshopname\""),
new Given("I follow \"$editassessmentform\""),
new Given("I fill the moodle form with:", $table),
new Given("I press \"$saveandclose\""),
);
}

/**
* Peer-assesses a workshop submission.
*
* @When /^I assess submission "(?P<submission_string>(?:[^"]|\\")*)" in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
* @param string $submission
* @param string $workshopname
* @param TableNode $table
*/
public function i_assess_submission_in_workshop_as($submission, $workshopname, TableNode $table) {
$workshopname = $this->escape($workshopname);
$submissionliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($submission);
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' assessment-summary ') ".
"and contains(.,$submissionliteral)]";
$assess = $this->escape(get_string('assess', 'workshop'));
$saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
return array(
new Given("I follow \"$workshopname\""),
new Given("I click on \"$assess\" \"button\" in the \"$xpath\" \"xpath_element\""),
new Given("I fill the moodle form with:", $table),
new Given("I press \"$saveandclose\""),
);
}

/**
* Checks that the user has particular grade set by his reviewing peer in workshop
*
* @Then /^I should see grade "(?P<grade_string>[^"]*)" for workshop participant "(?P<participant_name_string>(?:[^"]|\\")*)" set by peer "(?P<reviewer_name_string>(?:[^"]|\\")*)"$/
* @param string $grade
* @param string $participant
* @param string $reviewer
*/
public function i_should_see_grade_for_workshop_participant_set_by_peer($grade, $participant, $reviewer) {
$participantliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($participant);
$reviewerliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($reviewer);
$gradeliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($grade);
$participantselector = "contains(concat(' ', normalize-space(@class), ' '), ' participant ') ".
"and contains(.,$participantliteral)";
$trxpath = "//table/tbody/tr[td[$participantselector]]";
$tdparticipantxpath = "//table/tbody/tr/td[$participantselector]";
$tdxpath = "/td[contains(concat(' ', normalize-space(@class), ' '), ' receivedgrade ') and contains(.,$reviewerliteral)]/".
"descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' grade ') and .=$gradeliteral]";

$tr = $this->find('xpath', $trxpath);
$rowspan = $this->find('xpath', $tdparticipantxpath)->getAttribute('rowspan');

$xpath = $trxpath.$tdxpath;
if (!empty($rowspan)) {
for ($i = 1; $i < $rowspan; $i++) {
$xpath .= ' | '.$trxpath."/following-sibling::tr[$i]".$tdxpath;
}
}
$this->find('xpath', $xpath);
}
}

0 comments on commit 12e33d7

Please sign in to comment.