Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
991ff539
Commit
991ff539
authored
Sep 24, 2008
by
webchick
Browse files
#296910
by catch and webchick: Add reset parameter to taxonomy_vocabulary_load().
parent
b43010c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
modules/taxonomy/taxonomy.module
View file @
991ff539
...
...
@@ -985,15 +985,22 @@ function taxonomy_get_term_by_name($name) {
* Return the vocabulary object matching a vocabulary ID.
*
* @param $vid
* The vocabulary's ID
* The vocabulary's ID.
*
* @param $reset
* A boolean flag indicating whether to reset the internal cache.
*
* @return
* The vocabulary object with all of its metadata, if exists, FALSE otherwise.
* Results are statically cached.
*/
function
taxonomy_vocabulary_load
(
$vid
)
{
function
taxonomy_vocabulary_load
(
$vid
,
$reset
=
FALSE
)
{
static
$vocabularies
=
array
();
if
(
$reset
)
{
unset
(
$vocabularies
[
$vid
]);
}
if
(
empty
(
$vocabularies
[
$vid
]))
{
// Initialize so if this vocabulary does not exist, we have
// that cached, and we will not try to load this later.
...
...
modules/taxonomy/taxonomy.test
View file @
991ff539
...
...
@@ -49,6 +49,26 @@ class TaxonomyVocabularyLoadTestCase extends DrupalWebTestCase {
$this
->
assertTrue
(
is_object
(
$vocabulary
),
t
(
'Vocabulary is an object'
));
$this
->
assertTrue
(
$vocabulary
->
vid
==
$vid
,
t
(
'Valid vocabulary vid is the same as our previously invalid one.'
));
}
/**
* Ensure that the vocabulary static reset works correctly.
*/
function
testTaxonomyVocabularyLoadStaticReset
()
{
// Load the first available vocabulary.
$original_vocabulary
=
taxonomy_vocabulary_load
(
1
);
// Change the name and description.
$edit
=
(
array
)
$original_vocabulary
;
$edit
[
'name'
]
=
$this
->
randomName
();
$edit
[
'description'
]
=
$this
->
randomName
();
$this
->
assertNotEqual
(
$edit
[
'name'
],
$original_vocabulary
->
name
);
taxonomy_save_vocabulary
(
$edit
);
// Load the vocabulary with $reset TRUE.
$new_vocabulary
=
taxonomy_vocabulary_load
(
$original_vocabulary
->
vid
,
TRUE
);
$this
->
assertEqual
(
$new_vocabulary
->
name
,
$edit
[
'name'
]);
$this
->
assertEqual
(
$new_vocabulary
->
name
,
$edit
[
'name'
]);
}
}
class
TaxonomyVocabularyFunctionsTestCase
extends
DrupalWebTestCase
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment