You are here

biblio.test in Bibliography Module 6.2

Same filename and directory in other branches
  1. 7.2 tests/biblio.test

File

tests/biblio.test
View source
<?php

/*
 * @file
 * Base class for all biblio tests
 */
class BiblioWebTestCase extends DrupalWebTestCase {

  // Keep a list of all keyword IDs created.
  protected $kids = array();

  // Keep a list of all contributor IDs created.
  protected $cids = array();

  // Keep a list of all node IDs created.
  protected $nids = array();
  protected $admin_user;

  /*
    function tearDown() {
      if(!empty($this->kids)){
        db_query('DELETE FROM {biblio_keyword} WHERE kid IN ('.implode(',', $this->kids).')');
        db_query('DELETE FROM {biblio_keyword_data} WHERE kid IN ('.implode(',', $this->kids).')');
      }

      foreach($this->nids as $nid) {
        node_delete($nid);
      }

      if(!empty($this->cids)) {
        db_query('DELETE FROM {biblio_contributor} WHERE cid IN ('.implode(',', $this->cids).')');
        db_query('DELETE FROM {biblio_contributor_data} WHERE cid IN ('.implode(',', $this->cids).')');
      }
      $this->cids = array();
    }
  */
  function createNode($type = 100, $fields = null) {
    $biblio_fields = array();
    if (!$fields) {
      $schema = drupal_get_schema('biblio', TRUE);
      foreach ($schema['fields'] as $name => $values) {
        if ($values['type'] == 'int') {
          continue;
        }
        switch ($values['type']) {
          case 'varchar':
            $length = $values['length'];
            break;
          case 'text':
            $length = 1000;
            break;
        }
        $biblio_fields[$name] = $name;
      }
    }
    else {
      foreach ($fields as $name) {
        $biblio_fields[$name] = $name;
      }
    }
    $settings = array(
      'title' => 'Biblio Title',
      'type' => 'biblio',
      // This replaces the default type
      'biblio_type' => $type,
      // This appends a new field.
      'biblio_year' => 2009,
      'biblio_contributors' => array(
        1 => array(
          0 => array(
            'name' => 'Ron J. Jeromezzzzzz',
            'auth_type' => 1,
          ),
          1 => array(
            'name' => 'John Smithzzzzzz',
            'auth_type' => 1,
          ),
          2 => array(
            'name' => 'George W. Bushzzzzzz',
            'auth_type' => 1,
          ),
        ),
      ),
      'biblio_keywords' => array(
        'biblio_keywords',
      ),
    );
    $settings = array_merge($biblio_fields, $settings);
    $node = $this
      ->drupalCreateNode($settings);
    $node = node_load($node->nid, NULL, TRUE);
    foreach ($node->biblio_contributors[1] as $author) {
      $this->cids[] = $author['cid'];
    }
    $this->nids[] = $node->nid;
    return $node;
  }
  function assertBiblioFields($node1, $node2, $fields = array()) {
    $count = 0;
    $cat = 0;
    foreach ($fields as $field) {
      if ($field == 'biblio_contributors') {
        foreach ($node1->{$field} as $cat => $authors) {
          foreach ($authors as $rank => $author) {
            if ($node1->biblio_contributors[$cat][$rank]['name'] != $node2->biblio_contributors[$cat][$rank]['name']) {
              $this
                ->assertEqual($node1->biblio_contributors[$cat][$rank]['name'], $node2->biblio_contributors[$cat][$rank]['name']);
              $count++;
            }
          }
        }
      }
      else {
        if (isset($node1->{$field}) && isset($node2->{$field}) && $node1->{$field} != $node2->{$field}) {
          $this
            ->assertEqual($node1->{$field}, $node2->{$field});
          $count++;
        }
      }
    }
    $this
      ->assertEqual($count, 0, "There were {$count} differences between the two nodes");
  }

}

Classes

Namesort descending Description
BiblioWebTestCase