コード例 #1
0
ファイル: LinkField.php プロジェクト: redcrackle/redtest-core
 /**
  * Fill link 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 default values could be filled in the field.
  *   (2) $values: Values that were filled for the field.
  *   (3) $msg: Message in case there is an error. This will be empty if
  *   $success is TRUE.
  */
 public static function fillRandomValues(Form $formObject, $field_name, $options = array())
 {
     $num = 1;
     $show_url = 0;
     $show_title = 'required';
     $link_target = 'default';
     $show_link_class = 0;
     $show_link_title = 0;
     $title_maxlength = 128;
     if (method_exists($formObject, 'getEntityObject')) {
         // This is an entity form.
         list($field, $instance, $num) = $formObject->getFieldDetails($field_name);
         $show_title = $instance['settings']['title'];
         $show_url = $instance['settings']['url'];
         $title_maxlength = $instance['settings']['title_maxlength'];
         $link_target = $instance['settings']['attributes']['target'];
         $show_link_class = $instance['settings']['attributes']['configurable_class'];
         $show_link_title = $instance['settings']['attributes']['configurable_title'];
     }
     $values = array();
     for ($i = 0; $i < $num; $i++) {
         $value = array();
         if ($show_url !== 'optional' || Utils::getRandomBool()) {
             $value['url'] = Utils::getRandomUrl();
         }
         if ($show_title == 'required' || empty($value['url']) || $show_title == 'optional' && Utils::getRandomBool()) {
             $value['title'] = Utils::getRandomText($title_maxlength);
         }
         if ($link_target == 'user' && Utils::getRandomBool()) {
             $value['attributes']['target'] = '_blank';
         }
         if ($show_link_class) {
             $value['attributes']['class'] = Utils::getRandomString(10);
         }
         if ($show_link_title) {
             $value['attributes']['title'] = Utils::getRandomText(15);
         }
         $values[] = $value;
     }
     $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, "");
 }