예제 #1
0
 /**
  * This function will create Billing profile
  *
  * @param object $order
  *   Order object
  */
 public function createBillingProfileProgrammatically($order)
 {
     $profile_id = $this->getEntity();
     global $user;
     $wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile_id);
     $wrapper->uid = $user->uid;
     $wrapper->commerce_customer_address->country = 'US';
     $wrapper->commerce_customer_address->name_line = Utils::getRandomString();
     $wrapper->commerce_customer_address->organisation_name = Utils::getRandomString();
     $wrapper->commerce_customer_address->administrative_area = 'CA';
     $wrapper->commerce_customer_address->locality = 'Sunnyvale';
     $wrapper->commerce_customer_address->dependent_locality = '';
     $wrapper->commerce_customer_address->postal_code = 94087;
     $wrapper->commerce_customer_address->thoroughfare = "929 E. El Camino Real";
     $wrapper->commerce_customer_address->premise = "Apt. 424";
     $wrapper->commerce_customer_address->phone_number = '(973) 328-6490';
     commerce_customer_profile_save($profile_id);
     return new Response(TRUE, $profile_id, "");
 }
예제 #2
0
 /**
  * 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);
 }
예제 #3
0
 /**
  * Create new users with default field values.
  *
  * @param int $num
  *   Number of entities to create.
  * @param array $options
  *   Options array. This array can have "roles" key that provides an array of
  *   role names that the newly created user will need to be assigned.
  *
  * @return Response
  *   Response object.
  */
 public static function createRandom($num = 1, $options = array())
 {
     $options += array('roles' => array(), 'required_fields_only' => TRUE);
     $output = array();
     for ($i = 0; $i < $num; $i++) {
         // Get a random username.
         do {
             $username = Utils::getRandomString(20);
         } while (!is_null(user_validate_name($username)) || user_load_by_name($username));
         // Get a random email address.
         do {
             $email = $username . '@' . Utils::getRandomString(20) . '.com';
         } while (!is_null(user_validate_mail($email)) || user_load_by_mail($email));
         // Get a random password.
         $password = Utils::getRandomString();
         $response = User::registerUser($username, $email, $password, $options['roles']);
         if (!$response->getSuccess()) {
             $response->setVar($output);
             return $response;
         }
         $output[] = $response->getVar();
     }
     return new Response(TRUE, Utils::normalize($output), "");
 }
예제 #4
0
 /**
  * Saves the file as a temporary managed file.
  *
  * @param array $file_info
  *   An array of information about the file. It should be in the following
  *   format:
  *   array(
  *     'uri' => 'Directory1/Filename1.jpg",
  *     'name' => 'Filename1.jpg', // this is an optional parameter
  *     'description' => 'File description 1', // this is an optional
  *                                            // parameter
  *     'scheme' => 'private', // this is an optional parameter
  *   )
  *
  * @return object
  *   Saved file object.
  */
 protected static function saveFile($file_info)
 {
     $filename = !empty($file_info['name']) ? $file_info['name'] : drupal_basename($file_info['uri']);
     $scheme = !empty($file_info['scheme']) ? $file_info['scheme'] : 'public';
     $file_temp = file_get_contents($file_info['uri']);
     // We add a random string in front of the file name to avoid race condition
     // in file upload with the same name in case we are running multiple
     // concurrent PHPUnit processes.
     $file_temp = file_save_data($file_temp, $scheme . '://' . Utils::getRandomString(20) . '_' . $filename, FILE_EXISTS_RENAME);
     if (!$file_temp) {
         return FALSE;
     }
     // Set file status to temporary otherwise there is validation error.
     $file_temp->status = 0;
     file_save($file_temp);
     return $file_temp;
 }
예제 #5
0
 /**
  * Create new users with default field values.
  *
  * @param int $num
  *   Number of entities to create.
  * @param array $options
  *   Options array. This array can have "roles" key that provides an array of
  *   role names that the newly created user will need to be assigned.
  *
  * @return Response
  *   Response object.
  */
 public static function createRandom($num = 1, $options = array())
 {
     if (!is_numeric($num)) {
         return new Response(FALSE, NULL, 'Number of users to be created has to be an integer.');
     }
     $options += array('roles' => array(), 'required_fields_only' => TRUE);
     // First get the references that need to be created.
     //static::processBeforeCreateRandom($options);
     $output = array();
     for ($i = 0; $i < $num; $i++) {
         // Get a random username.
         do {
             $username = Utils::getRandomString(20);
         } while (!is_null(user_validate_name($username)) || user_load_by_name($username));
         // Get a random email address.
         do {
             $email = $username . '@' . Utils::getRandomString(20) . '.com';
         } while (!is_null(user_validate_mail($email)) || user_load_by_mail($email));
         // Get a random password.
         $password = Utils::getRandomString();
         $response = User::registerUser($username, $email, $password, $options);
         if (!$response->getSuccess()) {
             $response->setVar($output);
             return $response;
         }
         $output[] = $response->getVar();
     }
     return new Response(TRUE, Utils::normalize($output), "");
 }