Пример #1
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), "");
 }
Пример #2
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), "");
 }