Ejemplo n.º 1
0
 /**
  * Create an authenticated user and log in as that user.
  */
 public static function setupBeforeClass()
 {
     self::$options = array('required_fields_only' => FALSE);
     User::logout();
     $userObject = User::createRandom()->verify(get_class());
     self::$userObject = User::login($userObject->getNameValues(), $userObject->getPasswordValues())->verify(get_class());
 }
 public static function tearDownAfterClass()
 {
     User::logout();
     if (static::$deleteCreatedEntities) {
         Utils::deleteCreatedEntities();
     }
 }
Ejemplo n.º 3
0
 /**
  * Create an authenticated user and log in as that user. Create an article.
  */
 public static function setupBeforeClass()
 {
     $userObject = User::loginProgrammatically(1)->verify(get_class());
     self::$articleObject = Article::createRandom()->verify(get_class());
     $userObject->logout();
     $userObject = User::createRandom()->verify(get_class());
     $userObject = User::login($userObject->getNameValues(), $userObject->getPasswordValues())->verify(get_class());
 }
 public static function tearDownAfterClass()
 {
     User::logout();
     if (static::$deleteCreatedEntities) {
         Utils::deleteCreatedEntities();
     }
     if (static::$deleteMailLog && module_exists('redtest_helper_mail_logger')) {
         Mail::delete();
     }
 }
Ejemplo n.º 5
0
 /**
  * Make sure that user is anonymous.
  */
 public static function setupBeforeClass()
 {
     $userObject = User::loginProgrammatically(1)->verify(get_class());
     self::$articleObject = Article::createRandom()->verify(get_class());
     /**
      * @todo ArticleComment::createDefault doesn't work yet. Need to fix it.
      */
     /*list($success, self::$articleCommentObject, $msg) = ArticleComment::createDefault(
         1,
         array('nid' => self::$articleObject->getId())
       );*/
     $articleCommentForm = new ArticleCommentForm(NULL, self::$articleObject->getId());
     $articleCommentForm->verify(get_class());
     $fields = $articleCommentForm->fillRandomValues()->verify(get_class());
     self::$articleCommentObject = $articleCommentForm->submit()->verify(get_class());
     self::$articleCommentObject->checkValues($fields)->verify(get_class());
     User::logout();
 }
Ejemplo n.º 6
0
 /**
  * Fill form with default values. These default values are what you define in
  * this function and are different from Drupal's default values for the
  * 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();
     // @todo Check about field access.
     if ((!$options['required_fields_only'] || $this->isTitleRequired()) && !in_array('title', $options['skip'])) {
         // Check if the field is required. We use '#required' key in form array
         // since it can be set or unset using custom code.
         // Field is not required. There is no need to fill this field.
         // @todo Provide the ability to pass max_length in $options array.
         $response = $this->fillTitleRandomValues();
         if (!$response->getSuccess()) {
             $response->setVar($fields);
             return $response;
         }
         $fields['title'] = $response->getVar();
     }
     // @todo Check in $skip array.
     if ($this->hasFieldAccess(array('options', 'status')) && isset($options['status'])) {
         $status = NULL;
         switch ($options['status']) {
             case 'random':
                 $status = Utils::getRandomBool();
                 break;
             case 'published':
                 $status = 1;
                 break;
             case 'unpublished':
                 $status = 0;
                 break;
         }
         if (!is_null($status)) {
             $response = $this->fillStatusValues($status);
             if (!$response->getSuccess()) {
                 $response->setVar($fields);
                 return $response;
             }
             $fields['status'] = $status;
         }
     }
     // @todo Check in $skip array.
     if ($this->hasFieldAccess(array('revision_information', 'revision')) && isset($options['revision'])) {
         $revision = NULL;
         $revision_log = NULL;
         switch ($options['revision']) {
             case 'random':
                 $revision = Utils::getRandomBool();
                 break;
             case TRUE:
                 $revision = 1;
                 break;
             case FALSE:
                 $revision = 0;
                 break;
         }
         if (!is_null($revision)) {
             $response = $this->fillRevisionValues($revision);
             if (!$response->getSuccess()) {
                 $response->setVar($fields);
                 return $response;
             }
             $fields['revision'] = $revision;
             if ($revision && $this->hasFieldAccess(array('revision_information', 'log')) && isset($options['revision_log'])) {
                 switch ($options['revision_log']) {
                     case 'random':
                         $revision_log = Utils::getRandomBool() ? Utils::getRandomText(25) : NULL;
                         break;
                     case TRUE:
                         $revision_log = Utils::getRandomText(25);
                         break;
                     case FALSE:
                         $revision_log = '';
                         break;
                 }
                 if (!is_null($revision_log)) {
                     $response = $this->fillLogValues($revision_log);
                     if (!$response->getSuccess()) {
                         $response->setVar($fields);
                         return $response;
                     }
                     $fields['log'] = $revision_log;
                 }
             }
         }
     }
     // @todo Check $skip array.
     if ($this->hasFieldAccess(array('author', 'name')) && isset($options['change_author']) && $options['change_author']) {
         // We'll need to create new author first.
         // Masquerade as user 1.
         list($superAdmin, $originalUser, $originalState) = User::masquerade(1);
         $response = User::createRandom();
         // Return to original user.
         User::unmasquerade($originalUser, $originalState);
         if (!$response->getSuccess()) {
             $response->setVar($fields);
             return $response;
         }
         $userObject = $response->getVar();
         $name = $userObject->getNameValues();
         $this->fillNameValues($name);
         $fields['name'] = $name;
     }
     // @todo Check $skip array.
     if ($this->hasFieldAccess(array('author', 'date')) && isset($options['change_published_date']) && $options['change_published_date']) {
         $now = time();
         $start = isset($options['start_published_date']) ? Utils::formatDate($options['start_published_date'], 'integer') : $now - 3 * 365 * 24 * 60 * 60;
         $end = isset($options['end_published_date']) ? Utils::formatDate($options['end_published_date'], 'integer') : $now + 3 * 365 * 24 * 60 * 60;
         $date = Utils::getRandomDate('Y-m-d H:i:s', $start, $end);
         $response = $this->fillDateValues($date);
         if (!$response->getSuccess()) {
             $response->setVar($fields);
             return $response;
         }
         $fields['date'] = $date;
     }
     return new Response(TRUE, $fields, "");
 }
Ejemplo n.º 7
0
 /**
  * Log in as uid 1 and create an article.
  */
 public static function setupBeforeClass()
 {
     $userObject = User::loginProgrammatically(1)->verify(get_class());
     self::$articleObject = Article::createRandom()->verify(get_class());
 }
