summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-03 20:19:29 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-03 20:19:29 +0000
commit2e34decb3bd4bfdbba54316d79154c24cc78bb6f (patch)
tree4a1a03dba3d4ecf40f06d5715834fb4dab95d88c /modules/simpletest
parenta1202e744f7cd6c40038afbe635aa9f59cf60778 (diff)
downloadbrdo-2e34decb3bd4bfdbba54316d79154c24cc78bb6f.tar.gz
brdo-2e34decb3bd4bfdbba54316d79154c24cc78bb6f.tar.bz2
#537044 by dropcube: Simplify and expand taxonomy hook tests.
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/tests/taxonomy_test.install15
-rw-r--r--modules/simpletest/tests/taxonomy_test.module76
2 files changed, 35 insertions, 56 deletions
diff --git a/modules/simpletest/tests/taxonomy_test.install b/modules/simpletest/tests/taxonomy_test.install
index ae741f0e6..2d771d0e2 100644
--- a/modules/simpletest/tests/taxonomy_test.install
+++ b/modules/simpletest/tests/taxonomy_test.install
@@ -10,14 +10,9 @@
* Implement hook_schema().
*/
function taxonomy_test_schema() {
- $schema['term_antonym'] = array(
- 'description' => 'Stores term antonyms.',
+ $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;
diff --git a/modules/simpletest/tests/taxonomy_test.module b/modules/simpletest/tests/taxonomy_test.module
index beda61a5d..536e5a100 100644
--- a/modules/simpletest/tests/taxonomy_test.module
+++ b/modules/simpletest/tests/taxonomy_test.module
@@ -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') {
- $antonyms = taxonomy_test_get_antonyms($form['#term']['tid']);
- $form['advanced']['antonyms'] = array(
- '#type' => 'textarea',
- '#title' => t('Antonyms'),
- '#default_value' => !empty($antonyms) ? implode("\n", $antonyms) : NULL,
- '#description' => t('Antonyms of this term, one antonym per line.')
+ $antonym = taxonomy_test_get_antonym($form['#term']['tid']);
+ $form['advanced']['antonym'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Antonym'),
+ '#default_value' => !empty($antonym) ? $antonym : '',
+ '#description' => t('Antonym of this term.')
);
}
}
/**
- * Return an array of antonyms 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();
}