entity_translation_test.module 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @file
  4. * Testing functionality for Entity Translation module.
  5. */
  6. /**
  7. * Implements hook_entity_translation_insert().
  8. */
  9. function entity_translation_test_entity_translation_insert($entity_type, $entity, $translation, $values = array()) {
  10. entity_translation_test_check_save($entity_type, $entity, $translation, 'insert');
  11. }
  12. /**
  13. * Implements hook_entity_translation_insert().
  14. */
  15. function entity_translation_test_entity_translation_update($entity_type, $entity, $translation, $values = array()) {
  16. entity_translation_test_check_save($entity_type, $entity, $translation, 'update');
  17. }
  18. /**
  19. * Test implementation for save hooks.
  20. */
  21. function entity_translation_test_check_save($entity_type, $entity, $translation, $hook) {
  22. list($id, ,) = entity_extract_ids($entity_type, $entity);
  23. $match = FALSE;
  24. $row = db_select('entity_translation', 'et')
  25. ->fields('et')
  26. ->condition('entity_type', $entity_type)
  27. ->condition('entity_id', $id)
  28. ->condition('language', $translation['language'])
  29. ->orderBy('created')
  30. ->execute()
  31. ->fetch(PDO::FETCH_ASSOC);
  32. if ($row) {
  33. $match = TRUE;
  34. foreach ($translation as $key => $value) {
  35. if ($row[$key] != $value) {
  36. $match = FALSE;
  37. break;
  38. }
  39. }
  40. }
  41. variable_set('entity_translation_test_save', array($hook => $match));
  42. }
  43. /**
  44. * Implements hook_entity_translation_delete().
  45. */
  46. function entity_translation_test_entity_translation_delete($entity_type, $entity, $langcode) {
  47. list($id, ,) = entity_extract_ids($entity_type, $entity);
  48. $row = db_select('entity_translation', 'et')
  49. ->fields('et')
  50. ->condition('entity_type', $entity_type)
  51. ->condition('entity_id', $id)
  52. ->condition('language', $langcode)
  53. ->orderBy('created')
  54. ->execute()
  55. ->fetch(PDO::FETCH_ASSOC);
  56. $info = variable_get('entity_translation_test_delete', array());
  57. $info[$langcode] = empty($row);
  58. variable_set('entity_translation_test_delete', $info);
  59. }