You are here

public function ClassifiedTestTestBasicTest::test1287674 in Classified Ads 7.3

Bug 1287674.

Node title and categories are doubly escaped in recent/popular blocks.

File

tests/classified_test_basic.test, line 260

Class

ClassifiedTestTestBasicTest
Basic test for known bugs in previous versions.

Code

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);
  }
}