- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
<?php
// $Id$
2008-11-16 14:59:33 +00:00
/**
* @file
* Tests for Taxonomy module.
*/
2008-11-22 12:05:02 +00:00
/**
* Class with common helper methods.
*/
class TaxonomyWebTestCase extends DrupalWebTestCase {
/**
* Returns a new vocabulary with random properties.
*/
function createVocabulary() {
// Create a vocabulary.
$vocabulary = new stdClass();
$vocabulary->name = $this->randomName();
$vocabulary->description = $this->randomName();
$vocabulary->help = '';
$vocabulary->nodes = array('article' => 'article');
$vocabulary->weight = mt_rand(0, 10);
taxonomy_vocabulary_save($vocabulary);
return $vocabulary;
}
/**
* Returns a new term with random properties in vocabulary $vid.
*/
function createTerm($vid) {
$term = new stdClass();
$term->name = $this->randomName();
$term->vid = $vid;
taxonomy_term_save($term);
return $term;
}
}
/**
* Tests for the taxonomy vocabulary interface.
*/
class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase {
2008-11-16 14:59:33 +00:00
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-11-16 14:59:33 +00:00
return array(
'name' => t('Taxonomy vocabulary interface'),
'description' => t('Test the taxonomy vocabulary interface.'),
'group' => t('Taxonomy'),
);
}
function setUp() {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('administer taxonomy'));
2008-11-22 12:05:02 +00:00
$this->drupalLogin($this->admin_user);
$this->vocabulary = $this->createVocabulary();
2008-11-16 14:59:33 +00:00
}
2008-09-24 02:59:42 +00:00
/**
2008-11-16 14:59:33 +00:00
* Create, edit and delete a vocabulary via the user interface.
2008-09-24 02:59:42 +00:00
*/
2008-11-16 14:59:33 +00:00
function testVocabularyInterface() {
// Visit the main taxonomy administration page.
$this->drupalGet('admin/content/taxonomy');
// Create a new vocabulary.
$this->clickLink(t('Add vocabulary'));
$edit = array();
$edit['name'] = $this->randomName();
$edit['description'] = $this->randomName();
$edit['help'] = $this->randomName();
$edit['nodes[article]'] = 'article';
$edit['tags'] = 1;
$edit['multiple'] = 1;
$edit['required'] = 1;
$this->drupalPost(NULL, $edit, t('Save'));
2008-11-22 13:43:13 +00:00
$this->assertRaw(t('Created new vocabulary %name.', array('%name' => $edit['name'])), t('Vocabulary created successfully'));
2008-11-16 14:59:33 +00:00
// Edit the vocabulary.
$this->drupalGet('admin/content/taxonomy');
$this->assertText($edit['name'], t('Vocabulary found in the vocabulary overview listing.'));
$this->clickLink(t('edit vocabulary'));
$edit = array();
$edit['name'] = $this->randomName();
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t('Updated vocabulary %name.', array('%name' => $edit['name'])));
$this->drupalGet('admin/content/taxonomy');
$this->assertText($edit['name'], t('Vocabulary found in the vocabulary overview listing.'));
}
2008-11-22 12:05:02 +00:00
/**
* Changing weights on the vocabulary overview with two or more vocabularies.
*/
function testTaxonomyAdminChangingWeights() {
// Create some vocabularies.
for ($i = 0; $i < 10; $i++) {
$this->createVocabulary();
}
// Get all vocabularies and change their weights.
$vocabularies = taxonomy_get_vocabularies();
$edit = array();
foreach ($vocabularies as $key => $vocabulary) {
$vocabulary->weight = -$vocabulary->weight;
$vocabularies[$key]->weight = $vocabulary->weight;
$edit[$key .'[weight]'] = $vocabulary->weight;
}
// Saving the new weights via the interface.
$this->drupalPost('admin/content/taxonomy/', $edit, t('Save'));
// Load the vocabularies from the database.
$new_vocabularies = taxonomy_get_vocabularies();
// Check that the weights are saved in the database correctly.
foreach ($vocabularies as $key => $vocabulary) {
$this->assertEqual($new_vocabularies[$key]->weight, $vocabularies[$key]->weight, t('The vocabulary weight was changed.'));
}
}
/**
* Test the vocabulary overview with no vocabularies.
*/
function testTaxonomyAdminNoVocabularies() {
// Delete all vocabularies.
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $key => $vocabulary) {
$edit = array();
$this->drupalPost('admin/content/taxonomy/' . $vocabulary->vid, $edit, t('Delete'));
// Submit the confirm form for deletion.
$this->drupalPost(NULL, NULL, t('Delete'));
}
// Confirm that no vocabularies are found in the database.
$this->assertFalse(taxonomy_get_vocabularies(), t('No vocabularies found in the database'));
// Check the default message for no vocabularies.
$this->assertText(t('No vocabularies available.'), t('No vocabularies were found.'));
}
/**
* Deleting a vocabulary.
*/
function testTaxonomyAdminDeletingVocabulary() {
// Create a vocabulary.
$edit = array(
'name' => $this->randomName(),
'nodes[article]' => 'article',
);
$this->drupalPost('admin/content/taxonomy/add', $edit, t('Save'));
$this->assertText(t('Created new vocabulary'), t('New vocabulary was created.'));
// Check the created vocabulary.
$vocabularies = taxonomy_get_vocabularies();
$vid = $vocabularies[count($vocabularies)-1]->vid;
2009-04-02 20:39:45 +00:00
drupal_static_reset('taxonomy_vocabulary_load_multiple');
$vocabulary = taxonomy_vocabulary_load($vid);
2008-11-22 12:05:02 +00:00
$this->assertTrue($vocabulary, t('Vocabulary found in database'));
// Delete the vocabulary.
$edit = array();
$this->drupalPost('admin/content/taxonomy/' .$vid, $edit, t('Delete'));
$this->assertRaw(t('Are you sure you want to delete the vocabulary %name?', array('%name' => $vocabulary->name)), t('[confirm deletion] Asks for confirmation.'));
$this->assertText(t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), t('[confirm deletion] Inform that all terms will be deleted.'));
// Confirm deletion.
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->name)), t('Vocabulary deleted'));
2009-04-02 20:39:45 +00:00
drupal_static_reset('taxonomy_vocabulary_load_multiple');
$this->assertFalse(taxonomy_vocabulary_load($vid), t('Vocabulary is not found in the database'));
2008-11-22 12:05:02 +00:00
}
2008-11-16 14:59:33 +00:00
}
/**
* Tests for taxonomy vocabulary functions.
*/
2008-11-22 12:05:02 +00:00
class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase {
2008-11-16 14:59:33 +00:00
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-09-24 02:59:42 +00:00
return array(
2008-11-16 14:59:33 +00:00
'name' => t('Taxonomy vocabularies'),
'description' => t('Test loading, saving and deleting vocabularies.'),
2008-09-24 02:59:42 +00:00
'group' => t('Taxonomy'),
);
}
function setUp() {
parent::setUp('taxonomy');
2008-11-16 14:59:33 +00:00
$admin_user = $this->drupalCreateUser(array('create article content', 'administer taxonomy'));
2008-09-24 02:59:42 +00:00
$this->drupalLogin($admin_user);
2008-11-22 12:05:02 +00:00
$this->vocabulary = $this->createVocabulary();
2008-09-24 02:59:42 +00:00
}
/**
* Ensure that when an invalid vocabulary vid is loaded, it is possible
* to load the same vid successfully if it subsequently becomes valid.
*/
function testTaxonomyVocabularyLoadReturnFalse() {
// Load a vocabulary that doesn't exist.
$vocabularies = taxonomy_get_vocabularies();
$vid = count($vocabularies) + 1;
$vocabulary = taxonomy_vocabulary_load($vid);
// This should not return an object because no such vocabulary exists.
2008-11-22 12:05:02 +00:00
$this->assertTrue(empty($vocabulary), t('No object loaded.'));
2008-09-24 02:59:42 +00:00
// Create a new vocabulary.
2008-11-22 12:05:02 +00:00
$this->createVocabulary();
2008-09-24 02:59:42 +00:00
// Load the vocabulary with the same $vid from earlier.
// This should return a vocabulary object since it now matches a real vid.
$vocabulary = taxonomy_vocabulary_load($vid);
2008-11-22 12:05:02 +00:00
$this->assertTrue(!empty($vocabulary) && is_object($vocabulary), t('Vocabulary is an object'));
2008-09-24 02:59:42 +00:00
$this->assertTrue($vocabulary->vid == $vid, t('Valid vocabulary vid is the same as our previously invalid one.'));
}
2008-09-24 18:42:00 +00:00
/**
* Ensure that the vocabulary static reset works correctly.
*/
function testTaxonomyVocabularyLoadStaticReset() {
2009-04-02 20:39:45 +00:00
$original_vocabulary = taxonomy_vocabulary_load($this->vocabulary->vid);
2008-11-16 14:59:33 +00:00
$this->assertTrue(is_object($original_vocabulary), t('Vocabulary loaded successfully'));
$this->assertEqual($this->vocabulary->name, $original_vocabulary->name, t('Vocabulary loaded successfully'));
2008-09-24 18:42:00 +00:00
// Change the name and description.
2008-11-05 12:47:23 +00:00
$vocabulary = $original_vocabulary;
$vocabulary->name = $this->randomName();
$vocabulary->description = $this->randomName();
taxonomy_vocabulary_save($vocabulary);
2008-09-24 18:42:00 +00:00
2009-04-02 20:39:45 +00:00
// Load the vocabulary.
$new_vocabulary = taxonomy_vocabulary_load($original_vocabulary->vid);
2008-11-05 12:47:23 +00:00
$this->assertEqual($new_vocabulary->name, $vocabulary->name);
$this->assertEqual($new_vocabulary->name, $vocabulary->name);
2008-11-16 14:59:33 +00:00
// Delete the vocabulary.
taxonomy_vocabulary_delete($this->vocabulary->vid);
$vocabularies = taxonomy_get_vocabularies();
$this->assertTrue(!isset($vocabularies[$this->vocabulary->vid]), t('The vocabulary was deleted'));
2008-09-24 18:42:00 +00:00
}
2009-03-30 05:18:49 +00:00
/**
* Tests for loading multiple vocabularies.
*/
function testTaxonomyVocabularyLoadMultiple() {
// Delete any existing vocabularies.
foreach (taxonomy_get_vocabularies() as $vocabulary) {
taxonomy_vocabulary_delete($vocabulary->vid);
}
// Create some vocabularies and assign weights.
$vocabulary1 = $this->createVocabulary();
$vocabulary1->weight = 0;
taxonomy_vocabulary_save($vocabulary1);
$vocabulary2 = $this->createVocabulary();
$vocabulary2->weight = 1;
taxonomy_vocabulary_save($vocabulary2);
$vocabulary3 = $this->createVocabulary();
$vocabulary3->weight = 2;
taxonomy_vocabulary_save($vocabulary3);
// Fetch all of the vocabularies using taxonomy_get_vocabularies().
// Confirm that the vocabularies are ordered by weight.
$vocabularies = taxonomy_get_vocabularies();
$this->assertEqual(array_shift($vocabularies), $vocabulary1, t('Vocabulary was found in the vocabularies array.'));
$this->assertEqual(array_shift($vocabularies), $vocabulary2, t('Vocabulary was found in the vocabularies array.'));
$this->assertEqual(array_shift($vocabularies), $vocabulary3, t('Vocabulary was found in the vocabularies array.'));
// Fetch the vocabularies with taxonomy_vocabulary_load_multiple(), specifying IDs.
// Ensure they are returned in the same order as the original array.
$vocabularies = taxonomy_vocabulary_load_multiple(array($vocabulary3->vid, $vocabulary2->vid, $vocabulary1->vid));
$this->assertEqual(array_shift($vocabularies), $vocabulary3, t('Vocabulary loaded successfully by ID.'));
$this->assertEqual(array_shift($vocabularies), $vocabulary2, t('Vocabulary loaded successfully by ID.'));
$this->assertEqual(array_shift($vocabularies), $vocabulary1, t('Vocabulary loaded successfully by ID.'));
// Fetch vocabulary 1 by name.
$this->assertTrue(current(taxonomy_vocabulary_load_multiple(array(), array('name' => $vocabulary1->name))) == $vocabulary1, t('Vocabulary loaded successfully by name.'));
// Fetch vocabulary 1 by name and ID.
$this->assertTrue(current(taxonomy_vocabulary_load_multiple(array($vocabulary1->vid), array('name' => $vocabulary1->name))) == $vocabulary1, t('Vocabulary loaded successfully by name and ID.'));
}
2008-09-24 02:59:42 +00:00
}
2009-01-28 01:14:39 +00:00
/**
* Unit tests for taxonomy term functions.
*/
class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-01-28 01:14:39 +00:00
return array(
'name' => t('Taxonomy term unit tests'),
'description' => t('Unit tests for taxonomy term functions.'),
'group' => t('Taxonomy'),
);
}
/**
* Tests for taxonomy_term_count_nodes().
*
* Attach nodes to a hierarchical vocabulary and check they are counted
* correctly.
*/
function testTaxonomyTermCountNodes() {
// Create a vocabulary with three terms.
$vocabulary = $this->createVocabulary();
$term1 = $this->createTerm($vocabulary->vid);
$term2 = $this->createTerm($vocabulary->vid);
$term3 = $this->createTerm($vocabulary->vid);
// Attach term1 to a node.
$node1 = $this->drupalCreateNode(array('type' => 'page'));
$node1->taxonomy = array($term1->tid);
node_save($node1);
$this->assertEqual(taxonomy_term_count_nodes($term1->tid), 1, t('Term has one valid node association.'));
// Attach term2 to a node.
$node2 = $this->drupalCreateNode(array('type' => 'article'));
$node2->taxonomy = array($term2->tid);
node_save($node2);
$this->assertEqual(taxonomy_term_count_nodes($term2->tid), 1, t('Term has one valid node association.'));
// Confirm that term3 is not associated with any nodes.
2009-04-02 20:39:45 +00:00
$this->assertEqual(taxonomy_term_count_nodes($term3->tid), 0, t('Term is not associated with any nodes'));
2009-01-28 01:14:39 +00:00
// Set term3 as the parent of term1.
$term1->parent = array($term3->tid);
taxonomy_term_save($term1);
// Confirm that the term hierarchy is altered correctly.
$children = taxonomy_get_children($term3->tid);
$this->assertTrue(isset($children[$term1->tid]), t('Term 3 saved as parent of term 1'));
2009-04-02 20:39:45 +00:00
$this->assertEqual(count(taxonomy_get_tree($term3->vid, $term3->tid)), 1, t('Term 3 has one child term'));
2009-01-28 01:14:39 +00:00
// Confirm that term3's parental relationship with term1 leads to a
// node assocation being counted.
2009-04-02 20:39:45 +00:00
$this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL), 1, t('Term has one valid node association due to child term.'));
2009-01-28 01:14:39 +00:00
// Set term3 as the parent of term2.
$term2->parent = array($term3->tid);
taxonomy_term_save($term2);
// term3 should now have two node associations counted.
2009-04-02 20:39:45 +00:00
$this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL), 2, t('Term has two valid node associations due to child terms.'));
2009-01-28 01:14:39 +00:00
// Save node1 with both child taxonomy terms, this should still result
// in term3 having two node associations.
$node1->taxonomy = array($term1->tid, $term2->tid);
node_save($node1);
2009-04-02 20:39:45 +00:00
$this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL), 2, t('Term has two valid node associations.'));
2009-01-28 01:14:39 +00:00
// Confirm that the node type argument returns a single node association.
2009-04-02 20:39:45 +00:00
$this->assertEqual(taxonomy_term_count_nodes($term3->tid, 'page'), 1, t("Term is associated with one node of type 'page'."));
2009-01-28 01:14:39 +00:00
}
}
2008-11-16 14:59:33 +00:00
/**
* Tests for taxonomy term functions.
*/
2008-11-22 12:05:02 +00:00
class TaxonomyTermTestCase extends TaxonomyWebTestCase {
2008-11-16 14:59:33 +00:00
2009-03-31 01:49:55 +00:00
public static function getInfo() {
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
return array(
2008-11-16 14:59:33 +00:00
'name' => t('Taxonomy term functions and forms.'),
'description' => t('Test load, save and delete for taxonomy terms.'),
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
'group' => t('Taxonomy')
);
}
2008-09-24 02:59:42 +00:00
function setUp() {
parent::setUp('taxonomy');
2008-11-16 14:59:33 +00:00
$this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'bypass node access'));
2008-11-22 12:05:02 +00:00
$this->drupalLogin($this->admin_user);
$this->vocabulary = $this->createVocabulary();
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
/**
2008-11-16 14:59:33 +00:00
* Test related terms.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
2008-11-16 14:59:33 +00:00
function testTaxonomyTermRelations() {
// Create two taxonomy terms.
2008-11-22 12:05:02 +00:00
$term1 = $this->createTerm($this->vocabulary->vid);
$term2 = $this->createTerm($this->vocabulary->vid);
2008-11-16 14:59:33 +00:00
// Edit $term1 and add $term2 as a relationship.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$edit = array();
2008-11-16 14:59:33 +00:00
$edit['relations[]'] = $term2->tid;
$this->drupalPost('taxonomy/term/' . $term1->tid . '/edit', $edit, t('Save'));
$related = taxonomy_get_related($term1->tid);
$this->assertTrue(isset($related[$term2->tid]), t('Related term was found'));
2008-12-04 10:57:17 +00:00
// Create a third term.
$term3 = $this->createTerm($this->vocabulary->vid);
$edit['relations[]'] = $term3->tid;
$this->drupalPost('taxonomy/term/' . $term1->tid . '/edit', $edit, t('Save'));
$related = taxonomy_get_related($term1->tid);
$this->assertTrue(isset($related[$term3->tid]), t('Related term was found'));
$this->assertFalse(isset($related[$term2->tid]), t('Term relationship no longer exists'));
2008-09-08 21:37:21 +00:00
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
2008-11-16 14:59:33 +00:00
* Test synonyms.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
2008-11-16 14:59:33 +00:00
function testTaxonomySynonyms() {
2008-11-22 12:05:02 +00:00
// Create a taxonomy term with one synonym.
$term = $this->createTerm($this->vocabulary->vid);
$term->synonyms = $this->randomName();
2008-11-05 14:08:11 +00:00
taxonomy_term_save($term);
2008-09-08 21:37:21 +00:00
2008-11-16 14:59:33 +00:00
// Fetch the synonyms.
$synonyms = taxonomy_get_synonyms($term->tid);
$count = count($synonyms);
$this->assertEqual($count, 1, t('@count synonyms were found.', array('@count' => $count)));
2008-09-08 21:37:21 +00:00
2008-11-16 14:59:33 +00:00
// Fetch the term using the synonyms.
$returned_term = taxonomy_get_synonym_root($synonyms[0]);
$this->assertEqual($term->tid, $returned_term->tid, t('Term ID returned correctly'));
2008-09-08 21:37:21 +00:00
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
2008-11-16 14:59:33 +00:00
* Test terms in a single and multiple hierarchy.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
2008-11-16 14:59:33 +00:00
function testTaxonomyTermHierarchy() {
// Create two taxonomy terms.
2008-11-22 12:05:02 +00:00
$term1 = $this->createTerm($this->vocabulary->vid);
$term2 = $this->createTerm($this->vocabulary->vid);
2008-11-16 14:59:33 +00:00
// Edit $term2, setting $term1 as parent.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$edit = array();
2008-11-16 14:59:33 +00:00
$edit['parent[]'] = $term1->tid;
$this->drupalPost('taxonomy/term/' . $term2->tid . '/edit', $edit, t('Save'));
// Check the hierarchy.
$children = taxonomy_get_children($term1->tid);
$parents = taxonomy_get_parents($term2->tid);
$this->assertTrue(isset($children[$term2->tid]), t('Child found correctly.'));
$this->assertTrue(isset($parents[$term1->tid]), t('Parent found correctly.'));
// Create a third term and save this as a parent of term2.
2008-11-22 12:05:02 +00:00
$term3 = $this->createTerm($this->vocabulary->vid);
2008-11-16 14:59:33 +00:00
$term2->parent = array($term1->tid, $term3->tid);
taxonomy_term_save($term2);
$parents = taxonomy_get_parents($term2->tid);
$this->assertTrue(isset($parents[$term1->tid]) && isset($parents[$term3->tid]), t('Both parents found successfully.'));
2008-09-11 19:47:40 +00:00
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
2009-03-08 04:25:07 +00:00
* Test that hook_node_$op implementations work correctly.
2008-11-22 12:05:02 +00:00
*
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
* Save & edit a node and assert that taxonomy terms are saved/loaded properly.
*/
function testTaxonomyNode() {
2008-11-22 12:05:02 +00:00
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary->vid);
$term2 = $this->createTerm($this->vocabulary->vid);
2008-11-16 14:59:33 +00:00
// Post an article.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$edit = array();
2008-11-16 14:59:33 +00:00
$edit['title'] = $this->randomName();
$edit['body'] = $this->randomName();
$edit['taxonomy[' . $this->vocabulary->vid . ']'] = $term1->tid;
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalPost('node/add/article', $edit, t('Save'));
2008-11-16 14:59:33 +00:00
// Check that the term is displayed when the node is viewed.
2008-12-05 22:18:46 +00:00
$node = $this->drupalGetNodeByTitle($edit['title']);
2008-11-16 14:59:33 +00:00
$this->drupalGet('node/' . $node->nid);
$this->assertText($term1->name, t('Term is displayed when viewing the node.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2008-11-16 14:59:33 +00:00
// Edit the node with a different term.
$edit['taxonomy[' . $this->vocabulary->vid . ']'] = $term2->tid;
2008-05-30 07:30:53 +00:00
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2008-11-16 14:59:33 +00:00
$this->drupalGet('node/' . $node->nid);
$this->assertText($term2->name, t('Term is displayed when viewing the node.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Delete node through browser.
2008-05-30 07:30:53 +00:00
$this->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
2008-11-16 14:59:33 +00:00
$this->drupalGet('node/' . $node->nid);
$this->assertNoText($term2->name, t('Checking if node exists'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Checking database fields.
2009-01-14 21:16:21 +00:00
$result = db_query('SELECT * FROM {taxonomy_term_node} WHERE nid = :nid', array(':nid' => $node->nid))->fetch();
2008-11-16 14:59:33 +00:00
$this->assertTrue(empty($result), t('Term/node relationships are no longer in the database table.'));
2008-09-11 19:47:40 +00:00
}
2008-11-09 00:58:03 +00:00
/**
* Test term creation with a free-tagging vocabulary from the node form.
*/
function testNodeTermCreation() {
2008-11-16 14:59:33 +00:00
// Enable tags in the vocabulary.
$this->vocabulary->tags = 1;
taxonomy_vocabulary_save($this->vocabulary);
2008-11-09 00:58:03 +00:00
$terms = array(
$this->randomName(),
$this->randomName(),
$this->randomName(),
);
$edit = array();
$edit['title'] = $this->randomName();
// Insert the terms in a comma separated list. Vocabulary 1 is a
// free-tagging field created by the default profile.
2008-11-16 14:59:33 +00:00
$edit['taxonomy[tags][' . $this->vocabulary->vid .']'] = implode(', ', $terms);
2008-11-09 00:58:03 +00:00
$edit['body'] = $this->randomName();
$this->drupalPost('node/add/article', $edit, t('Save'));
$this->assertRaw(t('@type %title has been created.', array('@type' => t('Article'), '%title' => $edit['title'])), t('The node was created successfully'));
foreach ($terms as $term) {
$this->assertText($term, t('The term was saved and appears on the node page'));
}
}
2008-09-11 19:47:40 +00:00
/**
2009-01-28 01:09:58 +00:00
* Save, edit and delete a term using the user interface.
2008-09-11 19:47:40 +00:00
*/
2009-01-28 01:09:58 +00:00
function testTermInterface() {
2008-09-11 19:47:40 +00:00
$edit = array(
'name' => $this->randomName(12),
'description' => $this->randomName(100),
);
2008-11-16 14:59:33 +00:00
// Explicitly set the parents field to 'root', to ensure that
2008-11-13 08:13:56 +00:00
// taxonomy_form_term_submit() handles the invalid term ID correctly.
$edit['parent[]'] = 0;
2008-09-11 19:47:40 +00:00
2008-11-16 14:59:33 +00:00
// Create the term to edit.
$this->drupalPost('admin/content/taxonomy/' . $this->vocabulary->vid . '/add', $edit, t('Save'));
2008-09-11 19:47:40 +00:00
$term = taxonomy_get_term_by_name($edit['name']);
$this->assertNotNull($term, t('Term found in database'));
// Submitting a term takes us to the add page; we need the List page.
2008-11-16 14:59:33 +00:00
$this->drupalGet('admin/content/taxonomy/' . $this->vocabulary->vid . '/list');
2008-09-11 19:47:40 +00:00
// Test edit link as accessed from Taxonomy administration pages.
// Because Simpletest creates its own database when running tests, we know
// the first edit link found on the listing page is to our term.
$this->clickLink(t('edit'));
// This failed inexplicably with assertText, so used assertRaw. @TODO: Why?
2008-09-19 20:25:03 +00:00
$this->assertText($edit['name'], t('The randomly generated term name is present.'));
2008-09-11 19:47:40 +00:00
$this->assertText($edit['description'], t('The randomly generated term description is present.'));
$edit = array(
'name' => $this->randomName(14),
'description' => $this->randomName(102),
);
// Edit the term.
2008-09-19 20:25:03 +00:00
$this->drupalPost('taxonomy/term/' . $term[0]->tid . '/edit', $edit, t('Save'));
2008-09-11 19:47:40 +00:00
// View the term and check that it is correct.
2008-09-19 20:25:03 +00:00
$this->drupalGet('taxonomy/term/' . $term[0]->tid);
2008-09-11 19:47:40 +00:00
$this->assertText($edit['name'], t('The randomly generated term name is present.'));
$this->assertText($edit['description'], t('The randomly generated term description is present.'));
2009-01-28 01:09:58 +00:00
// Delete the term.
$this->drupalPost('taxonomy/term/' . $term[0]->tid . '/edit', array(), t('Delete'));
$this->drupalPost(NULL, NULL, t('Delete'));
// Assert that the term no longer exists.
$this->drupalGet('taxonomy/term/' . $term[0]->tid);
$this->assertResponse(404, t('The taxonomy term page was not found'));
2008-09-11 19:47:40 +00:00
}
2008-09-15 20:48:10 +00:00
}
2008-12-05 22:18:46 +00:00
/**
* Test the taxonomy_term_load_multiple() function.
*/
class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-12-05 22:18:46 +00:00
return array(
'name' => t('Taxonomy term multiple loading'),
'description' => t('Test the loading of multiple taxonomy terms at once'),
'group' => t('Taxonomy'),
);
}
function setUp() {
parent::setUp();
$this->taxonomy_admin = $this->drupalCreateUser(array('administer taxonomy'));
$this->drupalLogin($this->taxonomy_admin);
}
/**
* Create a vocabulary and some taxonomy terms, ensuring they're loaded
* correctly using taxonomy_term_load_multiple().
*/
function testTaxonomyTermMultipleLoad() {
// Create a vocabulary.
$vocabulary = $this->createVocabulary();
// Create five terms in the vocabulary.
$i = 0;
while ($i < 5) {
$i++;
$this->createTerm($vocabulary->vid);
}
// Load the terms from the vocabulary.
$terms = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid));
$count = count($terms);
$this->assertTrue($count == 5, t('Correct number of terms were loaded. !count terms.', array('!count' => $count)));
// Load the same terms again by tid.
$terms2 = taxonomy_term_load_multiple(array_keys($terms));
$this->assertTrue($count == count($terms2), t('Five terms were loaded by tid'));
$this->assertEqual($terms, $terms2, t('Both arrays contain the same terms'));
// Load the terms by tid, with a condition on vid.
$terms3 = taxonomy_term_load_multiple(array_keys($terms2), array('vid' => $vocabulary->vid));
$this->assertEqual($terms2, $terms3);
// Remove one term from the array, then delete it.
$deleted = array_shift($terms3);
taxonomy_term_delete($deleted->tid);
2009-04-02 20:39:45 +00:00
$deleted_term = taxonomy_term_load($deleted->tid);
2008-12-05 22:18:46 +00:00
$this->assertFalse($deleted_term);
// Load terms from the vocabulary by vid.
2009-04-02 20:39:45 +00:00
$terms4 = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid));
2008-12-05 22:18:46 +00:00
$this->assertTrue(count($terms4 == 4), t('Correct number of terms were loaded.'));
$this->assertFalse(isset($terms4[$deleted->tid]));
2008-12-19 15:34:27 +00:00
// Create a single term and load it by name.
$term = $this->createTerm($vocabulary->vid);
$loaded_terms = taxonomy_term_load_multiple(array(), array('name' => $term->name));
$this->assertEqual(count($loaded_terms), 1, t('One term was loaded'));
$loaded_term = reset($loaded_terms);
$this->assertEqual($term->tid, $loaded_term->tid, t('Term loaded by name successfully.'));
2008-12-05 22:18:46 +00:00
}
}
2009-01-22 18:25:59 +00:00
/**
* Tests for taxonomy hook invocation.
*/
class TaxonomyHooksTestCase extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-01-22 18:25:59 +00:00
return array(
'name' => t('Taxonomy term hooks'),
'description' => t('Hooks for taxonomy term load/save/delete.'),
'group' => t('Taxonomy')
);
}
function setUp() {
parent::setUp('taxonomy', 'taxonomy_test');
$taxonomy_admin = $this->drupalCreateUser(array('administer taxonomy'));
$this->drupalLogin($taxonomy_admin);
}
/**
* Test that hooks are run correctly on creating, editing and deleting a term.
*/
function testTaxonomyTermHooks() {
// Create a taxonomy vocabulary.
$edit = array(
'name' => $this->randomName(),
);
$this->drupalPost('admin/content/taxonomy/add', $edit, t('Save'));
// Create a term with one antonym.
$edit = array(
'name' => $this->randomName(),
'antonyms' => 'Long',
);
$this->drupalPost('admin/content/taxonomy/1/add', $edit, t('Save'));
$terms = taxonomy_get_term_by_name($edit['name']);
$term = taxonomy_term_load($terms[0]->tid);
$this->assertEqual($term->antonyms[0], $edit['antonyms'], t('Antonyms were loaded into the term object'));
// Update the term with a different antonym.
$edit = array(
'name' => $this->randomName(),
'antonyms' => 'Short',
);
$this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save'));
2009-04-02 20:39:45 +00:00
taxonomy_terms_static_reset();
$term = taxonomy_term_load($term->tid);
2009-01-22 18:25:59 +00:00
$this->assertTrue(in_array($edit['antonyms'], $term->antonyms), t('Antonym was successfully edited'));
// Delete the term.
taxonomy_term_delete($term->tid);
$antonyms = db_query('SELECT taid FROM {term_antonym} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField();
$this->assertFalse($antonyms, t('The antonyms were deleted from the database.'));
}
}