You are here

class ClassifiedTestTestBasicTest in Classified Ads 7.3

Basic test for known bugs in previous versions.

Hierarchy

Expanded class hierarchy of ClassifiedTestTestBasicTest

File

tests/classified_test_basic.test, line 16

View source
class ClassifiedTestTestBasicTest extends ClassifiedTestAbstractTest {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => t('Classified'),
      'description' => t('Basic tests for Classified.'),
      'group' => t('Classified'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $this->group = __FUNCTION__;
    parent::setUp('field', 'taxonomy', 'statistics', 'classified', 'classified_test');
  }

  /**
   * Bug 123396: Unchecking Publish doesn't prevent nodes from being published.
   *
   * Also catches bug 143680: Expiration date by term is not correctly applied.
   *
   * Goes much further by testing the expiration dates resulting from all
   * creation and updating scenarios. Already done:
   * - creation, default,
   * - creation, default with explicit lifetime,
   * - creation, forced.
   */
  public function test0123396And0143680() {
    $this->group = __FUNCTION__;

    // Include seconds in date comparison displays.
    $format = 'Y-m-d H:i:s';

    // 1. Get the Classified vocabulary id and field name.
    $vid = _classified_get('vid');
    $category_field_name = _classified_get('field-category');

    // 2a. Create a term in it, do not assign a specific lifetime.
    $term = (object) array(
      'name' => $this
        ->randomName(8),
      'description' => $this
        ->randomString(20),
      'vid' => $vid,
    );
    $status = taxonomy_term_save($term);
    $tid = $term->tid;
    $this
      ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
      '@tid' => $tid,
    )), 'setup');

    // 2b. Create a node bearing that term.
    $this->group = t('new, default');
    $node = $this
      ->createNode(array(
      $category_field_name => array(
        LANGUAGE_NONE => array(
          0 => array(
            'tid' => $tid,
          ),
        ),
      ),
    ));
    $this
      ->assertTrue(isset($node->expires) && is_numeric($node->expires), t('node has an expires timestamp'), $this->group);

    // 2c. Make sure it uses the default taxonomy-derived lifetime.
    $lifetimes = _classified_get('lifetimes');
    $lifetime = isset($lifetimes[$tid]) ? $lifetimes[$tid] : reset($lifetimes);
    $expected_expires = $node->created + $lifetime * 60 * 60 * 24;
    $this
      ->assertEqual($node->expires, $expected_expires, t('Node expire date %actual matches expected date: %expected', array(
      '%actual' => format_date($node->expires, 'custom', $format),
      '%expected' => format_date($expected_expires, 'custom', $format),
    )), $this->group);

    // 3a. Assign a specific lifetime to term.
    $this->group = t('new, reset');
    $lifetimes[$tid] = $random = mt_rand(0, 90);
    variable_set('classified-lifetimes', $lifetimes);
    $lifetimes = _classified_get('lifetimes');
    $lifetime = isset($lifetimes[$tid]) ? $lifetimes[$tid] : reset($lifetimes);
    $this
      ->assertEqual($random, $lifetime, t('Lifetime correctly set to @random = @lifetime', array(
      '@random' => $random,
      '@lifetime' => $lifetime,
    )), $this->group);

    // 3b. Create a node bearing that term, now with a specific lifetime.
    $node = $this
      ->createNode(array(
      $category_field_name => array(
        LANGUAGE_NONE => array(
          0 => array(
            'tid' => $tid,
          ),
        ),
      ),
      'expire_mode' => 'reset',
    ));
    $this
      ->assertTrue(isset($node->expires) && is_numeric($node->expires), t('node has an expires timestamp'), $this->group);

    // 3c. Make sure it uses the explicit taxonomy-derived lifetime.
    $expected_expires = $node->created + $lifetime * 60 * 60 * 24;
    $this
      ->assertEqual($node->expires, $expected_expires, t('Node expire date %actual matches expected date: %expected', array(
      '%actual' => format_date($node->expires, 'custom', $format),
      '%expected' => format_date($expected_expires, 'custom', $format),
    )), $this->group);

    // 4a. Create a node bearing that term, but use force mode.
    $this->group = t('new, force');
    $expected_expires = REQUEST_TIME + mt_rand(0, 90 * 24 * 60 * 60);
    $this
      ->pass(t('Limit set to @date', array(
      '@date' => format_date($expected_expires, 'custom', $format),
    )), $this->group);
    $node = $this
      ->createNode(array(
      $category_field_name => array(
        LANGUAGE_NONE => array(
          0 => array(
            'tid' => $tid,
          ),
        ),
      ),
      'expire_mode' => 'force',
      'expire_date_ts' => $expected_expires,
    ));
    $this
      ->assertTrue(isset($node->expires) && is_numeric($node->expires), t('node has an expires timestamp'), $this->group);

    // 4b. Make sure it uses the explicit taxonomy-derived lifetime.
    $this
      ->assertEqual($node->expires, $expected_expires, t('Node expire date %actual matches expected date: %expected', array(
      '%actual' => format_date($node->expires, 'custom', $format),
      '%expected' => format_date($expected_expires, 'custom', $format),
    )), $this->group);
  }

  /**
   * Bug 547214: view Ads tab for users without permission.
   */
  public function test0547214() {
    $this->group = __FUNCTION__;
    $accounts = array(
      'admin',
      'basic',
      'creator',
    );
    $this
      ->createUsers($accounts);
    foreach ($accounts as $account_name) {
      $this
        ->drupalLogin($this->{$account_name . 'User'});
      $this
        ->assertLink(t('Ads'), 0, t('User %name (@uid) sees "Ads" tab on his own account page', array(
        '%name' => $account_name,
        '@uid' => $this->{$account_name . 'User'}->uid,
      )), 'Ads Tab');
      $this
        ->drupalGet('user/' . $this->adminUser->uid);
      if ($account_name == 'creator') {
        $this
          ->assertLink(t('Ads'), 0, t('User %name sees "Ads" tab on other account pages', array(
          '%name' => $account_name,
        )), 'Ads Tab');
      }
      elseif ($account_name == 'basic') {
        $this
          ->assertNoLink(t('Ads'), t('User %name does not see "Ads" tab on other account pages', array(
          '%name' => $account_name,
        )), 'Ads Tab');
      }

      // No else: admin seeing admin has already been tested.
      $this
        ->drupalLogout();
    }
  }

  /**
   * Bug 1244300: Anonymous user unable to post regardless of permission grants.
   */
  public function test1244300() {
    $this->group = __FUNCTION__;
    $this
      ->assertFalse(in_array('create classified ad content', array_keys(module_invoke_all('permission'))), t('D6-style node creation permission is not valid'), $this->group);
    $permissions = array(
      'create classified content',
    );
    $this
      ->assertTrue($this
      ->checkPermissions($permissions, TRUE), t('D7-style node creation permission is valid'), $this->group);
    user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, $permissions);
    $this
      ->drupalGet('node/add/classified');
    $this
      ->assertResponse(403, t('Anonymous user without %permissions may not access the ad creation form', array(
      '%permissions' => implode(', ', $permissions),
    )), $this->group);
    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, $permissions);

    // Use:
    // debug(user_role_permissions(array(DRUPAL_ANONYMOUS_RID => NULL)));
    // when needing to check the grant results.
    $this
      ->drupalGet('node/add/classified');
    $this
      ->assertResponse(200, t('Anonymous user with %permissions may access the ad creation form', array(
      '%permissions' => implode(', ', $permissions),
    )), $this->group);
  }

  /**
   * Convert a host-relative path like /drupal/taxonomy to a drupal path.
   *
   * @param string $href
   *   Some path like "/drupal/taxonomy" or "/taxonomy".
   *
   * @return string
   *   The internal still aliased path like "taxonomy", or "/" if path does not
   *   belong in the current site.
   *
   * @see test1265524()
   */
  protected function relativizeHref($href) {
    $base = base_path();
    if (strpos($href, $base) === 0) {
      $ret = drupal_substr($href, drupal_strlen($base));
    }
    else {
      $ret = '/';
    }
    return $ret;
  }

  /**
   * Bug 1265524: Can not edit taxonomy terms.
   *
   * Regex in hook_url_outbound_alter() was too lax.
   */
  public function test1265524() {
    $this->group = __FUNCTION__;
    $this
      ->createUsers(array(
      'admin',
    ));
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet('admin/structure/taxonomy/classified_categories');
    $links = $this
      ->xpath('//a[normalize-space(text())=:label]', array(
      ':label' => t('edit'),
    ));

    // 2 categories created on install.
    $this
      ->assert(count($links) == 2, t('Found 2 "edit" links'), $this->group);
    $pattern = 'taxonomy/term/*/edit';
    foreach ($links as $link) {
      $href = (string) $link['href'];
      $href = $this
        ->relativizeHref($href);
      $parsed = drupal_parse_url($href);
      $path = $parsed['path'];
      $this
        ->assertTrue(drupal_match_path($path, $pattern), t('Path %path matches %pattern', array(
        '%path' => $path,
        '%pattern' => $pattern,
      )), $this->group);
    }
  }

  /**
   * Bug 1287674.
   *
   * Node title and categories are doubly escaped in recent/popular blocks.
   */
  public function test1287674() {
    $this->group = __FUNCTION__;
    $this
      ->createUsers(array(
      'admin',
    ));
    $this
      ->pass(t('Enable "count content views".'), $this->group);
    variable_set('statistics_count_content_views', 1);
    $deltas = array(
      'popular',
      'recent',
    );
    $this
      ->drupalLogin($this->adminUser);
    foreach ($deltas as $delta) {
      $block = array();
      $block['module'] = 'classified';
      $block['delta'] = $delta;

      // Set the created block to a specific region.
      $edit = array();
      $edit['blocks[' . $block['module'] . '_' . $block['delta'] . '][region]'] = 'sidebar_first';
      $this
        ->drupalPost('admin/structure/block', $edit, t('Save blocks'));
    }
    $this
      ->pass('Classified blocks enabled', $this->group);

    // Get the Classified vocabulary id and field name.
    $vid = _classified_get('vid');
    $category_field_name = _classified_get('field-category');

    // Create a term in it, do not assign a specific lifetime.
    $term_name = $this
      ->randomName(4) . " ' " . $this
      ->randomName(4);
    $term = (object) array(
      'name' => $term_name,
      'description' => $this
        ->randomString(20),
      'vid' => $vid,
    );
    $status = taxonomy_term_save($term);
    $tid = $term->tid;
    $this
      ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
      '@tid' => $tid,
    )), 'setup');

    // Create a node bearing that term.
    $quoted_title = $this
      ->randomName(4) . " ' " . $this
      ->randomName(4);
    $node = $this
      ->createNode(array(
      $category_field_name => array(
        LANGUAGE_NONE => array(
          0 => array(
            'tid' => $tid,
          ),
        ),
      ),
      'title' => $quoted_title,
    ));
    $this
      ->drupalGet('node/' . $node->nid);
    foreach ($deltas as $delta) {
      $content = $this
        ->xpath("//*[@id='block-classified-{$delta}']/*[@class='content']/descendant::a[@href]");

      // SimpleXMLElement.
      $content = reset($content);
      $this
        ->assertNotIdentical(FALSE, strpos($content, $quoted_title), t('Title found in @delta block', array(
        '@delta' => $delta,
      )), $this->group);
      $this
        ->assertNotIdentical(FALSE, strpos($content, $term_name), t('Term found in @delta block', array(
        '@delta' => $delta,
      )), $this->group);
    }

    // Extra test disabled at this stage.
    if (FALSE) {
      $pattern = implode(array(
        '/',
        t('Recent ads'),
        '.*',
        htmlentities($quoted_title, ENT_QUOTES),
        ' \\(',
        htmlentities($term_name, ENT_QUOTES),
        '\\).*',
        t('Popular ads'),
        '/ms',
      ));
      debug($pattern);
      $this
        ->assertPattern($pattern, t('Ad correctly listed in the "Recent ads" block.'), $this->group);
    }
  }

  /**
   * Issue #1382234: Create new ad link missing.
   *
   * Root cause: improper caching.
   */
  public function test1382234() {
    $this->group = __FUNCTION__;
    $accounts = array(
      'creator',
    );
    $this
      ->createUsers($accounts);
    $this
      ->drupalLogin($this->creatorUser);

    // Force caching of overview page.
    cache_clear_all('classified:overview', 'cache');
    $this
      ->drupalGet('classified');
    $this
      ->assertLink(t('Add one'), 0, t('Creator sees ad creation link.'));

    // Anon. should not get creation link from page cached for auth. users.
    $this
      ->drupalLogout();
    $this
      ->drupalGet('classified');
    $this
      ->assertNoLink(t('Add one'), t('Anonymous users do not see ad creation link.'));
    cache_clear_all('classified:overview', 'cache');
    $this
      ->drupalGet('classified');
    $this
      ->assertNoLink(t('Add one'), t('Anonymous users do not see ad creation link.'));

    // Creator user should see the Add one link on the cached page.
    $this
      ->drupalLogin($this->creatorUser);
    $this
      ->drupalGet('classified');
    $this
      ->assertLink(t('Add one'), 0, t('Creator sees ad creation link.'));
  }

  /**
   * Bug 1412840: invalid taxonomy term paths were not handled correctly.
   */
  public function test1412840() {
    $this->group = __FUNCTION__;

    // This get threw an error per #1412840.
    $this
      ->drupalGet('classified-test/invalid-term-path');
    $this
      ->assertNoText('Trying to get property of non-object', t('Invalid taxonomy URL did not cause a syntax notice'), $this->group);
  }

  /**
   * Bug 1432606: Ads can be viewed when not published.
   */
  public function test1432606() {
    $this->group = __FUNCTION__;
    $accounts = array(
      'admin',
      'basic',
      'creator',
    );
    $this
      ->createUsers($accounts);

    // 1. Get the Classified vocabulary id and field name.
    $vid = _classified_get('vid');
    $category_field_name = _classified_get('field-category');

    // 2a. Create a term in it, do not assign a specific lifetime.
    $term = (object) array(
      'name' => $this
        ->randomName(8),
      'description' => $this
        ->randomString(20),
      'vid' => $vid,
    );
    $status = taxonomy_term_save($term);
    $tid = $term->tid;
    $this
      ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
      '@tid' => $tid,
    )), 'setup');

    // 2b. Create a published node bearing that term, belonging to "creator".
    $node = $this
      ->createNode(array(
      $category_field_name => array(
        LANGUAGE_NONE => array(
          0 => array(
            'tid' => $tid,
          ),
        ),
      ),
      'uid' => $this->creatorUser->uid,
      'status' => 1,
    ));
    $path = 'node/' . $node->nid;

    // 3. All four profiles should see published node.
    $this
      ->drupalLogout();
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(200, t('Anonymous user sees published ad.'));
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(200, t('Ads administrator sees published ad.'));
    $this
      ->drupalLogin($this->basicUser);
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(200, t('Non-author user sees published ad.'));
    $this
      ->drupalLogin($this->creatorUser);
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(200, t('Author sees his published ad.'));

    // 4a. Unpublish the ad.
    $node->status = 0;
    node_save($node);

    // 4b. Ad is unpublished: only admin and creator should be able to see it.
    $this
      ->drupalLogout();
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(403, t('Anonymous user does not see unpublished ad.'));
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(200, t('Ads administrator sees unpublished ad.'));
    $this
      ->drupalLogin($this->basicUser);
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(403, t('Non-author user does not see unpublished ad.'));
    $this
      ->drupalLogin($this->creatorUser);
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(200, t('Author sees his unpublished ad.'));
  }

  /**
   * Test token generation for issue #1491880.
   */
  public function test1491880() {
    $this->group = __FUNCTION__;
    $accounts = array(
      'creator',
    );
    $this
      ->createUsers($accounts);

    // 1. Get the Classified vocabulary id and field name.
    $vid = _classified_get('vid');
    $category_field_name = _classified_get('field-category');

    // 2a. Create a term in it, do not assign a specific lifetime.
    $term = (object) array(
      'name' => $this
        ->randomName(8),
      'description' => $this
        ->randomString(20),
      'vid' => $vid,
    );
    $status = taxonomy_term_save($term);
    $tid = $term->tid;
    $this
      ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
      '@tid' => $tid,
    )), 'setup');

    // 2b. Create a published node bearing that term, belonging to "creator".
    // Avoid escaping problems and "/" to use a regexp.
    $title = check_plain($this
      ->randomName(20));
    $node = $this
      ->createNode(array(
      $category_field_name => array(
        LANGUAGE_NONE => array(
          0 => array(
            'tid' => $tid,
          ),
        ),
      ),
      'uid' => $this->creatorUser->uid,
      'title' => $title,
      'status' => 1,
    ));

    // Make sure tokens are visible.
    $tokens = token_info();
    $tokens = $tokens['tokens']['user'];
    $token_names = array(
      'classified-ads',
      'classified-ads-plain',
      'classified-ads-url',
    );
    foreach ($token_names as $token) {
      $this
        ->assertFalse(empty($tokens[$token]), t('%token token found in user tokens.', array(
        '%token' => $token,
      )), $this->group);
    }

    // Check token replacement.
    $token = 'classified-ads';
    $translation = token_replace("[user:{$token}]", array(
      'user' => $this->creatorUser,
    ));
    $this
      ->assertTrue(preg_match('/' . $node->title . '/', $translation), t('Node title from %token.', array(
      '%token' => $token,
    )), $this->group);
    $token = 'classified-ads-plain';
    $translation = token_replace("[user:{$token}]", array(
      'user' => $this->creatorUser,
    ));
    $this
      ->assertTrue(preg_match('/' . $node->title . '/', $translation), t('Node title from %token.', array(
      '%token' => $token,
    )), $this->group);
    $token = 'classified-ads-url';
    $translation = token_replace("[user:{$token}]", array(
      'user' => $this->creatorUser,
    ));
    $url = url('user/' . $node->uid . '/classified', array(
      'absolute' => TRUE,
    ));

    // URLs may contain a ?q=, which would be interpreted in a regex.
    $url = str_replace('?', '\\?', $url);
    $this
      ->assertTrue(preg_match("@{$url}@", $translation), t('User ads URL found from %token.', array(
      '%token' => $token,
    )), $this->group);
  }

  /**
   * Add server-side body length validation.
   */
  public function test1653560() {
    $this->group = __FUNCTION__;
    $accounts = array(
      'creator',
    );
    $this
      ->createUsers($accounts);
    $this
      ->drupalLogin($this->creatorUser);

    // 1. Get the node type name.
    $type = node_type_get_name('classified');

    // 2. Get the Classified vocabulary id.
    $vid = _classified_get('vid');

    // 3a. Create a term in it, do not assign a specific lifetime.
    $term = (object) array(
      'name' => $this
        ->randomName(8),
      'description' => $this
        ->randomString(20),
      'vid' => $vid,
    );
    $status = taxonomy_term_save($term);
    $tid = $term->tid;
    $this
      ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
      '@tid' => $tid,
    )), 'setup');

    // 3b. Limit the maximum body length.
    $max_length = 20;
    variable_set('classified-max-length', $max_length);

    // 4a. Try to create an ad bearing that term, with a body below max length.
    $count = db_query('SELECT COUNT(nid) FROM {node}')
      ->fetchField();
    $this
      ->assertEqual(0, $count, t('No node found before creation of first ad'), $this->group);
    $langcode = LANGUAGE_NONE;
    $body_key = "body[{$langcode}][0][value]";
    $term_key = "classified_category[{$langcode}]";
    $edit = array(
      'title' => $this
        ->randomString(10),
      $term_key => $tid,
      $body_key => 'A short body',
      'expire_mode' => 'reset',
    );
    $this
      ->drupalPost('node/add/classified', $edit, t('Save'));
    $raw = t('@type %title has been created.', array(
      '@type' => $type,
      '%title' => $edit['title'],
    ));
    $this
      ->assertRaw($raw, t('Ad with proper body receives creation confirmation'), $this->group);
    $count = db_query('SELECT COUNT(nid) FROM {node}')
      ->fetchField();
    $this
      ->assertEqual(1, $count, t('Ad with proper body actually created.'), $this->group);

    // 4b. Try to create an ad bearing that term, with a body above max length.
    $edit = array(
      'title' => $this
        ->randomString(10),
      $term_key => $tid,
      $body_key => 'A body longer than 20 characters',
    );
    $this
      ->drupalPost('node/add/classified', $edit, t('Save'));
    $raw = t('Text is longer than maximum authorized length: @body_length characters vs @max_length authorized.', array(
      '@body_length' => drupal_strlen($edit[$body_key]),
      '@max_length' => $max_length,
    ));
    $this
      ->assertRaw($raw, t('Ad with extra-long body receives post error.'), $this->group);
    $count = db_query('SELECT COUNT(nid) FROM {node}')
      ->fetchField();
    $this
      ->assertEqual(1, $count, t('Ad with extra-long body actually not created.'), $this->group);
  }

  /**
   * Bug 1733594: Infinite grace (-1) being handled like a normal duration.
   */
  public function test1733594() {
    $this->group = 'Infinite';

    // 1. Get the Classified vocabulary id and field name.
    $vid = _classified_get('vid');
    $category_field_name = _classified_get('field-category');

    // 2a. Create a term in it, do not assign a specific lifetime.
    $term = (object) array(
      'name' => $this
        ->randomName(8),
      'description' => $this
        ->randomString(20),
      'vid' => $vid,
    );
    $status = taxonomy_term_save($term);
    $tid = $term->tid;
    $this
      ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
      '@tid' => $tid,
    )), 'setup');

    // 2b. Create a node bearing that term.
    $node = $this
      ->createNode(array(
      $category_field_name => array(
        LANGUAGE_NONE => array(
          0 => array(
            'tid' => $tid,
          ),
        ),
      ),
    ));

    // 2c. Get lifetimes information.
    $lifetimes = _classified_get('lifetimes');
    $default_lifetime = reset($lifetimes);

    // 2d. Validate lifetime.
    $this
      ->assertTrue(isset($node->expires) && is_numeric($node->expires) && $node->expires - $node->created == $default_lifetime * 24 * 60 * 60, t('node has correct timestamp'), $this->group);

    // 3. Try purge one year beyond expiration with infinite grace.
    variable_set('classified-grace', -1);
    $future = $node->expires + 365 * 24 * 60 * 60;
    $ads = _classified_scheduled_build_purge($future);

    // 4. Ensure purge did not happen.
    $this
      ->assertTrue(empty($ads), "No ad has been reported as deleted upon purge.", $this->group);
    $node2 = node_load($node->nid, NULL, TRUE);
    $this
      ->assertTrue(isset($node2->nid) && $node2->nid == $node->nid, 'Node is still present in database after purge.', $this->group);

    // 5. Try purge one week beyond expiration with normal one day grace.
    $this->group = "Finite";
    variable_set('classified-grace', 1);
    $future = $node->expires + 7 * 24 * 60 * 60;
    $ads = _classified_scheduled_build_purge($future);

    // 6. Ensure purge was performed. Format: {uid: {nid: title, ...}, ...}.
    $this
      ->assertTrue(count($ads) == 1, "Purges happened for one account.", $this->group);
    $purges = reset($ads);
    $this
      ->assertTrue(count($purges) == 1, "One node was purged", $this->group);
    $this
      ->assertEqual(key($purges), $node->nid, "Nid of purged node is correct", $this->group);
    $this
      ->assertEqual(current($purges), $node->title, "Title of purged node is correct", $this->group);
    $node2 = node_load($node->nid, NULL, TRUE);
    $this
      ->assertFalse($node2, "Node is no longer in database", $this->group);
  }

  /**
   * Security issue: XSS on term name on Classified config screen.
   */
  public function testSecurity146738() {
    $this->group = 'XSS';

    // 1. Get the Classified vocabulary id.
    $vid = _classified_get('vid');

    // 2. Create a term in it with a XSS attempt,
    $name = <<<XSS
term<script type="text/javascript">alert('XSS');</script>name
XSS;
    $term = (object) array(
      'name' => $name,
      'description' => $this
        ->randomString(20),
      'vid' => $vid,
    );
    $status = taxonomy_term_save($term);
    $tid = $term->tid;
    $this
      ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
      '@tid' => $tid,
    )), 'setup');

    // 3. Create an administrator using the Classified admin panel.
    $this
      ->createUsers(array(
      'admin',
    ));
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet('admin/config/content/classified');
    $this
      ->assertResponse(200, t('Admin sees Classified administration.'));
    $this
      ->assertNoRaw($name);
    $this
      ->assertRaw(check_plain($name));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClassifiedTestAbstractTest::$adminUser public property A user with administrative permissions.