Ejemplo n.º 8
0
 /**
  * Log the user out. This should not really be needed but just to be sure.
  */
 public static function setUpBeforeClass()
 {
     User::logout();
 }
 /**
  * Create taxonomy terms before a new entity form is invoked.
  *
  * @param Form $formObject
  *   Form object.
  * @param string $field_name
  *   Field name.
  * @param array $options
  *   Options array. "references" key is used here.
  *
  * @return array
  *   An array with two values:
  *   (1) $success: Whether the function executed successfully.
  *   (2) $msg: A message if $success is FALSE.
  */
 public static function processBeforeCreateRandom(Form $formObject, $field_name, &$options)
 {
     $field_info = self::getFieldInfo($field_name);
     $vocabulary = $field_info['settings']['allowed_values'][0]['vocabulary'];
     $cardinality = $field_info['cardinality'];
     $num = 1;
     if ($cardinality == -1) {
         // -1 denotes that cardinality is unlimited.
         $num = 5;
     } else {
         $num = intval($cardinality);
     }
     // Check if $references has these terms already.
     $options += array('references' => array());
     $references =& $options['references'];
     if (isset($references['taxonomy_terms'][$vocabulary])) {
         if (sizeof($references['taxonomy_terms'][$vocabulary]) < $num) {
             $num -= sizeof($references['taxonomy_terms'][$vocabulary]);
         } else {
             $num = 0;
         }
     } else {
         $references['taxonomy_terms'][$vocabulary] = array();
     }
     if ($num) {
         $base_path = "RedTest\\entities\\TaxonomyTerm\\";
         $class = $base_path . Utils::makeTitleCase($vocabulary);
         // Masquerade as user 1 so that there is no access problem.
         list($superUserObject, $userObject, $old_state) = User::masquerade(1);
         $response = $class::createRandom($num);
         if (!$response->getSuccess()) {
             return new Response(FALSE, NULL, "Could not create terms of vocabulary {$vocabulary} attached to {$field_name}: " . $response->getMsg());
         }
         User::unmasquerade($userObject, $old_state);
         $termObjects = $response->getVar();
         if (is_object($termObjects)) {
             $termObjects = array($termObjects);
         }
         $references['taxonomy_terms'][$vocabulary] = array_merge($references['taxonomy_terms'][$vocabulary], $termObjects);
     }
     return new Response(TRUE, NULL, "");
 }
Ejemplo n.º 10
0
 /**
  * Log in as uid 1.
  */
 public static function setupBeforeClass()
 {
     $userObject = User::loginProgrammatically(1)->verify(get_class());
     self::$options = array('required_fields_only' => FALSE);
 }
Ejemplo n.º 11
0
 /**
  * Create an authenticated user and log in as that user.
  */
 public static function setUpBeforeClass()
 {
     $userObject = User::createRandom()->verify(get_class());
     $userObject = User::login($userObject->getNameValues(), $userObject->getPasswordValues())->verify(get_class());
 }
Ejemplo n.º 12
0
 /**
  * Switch the user back to the original user.
  *
  * @param User $original_user_object
  *   Original user object.
  * @param array $old_state
  *   SESSION values of original user.
  */
 public static function unmasquerade(User $original_user_object, $old_state)
 {
     global $user;
     $user = $original_user_object->getEntity();
     drupal_save_session($old_state);
 }
Ejemplo n.º 13
0
 /**
  * Log in as uid 1.
  */
 public static function setUpBeforeClass()
 {
     $userObject = User::loginProgrammatically(1)->verify(get_class());
 }