X-Git-Url: http://git.moodle.org/gw?p=moodle.git;a=blobdiff_plain;f=grade%2Ftests%2Fbehat%2Fbehat_grade.php;h=5b5ed8159c074a987e96c9b11069218b023b185a;hp=46a7c3f01bc1d8532bd2d8d151e6d0b5a7b1c9d8;hb=12a4770d9bf2201d17f19a29b121c3ee6f153e2a;hpb=d8ee5712988f2c7b667526b9dfc596b6a4113df2 diff --git a/grade/tests/behat/behat_grade.php b/grade/tests/behat/behat_grade.php index 46a7c3f01bc..5b5ed8159c0 100644 --- a/grade/tests/behat/behat_grade.php +++ b/grade/tests/behat/behat_grade.php @@ -79,6 +79,60 @@ class behat_grade extends behat_base { return $steps; } + /** + * Sets a calculated manual grade item. Needs a table with item name - idnumber relation. The step requires you to be in categories and items page. + * + * @Given /^I set "(?P(?:[^"]|\\")*)" calculation for grade item "(?P(?:[^"]|\\")*)" with idnumbers:$/ + * @param string $calculation The calculation. + * @param string $gradeitem The grade item name. + * @param TableNode $TableNode The grade item name - idnumbers relation. + * @return Given[] + */ + public function i_set_calculation_for_grade_item_with_idnumbers($calculation, $gradeitem, TableNode $data) { + + $steps = array(); + $gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem); + + if ($this->running_javascript()) { + $xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]"; + if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { + $steps[] = new Given('I click on "' . $this->escape($xpath) . '" "xpath_element"'); + } + } + + // Going to edit calculation. + $savechanges = get_string('savechanges', 'grades'); + $edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades')); + $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]"; + $steps[] = new Given('I click on "' . $this->escape($linkxpath) . '" "xpath_element"'); + + // After adding id numbers we should wait until the page is reloaded. + $steps[] = new Given('I wait until the page is ready'); + + // Mapping names to idnumbers. + $datahash = $data->getRowsHash(); + foreach ($datahash as $gradeitem => $idnumber) { + // This xpath looks for course, categories and items with the provided name. + // Grrr, we can't equal in categoryitem and courseitem because there is a line jump... + $inputxpath ="//input[@class='idnumber'][" . + "parent::li[@class='item'][text()='" . $gradeitem . "']" . + " | " . + "parent::li[@class='categoryitem' | @class='courseitem']/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" . + "]"; + $steps[] = new Given('I set the field with xpath "' . $inputxpath . '" to "' . $idnumber . '"'); + } + + $steps[] = new Given('I press "' . get_string('addidnumbers', 'grades') . '"'); + + // After adding id numbers we should wait until the page is reloaded. + $steps[] = new Given('I wait until the page is ready'); + + $steps[] = new Given('I set the field "' . get_string('calculation', 'grades') . '" to "' . $calculation . '"'); + $steps[] = new Given('I press "' . $savechanges . '"'); + + return $steps; + } + /** * Resets the weights for the grade category *