ClassifiedTestAbstractTest::$basicUser public property A plain authenticated user.
ClassifiedTestAbstractTest::$creatorUser public property A user with ad creation permissions.
ClassifiedTestAbstractTest::$group public property Test group.
ClassifiedTestAbstractTest::createNode protected function Build a node from settings, providing classified-specific defaults.
ClassifiedTestAbstractTest::createUsers protected function Create a set of typical users with profiles related to Classified Ads.
ClassifiedTestTestBasicTest::getInfo public static function
ClassifiedTestTestBasicTest::relativizeHref protected function Convert a host-relative path like /drupal/taxonomy to a drupal path.
ClassifiedTestTestBasicTest::setUp public function Sets up a Drupal site for running functional and integration tests. Overrides DrupalWebTestCase::setUp
ClassifiedTestTestBasicTest::test0123396And0143680 public function Bug 123396: Unchecking Publish doesn't prevent nodes from being published.
ClassifiedTestTestBasicTest::test0547214 public function Bug 547214: view Ads tab for users without permission.
ClassifiedTestTestBasicTest::test1244300 public function Bug 1244300: Anonymous user unable to post regardless of permission grants.
ClassifiedTestTestBasicTest::test1265524 public function Bug 1265524: Can not edit taxonomy terms.
ClassifiedTestTestBasicTest::test1287674 public function Bug 1287674.
ClassifiedTestTestBasicTest::test1382234 public function Issue #1382234: Create new ad link missing.
ClassifiedTestTestBasicTest::test1412840 public function Bug 1412840: invalid taxonomy term paths were not handled correctly.
ClassifiedTestTestBasicTest::test1432606 public function Bug 1432606: Ads can be viewed when not published.
ClassifiedTestTestBasicTest::test1491880 public function Test token generation for issue #1491880.
ClassifiedTestTestBasicTest::test1653560 public function Add server-side body length validation.
ClassifiedTestTestBasicTest::test1733594 public function Bug 1733594: Infinite grace (-1) being handled like a normal duration.
ClassifiedTestTestBasicTest::testSecurity146738 public function Security issue: XSS on term name on Classified config screen.
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1