Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
2e34decb
Commit
2e34decb
authored
Aug 03, 2009
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#537044
by dropcube: Simplify and expand taxonomy hook tests.
parent
a1202e74
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
62 deletions
+41
-62
modules/simpletest/tests/taxonomy_test.install
modules/simpletest/tests/taxonomy_test.install
+3
-12
modules/simpletest/tests/taxonomy_test.module
modules/simpletest/tests/taxonomy_test.module
+32
-44
modules/taxonomy/taxonomy.test
modules/taxonomy/taxonomy.test
+6
-6
No files found.
modules/simpletest/tests/taxonomy_test.install
View file @
2e34decb
...
...
@@ -10,14 +10,9 @@
* Implement hook_schema().
*/
function
taxonomy_test_schema
()
{
$schema
[
'term_antonym'
]
=
array
(
'description'
=>
'Stores term antonym
s
.'
,
$schema
[
'
taxonomy_
term_antonym'
]
=
array
(
'description'
=>
'Stores term antonym.'
,
'fields'
=>
array
(
'taid'
=>
array
(
'type'
=>
'serial'
,
'not null'
=>
TRUE
,
'description'
=>
'Primary Key: Unique term antonym ID.'
,
),
'tid'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
...
...
@@ -33,11 +28,7 @@ function taxonomy_test_schema() {
'description'
=>
'The name of the antonym.'
,
),
),
'indexes'
=>
array
(
'tid'
=>
array
(
'tid'
),
'name_tid'
=>
array
(
'name'
,
'tid'
),
),
'primary key'
=>
array
(
'taid'
),
'primary key'
=>
array
(
'tid'
),
);
return
$schema
;
...
...
modules/simpletest/tests/taxonomy_test.module
View file @
2e34decb
...
...
@@ -11,7 +11,10 @@
*/
function
taxonomy_test_taxonomy_term_load
(
&
$terms
)
{
foreach
(
$terms
as
$term
)
{
$term
->
antonyms
=
taxonomy_test_get_antonyms
(
$term
->
tid
);
$antonym
=
taxonomy_test_get_antonym
(
$term
->
tid
);
if
(
$antonym
)
{
$term
->
antonym
=
$antonym
;
}
}
}
...
...
@@ -19,17 +22,13 @@ function taxonomy_test_taxonomy_term_load(&$terms) {
* Implement hook_taxonomy_term_insert().
*/
function
taxonomy_test_taxonomy_term_insert
(
$term
)
{
if
(
!
empty
(
$term
->
antonyms
))
{
foreach
(
explode
(
"
\n
"
,
str_replace
(
"
\r
"
,
''
,
$term
->
antonyms
))
as
$antonym
)
{
if
(
$antonym
)
{
db_insert
(
'term_antonym'
)
->
fields
(
array
(
'tid'
=>
$term
->
tid
,
'name'
=>
rtrim
(
$antonym
),
))
->
execute
();
}
}
if
(
!
empty
(
$term
->
antonym
))
{
db_insert
(
'taxonomy_term_antonym'
)
->
fields
(
array
(
'tid'
=>
$term
->
tid
,
'name'
=>
trim
(
$term
->
antonym
)
))
->
execute
();
}
}
...
...
@@ -37,18 +36,13 @@ function taxonomy_test_taxonomy_term_insert($term) {
* Implement hook_taxonomy_term_update().
*/
function
taxonomy_test_taxonomy_term_update
(
$term
)
{
taxonomy_test_taxonomy_term_delete
(
$term
);
if
(
!
empty
(
$term
->
antonyms
))
{
foreach
(
explode
(
"
\n
"
,
str_replace
(
"
\r
"
,
''
,
$term
->
antonyms
))
as
$antonym
)
{
if
(
$antonym
)
{
db_insert
(
'term_antonym'
)
->
fields
(
array
(
'tid'
=>
$term
->
tid
,
'name'
=>
rtrim
(
$antonym
),
))
->
execute
();
}
}
if
(
!
empty
(
$term
->
antonym
))
{
db_merge
(
'taxonomy_term_antonym'
)
->
key
(
array
(
'tid'
=>
$term
->
tid
))
->
fields
(
array
(
'name'
=>
trim
(
$term
->
antonym
)
))
->
execute
();
}
}
...
...
@@ -56,7 +50,7 @@ function taxonomy_test_taxonomy_term_update($term) {
* Implement hook_taxonomy_term_delete().
*/
function
taxonomy_test_taxonomy_term_delete
(
$term
)
{
db_delete
(
'term_antonym'
)
db_delete
(
'
taxonomy_
term_antonym'
)
->
condition
(
'tid'
,
$term
->
tid
)
->
execute
();
}
...
...
@@ -66,29 +60,23 @@ function taxonomy_test_taxonomy_term_delete($term) {
*/
function
taxonomy_test_form_alter
(
&
$form
,
$form_state
,
$form_id
)
{
if
(
$form_id
==
'taxonomy_form_term'
)
{
$antonym
s
=
taxonomy_test_get_antonym
s
(
$form
[
'#term'
][
'tid'
]);
$form
[
'advanced'
][
'antonym
s
'
]
=
array
(
'#type'
=>
'text
area
'
,
'#title'
=>
t
(
'Antonym
s
'
),
'#default_value'
=>
!
empty
(
$antonym
s
)
?
implode
(
"
\n
"
,
$antonym
s
)
:
NULL
,
'#description'
=>
t
(
'Antonym
s
of this term
, one antonym per line
.'
)
$antonym
=
taxonomy_test_get_antonym
(
$form
[
'#term'
][
'tid'
]);
$form
[
'advanced'
][
'antonym'
]
=
array
(
'#type'
=>
'text
field
'
,
'#title'
=>
t
(
'Antonym'
),
'#default_value'
=>
!
empty
(
$antonym
)
?
$antonym
:
''
,
'#description'
=>
t
(
'Antonym of this term.'
)
);
}
}
/**
* Return
an array of
antonym
s
of the given term ID.
* Return
the
antonym of the given term ID.
*/
function
taxonomy_test_get_antonyms
(
$tid
)
{
if
(
$tid
)
{
$antonyms
=
array
();
$result
=
db_query
(
'SELECT name FROM {term_antonym} WHERE tid = :tid'
,
array
(
':tid'
=>
$tid
));
foreach
(
$result
as
$antonym
)
{
$antonyms
[]
=
$antonym
->
name
;
}
return
$antonyms
;
}
else
{
return
FALSE
;
}
function
taxonomy_test_get_antonym
(
$tid
)
{
return
db_select
(
'taxonomy_term_antonym'
,
'ta'
)
->
fields
(
'ta'
,
array
(
'name'
))
->
condition
(
'tid'
,
$tid
)
->
execute
()
->
fetchField
();
}
modules/taxonomy/taxonomy.test
View file @
2e34decb
...
...
@@ -705,26 +705,26 @@ class TaxonomyHooksTestCase extends TaxonomyWebTestCase {
// Create a term with one antonym.
$edit
=
array
(
'name'
=>
$this
->
randomName
(),
'antonym
s
'
=>
'Long'
,
'antonym'
=>
'Long'
,
);
$this
->
drupalPost
(
'admin/structure/taxonomy/'
.
$vocabulary
->
vid
.
'/add'
,
$edit
,
t
(
'Save'
));
$term
=
reset
(
taxonomy_get_term_by_name
(
$edit
[
'name'
]));
$this
->
assertEqual
(
$term
->
antonym
s
[
0
]
,
$edit
[
'antonym
s
'
],
t
(
'Antonym
s
w
ere
loaded into the term object'
));
$this
->
assertEqual
(
$term
->
antonym
,
$edit
[
'antonym'
],
t
(
'Antonym w
as
loaded into the term object'
));
// Update the term with a different antonym.
$edit
=
array
(
'name'
=>
$this
->
randomName
(),
'antonym
s
'
=>
'Short'
,
'antonym'
=>
'Short'
,
);
$this
->
drupalPost
(
'taxonomy/term/'
.
$term
->
tid
.
'/edit'
,
$edit
,
t
(
'Save'
));
taxonomy_terms_static_reset
();
$term
=
taxonomy_term_load
(
$term
->
tid
);
$this
->
assert
True
(
in_array
(
$edit
[
'antonym
s
'
],
$term
->
antonym
s
)
,
t
(
'Antonym was successfully edited'
));
$this
->
assert
Equal
(
$edit
[
'antonym'
],
$term
->
antonym
,
t
(
'Antonym was successfully edited'
));
// Delete the term.
taxonomy_term_delete
(
$term
->
tid
);
$antonym
s
=
db_query
(
'SELECT t
a
id FROM {term_antonym} WHERE tid = :tid'
,
array
(
':tid'
=>
$term
->
tid
))
->
fetchField
();
$this
->
assertFalse
(
$antonym
s
,
t
(
'The antonym
s
were deleted from the database.'
));
$antonym
=
db_query
(
'SELECT tid FROM {
taxonomy_
term_antonym} WHERE tid = :tid'
,
array
(
':tid'
=>
$term
->
tid
))
->
fetchField
();
$this
->
assertFalse
(
$antonym
,
t
(
'The antonym were deleted from the database.'
));
}
}
...
...
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