Esempio n. 1
0
 /**
  * Use the current user data for filling fields.
  *
  * @example
  * Then I fill "First name" with value of field "First name" of current user
  * And fill "field_last_name[und][0]" with value of field "field_user_last_name" of current user
  *
  * @param string $field
  *   The name of field to fill in. HTML Label, name or ID can be user as selector.
  * @param string $user_field
  *   The name of field from which the data will taken. Drupal label or machine name can be used as selector.
  *
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @throws \Exception
  * @throws NoSuchElement
  *   When field cannot be found.
  *
  * @Then /^(?:I )fill "([^"]*)" with value of field "([^"]*)" of current user$/
  */
 public function fillInWithValueOfFieldOfCurrentUser($field, $user_field)
 {
     if (!empty($this->user) && !$this->user->uid) {
         throw new \Exception('Anonymous user have no fields');
     }
     $entity = new EntityDrupalWrapper('user');
     $wrapper = $entity->wrapper($this->user->uid);
     $user_field = $entity->getFieldNameByLocator($user_field);
     if (empty($wrapper->{$user_field})) {
         throw new \InvalidArgumentException(sprintf('User entity has no "%s" field.', $user_field));
     }
     $value = $wrapper->{$user_field}->value();
     if (empty($value)) {
         throw new \UnexpectedValueException('The value of "%s" field is empty.', $user_field);
     }
     $this->fillField($field, $value);
 }