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) { if(!$fields) { $schema = drupal_get_schema('biblio'); 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 ($node1->$field != $node2->$field) { $this->assertEqual($node1->$field, $node2->$field); $count++; } } } $this->assertEqual($count, 0, "There were $count differences between the two nodes"); } }