summaryrefslogtreecommitdiff
path: root/modules/taxonomy
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2012-02-28 11:13:18 -0800
committerwebchick <webchick@24967.no-reply.drupal.org>2012-02-28 11:13:18 -0800
commit3da69625986d0b1a2ae09899ac539ad3ef07e2a3 (patch)
tree8c64c11ebf1c4ae7493b7a7bb6fb663d17811965 /modules/taxonomy
parent5589b60aef70d852518acc65ad1725f85aecb854 (diff)
downloadbrdo-3da69625986d0b1a2ae09899ac539ad3ef07e2a3.tar.gz
brdo-3da69625986d0b1a2ae09899ac539ad3ef07e2a3.tar.bz2
Issue #872488 by acouch, Albert Volkman, mfb, musicnode, no_commit_credit: Regression: no way to get taxonomy tags into RSS feeds.
Diffstat (limited to 'modules/taxonomy')
-rw-r--r--modules/taxonomy/taxonomy.module16
-rw-r--r--modules/taxonomy/taxonomy.test93
2 files changed, 109 insertions, 0 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 8cf6487b2..28d488ec8 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -1418,6 +1418,10 @@ function taxonomy_field_formatter_info() {
'label' => t('Plain text'),
'field types' => array('taxonomy_term_reference'),
),
+ 'taxonomy_term_reference_rss_category' => array(
+ 'label' => t('RSS category'),
+ 'field types' => array('taxonomy_term_reference'),
+ ),
);
}
@@ -1460,6 +1464,18 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
);
}
break;
+
+ case 'taxonomy_term_reference_rss_category':
+ foreach ($items as $delta => $item) {
+ $entity->rss_elements[] = array(
+ 'key' => 'category',
+ 'value' => $item['tid'] != 'autocreate' ? $item['taxonomy_term']->name : $item['name'],
+ 'attributes' => array(
+ 'domain' => $item['tid'] != 'autocreate' ? url('taxonomy/term/' . $item['tid'], array('absolute' => TRUE)) : '',
+ ),
+ );
+ }
+ break;
}
return $element;
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index 25743bfea..cb80f57eb 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -891,6 +891,99 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
}
/**
+ * Tests the rendering of term reference fields in RSS feeds.
+ */
+class TaxonomyRSSTestCase extends TaxonomyWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Taxonomy RSS Content.',
+ 'description' => 'Ensure that data added as terms appears in RSS feeds if "RSS Category" format is selected.',
+ 'group' => 'Taxonomy',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('taxonomy');
+ $this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'bypass node access', 'administer content types'));
+ $this->drupalLogin($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' => 'article',
+ '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() {
+ // Create two taxonomy terms.
+ $term1 = $this->createTerm($this->vocabulary);
+
+ // RSS display must be added manually.
+ $this->drupalGet("admin/structure/types/manage/article/display");
+ $edit = array(
+ "view_modes_custom[rss]" => '1',
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+
+ // Change the format to 'RSS category'.
+ $this->drupalGet("admin/structure/types/manage/article/display/rss");
+ $edit = array(
+ "fields[taxonomy_" . $this->vocabulary->machine_name . "][type]" => 'taxonomy_term_reference_rss_category',
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+
+ // Post an article.
+ $edit = array();
+ $langcode = LANGUAGE_NONE;
+ $edit["title"] = $this->randomName();
+ $edit[$this->instance['field_name'] . '[' . $langcode .'][]'] = $term1->tid;
+ $this->drupalPost('node/add/article', $edit, t('Save'));
+
+ // Check that the term is displayed when the RSS feed is viewed.
+ $this->drupalGet('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 {