You are here

classified_test_basic.test in Classified Ads 7.3

File

tests/classified_test_basic.test
View source
<?php

/**
 * Acknowledge breaking PSR1 compliance for test.
 *
 * This is a legacy Simpletest requirement, preventing PSR1 compliance.
 *
 * phpcs:disable PSR1.Files.SideEffects,PSR1.Classes.ClassDeclaration
 */
require_once __DIR__ . '/classified_test_abstract.test';

/**
 * Basic test for known bugs in previous versions.
 */
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));
  }

}

Classes

Namesort descending Description
ClassifiedTestTestBasicTest Basic test for known bugs in previous versions.