You are here

public function ClassifiedBasicTest::test1525392 in Classified Ads 6.3

File

tests/classified_basic.test, line 574
Basic test for known bugs in previous versions.

Class

ClassifiedBasicTest

Code

public function test1525392() {
  $this->group = __FUNCTION__;
  $this
    ->createUsers(array(
    'creator',
  ));
  $this
    ->drupalLogin($this->creatorUser);
  $types = array_keys(classified_node_info());
  $type = reset($types);

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

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

  // Create a term below the first one, do not assign a specific lifetime.
  $child_term_name = $this
    ->randomName(4) . " ' " . $this
    ->randomName(4);
  $child_term = array(
    'name' => $child_term_name,
    'description' => $this
      ->randomString(20),
    'vid' => $vid,
    'parent' => $tid,
  );
  $status = taxonomy_save_term($child_term);
  $child_tid = $child_term['tid'];
  $this
    ->assertEqual($status, SAVED_NEW, t('Term @child_tid created below @tid in default vocabulary.', array(
    '@child_tid' => $child_tid,
    '@tid' => $tid,
  )), 'setup');

  // Create two ads in the child category.
  // Create a node bearing that term.
  for ($i = 0; $i < 2; $i++) {
    $title = $this
      ->randomName(4) . ' ' . $this
      ->randomName(4);
    module_load_include('inc', 'node', 'node.pages');
    $body = $this
      ->randomName(4) . ' ' . $this
      ->randomString(40);
    $format = FILTER_FORMAT_DEFAULT;
    $settings = array(
      'type' => $type,
      'format' => $format,
      'taxonomy' => array(
        $vid => $child_tid,
      ),
      'title' => $title,
      'body' => $body,
      'uid' => $this->creatorUser->uid,
    );
    $node = $this
      ->createNode($settings);
  }
  $this
    ->drupalGet('classified');
  $xpath = '//table[contains(@class, "classified-term-list")]/caption/text()';
  $fields = $this
    ->xpath($xpath);
  if ($fields) {
    if (count($fields) > 1) {
      $this
        ->fail(t('More than one total ads count (@count) found on page.', array(
        '@count' => count($field),
      )), $this->group);
    }
    $text = dom_import_simplexml(reset($fields))->textContent;
    $sts = preg_match('/^2[\\s\\w]+\\./', $text, $matches);
    $this
      ->assertEqual(1, $sts, t('Total ads count is 2 (@count).'), $this->group);
  }
  else {
    $this
      ->fail(t('Ads total count not found on page.'), $this->group);
  }
}