/**
  * Given a field locator, appends a value to it.
  *
  * @Given /^I append to "([^"]*)" "([^"]*)"$/
  */
 public function i_append_to($fieldlocator, $value)
 {
     $field = behat_field_manager::get_form_field_from_label($fieldlocator, $this);
     $configuration = $field->get_value();
     $configuration .= "\n" . $value;
     $field->set_value($configuration);
 }
Exemple #2
0
 /**
  * Select the text in an Atto field.
  *
  * @Given /^I select the text in the "([^"]*)" Atto editor$/
  * @throws ElementNotFoundException Thrown by behat_base::find
  * @param string $field
  * @return void
  */
 public function select_the_text_in_the_atto_editor($fieldlocator)
 {
     if (!$this->running_javascript()) {
         throw new coding_exception('Selecting text requires javascript.');
     }
     // We delegate to behat_form_field class, it will
     // guess the type properly.
     $field = behat_field_manager::get_form_field_from_label($fieldlocator, $this);
     if (!method_exists($field, 'select_text')) {
         throw new coding_exception('Field does not support the select_text function.');
     }
     $field->select_text();
 }
 protected function upload_file_to_filemanager($filepath, $filemanagerelement, TableNode $data, $overwriteaction = false)
 {
     global $CFG;
     $filemanagernode = $this->get_filepicker_node($filemanagerelement);
     // Opening the select repository window and selecting the upload repository.
     $this->open_add_file_window($filemanagernode, get_string('pluginname', 'repository_upload'));
     // Ensure all the form is ready.
     $noformexception = new ExpectationException('The upload file form is not ready', $this->getSession());
     $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' file-picker ')]" . "[contains(concat(' ', normalize-space(@class), ' '), ' repository_upload ')]" . "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]" . "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-upload-form ')]" . "/descendant::form", $noformexception);
     // After this we have the elements we want to interact with.
     // Form elements to interact with.
     $file = $this->find_file('repo_upload_file');
     // Attaching specified file to the node.
     // Replace 'admin/' if it is in start of path with $CFG->admin .
     if (substr($filepath, 0, 6) === 'admin/') {
         $filepath = $CFG->dirroot . DIRECTORY_SEPARATOR . $CFG->admin . DIRECTORY_SEPARATOR . substr($filepath, 6);
     }
     $filepath = str_replace('/', DIRECTORY_SEPARATOR, $filepath);
     if (!is_readable($filepath)) {
         $filepath = $CFG->dirroot . DIRECTORY_SEPARATOR . $filepath;
         if (!is_readable($filepath)) {
             throw new ExpectationException('The file to be uploaded does not exist.', $this->getSession());
         }
     }
     $file->attachFile($filepath);
     // Fill the form in Upload window.
     $datahash = $data->getRowsHash();
     // The action depends on the field type.
     foreach ($datahash as $locator => $value) {
         $field = behat_field_manager::get_form_field_from_label($locator, $this);
         // Delegates to the field class.
         $field->set_value($value);
     }
     // Submit the file.
     $submit = $this->find_button(get_string('upload', 'repository'));
     $submit->press();
     // We wait for all the JS to finish as it is performing an action.
     $this->getSession()->wait(self::TIMEOUT, self::PAGE_READY_JS);
     if ($overwriteaction !== false) {
         $overwritebutton = $this->find_button($overwriteaction);
         $this->ensure_node_is_visible($overwritebutton);
         $overwritebutton->click();
         // We wait for all the JS to finish.
         $this->getSession()->wait(self::TIMEOUT, self::PAGE_READY_JS);
     }
 }
 /**
  * Picks the file from private files repository
  *
  * @throws ExpectationException Thrown by behat_base::find
  * @param string $filepath
  * @param string $repository
  * @param string $filemanagerelement
  * @param TableNode $data Data to fill the form in Select file dialogue
  * @param false|string $overwriteaction false if we don't expect that file with the same name already exists,
  *     or button text in overwrite dialogue ("Overwrite", "Rename to ...", "Cancel")
  */
 protected function add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, TableNode $data, $overwriteaction = false)
 {
     $filemanagernode = $this->get_filepicker_node($filemanagerelement);
     // Opening the select repository window and selecting the upload repository.
     $this->open_add_file_window($filemanagernode, $repository);
     $this->open_element_contextual_menu($filepath);
     // Fill the form in Select window.
     $datahash = $data->getRowsHash();
     // The action depends on the field type.
     foreach ($datahash as $locator => $value) {
         $field = behat_field_manager::get_form_field_from_label($locator, $this);
         // Delegates to the field class.
         $field->set_value($value);
     }
     $this->find_button(get_string('getfile', 'repository'))->click();
     // We wait for all the JS to finish as it is performing an action.
     $this->getSession()->wait(self::TIMEOUT, self::PAGE_READY_JS);
     if ($overwriteaction !== false) {
         $overwritebutton = $this->find_button($overwriteaction);
         $this->ensure_node_is_visible($overwritebutton);
         $overwritebutton->click();
         // We wait for all the JS to finish.
         $this->getSession()->wait(self::TIMEOUT, self::PAGE_READY_JS);
     }
 }
Exemple #5
0
 /**
  * Generic field setter.
  *
  * Internal API method, a generic *I set "VALUE" to "FIELD" field*
  * could be created based on it.
  *
  * @param string $fieldlocator The pointer to the field, it will depend on the field type.
  * @param string $value
  * @return void
  */
 protected function set_field_value($fieldlocator, $value)
 {
     // We delegate to behat_form_field class, it will
     // guess the type properly as it is a select tag.
     $field = behat_field_manager::get_form_field_from_label($fieldlocator, $this);
     $field->set_value($value);
 }
Exemple #6
0
 /**
  * Tries to fill the current page form elements with the provided options.
  *
  * This step is slow as it spins over each provided option, we are
  * not expected to have lots of provided options, anyways, is better
  * to be conservative and wait for the elements to appear rather than
  * to have false failures.
  *
  * @param TableNode $options The backup and restore options or false if no options provided
  * @return void
  */
 protected function fill_backup_restore_form($options)
 {
     // Nothing to fill if no options are provided.
     if (!$options) {
         return;
     }
     // If we find any of the provided options in the current form we should set the value.
     $datahash = $options->getRowsHash();
     foreach ($datahash as $locator => $value) {
         $field = behat_field_manager::get_form_field_from_label($locator, $this);
         $field->set_value($value);
     }
 }
 /**
  * Tries to fill the current page form elements with the provided options.
  *
  * This step is slow as it spins over each provided option, we are
  * not expected to have lots of provided options, anyways, is better
  * to be conservative and wait for the elements to appear rather than
  * to have false failures.
  *
  * @param TableNode $options The backup and restore options or false if no options provided
  * @return void
  */
 protected function fill_backup_restore_form($options)
 {
     // Nothing to fill if no options are provided.
     if (!$options) {
         return;
     }
     // If we find any of the provided options in the current form we should set the value.
     $datahash = $options->getRowsHash();
     foreach ($datahash as $locator => $value) {
         try {
             $field = behat_field_manager::get_form_field_from_label($locator, $this);
             $field->set_value($value);
         } catch (ElementNotFoundException $e) {
             // Next provided option then, this one should be part of another page's fields.
         }
     }
 }