entity_translation_test.module in Entity Translation 7
Testing functionality for Entity Translation module.
File
tests/entity_translation_test.moduleView source
<?php
/**
* @file
* Testing functionality for Entity Translation module.
*/
/**
* Implements hook_form_alter().
*/
function entity_translation_test_form_alter(&$form, &$form_state) {
if ($info = entity_translation_edit_form_info($form, $form_state)) {
$handler = entity_translation_get_handler($info['entity type'], $info['entity']);
if (entity_translation_enabled($info['entity type'], $info['entity'])) {
$form_state['no_cache'] = $handler
->isNewEntity() && variable_get('entity_translation_test_disable_form_cache', FALSE);
}
}
}
/**
* Implements hook_entity_translation_insert().
*/
function entity_translation_test_entity_translation_insert($entity_type, $entity, $translation, $values = array()) {
entity_translation_test_check_save($entity_type, $entity, $translation, 'insert');
}
/**
* Implements hook_entity_translation_insert().
*/
function entity_translation_test_entity_translation_update($entity_type, $entity, $translation, $values = array()) {
entity_translation_test_check_save($entity_type, $entity, $translation, 'update');
}
/**
* Test implementation for save hooks.
*/
function entity_translation_test_check_save($entity_type, $entity, $translation, $hook) {
list($id, , ) = entity_extract_ids($entity_type, $entity);
$match = FALSE;
$row = db_select('entity_translation', 'et')
->fields('et')
->condition('entity_type', $entity_type)
->condition('entity_id', $id)
->condition('language', $translation['language'])
->orderBy('created')
->execute()
->fetch(PDO::FETCH_ASSOC);
if ($row) {
$match = TRUE;
foreach ($translation as $key => $value) {
if ($row[$key] != $value) {
$match = FALSE;
break;
}
}
}
variable_set('entity_translation_test_save', array(
$hook => $match,
));
}
/**
* Implements hook_entity_translation_delete().
*/
function entity_translation_test_entity_translation_delete($entity_type, $entity, $langcode) {
list($id, , ) = entity_extract_ids($entity_type, $entity);
$row = db_select('entity_translation', 'et')
->fields('et')
->condition('entity_type', $entity_type)
->condition('entity_id', $id)
->condition('language', $langcode)
->orderBy('created')
->execute()
->fetch(PDO::FETCH_ASSOC);
$info = variable_get('entity_translation_test_delete', array());
$info[$langcode] = empty($row);
variable_set('entity_translation_test_delete', $info);
}
Functions
Name | Description |
---|---|
entity_translation_test_check_save | Test implementation for save hooks. |
entity_translation_test_entity_translation_delete | Implements hook_entity_translation_delete(). |
entity_translation_test_entity_translation_insert | Implements hook_entity_translation_insert(). |
entity_translation_test_entity_translation_update | Implements hook_entity_translation_insert(). |
entity_translation_test_form_alter | Implements hook_form_alter(). |