| Línea 238... |
Línea 238... |
| 238 |
$courseid = $DB->get_field('course', 'id', array('shortname' => $coursename), MUST_EXIST);
|
238 |
$courseid = $DB->get_field('course', 'id', array('shortname' => $coursename), MUST_EXIST);
|
| 239 |
set_config('gradebook_calculations_freeze_' . $courseid, $version);
|
239 |
set_config('gradebook_calculations_freeze_' . $courseid, $version);
|
| 240 |
}
|
240 |
}
|
| Línea 241... |
Línea 241... |
| 241 |
|
241 |
|
| 242 |
/**
|
- |
|
| 243 |
* Select the tab in the gradebook. We must be on one of the gradebook pages already.
|
- |
|
| 244 |
*
|
242 |
/**
|
| 245 |
* @deprecated since 4.0 - use behat_forms::i_set_the_field_to() instead.
|
- |
|
| 246 |
* @param string $gradepath examples: "View > User report", "Letters > View", "Scales"
|
243 |
* @deprecated since 4.0 - use behat_forms::i_set_the_field_to() instead.
|
| 247 |
*/
|
- |
|
| 248 |
protected function select_in_gradebook_tabs($gradepath) {
|
- |
|
| 249 |
debugging('The function select_in_gradebook_tabs() is deprecated, please use ' .
|
244 |
*/
|
| 250 |
'behat_forms::i_set_the_field_to() instead.', DEBUG_DEVELOPER);
|
- |
|
| 251 |
|
- |
|
| 252 |
$gradepath = preg_split('/\s*>\s*/', trim($gradepath));
|
245 |
#[\core\attribute\deprecated('behat_forms::i_set_the_field_to', since: '4.0', final: true)]
|
| 253 |
if (count($gradepath) > 2) {
|
- |
|
| 254 |
throw new coding_exception('Grade path is too long (must have no more than two items separated with ">")');
|
- |
|
| 255 |
}
|
- |
|
| 256 |
|
- |
|
| 257 |
$xpath = '//div[contains(@class,\'grade-navigation\')]';
|
- |
|
| 258 |
|
- |
|
| 259 |
// If the first row of the grade-navigation tabs does not have $gradepath[0] as active tab, click on it.
|
- |
|
| 260 |
$link = '\'' . $this->escape($gradepath[0]) . '\'';
|
- |
|
| 261 |
$xpathrow1 = $xpath . '//ul[1]//*[contains(@class,\'active\') and contains(normalize-space(.), ' . $link . ')]';
|
246 |
protected function select_in_gradebook_tabs() {
|
| 262 |
if (!$this->getSession()->getPage()->findAll('xpath', $xpathrow1)) {
|
- |
|
| 263 |
$this->find('xpath', $xpath . '//ul[1]/li/a[text()=' . $link . ']')->click();
|
- |
|
| 264 |
$this->wait_for_pending_js();
|
- |
|
| 265 |
}
|
- |
|
| 266 |
|
- |
|
| 267 |
if (isset($gradepath[1])) {
|
- |
|
| 268 |
// If the second row of the grade-navigation tabs does not have $gradepath[1] as active tab, click on it.
|
- |
|
| 269 |
$link = '\'' . $this->escape($gradepath[1]) . '\'';
|
- |
|
| 270 |
$xpathrow2 = $xpath . '//ul[2]//*[contains(@class,\'active\') and contains(normalize-space(.), ' . $link . ')]';
|
- |
|
| 271 |
if (!$this->getSession()->getPage()->findAll('xpath', $xpathrow2)) {
|
- |
|
| 272 |
$this->find('xpath', $xpath . '//ul[2]/li/a[text()=' . $link . ']')->click();
|
- |
|
| 273 |
$this->wait_for_pending_js();
|
- |
|
| 274 |
}
|
- |
|
| 275 |
}
|
247 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
| Línea 276... |
Línea 248... |
| 276 |
}
|
248 |
}
|
| 277 |
|
249 |
|
| 278 |
/**
|
250 |
/**
|
| Línea 329... |
Línea 301... |
| 329 |
$this->i_navigate_to_in_the_course_gradebook("More > Export");
|
301 |
$this->i_navigate_to_in_the_course_gradebook("More > Export");
|
| 330 |
$this->execute('behat_forms::i_set_the_field_to', [get_string('exportas', 'grades'), $gradeexportoption]);
|
302 |
$this->execute('behat_forms::i_set_the_field_to', [get_string('exportas', 'grades'), $gradeexportoption]);
|
| 331 |
}
|
303 |
}
|
| Línea 332... |
Línea 304... |
| 332 |
|
304 |
|
| 333 |
/**
|
- |
|
| 334 |
* Select a given option from a navigation URL selector in the gradebook. We must be on one of the gradebook pages
|
- |
|
| 335 |
* already.
|
- |
|
| 336 |
*
|
305 |
/**
|
| 337 |
* @deprecated since 4.1 - use behat_forms::i_set_the_field_to() instead.
|
- |
|
| 338 |
* @param string $path The string path that is used to identify an item within the navigation selector. If the path
|
- |
|
| 339 |
* has two items (ex. "More > Grade letters"), the first item ("More") will be used to identify
|
- |
|
| 340 |
* an option group in the navigation selector, while the second ("Grade letters") will be used to
|
- |
|
| 341 |
* identify an option within that option group. Otherwise, a single item in a path (ex. "Scales")
|
- |
|
| 342 |
* will be used to identify an option in the navigation selector regardless of the option group.
|
- |
|
| 343 |
* @param string $formid The ID of the form element which contains the navigation URL selector element.
|
- |
|
| 344 |
*/
|
- |
|
| 345 |
protected function select_in_gradebook_navigation_selector(string $path, string $formid) {
|
- |
|
| 346 |
debugging('The function select_in_gradebook_navigation_selector() is deprecated, please use ' .
|
- |
|
| 347 |
'behat_forms::i_set_the_field_to() instead.', DEBUG_DEVELOPER);
|
- |
|
| 348 |
|
- |
|
| 349 |
// Split the path string by ">".
|
- |
|
| 350 |
$path = preg_split('/\s*>\s*/', trim($path));
|
- |
|
| 351 |
|
- |
|
| 352 |
// Make sure that the path does not have more than two items separated with ">".
|
- |
|
| 353 |
if (count($path) > 2) {
|
- |
|
| 354 |
throw new coding_exception('The path is too long (must have no more than two items separated with ">")');
|
- |
|
| 355 |
}
|
- |
|
| 356 |
|
- |
|
| 357 |
// Get the select element.
|
- |
|
| 358 |
$selectxpath = "//form[contains(@id,'{$formid}')]//select";
|
- |
|
| 359 |
$select = $this->find('xpath', $selectxpath);
|
- |
|
| 360 |
|
- |
|
| 361 |
// Define the xpath to the option element depending on the provided path.
|
- |
|
| 362 |
// If two items are provided in the path, the first item will be considered as an identifier of an existing
|
- |
|
| 363 |
// option group in the select select element, while the second item will identify an existing option within
|
- |
|
| 364 |
// that option group.
|
- |
|
| 365 |
// If one item is provided in the path, this item will identify any existing option in the select element
|
- |
|
| 366 |
// regardless of the option group. Also, this is useful when option elements are not a part of an option group
|
- |
|
| 367 |
// which is possible.
|
- |
|
| 368 |
if (count($path) === 2) {
|
- |
|
| 369 |
$optionxpath = $selectxpath . '/optgroup[@label="' . $this->escape($path[0]) . '"]' .
|
- |
|
| 370 |
'/option[contains(.,"' . $this->escape($path[1]) . '")]';
|
- |
|
| 371 |
} else {
|
- |
|
| 372 |
$optionxpath = $selectxpath . '//option[contains(.,"' . $this->escape($path[0]) . '")]';
|
- |
|
| 373 |
}
|
- |
|
| 374 |
|
- |
|
| 375 |
// Get the option element that we are looking to select.
|
- |
|
| 376 |
$option = $this->find('xpath', $optionxpath);
|
- |
|
| 377 |
|
- |
|
| 378 |
// Select the given option in the select element.
|
- |
|
| 379 |
$field = behat_field_manager::get_field_instance('select', $select, $this->getSession());
|
- |
|
| 380 |
$field->set_value($this->escape($option->getValue()));
|
- |
|
| 381 |
|
- |
|
| 382 |
if (!$this->running_javascript()) {
|
- |
|
| 383 |
$this->execute('behat_general::i_click_on_in_the', [get_string('go'), 'button',
|
- |
|
| 384 |
"#{$formid}", 'css_element']);
|
- |
|
| 385 |
}
|
- |
|
| 386 |
}
|
- |
|
| 387 |
|
- |
|
| 388 |
/**
|
- |
|
| 389 |
* We tend to use this series of steps a bit so define em once.
|
- |
|
| 390 |
*
|
- |
|
| 391 |
* @param string $haystack What are we searching within?
|
- |
|
| 392 |
* @param string $needle What are we looking for?
|
- |
|
| 393 |
* @param bool $fieldset Do we want to set the search field at the same time?
|
- |
|
| 394 |
* @return string
|
- |
|
| 395 |
* @throws coding_exception
|
- |
|
| 396 |
*/
|
- |
|
| 397 |
private function get_dropdown_selector(string $haystack, string $needle, bool $fieldset = true): string {
|
- |
|
| 398 |
$this->execute("behat_general::wait_until_the_page_is_ready");
|
- |
|
| 399 |
|
- |
|
| 400 |
// Set the default field to search and handle any special preamble.
|
- |
|
| 401 |
$string = get_string('searchusers', 'core');
|
- |
|
| 402 |
$selector = '.usersearchdropdown';
|
- |
|
| 403 |
if (strtolower($haystack) === 'group') {
|
- |
|
| 404 |
$string = get_string('searchgroups', 'core');
|
- |
|
| 405 |
$selector = '.groupsearchdropdown';
|
- |
|
| 406 |
$trigger = ".groupsearchwidget";
|
- |
|
| 407 |
$node = $this->find("css_element", $selector);
|
- |
|
| 408 |
if (!$node->isVisible()) {
|
- |
|
| 409 |
$this->execute("behat_general::i_click_on", [$trigger, "css_element"]);
|
- |
|
| 410 |
}
|
- |
|
| 411 |
} else if (strtolower($haystack) === 'grade') {
|
- |
|
| 412 |
$string = get_string('searchitems', 'core');
|
- |
|
| 413 |
$selector = '.gradesearchdropdown';
|
- |
|
| 414 |
$trigger = ".gradesearchwidget";
|
- |
|
| 415 |
$node = $this->find("css_element", $selector);
|
- |
|
| 416 |
if (!$node->isVisible()) {
|
- |
|
| 417 |
$this->execute("behat_general::i_click_on", [$trigger, "css_element"]);
|
- |
|
| 418 |
}
|
- |
|
| 419 |
}
|
- |
|
| 420 |
|
- |
|
| 421 |
if ($fieldset) {
|
- |
|
| 422 |
$this->execute("behat_forms::set_field_value", [$string, $needle]);
|
- |
|
| 423 |
$this->execute("behat_general::wait_until_exists", [$needle, "list_item"]);
|
- |
|
| 424 |
}
|
- |
|
| 425 |
return $selector;
|
- |
|
| 426 |
}
|
- |
|
| 427 |
|
- |
|
| 428 |
/**
|
- |
|
| 429 |
* Confirm if a value is within the search widget within the gradebook.
|
- |
|
| 430 |
*
|
- |
|
| 431 |
* Examples:
|
- |
|
| 432 |
* - I confirm "User" in "user" search within the gradebook widget exists
|
- |
|
| 433 |
* - I confirm "Group" in "group" search within the gradebook widget exists
|
- |
|
| 434 |
* - I confirm "Grade item" in "grade" search within the gradebook widget exists
|
- |
|
| 435 |
*
|
- |
|
| 436 |
* @Given /^I confirm "(?P<needle>(?:[^"]|\\")*)" in "(?P<haystack>(?:[^"]|\\")*)" search within the gradebook widget exists$/
|
- |
|
| 437 |
* @param string $needle The value to search for.
|
- |
|
| 438 |
* @param string $haystack The type of the search widget.
|
- |
|
| 439 |
*/
|
- |
|
| 440 |
public function i_confirm_in_search_within_the_gradebook_widget_exists($needle, $haystack) {
|
- |
|
| 441 |
$this->execute("behat_general::assert_element_contains_text",
|
- |
|
| 442 |
[$needle, $this->get_dropdown_selector($haystack, $needle, false), "css_element"]);
|
- |
|
| 443 |
}
|
- |
|
| 444 |
|
- |
|
| 445 |
/**
|
- |
|
| 446 |
* Confirm if a value is not within the search widget within the gradebook.
|
- |
|
| 447 |
*
|
- |
|
| 448 |
* Examples:
|
- |
|
| 449 |
* - I confirm "User" in "user" search within the gradebook widget does not exist
|
- |
|
| 450 |
* - I confirm "Group" in "group" search within the gradebook widget does not exist
|
- |
|
| 451 |
* - I confirm "Grade item" in "grade" search within the gradebook widget does not exist
|
- |
|
| 452 |
*
|
- |
|
| 453 |
* @Given /^I confirm "(?P<needle>(?:[^"]|\\")*)" in "(?P<haystack>(?:[^"]|\\")*)" search within the gradebook widget does not exist$/
|
- |
|
| 454 |
* @param string $needle The value to search for.
|
- |
|
| 455 |
* @param string $haystack The type of the search widget.
|
- |
|
| 456 |
*/
|
- |
|
| 457 |
public function i_confirm_in_search_within_the_gradebook_widget_does_not_exist($needle, $haystack) {
|
- |
|
| 458 |
$this->execute("behat_general::assert_element_not_contains_text",
|
- |
|
| 459 |
[$needle, $this->get_dropdown_selector($haystack, $needle, false), "css_element"]);
|
- |
|
| 460 |
}
|
- |
|
| 461 |
|
- |
|
| 462 |
/**
|
- |
|
| 463 |
* Clicks on an option from the specified search widget in the current gradebook page.
|
- |
|
| 464 |
*
|
- |
|
| 465 |
* Examples:
|
- |
|
| 466 |
* - I click on "Student" in the "user" search widget
|
- |
|
| 467 |
* - I click on "Group" in the "group" search widget
|
- |
|
| 468 |
* - I click on "Grade item" in the "grade" search widget
|
- |
|
| 469 |
*
|
- |
|
| 470 |
* @Given /^I click on "(?P<needle>(?:[^"]|\\")*)" in the "(?P<haystack>(?:[^"]|\\")*)" search widget$/
|
- |
|
| 471 |
* @param string $needle The value to search for.
|
- |
|
| 472 |
* @param string $haystack The type of the search widget.
|
306 |
* @deprecated since 4.1 - use behat_forms::i_set_the_field_to() instead.
|
| 473 |
*/
|
307 |
*/
|
| 474 |
public function i_click_on_in_search_widget(string $needle, string $haystack) {
|
- |
|
| 475 |
$selector = $this->get_dropdown_selector($haystack, $needle);
|
308 |
#[\core\attribute\deprecated('behat_forms::i_set_the_field_to', since: '4.1', final: true)]
|
| 476 |
$this->execute('behat_general::i_click_on_in_the', [
|
- |
|
| 477 |
$needle, "list_item",
|
- |
|
| 478 |
$selector, "css_element"
|
- |
|
| 479 |
]);
|
309 |
protected function select_in_gradebook_navigation_selector() {
|
| 480 |
$this->execute("behat_general::i_wait_to_be_redirected");
|
310 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
| 481 |
}
|
311 |
}
|