Пример #1
0
 /**
  * Gets an instance of the form field from it's label
  *
  * @param string $label
  * @param RawMinkContext $context
  * @return behat_form_field
  */
 public static function get_form_field_from_label($label, RawMinkContext $context)
 {
     // There are moodle form elements that are not directly related with
     // a basic HTML form field, we should also take care of them.
     // The DOM node.
     $fieldnode = $context->find_field($label);
     // The behat field manager.
     return self::get_form_field($fieldnode, $context->getSession());
 }
Пример #2
0
 public static function getJson(RawMinkContext $context)
 {
     $content = $context->getSession()->getPage()->getContent();
     $result = json_decode($content, true);
     if (json_last_error() !== JSON_ERROR_NONE) {
         throw new \Exception('The response is not in JSON');
     }
     return $result;
 }
Пример #3
0
 /**
  * Gets an instance of the form field from it's label
  *
  * @param string $label
  * @param RawMinkContext $context
  * @return behat_form_field
  */
 public static function get_form_field_from_label($label, RawMinkContext $context)
 {
     // There are moodle form elements that are not directly related with
     // a basic HTML form field, we should also take care of them.
     try {
         // The DOM node.
         $fieldnode = $context->find_field($label);
     } catch (ElementNotFoundException $fieldexception) {
         // Looking for labels that points to filemanagers.
         try {
             $fieldnode = $context->find_filemanager($label);
         } catch (ElementNotFoundException $filemanagerexception) {
             // We want the generic 'field' exception.
             throw $fieldexception;
         }
     }
     // The behat field manager.
     return self::get_form_field($fieldnode, $context->getSession());
 }
Пример #4
0
 /**
  * Get page session
  *
  * @param string|null $name
  * @return Session
  */
 public function getSession($name = null)
 {
     return parent::getSession($name);
 }
Пример #5
0
 public function locatePath($path)
 {
     $path = parent::locatePath($path);
     $currentUsername = $this->getMainContext()->getCurrentUserId();
     $userDetails = $this->getStorage()->getUser($currentUsername);
     // in case we need to reference an id in the URL, but don't know the id
     $path = str_replace('{current_user_id}', $userDetails['id'], $path);
     return $path;
 }