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_string>(?:[^"]|\\")*)" calculation for grade item "(?P<grade_item_string>(?:[^"]|\\")*)" 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
*