コード例 #1
0
ファイル: Email.php プロジェクト: redcrackle/redtest-core
 /**
  * Fill email field with random values.
  *
  * @param Form $formObject
  *   Form object.
  * @param string $field_name
  *   Field name.
  * @param array $options
  *   Options array.
  *
  * @return array
  *   An array with 3 values:
  *   (1) $success: Whether the field could be filled with provided values.
  *   (2) $values: Values that were filled.
  *   (3) $msg: Error message if $success is FALSE and empty otherwise.
  */
 public static function fillRandomValues(Form $formObject, $field_name, $options = array())
 {
     $num = 1;
     if (method_exists($formObject, 'getEntityObject')) {
         // This is an entity form.
         list($field, $instance, $num) = $formObject->getFieldDetails($field_name);
     }
     $values = array();
     for ($i = 0; $i < $num; $i++) {
         $values[] = Utils::getRandomEmail();
     }
     $function = "fill" . Utils::makeTitleCase($field_name) . "Values";
     return $formObject->{$function}($values);
 }
コード例 #2
0
 /**
  * Fills random values in fields.
  *
  * @param array $options
  *   An associative options array. It can have the following keys:
  *   (a) skip: An array of field names which are not to be filled.
  *   (b) required_fields_only: TRUE if only required fields are to be filled
  *   and FALSE if all fields are to be filled.
  *
  * @return Response
  *   Response object.
  */
 public function fillRandomValues($options = array())
 {
     $options += array('skip' => array(), 'required_fields_only' => TRUE);
     $response = parent::fillRandomValues($options);
     if (!$response->getSuccess()) {
         return $response;
     }
     $fields = $response->getVar();
     if (($this->isSubjectRequired() || !$options['required_fields_only']) && $this->hasSubjectAccess()) {
         $response = $this->fillSubjectRandomValues();
         if (!$response->getSuccess()) {
             return new Response(FALSE, $fields, $response->getMsg());
         }
         $fields['subject'] = $response->getVar();
     }
     if ($this->isAuthorSubfieldToBeFilled('name', $options['required_fields_only'])) {
         $response = $this->fillFieldValues(array('author', 'name'), Utils::getRandomText(10));
         if (!$response->getSuccess()) {
             return new Response(FALSE, $fields, $response->getMsg());
         }
         $fields['name'] = $response->getVar();
     }
     if ($this->isAuthorSubfieldToBeFilled('mail', $options['required_fields_only'])) {
         $response = $this->fillFieldValues(array('author', 'mail'), Utils::getRandomEmail());
         if (!$response->getSuccess()) {
             return new Response(FALSE, $fields, $response->getMsg());
         }
         $fields['mail'] = $response->getVar();
     }
     if ($this->isAuthorSubfieldToBeFilled('homepage', $options['required_fields_only'])) {
         $response = $this->fillFieldValues(array('account', 'homepage'), Utils::getRandomUrl());
         if (!$response->getSuccess()) {
             return new Response(FALSE, $fields, $response->getMsg());
         }
         $fields['homepage'] = $response->getVar();
     }
     return new Response(TRUE, $fields, "");
 }