From 0de72ee48438140ad16d15e5b4819bdc0d3ab995 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Fri, 5 Jun 2009 05:23:58 +0000 Subject: [PATCH] - Patch #225864 by pwolanin: prevent PHP errors from cron.php. --- modules/taxonomy/taxonomy.module | 6 ++++-- modules/taxonomy/taxonomy.test | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 7c6889c03d12..1db7564584ee 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -1639,8 +1639,10 @@ function taxonomy_node_validate($node, $form) { */ function taxonomy_node_update_index($node) { $output = array(); - foreach ($node->taxonomy as $term) { - $output[] = $term->name; + if (isset($node->taxonomy) && is_array($node->taxonomy)) { + foreach ($node->taxonomy as $term) { + $output[] = $term->name; + } } if (count($output)) { return '<strong>(' . implode(', ', $output) . ')</strong>'; diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 24f12bd50140..87123bc39dbd 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -354,6 +354,20 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase { // Confirm that the node type argument returns a single node association. $this->assertEqual(taxonomy_term_count_nodes($term3->tid, 'page'), 1, t("Term is associated with one node of type 'page'.")); + + // Test hook_nodeapi_update_index(). + // Load the node so taxonomy terms are fully populated. + $node = node_load($node1->nid); + $output = taxonomy_node_update_index($node); + $this->assertFalse(empty($output), t('Node with taxonomy has content when calling update index')); + // Remove all taxonomy. + unset($node->taxonomy); + $output = taxonomy_node_update_index($node); + $this->assertTrue(empty($output), t('Node with no taxonomy has no content when calling update index')); + // Set taxonomy to a scalar (non-array). + $node->taxonomy = 1; + $output = taxonomy_node_update_index($node); + $this->assertTrue(empty($output), t('Node with non-array taxonomy has no content when calling update index')); } } -- GitLab