- <?php
- * @file
- * Tests for taxonomy.module.
- */
-
- * Provides common helper methods for Taxonomy module tests.
- */
- class TaxonomyWebTestCase extends BackdropWebTestCase {
-
-
- * Returns a new vocabulary with random properties.
- */
- function createVocabulary() {
-
- $vocabulary = new TaxonomyVocabulary(array(
- 'name' => $this->randomName(),
- 'description' => $this->randomName(),
- 'machine_name' => backdrop_strtolower($this->randomName()),
- 'weight' => mt_rand(0, 10),
- ));
- taxonomy_vocabulary_save($vocabulary);
- return $vocabulary;
- }
-
-
- * Returns a new term with random properties in the given vocabulary.
- */
- function createTerm($vocabulary) {
- $term = entity_create('taxonomy_term', array(
- 'name' => $this->randomName(),
- 'description' => $this->randomName(),
- 'format' => filter_default_format(),
- 'vocabulary' => $vocabulary->machine_name,
- 'langcode' => LANGUAGE_NONE,
- ));
- taxonomy_term_save($term);
- return $term;
- }
-
- }
-
- * Tests the taxonomy vocabulary interface.
- */
- class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp();
- $this->admin_user = $this->backdropCreateUser(array('administer taxonomy'));
- $this->backdropLogin($this->admin_user);
- $this->vocabulary = $this->createVocabulary();
- }
-
-
- * Create, configure and delete a vocabulary via the user interface.
- */
- function testVocabularyInterface() {
-
- $this->backdropGet('admin/structure/taxonomy');
-
-
- $this->clickLink(t('Add vocabulary'));
- $edit = array();
- $machine_name = backdrop_strtolower($this->randomName());
- $edit['name'] = $this->randomName();
- $edit['description'] = $this->randomName();
- $edit['machine_name'] = $machine_name;
- $this->backdropPost(NULL, $edit, t('Save and add terms'));
- $this->assertRaw(t('Created new vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary created successfully.');
- $this->assertRaw(t('Add term'), 'Redirected to add term form');
-
-
- $this->backdropGet('admin/structure/taxonomy');
- $this->clickLink(t('Add vocabulary'));
- $edit = array();
- $machine_name = backdrop_strtolower($this->randomName());
- $edit['name'] = $this->randomName();
- $edit['description'] = $this->randomName();
- $edit['machine_name'] = $machine_name;
- $this->backdropPost(NULL, $edit, t('Save vocabulary'));
- $this->assertRaw(t('Created new vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary created successfully.');
- $this->assertRaw(t('Add vocabulary'), 'Redirected to vocabulary listing page');
-
-
- $this->backdropGet('admin/structure/taxonomy');
- $this->assertText($edit['name'], 'Vocabulary found in the vocabulary overview listing.');
- $this->clickLink(t('Configure'));
- $edit = array();
- $edit['name'] = $this->randomName();
- $this->backdropPost(NULL, $edit, t('Save vocabulary'));
- $this->backdropGet('admin/structure/taxonomy');
- $this->assertText($edit['name'], 'Vocabulary found in the vocabulary overview listing.');
-
-
- $edit['machine_name'] = $machine_name;
- $this->backdropPost('admin/structure/taxonomy/add', $edit, t('Save vocabulary'));
- $this->assertText(t('The machine-readable name is already in use. It must be unique.'));
-
-
- $edit['machine_name'] = '!&^%';
- $this->backdropPost('admin/structure/taxonomy/add', $edit, t('Save vocabulary'));
- $this->assertText(t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
-
-
- $edit = array();
- $edit['name'] = 'Don\'t Panic';
- $edit['description'] = $this->randomName();
- $edit['machine_name'] = 'don_t_panic';
- $this->backdropPost('admin/structure/taxonomy/add', $edit, t('Save vocabulary'));
-
- $site_name = config_get('system.core', 'site_name');
- $this->backdropGet('admin/structure/taxonomy/don_t_panic');
- $this->assertTitle(t('Don\'t Panic | @site-name', array('@site-name' => $site_name)));
- $this->assertNoTitle(t('Don't Panic | @site-name', array('@site-name' => $site_name)));
-
-
- $vocabulary = $this->createVocabulary();
- $this->backdropGet('admin/structure/taxonomy');
- $this->assertText($vocabulary->name, 'Vocabulary created.');
- $this->assertText('0', 'Vocabulary has term count of zero.');
- $this->createTerm($vocabulary);
- $this->backdropGet('admin/structure/taxonomy');
- $this->assertText('1', 'Vocabulary has term count of one.');
- $this->createTerm($vocabulary);
- $this->backdropGet('admin/structure/taxonomy');
- $this->assertText('2', 'Vocabulary has term count of two.');
- }
-
-
- * Tests that vocabulary permissions are correctly set from the Taxonomy UI.
- */
- function testVocabularyPermissions() {
-
- $admin_user = $this->backdropCreateUser(array(
- 'administer taxonomy',
- 'administer permissions',
- 'assign roles',
- 'administer users',
- 'access user profiles',
- ));
- $this->backdropLogin($admin_user);
-
-
- $role_name = $this->backdropCreateRole(array('access content'));
- $web_user = $this->backdropCreateUser();
-
-
- $this->backdropPost('user/' . $web_user->uid . '/edit', array("roles[$role_name]" => $role_name), t('Save'));
-
-
- $this->backdropGet('admin/structure/taxonomy/tags/configure');
- $this->assertText($role_name, "$role_name is found on vocabulary form.");
-
-
- $this->assertFieldByName($role_name . '[edit terms in tags]', 'edit terms in tags', "Role $role_name does not have edit terms in tags permission.");
-
-
- $edit = array(
- $role_name . '[edit terms in tags]' => TRUE,
- );
- $this->backdropPost('admin/structure/taxonomy/tags/configure', $edit, t('Save vocabulary'));
-
-
- $this->backdropGet('admin/config/people/permissions');
- $this->assertFieldByName($role_name . '[edit terms in tags]', 'edit terms in tags', "Role $role_name has edit terms in tags permission.");
-
-
- $this->assertFieldByName($role_name . '[delete terms in tags]', 'delete terms in tags', "Role $role_name does not have delete terms in tags permission.");
-
-
- $edit = array(
- $role_name . '[delete terms in tags]' => TRUE,
- );
- $this->backdropPost('admin/config/people/permissions', $edit, t('Save permissions'));
-
-
- $this->backdropGet('admin/structure/taxonomy/tags/configure');
- $this->assertFieldByName($role_name . '[delete terms in tags]', 'delete terms in tags', "Role $role_name has delete terms in tags permission.");
-
-
- $this->backdropLogin($web_user);
- backdrop_static_reset('user_roles');
- backdrop_static_reset('user_access');
-
- $account = user_load($web_user->uid, TRUE);
- $this->assertTrue(user_access('edit terms in tags', $account), "Web user has edit terms in tags permission.");
- $this->assertTrue(user_access('delete terms in tags', $account), "Web user has delete terms in tags permission.");
-
- $vocabulary = taxonomy_vocabulary_load('tags');
- $this->createTerm($vocabulary);
- $this->createTerm($vocabulary);
- $this->backdropGet('admin/structure/taxonomy/tags');
- $this->assertText(t('Edit'), "Edit action is found on vocabulary form.");
- $this->assertText(t('Delete'), "Delete action is found on vocabulary form.");
- $this->assertNoText(t('Add term'), "Add term link found on vocabulary form.");
- $this->assertText(t('Weight for added term'), 'Weight visible on term listing page.');
-
-
- $this->backdropLogin($admin_user);
- backdrop_static_reset('user_roles');
- backdrop_static_reset('user_access');
-
- $edit = array(
- $role_name . '[create terms in tags]' => TRUE,
- );
- $this->backdropPost('admin/config/people/permissions', $edit, t('Save permissions'));
-
-
- $this->backdropLogin($web_user);
- backdrop_static_reset('user_roles');
- backdrop_static_reset('user_access');
-
- $this->backdropGet('admin/structure/taxonomy/tags');
- $this->assertText(t('Add term'), "Add term link found on vocabulary form.");
- }
-
-
- * Test the vocabulary overview with no vocabularies.
- */
- function testTaxonomyAdminNoVocabularies() {
-
- $vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
- foreach ($vocabularies as $key => $vocabulary) {
- taxonomy_vocabulary_delete($key);
- }
-
- $this->assertFalse(taxonomy_vocabulary_load_multiple(FALSE), 'No vocabularies found in the database.');
- $this->backdropGet('admin/structure/taxonomy');
-
- $this->assertText(t('No vocabularies available.'), 'No vocabularies were found.');
- }
-
-
- * Deleting a vocabulary.
- */
- function testTaxonomyAdminDeletingVocabulary() {
-
- $vocabulary_name = backdrop_strtolower($this->randomName());
- $edit = array(
- 'name' => $this->randomName(),
- 'machine_name' => $vocabulary_name,
- );
- $this->backdropPost('admin/structure/taxonomy/add', $edit, t('Save vocabulary'));
- $this->assertText(t('Created new vocabulary'), 'New vocabulary was created.');
-
-
- backdrop_static_reset('taxonomy_vocabulary_load_multiple');
- $vocabulary = taxonomy_vocabulary_load($vocabulary_name);
- $this->assertTrue($vocabulary, 'Vocabulary found in database.');
-
-
- $this->backdropPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/delete', NULL, t('Delete'));
- $this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->name)), 'Vocabulary deleted.');
- backdrop_static_reset('taxonomy_vocabulary_load_multiple');
- $this->assertFalse(taxonomy_vocabulary_load($vocabulary_name), 'Vocabulary is not found in config.');
- }
- }
-
-
- * Tests for taxonomy vocabulary functions.
- */
- class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp('taxonomy', 'field_test');
- $admin_user = $this->backdropCreateUser(array('create post content', 'administer taxonomy'));
- $this->backdropLogin($admin_user);
- $this->vocabulary = $this->createVocabulary();
- }
-
-
- * Test deleting a taxonomy that contains terms.
- */
- function testTaxonomyVocabularyDeleteWithTerms() {
-
- foreach (taxonomy_vocabulary_load_multiple(FALSE) as $vocabulary) {
- taxonomy_vocabulary_delete($vocabulary->machine_name);
- }
-
-
- $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField());
-
-
- $vocabulary = $this->createVocabulary();
- $terms = array();
- for ($i = 0; $i < 5; $i++) {
- $terms[$i] = $this->createTerm($vocabulary);
- }
-
-
- $terms[2]->parent = array($terms[1]->tid);
- taxonomy_term_save($terms[2]);
- $terms[4]->parent = array($terms[1]->tid, $terms[2]->tid);
- taxonomy_term_save($terms[4]);
-
-
- $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField());
-
- taxonomy_vocabulary_delete($vocabulary->machine_name);
-
-
- $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField());
- }
-
-
- * Ensure that the vocabulary static reset works correctly.
- */
- function testTaxonomyVocabularyLoadStaticReset() {
- $original_vocabulary = taxonomy_vocabulary_load($this->vocabulary->machine_name);
- $this->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.');
- $this->assertEqual($this->vocabulary->name, $original_vocabulary->name, 'Vocabulary loaded successfully.');
-
-
- $vocabulary = $original_vocabulary;
- $vocabulary->name = $this->randomName();
- $vocabulary->description = $this->randomName();
- taxonomy_vocabulary_save($vocabulary);
-
-
- $new_vocabulary = taxonomy_vocabulary_load($original_vocabulary->machine_name);
- $this->assertEqual($new_vocabulary->name, $vocabulary->name);
- $this->assertEqual($new_vocabulary->name, $vocabulary->name);
-
-
- taxonomy_vocabulary_delete($this->vocabulary->machine_name);
- $vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
- $this->assertTrue(!isset($vocabularies[$this->vocabulary->machine_name]), 'The vocabulary was deleted.');
- }
-
-
- * Tests for loading multiple vocabularies.
- */
- function testTaxonomyVocabularyLoadMultiple() {
-
-
- foreach (taxonomy_vocabulary_load_multiple(FALSE) as $vocabulary) {
- taxonomy_vocabulary_delete($vocabulary->machine_name);
- }
-
-
- $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);
-
-
-
- $vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
- $this->assertEqual($vocabularies[$vocabulary1->machine_name]->name, $vocabulary1->name, 'Vocabulary 1 name found.');
-
-
-
- $this->assertEqual(array_shift($vocabularies)->machine_name, $vocabulary1->machine_name, 'Vocabulary was found in the vocabularies array.');
- $this->assertEqual(array_shift($vocabularies)->machine_name, $vocabulary2->machine_name, 'Vocabulary was found in the vocabularies array.');
- $this->assertEqual(array_shift($vocabularies)->machine_name, $vocabulary3->machine_name, 'Vocabulary was found in the vocabularies array.');
- }
-
-
- * Test uninstall and reinstall of the taxonomy module.
- */
- function testUninstallReinstall() {
-
-
- $this->field_name = backdrop_strtolower($this->randomName() . '_field_name');
- $this->field = array('field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4);
- $this->field = field_create_field($this->field);
- $this->instance = array(
- 'field_name' => $this->field_name,
- 'entity_type' => 'taxonomy_term',
- 'bundle' => $this->vocabulary->machine_name,
- 'label' => $this->randomName() . '_label',
- );
- field_create_instance($this->instance);
-
- module_disable(array('taxonomy'));
- require_once BACKDROP_ROOT . '/core/includes/install.inc';
- backdrop_uninstall_modules(array('taxonomy'));
- module_enable(array('taxonomy'));
-
-
-
-
-
- taxonomy_vocabulary_save($this->vocabulary);
- unset($this->field['id']);
- field_create_field($this->field);
- field_create_instance($this->instance);
- }
-
- }
-
- * Unit tests for taxonomy term functions.
- */
- class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
- function testTermDelete() {
- $vocabulary = $this->createVocabulary();
- $valid_term = $this->createTerm($vocabulary);
-
- taxonomy_term_delete($valid_term->tid);
- $terms = taxonomy_term_load_multiple(array(), array('vocabulary' => $vocabulary->machine_name));
- $this->assertTrue(empty($terms), 'Vocabulary is empty after deletion.');
-
-
- taxonomy_term_delete(42);
- }
-
-
- * Test a taxonomy with terms that have multiple parents of different depths.
- */
- function testTaxonomyVocabularyTree() {
-
- $vocabulary = $this->createVocabulary();
- $term = array();
- for ($i = 0; $i < 6; $i++) {
- $term[$i] = $this->createTerm($vocabulary);
- }
-
-
- $term[2]->parent = array($term[1]->tid, $term[5]->tid);
- taxonomy_term_save($term[2]);
-
- $term[3]->parent = array($term[2]->tid);
- taxonomy_term_save($term[3]);
-
- $term[5]->parent = array($term[4]->tid);
- taxonomy_term_save($term[5]);
-
-
- * Expected tree:
- * term[0] | depth: 0
- * term[1] | depth: 0
- * -- term[2] | depth: 1
- * ---- term[3] | depth: 2
- * term[4] | depth: 0
- * -- term[5] | depth: 1
- * ---- term[2] | depth: 2
- * ------ term[3] | depth: 3
- */
-
- $tree = taxonomy_get_tree($vocabulary->machine_name, $term[1]->tid, 1);
- $this->assertEqual(1, count($tree), 'We have one parent with depth 1.');
-
-
- $tree = taxonomy_get_tree($vocabulary->machine_name);
- $this->assertEqual(8, count($tree), 'We have all vocabulary tree elements.');
-
-
- foreach ($tree as $element) {
- if (!isset($depth_count[$element->depth])) {
- $depth_count[$element->depth] = 0;
- }
- $depth_count[$element->depth]++;
- }
- $this->assertEqual(3, $depth_count[0], 'Three elements in taxonomy tree depth 0.');
- $this->assertEqual(2, $depth_count[1], 'Two elements in taxonomy tree depth 1.');
- $this->assertEqual(2, $depth_count[2], 'Two elements in taxonomy tree depth 2.');
- $this->assertEqual(1, $depth_count[3], 'One element in taxonomy tree depth 3.');
- }
-
- }
-
- * Test for legacy node bug.
- */
- class TaxonomyLegacyTestCase extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp('taxonomy');
- $this->admin_user = $this->backdropCreateUser(array('administer taxonomy', 'administer nodes', 'bypass node access'));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Test taxonomy functionality with nodes prior to 1970.
- */
- function testTaxonomyLegacyNode() {
-
- $langcode = LANGUAGE_NONE;
- $edit = array();
- $edit['title'] = $this->randomName();
- $edit['date[date]'] = '1969-01-01';
- $edit['date[time]'] = '00:00:00';
- $edit["body[$langcode][0][value]"] = $this->randomName();
- $edit["field_tags[$langcode]"] = $this->randomName();
- $this->backdropPost('node/add/post', $edit, t('Save'));
-
- $node = $this->backdropGetNodeByTitle($edit['title']);
- $date = new BackdropDateTime('1969-01-01 00:00:00', $this->admin_user->timezone);
- $this->assertEqual($node->created, $date->format('U'), 'Legacy node was saved with the right date.');
- }
-
- }
-
- * Tests for taxonomy term functions.
- */
- class TaxonomyTermTestCase extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp('taxonomy');
- $this->admin_user = $this->backdropCreateUser(array('administer taxonomy', 'bypass node access'));
- $this->backdropLogin($this->admin_user);
- $this->vocabulary = $this->createVocabulary();
-
- $field = array(
- 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
- 'type' => 'taxonomy_term_reference',
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => 0,
- ),
- ),
- ),
- );
- field_create_field($field);
-
- $this->instance = array(
- 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
- 'bundle' => 'post',
- 'entity_type' => 'node',
- 'widget' => array(
- 'type' => 'options_select',
- ),
- 'display' => array(
- 'default' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance);
- }
-
-
- * Test terms in a single and multiple hierarchy.
- */
- function testTaxonomyTermHierarchy() {
-
- $term1 = $this->createTerm($this->vocabulary);
- $term2 = $this->createTerm($this->vocabulary);
-
-
- $vocabulary = taxonomy_vocabulary_load($this->vocabulary->machine_name);
- $this->assertEqual(0, $vocabulary->hierarchy, 'Vocabulary is flat.');
-
-
- $edit = array();
- $edit['parent[]'] = array($term1->tid);
- $this->backdropPost('taxonomy/term/' . $term2->tid . '/edit', $edit, t('Save'));
-
-
- $children = taxonomy_term_load_children($term1->tid);
- $parents = taxonomy_term_load_parents($term2->tid);
- $this->assertTrue(isset($children[$term2->tid]), 'Child found correctly.');
- $this->assertTrue(isset($parents[$term1->tid]), 'Parent found correctly.');
-
-
- $term = taxonomy_term_load($term2->tid);
- taxonomy_term_save($term);
- $parents = taxonomy_term_load_parents($term2->tid);
- $this->assertTrue(isset($parents[$term1->tid]), 'Parent found correctly.');
-
-
- $term3 = $this->createTerm($this->vocabulary);
- $term2->parent = array($term1->tid, $term3->tid);
- taxonomy_term_save($term2);
- $parents = taxonomy_term_load_parents($term2->tid);
- $this->assertTrue(isset($parents[$term1->tid]) && isset($parents[$term3->tid]), 'Both parents found successfully.');
- }
-
-
- * Test that hook_node_$op implementations work correctly.
- *
- * Save & edit a node and assert that taxonomy terms are saved/loaded properly.
- */
- function testTaxonomyNode() {
-
- $term1 = $this->createTerm($this->vocabulary);
- $term2 = $this->createTerm($this->vocabulary);
-
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName();
- $edit["body[$langcode][0][value]"] = $this->randomName();
- $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid;
- $this->backdropPost('node/add/post', $edit, t('Save'));
-
-
- $node = $this->backdropGetNodeByTitle($edit["title"]);
- $this->backdropGet('node/' . $node->nid);
- $this->assertText($term1->name, 'Term is displayed when viewing the node.');
-
-
- $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term2->tid;
- $this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));
-
- $this->backdropGet('node/' . $node->nid);
- $this->assertText($term2->name, 'Term is displayed when viewing the node.');
- }
-
-
- * Test term creation with a free-tagging vocabulary from the node form.
- */
- function testNodeTermCreationAndDeletion() {
-
- $instance = $this->instance;
- $instance['widget'] = array('type' => 'taxonomy_autocomplete');
- $instance['bundle'] = 'page';
- field_create_instance($instance);
- $terms = array(
- 'term1' => $this->randomName(),
- 'term2' => $this->randomName(),
- 'term3' => $this->randomName() . ', ' . $this->randomName(),
- 'term4' => $this->randomName(),
- );
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName();
- $edit["body[$langcode][0][value]"] = $this->randomName();
-
-
- $edit[$instance['field_name'] . "[$langcode]"] = backdrop_implode_tags($terms);
-
-
- backdrop_static_reset();
-
-
- $this->backdropPost('node/add/page', $edit, t('Save'));
- $this->assertRaw(t('@type %title has been created.', array('@type' => t('Page'), '%title' => $edit["title"])), 'The node was created successfully.');
- foreach ($terms as $term) {
- $this->assertText($term, 'The term was saved and appears on the node page.');
- }
-
-
- $term_objects = array();
- foreach ($terms as $key => $term) {
- $term_objects[$key] = taxonomy_term_load_multiple_by_name($term);
- $term_objects[$key] = reset($term_objects[$key]);
- }
-
-
- $node = $this->backdropGetNodeByTitle($edit["title"]);
- $this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- foreach ($terms as $term) {
- $this->assertText($term, 'The term was retained after edit and still appears on the node page.');
- }
-
-
- $this->backdropPost('taxonomy/term/' . $term_objects['term1']->tid . '/edit', array(), t('Delete'));
- $this->backdropPost(NULL, NULL, t('Delete'));
-
-
- $this->backdropPost('taxonomy/term/' . $term_objects['term2']->tid . '/delete', array(), t('Delete'));
- $term_names = array($term_objects['term3']->name, $term_objects['term4']->name);
-
-
- $this->backdropGet('node/' . $node->nid);
-
- foreach ($term_names as $term_name) {
- $this->assertText($term_name, format_string('The term %name appears on the node page after one term %deleted was deleted', array('%name' => $term_name, '%deleted' => $term_objects['term1']->name)));
- }
- $this->assertNoText($term_objects['term1']->name, format_string('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term1']->name)));
- $this->assertNoText($term_objects['term2']->name, format_string('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term2']->name)));
-
-
-
- $input = substr($term_objects['term3']->name, 0, 3);
- $this->backdropGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input);
- $this->assertRaw('{"\u0022' . $term_objects['term3']->name . '\u0022":"' . $term_objects['term3']->name . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->name)));
-
-
-
- $input = substr($term_objects['term4']->name, 0, 3);
- $this->backdropGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input);
- $this->assertRaw('{"' . $term_objects['term4']->name . '":"' . $term_objects['term4']->name . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->name)));
-
-
- $field_name = $this->randomName();
- $tag = $this->randomName();
- $message = t("Taxonomy field @field_name not found.", array('@field_name' => $field_name));
- $this->assertFalse(field_info_field($field_name), format_string('Field %field_name does not exist.', array('%field_name' => $field_name)));
- $this->backdropGet('taxonomy/autocomplete/' . $field_name . '/' . $tag);
- $this->assertRaw($message, 'Autocomplete returns correct error message when the taxonomy field does not exist.');
-
-
-
- $field_name = '';
- $message = t("Taxonomy field @field_name not found.", array('@field_name' => $field_name));
- $this->backdropGet('taxonomy/autocomplete');
- $this->assertRaw($message, 'Autocomplete returns correct error message when no taxonomy field is given.');
- }
-
-
- * Save, edit and delete a term using the user interface.
- */
- function testTermInterface() {
- $edit = array(
- 'name' => $this->randomName(12),
- 'description[value]' => $this->randomName(100),
- );
-
-
- $edit['parent[]'] = array(0);
-
-
- $this->backdropPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add', $edit, t('Save'));
-
- $terms = taxonomy_term_load_multiple_by_name($edit['name']);
- $term = reset($terms);
- $this->assertNotNull($term, 'Term found in database.');
-
-
- $this->backdropGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name);
-
-
-
-
- $this->clickLink(t('Edit'), 0);
-
- $this->assertRaw($edit['name'], 'The randomly generated term name is present.');
- $this->assertText($edit['description[value]'], 'The randomly generated term description is present.');
-
- $edit = array(
- 'name' => $this->randomName(14),
- 'description[value]' => $this->randomName(102),
- );
-
-
- $this->backdropPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save'));
-
-
- $this->backdropGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name);
- $this->assertText($edit['name'], 'The randomly generated term name is present.');
- $this->assertLink(t('Edit'));
-
-
- $this->backdropGet('taxonomy/term/' . $term->tid);
- $this->assertText($edit['name'], 'The randomly generated term name is present.');
- $this->assertText($edit['description[value]'], 'The randomly generated term description is present.');
-
-
- $this->assertPattern('|class="taxonomy-term-description"|', 'Term page displayed the term description element.');
-
- $term->description = '';
- taxonomy_term_save($term);
- $this->backdropGet('taxonomy/term/' . $term->tid);
- $this->assertNoPattern('|class="taxonomy-term-description"|', 'Term page did not display the term description when description was blank.');
-
-
- $this->backdropGet('taxonomy/term/' . $term->tid . '/feed');
-
-
-
- $this->backdropGet('taxonomy/term/' . $term->tid . '/edit/' . $this->randomName());
-
-
- $this->backdropPost('taxonomy/term/' . $term->tid . '/edit', array(), t('Delete'));
- $this->backdropPost(NULL, NULL, t('Delete'));
-
-
- $this->backdropGet('taxonomy/term/' . $term->tid);
- $this->assertResponse(404, 'The taxonomy term page was not found.');
- }
-
-
- * Save, edit and delete a term using the user interface.
- */
- function testTermReorder() {
- $this->createTerm($this->vocabulary);
- $this->createTerm($this->vocabulary);
- $this->createTerm($this->vocabulary);
-
-
-
- backdrop_static_reset('taxonomy_get_tree');
- backdrop_static_reset('taxonomy_get_treeparent');
- backdrop_static_reset('taxonomy_get_treeterms');
- list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->machine_name);
-
- $this->backdropGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name);
-
-
-
-
-
- $edit = array(
- 'tid:' . $term2->tid . ':0[tid]' => $term2->tid,
- 'tid:' . $term2->tid . ':0[parent]' => 0,
- 'tid:' . $term2->tid . ':0[depth]' => 0,
- 'tid:' . $term2->tid . ':0[weight]' => 0,
- 'tid:' . $term3->tid . ':0[tid]' => $term3->tid,
- 'tid:' . $term3->tid . ':0[parent]' => $term2->tid,
- 'tid:' . $term3->tid . ':0[depth]' => 1,
- 'tid:' . $term3->tid . ':0[weight]' => 1,
- 'tid:' . $term1->tid . ':0[tid]' => $term1->tid,
- 'tid:' . $term1->tid . ':0[parent]' => 0,
- 'tid:' . $term1->tid . ':0[depth]' => 0,
- 'tid:' . $term1->tid . ':0[weight]' => 2,
- );
- $this->backdropPost(NULL, $edit, t('Save'));
-
- backdrop_static_reset('taxonomy_get_tree');
- backdrop_static_reset('taxonomy_get_treeparent');
- backdrop_static_reset('taxonomy_get_treeterms');
- $terms = taxonomy_get_tree($this->vocabulary->machine_name);
- $this->assertEqual($terms[0]->tid, $term2->tid, 'Term 2 was moved above term 1.');
- $this->assertEqual($terms[1]->parents, array($term2->tid), 'Term 3 was made a child of term 2.');
- $this->assertEqual($terms[2]->tid, $term1->tid, 'Term 1 was moved below term 2.');
-
- $this->backdropPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name, array(), t('Reset to alphabetical'));
-
- $this->backdropPost(NULL, array(), t('Reset to alphabetical'));
-
- backdrop_static_reset('taxonomy_get_tree');
- backdrop_static_reset('taxonomy_get_treeparent');
- backdrop_static_reset('taxonomy_get_treeterms');
- $terms = taxonomy_get_tree($this->vocabulary->machine_name);
- $this->assertEqual($terms[0]->tid, $term1->tid, 'Term 1 was moved to back above term 2.');
- $this->assertEqual($terms[1]->tid, $term2->tid, 'Term 2 was moved to back below term 1.');
- $this->assertEqual($terms[2]->tid, $term3->tid, 'Term 3 is still below term 2.');
- $this->assertEqual($terms[2]->parents, array($term2->tid), 'Term 3 is still a child of term 2.' . var_export($terms[1]->tid, 1));
- }
-
-
- * Test saving a term with multiple parents through the UI.
- */
- function testTermMultipleParentsInterface() {
-
- $parent = $this->createTerm($this->vocabulary);
-
-
- $edit = array(
- 'name' => $this->randomName(12),
- 'description[value]' => $this->randomName(100),
- 'parent[]' => array(0, $parent->tid),
- );
-
- $this->backdropPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add', $edit, t('Save'));
-
-
- $terms = taxonomy_term_load_multiple_by_name($edit['name']);
- $term = reset($terms);
- $this->assertNotNull($term, 'Term found in database.');
- $this->assertEqual($edit['name'], $term->name, 'Term name was successfully saved.');
- $this->assertEqual($edit['description[value]'], $term->description, 'Term description was successfully saved.');
-
-
- $parents = taxonomy_term_load_parents($term->tid);
- $parent = reset($parents);
- $this->assertEqual($edit['parent[]'][1], $parent->tid, 'Term parents were successfully saved.');
- }
-
-
- * Test taxonomy_term_load_multiple_by_name().
- */
- function testTaxonomyGetTermByName() {
- $term = $this->createTerm($this->vocabulary);
-
-
- $terms = taxonomy_term_load_multiple_by_name($term->name);
- $this->assertTrue(isset($terms[$term->tid]), 'Term loaded using exact name.');
-
-
- $terms = taxonomy_term_load_multiple_by_name(' ' . $term->name . ' ');
- $this->assertTrue(isset($terms[$term->tid]), 'Term loaded with extra whitespace.');
-
-
- $terms = taxonomy_term_load_multiple_by_name(strtoupper($term->name));
- $this->assertTrue(isset($terms[$term->tid]), 'Term loaded with uppercased name.');
-
-
- $terms = taxonomy_term_load_multiple_by_name(strtolower($term->name));
- $this->assertTrue(isset($terms[$term->tid]), 'Term loaded with lowercased name.');
-
-
- $terms = taxonomy_term_load_multiple_by_name('Banana');
- $this->assertFalse($terms);
-
-
- $terms = taxonomy_term_load_multiple_by_name(backdrop_substr($term->name, 2));
- $this->assertFalse($terms);
-
-
- $new_vocabulary = $this->createVocabulary();
- $new_term = entity_create('taxonomy_term', array(
- 'name' => $term->name,
- 'vocabulary' => $new_vocabulary->machine_name,
- ));
- taxonomy_term_save($new_term);
-
-
- $terms = taxonomy_term_load_multiple_by_name($term->name);
- $this->assertEqual(count($terms), 2, 'Two terms loaded with the same name.');
-
-
- $terms = taxonomy_term_load_multiple_by_name($term->name, $this->vocabulary->machine_name);
- $this->assertEqual(count($terms), 1, 'One term loaded when restricted by vocabulary.');
- $this->assertTrue(isset($terms[$term->tid]), 'Term loaded using exact name and vocabulary machine name.');
-
-
- $term2 = $this->createTerm($this->vocabulary);
-
-
-
- $terms = taxonomy_term_load_multiple_by_name($term2->name, $new_vocabulary->machine_name);
- $this->assertFalse($terms, 'Invalid term name restricted by vocabulary machine name not loaded.');
-
-
- $terms = taxonomy_term_load_multiple_by_name($term2->name, 'non_existing_vocabulary');
- $this->assertEqual(count($terms), 0, 'No terms loaded when restricted by a non-existing vocabulary.');
- }
- }
-
- * Tests the rendering of term reference fields in RSS feeds.
- */
- class TaxonomyRSSTestCase extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp('taxonomy');
- $this->admin_user = $this->backdropCreateUser(array('administer taxonomy', 'bypass node access', 'administer content types', 'administer fields', 'administer view modes'));
- $this->backdropLogin($this->admin_user);
- $this->vocabulary = $this->createVocabulary();
-
- $field = array(
- 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
- 'type' => 'taxonomy_term_reference',
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => 0,
- ),
- ),
- ),
- );
- field_create_field($field);
-
- $this->instance = array(
- 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
- 'bundle' => 'post',
- 'entity_type' => 'node',
- 'widget' => array(
- 'type' => 'options_select',
- ),
- 'display' => array(
- 'default' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance);
- }
-
-
- * Tests that terms added to nodes are displayed in core RSS feed.
- *
- * Create a node and assert that taxonomy terms appear in rss.xml.
- */
- function testTaxonomyRSS() {
-
- $term1 = $this->createTerm($this->vocabulary);
-
-
- $this->backdropGet("admin/structure/types/manage/post/display");
- list($enable_link) = $this->xpath('//tr[contains(@class, "view-mode--rss")]//a');
- $enable_href_parts = backdrop_parse_url($enable_link['href']);
- $this->backdropGet($enable_href_parts['path'], $enable_href_parts);
-
-
- $this->backdropGet("admin/structure/types/manage/post/display/rss");
- $edit = array(
- "fields[taxonomy_" . $this->vocabulary->machine_name . "][type]" => 'taxonomy_term_reference_rss_category',
- );
- $this->backdropPost(NULL, $edit, t('Save'));
-
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName();
- $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid;
- $this->backdropPost('node/add/post', $edit, t('Save'));
-
-
- $this->backdropGet('rss.xml');
- $test_element = array(
- 'key' => 'category',
- 'value' => $term1->name,
- 'attributes' => array(
- 'domain' => url('taxonomy/term/' . $term1->tid, array('absolute' => TRUE)),
- ),
- );
- $this->assertRaw(format_xml_elements(array($test_element)), 'Term is displayed when viewing the rss feed.');
- }
-
- }
-
- * Tests the hook implementations that maintain the taxonomy index.
- */
- class TaxonomyTermIndexTestCase extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp('taxonomy');
-
-
- $this->admin_user = $this->backdropCreateUser(array('administer taxonomy', 'bypass node access'));
- $this->backdropLogin($this->admin_user);
-
-
- $this->vocabulary = $this->createVocabulary();
-
- $this->field_name_1 = backdrop_strtolower($this->randomName());
- $this->field_1 = array(
- 'field_name' => $this->field_name_1,
- 'type' => 'taxonomy_term_reference',
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => 0,
- ),
- ),
- ),
- );
- field_create_field($this->field_1);
- $this->instance_1 = array(
- 'field_name' => $this->field_name_1,
- 'bundle' => 'post',
- 'entity_type' => 'node',
- 'widget' => array(
- 'type' => 'options_select',
- ),
- 'display' => array(
- 'default' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance_1);
-
- $this->field_name_2 = backdrop_strtolower($this->randomName());
- $this->field_2 = array(
- 'field_name' => $this->field_name_2,
- 'type' => 'taxonomy_term_reference',
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => 0,
- ),
- ),
- ),
- );
- field_create_field($this->field_2);
- $this->instance_2 = array(
- 'field_name' => $this->field_name_2,
- 'bundle' => 'post',
- 'entity_type' => 'node',
- 'widget' => array(
- 'type' => 'options_select',
- ),
- 'display' => array(
- 'default' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance_2);
- }
-
-
- * Tests that the taxonomy index is maintained properly.
- */
- function testTaxonomyIndex() {
-
- $term_1 = $this->createTerm($this->vocabulary);
- $term_2 = $this->createTerm($this->vocabulary);
-
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName();
- $edit["body[$langcode][0][value]"] = $this->randomName();
- $edit["{$this->field_name_1}[$langcode][]"] = $term_1->tid;
- $edit["{$this->field_name_2}[$langcode][]"] = $term_1->tid;
- $this->backdropPost('node/add/post', $edit, t('Save'));
-
-
- $node = $this->backdropGetNodeByTitle($edit["title"]);
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_1->tid,
- ))->fetchField();
- $this->assertEqual(1, $index_count, 'Term 1 is indexed once.');
-
-
- $edit["{$this->field_name_1}[$langcode][]"] = $term_2->tid;
- $this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));
-
-
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_1->tid,
- ))->fetchField();
- $this->assertEqual(1, $index_count, 'Term 1 is indexed.');
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_2->tid,
- ))->fetchField();
- $this->assertEqual(1, $index_count, 'Term 2 is indexed.');
-
-
- $edit["{$this->field_name_2}[$langcode][]"] = $term_2->tid;
- $this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));
-
-
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_1->tid,
- ))->fetchField();
- $this->assertEqual(0, $index_count, 'Term 1 is not indexed.');
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_2->tid,
- ))->fetchField();
- $this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
-
-
- $node->title = $this->randomName();
- unset($node->{$this->field_name_1});
- unset($node->{$this->field_name_2});
-
-
- $node->save();
-
-
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_1->tid,
- ))->fetchField();
- $this->assertEqual(0, $index_count, 'Term 1 is not indexed.');
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_2->tid,
- ))->fetchField();
- $this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
-
-
- $node->{$this->field_name_1}[$langcode] = array(array('tid' => $term_1->tid));
- $node->save();
-
-
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_1->tid,
- ))->fetchField();
- $this->assertEqual(1, $index_count, 'Term 1 is indexed.');
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_2->tid,
- ))->fetchField();
- $this->assertEqual(1, $index_count, 'Term 2 is indexed.');
-
-
- $node->{$this->field_name_2}[$langcode] = array(array('tid' => $term_1->tid));
- $node->save();
-
-
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_1->tid,
- ))->fetchField();
- $this->assertEqual(1, $index_count, 'Term 1 is indexed once.');
- $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
- ':nid' => $node->nid,
- ':tid' => $term_2->tid,
- ))->fetchField();
- $this->assertEqual(0, $index_count, 'Term 2 is not indexed.');
- }
-
-
- * Tests that there is a link to the parent term on the child term page.
- */
- function testTaxonomyTermHierarchyBreadcrumbs() {
-
- $term1 = $this->createTerm($this->vocabulary);
- $term2 = $this->createTerm($this->vocabulary);
- $term1->parent = array($term2->tid);
- taxonomy_term_save($term1);
-
-
- $this->backdropGet('taxonomy/term/' . $term1->tid);
- $this->assertRaw(l($term2->name, 'taxonomy/term/' . $term2->tid), 'Parent term link is displayed when viewing the node.');
- }
-
- }
-
- * Test the taxonomy_term_load_multiple() function.
- */
- class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp();
- $this->taxonomy_admin = $this->backdropCreateUser(array('administer taxonomy'));
- $this->backdropLogin($this->taxonomy_admin);
- }
-
-
- * Create a vocabulary and some taxonomy terms, ensuring they're loaded
- * correctly using taxonomy_term_load_multiple().
- */
- function testTaxonomyTermMultipleLoad() {
-
- $vocabulary = $this->createVocabulary();
-
-
- $i = 0;
- while ($i < 5) {
- $i++;
- $this->createTerm($vocabulary);
- }
-
- $terms = taxonomy_term_load_multiple(NULL, array('vocabulary' => $vocabulary->machine_name));
- $count = count($terms);
- $this->assertEqual($count, 5, format_string('Correct number of terms were loaded. !count terms.', array('!count' => $count)));
-
-
- $terms2 = taxonomy_term_load_multiple(array_keys($terms));
- $this->assertEqual($count, count($terms2), 'Five terms were loaded by tid.');
- $this->assertEqual($terms, $terms2, 'Both arrays contain the same terms.');
-
-
- $terms3 = taxonomy_term_load_multiple(array_keys($terms2), array('vocabulary' => $vocabulary->machine_name));
- $this->assertEqual($terms2, $terms3, 'Same terms found when limiting load to vocabulary.');
-
-
- $deleted = array_shift($terms3);
- taxonomy_term_delete($deleted->tid);
- $deleted_term = taxonomy_term_load($deleted->tid);
- $this->assertFalse($deleted_term);
-
-
- $terms4 = taxonomy_term_load_multiple(NULL, array('vocabulary' => $vocabulary->machine_name));
- $this->assertEqual(count($terms4), 4, 'Correct number of terms were loaded.');
- $this->assertFalse(isset($terms4[$deleted->tid]));
-
-
- $term = $this->createTerm($vocabulary);
- $loaded_terms = taxonomy_term_load_multiple(array(), array('name' => $term->name));
- $this->assertEqual(count($loaded_terms), 1, 'One term was loaded.');
- $loaded_term = reset($loaded_terms);
- $this->assertEqual($term->tid, $loaded_term->tid, 'Term loaded by name successfully.');
- }
- }
-
- * Tests for taxonomy hook invocation.
- */
- class TaxonomyHooksTestCase extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp('taxonomy', 'taxonomy_test');
- module_load_include('inc', 'taxonomy', 'includes/taxonomy.pages');
- $taxonomy_admin = $this->backdropCreateUser(array('administer taxonomy'));
- $this->backdropLogin($taxonomy_admin);
- }
-
-
- * Test that hooks are run correctly on creating, editing, viewing,
- * and deleting a term.
- *
- * @see taxonomy_test.module
- */
- function testTaxonomyTermHooks() {
- $vocabulary = $this->createVocabulary();
-
-
- $edit = array(
- 'name' => $this->randomName(),
- 'antonym' => 'Long',
- );
- $this->backdropPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add', $edit, t('Save'));
- $terms = taxonomy_term_load_multiple_by_name($edit['name']);
- $term = reset($terms);
- $this->assertEqual($term->antonym, $edit['antonym'], 'Antonym was loaded into the term object.');
-
-
- $edit = array(
- 'name' => $this->randomName(),
- 'antonym' => 'Short',
- );
- $this->backdropPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save'));
- taxonomy_terms_static_reset();
- $term = taxonomy_term_load($term->tid);
- $this->assertEqual($edit['antonym'], $term->antonym, 'Antonym was successfully edited.');
-
-
-
- $term = taxonomy_term_load($term->tid);
- module_load_include('inc', 'taxonomy', 'taxonomy.pages');
- $term_build = taxonomy_term_page($term);
- $this->assertFalse(empty($term_build['term_heading']['term']['taxonomy_test_term_view_check']), 'hook_taxonomy_term_view() was invoked when viewing the term.');
- $this->assertFalse(empty($term_build['term_heading']['term']['taxonomy_test_entity_view_check']), 'hook_entity_view() was invoked when viewing the term.');
-
-
- taxonomy_term_delete($term->tid);
- $antonym = db_query('SELECT tid FROM {taxonomy_term_antonym} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField();
- $this->assertFalse($antonym, 'The antonym were deleted from the database.');
- }
- }
-
- * Tests for taxonomy term field and formatter.
- */
- class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase {
- protected $instance;
- protected $vocabulary;
-
- function setUp() {
- parent::setUp('field_test');
-
- $web_user = $this->backdropCreateUser(array('access field_test content', 'administer field_test content', 'administer taxonomy'));
- $this->backdropLogin($web_user);
- $this->vocabulary = $this->createVocabulary();
-
-
- $this->field_name = backdrop_strtolower($this->randomName());
- $this->field = array(
- 'field_name' => $this->field_name,
- 'type' => 'taxonomy_term_reference',
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => '0',
- ),
- ),
- )
- );
- field_create_field($this->field);
- $this->instance = array(
- 'field_name' => $this->field_name,
- 'entity_type' => 'test_entity',
- 'bundle' => 'test_bundle',
- 'widget' => array(
- 'type' => 'options_select',
- ),
- 'display' => array(
- 'full' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance);
- }
-
-
- * Test term field validation.
- */
- function testTaxonomyTermFieldValidation() {
-
- $langcode = LANGUAGE_NONE;
- $entity = field_test_create_entity();
- $term = $this->createTerm($this->vocabulary);
- $entity->{$this->field_name}[$langcode][0]['tid'] = $term->tid;
- try {
- field_attach_validate('test_entity', $entity);
- $this->pass('Correct term does not cause validation error.');
- }
- catch (FieldValidationException $e) {
- $this->fail('Correct term does not cause validation error.');
- }
-
- $entity = field_test_create_entity();
- $bad_term = $this->createTerm($this->createVocabulary());
- $entity->{$this->field_name}[$langcode][0]['tid'] = $bad_term->tid;
- try {
- field_attach_validate('test_entity', $entity);
- $this->fail('Wrong term causes validation error.');
- }
- catch (FieldValidationException $e) {
- $this->pass('Wrong term causes validation error.');
- }
- }
-
-
- * Test widgets.
- */
- function testTaxonomyTermFieldWidgets() {
-
- $term = $this->createTerm($this->vocabulary);
-
-
- $langcode = LANGUAGE_NONE;
- $this->backdropGet('test-entity/add/test-bundle');
- $this->assertFieldByName("{$this->field_name}[$langcode]", '', 'Widget is displayed.');
-
-
- $edit = array(
- "{$this->field_name}[$langcode]" => array($term->tid),
- );
- $this->backdropPost(NULL, $edit, t('Save'));
- preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
- $id = $match[1];
- $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created.');
-
-
- $entity = field_test_entity_test_load($id);
- $entities = array($id => $entity);
- field_attach_prepare_view('test_entity', $entities, 'full');
- $entity->content = field_attach_view('test_entity', $entity, 'full');
- $this->content = backdrop_render($entity->content);
- $this->assertText($term->name, 'Term name is displayed.');
-
-
- taxonomy_vocabulary_delete($this->vocabulary->machine_name);
- $this->backdropGet('test-entity/add/test-bundle');
- $this->assertNoFieldByName("{$this->field_name}[$langcode]", '', 'Widget is not displayed.');
- }
- }
-
- * Tests a taxonomy term reference field that allows multiple vocabularies.
- */
- class TaxonomyTermFieldMultipleVocabularyTestCase extends TaxonomyWebTestCase {
- protected $instance;
- protected $vocabulary1;
- protected $vocabulary2;
-
- function setUp() {
- parent::setUp('field_test');
-
- $web_user = $this->backdropCreateUser(array('access field_test content', 'administer field_test content', 'administer taxonomy'));
- $this->backdropLogin($web_user);
- $this->vocabulary1 = $this->createVocabulary();
- $this->vocabulary2 = $this->createVocabulary();
-
-
- $this->field_name = backdrop_strtolower($this->randomName());
- $this->field = array(
- 'field_name' => $this->field_name,
- 'type' => 'taxonomy_term_reference',
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary1->machine_name,
- 'parent' => '0',
- ),
- array(
- 'vocabulary' => $this->vocabulary2->machine_name,
- 'parent' => '0',
- ),
- ),
- )
- );
- field_create_field($this->field);
- $this->instance = array(
- 'field_name' => $this->field_name,
- 'entity_type' => 'test_entity',
- 'bundle' => 'test_bundle',
- 'widget' => array(
- 'type' => 'options_select',
- ),
- 'display' => array(
- 'full' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance);
- }
-
-
- * Tests term reference field and widget with multiple vocabularies.
- */
- function testTaxonomyTermFieldMultipleVocabularies() {
-
- $term1 = $this->createTerm($this->vocabulary1);
- $term2 = $this->createTerm($this->vocabulary2);
-
-
- $langcode = LANGUAGE_NONE;
- $this->backdropGet('test-entity/add/test-bundle');
- $this->assertFieldByName("{$this->field_name}[$langcode][]", '', 'Widget is displayed.');
- $edit = array(
- "{$this->field_name}[$langcode][]" => array($term1->tid, $term2->tid),
- );
- $this->backdropPost(NULL, $edit, t('Save'));
- preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
- $id = $match[1];
- $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created.');
-
-
- $entity = field_test_entity_test_load($id);
- $entities = array($id => $entity);
- field_attach_prepare_view('test_entity', $entities, 'full');
- $entity->content = field_attach_view('test_entity', $entity, 'full');
- $this->content = backdrop_render($entity->content);
- $this->assertText($term1->name, 'Term 1 name is displayed.');
- $this->assertText($term2->name, 'Term 2 name is displayed.');
-
-
- taxonomy_vocabulary_delete($this->vocabulary2->machine_name);
-
-
- $entity = field_test_entity_test_load($id);
- $entities = array($id => $entity);
- field_attach_prepare_view('test_entity', $entities, 'full');
- $entity->content = field_attach_view('test_entity', $entity, 'full');
- $this->plainTextContent = FALSE;
- $this->content = backdrop_render($entity->content);
-
-
- $this->assertText($term1->name, 'Term 1 name is displayed.');
- $this->assertNoText($term2->name, 'Term 2 name is not displayed.');
-
-
- $field_info = field_info_field($this->field_name);
- $this->assertEqual(sizeof($field_info['settings']['allowed_values']), 1, 'Only one vocabulary is allowed for the field.');
-
-
- $this->backdropGet('test-entity/add/test-bundle');
- $this->assertFieldByName("{$this->field_name}[$langcode][]", '', 'Widget is still displayed.');
-
-
- $edit = array(
- "{$this->field_name}[$langcode][]" => array($term1->tid),
- );
- $this->backdropPost(NULL, $edit, t('Save'));
- }
- }
-
-
- * Test taxonomy token replacement in strings.
- */
- class TaxonomyTokenReplaceTestCase extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp();
- $this->admin_user = $this->backdropCreateUser(array('administer taxonomy', 'bypass node access'));
- $this->backdropLogin($this->admin_user);
- $this->vocabulary = $this->createVocabulary();
- $this->langcode = LANGUAGE_NONE;
-
- $field = array(
- 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
- 'type' => 'taxonomy_term_reference',
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => 0,
- ),
- ),
- ),
- );
- field_create_field($field);
-
- $this->instance = array(
- 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
- 'bundle' => 'post',
- 'entity_type' => 'node',
- 'widget' => array(
- 'type' => 'options_select',
- ),
- 'display' => array(
- 'default' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance);
- }
-
-
- * Creates some terms and a node, then tests the tokens generated from them.
- */
- function testTaxonomyTokenReplacement() {
- global $language;
-
-
- $term1 = $this->createTerm($this->vocabulary);
- $term2 = $this->createTerm($this->vocabulary);
-
-
- $edit = array();
- $edit['name'] = '<blink>Blinking Text</blink>';
- $edit['parent[]'] = array($term1->tid);
- $this->backdropPost('taxonomy/term/' . $term2->tid . '/edit', $edit, t('Save'));
-
-
- $edit = array();
- $node = $this->backdropCreateNode(array('type' => 'post'));
- $edit[$this->instance['field_name'] . '[' . $this->langcode . '][]'] = $term2->tid;
- $this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));
-
-
- $tests = array();
- $tests['[term:tid]'] = $term1->tid;
- $tests['[term:name]'] = check_plain($term1->name);
- $tests['[term:description]'] = check_markup($term1->description, $term1->format);
- $tests['[term:url]'] = url('taxonomy/term/' . $term1->tid, array('absolute' => TRUE));
- $tests['[term:node-count]'] = 0;
- $tests['[term:parent:name]'] = '[term:parent:name]';
- $tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name);
-
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('term' => $term1), array('language' => $language));
- $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
- }
-
-
- $tests = array();
- $tests['[term:tid]'] = $term2->tid;
- $tests['[term:name]'] = check_plain($term2->name);
- $tests['[term:description]'] = check_markup($term2->description, $term2->format);
- $tests['[term:url]'] = url('taxonomy/term/' . $term2->tid, array('absolute' => TRUE));
- $tests['[term:node-count]'] = 1;
- $tests['[term:parent:name]'] = check_plain($term1->name);
- $tests['[term:parent:url]'] = url('taxonomy/term/' . $term1->tid, array('absolute' => TRUE));
- $tests['[term:parent:parent:name]'] = '[term:parent:parent:name]';
- $tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name);
-
-
- $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
-
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('term' => $term2), array('language' => $language));
- $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
- }
-
-
- $tests['[term:name]'] = $term2->name;
- $tests['[term:description]'] = $term2->description;
- $tests['[term:parent:name]'] = $term1->name;
- $tests['[term:vocabulary:name]'] = $this->vocabulary->name;
-
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('term' => $term2), array('language' => $language, 'sanitize' => FALSE));
- $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input)));
- }
-
-
- $tests = array();
- $tests['[vocabulary:machine-name]'] = $this->vocabulary->machine_name;
- $tests['[vocabulary:name]'] = check_plain($this->vocabulary->name);
- $tests['[vocabulary:description]'] = filter_xss($this->vocabulary->description);
- $tests['[vocabulary:node-count]'] = 1;
- $tests['[vocabulary:term-count]'] = 2;
-
-
- $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
-
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('vocabulary' => $this->vocabulary), array('language' => $language));
- $this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
- }
-
-
- $tests['[vocabulary:name]'] = $this->vocabulary->name;
- $tests['[vocabulary:description]'] = $this->vocabulary->description;
-
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('vocabulary' => $this->vocabulary), array('language' => $language, 'sanitize' => FALSE));
- $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
- }
- }
- }
-
- * Tests setting languages for taxonomy.
- */
- class TaxonomyLanguageFunctionalTest extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp('node', 'language');
- $this->admin_user = $this->backdropCreateUser(array('administer taxonomy', 'bypass node access', 'administer languages', 'administer content types', 'administer fields'));
- $this->backdropLogin($this->admin_user);
-
- $this->vocabulary = taxonomy_vocabulary_load('tags');
-
- $this->backdropGet('admin/config/regional/language');
- $edit = array();
- $edit['predefined_langcode'] = 'es';
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
-
- $this->backdropGet('admin/structure/types/manage/post');
- $edit = array();
- $edit['language'] = 1;
- $this->backdropPost('admin/structure/types/manage/post', $edit, t('Save content type'));
- $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Post')), 'Post content type has been updated.');
-
-
- $this->backdropGet('admin/structure/types/manage/post/fields/field_tags');
- $this->assertFieldChecked('edit-instance-widget-settings-follow-content-language', 'Tags will be saved in language of content.');
-
-
- backdrop_static_reset();
- }
-
-
- * Create, configure and delete a vocabulary via the user interface.
- */
- function testVocabularyLanguageInterface() {
-
- $this->backdropGet('admin/structure/taxonomy');
- $this->clickLink(t('Configure'));
- $edit = array();
- $edit['language'] = TAXONOMY_LANGUAGE_ENABLED;
- $this->backdropPost(NULL, $edit, t('Save vocabulary'));
-
-
- $this->backdropGet('admin/structure/taxonomy');
- $this->clickLink(t('Configure'));
- $this->assertFieldChecked('edit-language', 'Multilingual support is enabled for vocabulary.');
- }
-
-
- * Test term creation with a free-tagging vocabulary from the node form.
- */
- function testNodeTermLanguageCreation() {
-
- $this->backdropGet('admin/structure/taxonomy');
- $this->clickLink(t('Configure'));
- $edit = array();
- $edit['language'] = TAXONOMY_LANGUAGE_ENABLED;
- $this->backdropPost(NULL, $edit, t('Save vocabulary'));
-
- $terms = array(
- 'term1' => $this->randomName(),
- 'term2' => $this->randomName(),
- );
-
- $edit = array();
- $field_langcode = LANGUAGE_NONE;
- $langcode = 'es';
-
- $edit["title"] = $this->randomName();
- $edit["body[$field_langcode][0][value]"] = $this->randomName();
-
-
- $edit['field_tags' . "[$field_langcode]"] = backdrop_implode_tags($terms);
- $edit['langcode'] = $langcode;
-
-
- backdrop_static_reset();
-
-
- $this->backdropPost('node/add/post', $edit, t('Save'));
- $this->assertRaw(t('@type %title has been created.', array('@type' => t('Post'), '%title' => $edit["title"])), 'The node was created successfully.');
- foreach ($terms as $term) {
- $this->assertText($term, 'The term was saved and appears on the node page.');
- }
-
-
- $term_objects = array();
- foreach ($terms as $key => $term) {
- $term_objects[$key] = taxonomy_term_load_multiple_by_name($term);
- $term_objects[$key] = reset($term_objects[$key]);
- }
-
-
- $node = $this->backdropGetNodeByTitle($edit["title"]);
- $this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- foreach ($terms as $term) {
- $this->assertText($term, 'The term was retained after edit and still appears on the node page.');
- }
-
-
- $this->backdropGet('taxonomy/term/' . $term_objects['term1']->tid . '/edit');
- $this->assertOptionSelected('edit-langcode', 'es', 'Term is the same language as the node it was created in.');
- }
- }
-
- * Tests for verifying that taxonomy pages use the correct theme.
- */
- class TaxonomyThemeTestCase extends TaxonomyWebTestCase {
- protected $profile = 'testing';
-
- function setUp() {
- parent::setUp('taxonomy');
-
-
-
- config_set('system.core', 'theme_default', 'bartik');
- config_set('system.core', 'admin_theme', 'seven');
-
-
-
- $admin_user = $this->backdropCreateUser(array('administer taxonomy', 'view the administration theme'));
- $this->backdropLogin($admin_user);
- }
-
-
- * Test the theme used when adding, viewing and editing taxonomy terms.
- */
- function testTaxonomyTermThemes() {
-
-
- $vocabulary = $this->createVocabulary();
- $this->backdropGet('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add');
- $this->assertRaw('seven/css/style.css', "The administrative theme's CSS appears on the page for adding a taxonomy term.");
-
-
- $term = $this->createTerm($vocabulary);
- $this->backdropGet('taxonomy/term/' . $term->tid);
- $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page for viewing a taxonomy term.");
-
-
- $this->backdropGet('taxonomy/term/' . $term->tid . '/edit');
- $this->assertRaw('seven/css/style.css', "The administrative theme's CSS appears on the page for editing a taxonomy term.");
- }
-
- }
-
- * Tests the functionality of EntityFieldQuery for taxonomy entities.
- */
- class TaxonomyEFQTestCase extends TaxonomyWebTestCase {
- function setUp() {
- parent::setUp();
- $this->admin_user = $this->backdropCreateUser(array('administer taxonomy'));
- $this->backdropLogin($this->admin_user);
- $this->vocabulary = $this->createVocabulary();
- }
-
-
- * Tests that a basic taxonomy EntityFieldQuery works.
- */
- function testTaxonomyEFQ() {
- $terms = array();
- for ($i = 0; $i < 5; $i++) {
- $term = $this->createTerm($this->vocabulary);
- $terms[$term->tid] = $term;
- }
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'taxonomy_term');
- $result = $query->execute();
- $result = $result['taxonomy_term'];
- asort($result);
- $this->assertEqual(array_keys($terms), array_keys($result), 'Taxonomy terms were retrieved by EntityFieldQuery.');
-
- $first_result = reset($result);
- $term = _field_create_entity_from_ids($first_result);
- $this->assertEqual($term->tid, $first_result->entity_id, 'Taxonomy term can be created based on the IDs');
-
-
- $vocabulary2 = $this->createVocabulary();
- $terms2 = array();
- for ($i = 0; $i < 5; $i++) {
- $term = $this->createTerm($vocabulary2);
- $terms2[$term->tid] = $term;
- }
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'taxonomy_term');
- $query->entityCondition('bundle', $vocabulary2->machine_name);
- $result = $query->execute();
- $result = $result['taxonomy_term'];
- asort($result);
- $this->assertEqual(array_keys($terms2), array_keys($result), format_string('Taxonomy terms from the %name vocabulary were retrieved by EntityFieldQuery.', array('%name' => $vocabulary2->name)));
- }
- }
-
- * Tests that appropriate query tags are added.
- */
- class TaxonomyQueryAlterTestCase extends TaxonomyWebTestCase {
- public function setUp() {
- parent::setUp('taxonomy_test');
- }
-
-
- * Tests that appropriate tags are added when querying the database.
- */
- public function testTaxonomyQueryAlter() {
-
- $vocabulary = $this->createVocabulary();
- $terms = array();
- for ($i = 0; $i < 5; $i++) {
- $terms[$i] = $this->createTerm($vocabulary);
- }
-
-
- $terms[2]->parent = array($terms[1]->tid);
- taxonomy_term_save($terms[2]);
-
- $this->setupQueryTagTestHooks();
- $loaded_term = taxonomy_term_load($terms[0]->tid);
- $this->assertEqual($loaded_term->tid, $terms[0]->tid, 'First term was loaded');
- $this->assertQueryTagTestResult(1, 'taxonomy_term_load()');
-
- $this->setupQueryTagTestHooks();
- $loaded_terms = taxonomy_get_tree($vocabulary->machine_name);
- $this->assertEqual(count($loaded_terms), count($terms), 'All terms were loaded');
- $this->assertQueryTagTestResult(1, 'taxonomy_get_tree()');
-
- $this->setupQueryTagTestHooks();
- $loaded_terms = taxonomy_term_load_parents($terms[2]->tid);
- $this->assertEqual(count($loaded_terms), 1, 'All parent terms were loaded');
- $this->assertQueryTagTestResult(2, 'taxonomy_term_load_parents()');
-
- $this->setupQueryTagTestHooks();
- $loaded_terms = taxonomy_term_load_children($terms[1]->tid);
- $this->assertEqual(count($loaded_terms), 1, 'All child terms were loaded');
- $this->assertQueryTagTestResult(2, 'taxonomy_term_load_children()');
-
- $this->setupQueryTagTestHooks();
- $query = db_select('taxonomy_term_data', 't');
- $query->addField('t', 'tid');
- $query->addTag('taxonomy_term_access');
- $tids = $query->execute()->fetchCol();
- $this->assertEqual(count($tids), count($terms), 'All term IDs were retrieved');
- $this->assertQueryTagTestResult(1, 'custom db_select() with taxonomy_term_access tag (preferred)');
-
- $this->setupQueryTagTestHooks();
- $query = db_select('taxonomy_term_data', 't');
- $query->addField('t', 'tid');
- $query->addTag('term_access');
- $tids = $query->execute()->fetchCol();
- $this->assertEqual(count($tids), count($terms), 'All term IDs were retrieved');
- $this->assertQueryTagTestResult(1, 'custom db_select() with term_access tag (deprecated)');
-
- $this->setupQueryTagTestHooks();
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'taxonomy_term');
- $query->addTag('taxonomy_term_access');
- $result = $query->execute();
- $this->assertEqual(count($result['taxonomy_term']), count($terms), 'All term IDs were retrieved');
- $this->assertQueryTagTestResult(1, 'custom EntityFieldQuery with taxonomy_term_access tag (preferred)');
-
- $this->setupQueryTagTestHooks();
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'taxonomy_term');
- $query->addTag('term_access');
- $result = $query->execute();
- $this->assertEqual(count($result['taxonomy_term']), count($terms), 'All term IDs were retrieved');
- $this->assertQueryTagTestResult(1, 'custom EntityFieldQuery with term_access tag (deprecated)');
- }
-
-
- * Sets up the hooks in the test module.
- */
- protected function setupQueryTagTestHooks() {
- taxonomy_terms_static_reset();
- state_set('taxonomy_test_query_alter', 0);
- state_set('taxonomy_test_query_term_access_alter', 0);
- state_set('taxonomy_test_query_taxonomy_term_access_alter', 0);
- }
-
-
- * Verifies invocation of the hooks in the test module.
- *
- * @param int $expected_invocations
- * The number of times the hooks are expected to have been invoked.
- * @param string $method
- * A string describing the invoked function which generated the query.
- */
- protected function assertQueryTagTestResult($expected_invocations, $method) {
- $this->assertIdentical($expected_invocations, state_get('taxonomy_test_query_alter'), 'hook_query_alter() invoked when executing ' . $method);
- $this->assertIdentical($expected_invocations, state_get('taxonomy_test_query_term_access_alter'), 'Deprecated hook_query_term_access_alter() invoked when executing ' . $method);
- $this->assertIdentical($expected_invocations, state_get('taxonomy_test_query_taxonomy_term_access_alter'), 'Preferred hook_query_taxonomy_term_access_alter() invoked when executing ' . $method);
- }
-
- }