diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-22 00:58:55 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-22 00:58:55 +0000 |
commit | 34a8a369aa0afb353d95578768903c6a1d5cd06b (patch) | |
tree | cd695ff9c71a5c221f9a5ea4603b04fbc5c2b3bd /modules/simpletest | |
parent | bc23bfaa11d6a8d40bb12812cfa081b9c5d9b672 (diff) | |
download | brdo-34a8a369aa0afb353d95578768903c6a1d5cd06b.tar.gz brdo-34a8a369aa0afb353d95578768903c6a1d5cd06b.tar.bz2 |
#367595 by plach, catch, sun, yched, et al: Added support for translatable fields to Field API.
Diffstat (limited to 'modules/simpletest')
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 4 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 2 | ||||
-rw-r--r-- | modules/simpletest/tests/field_test.module | 63 |
3 files changed, 60 insertions, 9 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 893c7e8c6..c23081467 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -693,7 +693,7 @@ class DrupalWebTestCase extends DrupalTestCase { protected function drupalCreateNode($settings = array()) { // Populate defaults array. $settings += array( - 'body' => array(array()), + 'body' => array(FIELD_LANGUAGE_NONE => array(array())), 'title' => $this->randomName(8), 'comment' => 2, 'changed' => REQUEST_TIME, @@ -730,7 +730,7 @@ class DrupalWebTestCase extends DrupalTestCase { 'value' => $this->randomName(32), 'format' => FILTER_FORMAT_DEFAULT ); - $settings['body'][0] += $body; + $settings['body'][FIELD_LANGUAGE_NONE][0] += $body; $node = (object) $settings; node_save($node); diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index ce9b0ade9..3a5036565 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -374,7 +374,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase { // Create a node, using the PHP filter that tests drupal_add_css(). $settings = array( 'type' => 'page', - 'body' => array(array('value' => t('This tests the inline CSS!') . "<?php drupal_add_css('$css', 'inline'); ?>", 'format' => 3)), // PHP filter. + 'body' => array(FIELD_LANGUAGE_NONE => array(array('value' => t('This tests the inline CSS!') . "<?php drupal_add_css('$css', 'inline'); ?>", 'format' => 3))), // PHP filter. 'promote' => 1, ); $node = $this->drupalCreateNode($settings); diff --git a/modules/simpletest/tests/field_test.module b/modules/simpletest/tests/field_test.module index 75dee80de..8192280ea 100644 --- a/modules/simpletest/tests/field_test.module +++ b/modules/simpletest/tests/field_test.module @@ -88,6 +88,15 @@ function field_test_fieldable_info() { } /** + * Implement hook_fieldable_info_alter(). + */ +function field_test_fieldable_info_alter(&$info) { + foreach (field_test_fieldable_info_translatable() as $obj_type => $translatable) { + $info[$obj_type]['translation_handlers']['field_test'] = TRUE; + } +} + +/** * Create a new bundle for test_entity objects. * * @param $bundle_name @@ -372,7 +381,7 @@ function field_test_field_schema($field) { /** * Implement hook_field_load(). */ -function field_test_field_load($obj_type, $objects, $field, $instances, &$items, $age) { +function field_test_field_load($obj_type, $objects, $field, $instances, $langcode, &$items, $age) { foreach ($items as $id => $item) { // To keep the test non-intrusive, only act for instances with the // test_hook_field_load setting explicitly set to TRUE. @@ -393,10 +402,10 @@ function field_test_field_load($obj_type, $objects, $field, $instances, &$items, * Possible error codes: * - 'field_test_invalid': The value is invalid. */ -function field_test_field_validate($obj_type, $object, $field, $instance, $items, &$errors) { +function field_test_field_validate($obj_type, $object, $field, $instance, $langcode, $items, &$errors) { foreach ($items as $delta => $item) { if ($item['value'] == -1) { - $errors[$field['field_name']][$delta][] = array( + $errors[$field['field_name']][$langcode][$delta][] = array( 'error' => 'field_test_invalid', 'message' => t('%name does not accept the value -1.', array('%name' => $instance['label'])), ); @@ -407,7 +416,7 @@ function field_test_field_validate($obj_type, $object, $field, $instance, $items /** * Implement hook_field_sanitize(). */ -function field_test_field_sanitize($obj_type, $object, $field, $instance, &$items) { +function field_test_field_sanitize($obj_type, $object, $field, $instance, $langcode, &$items) { foreach ($items as $delta => $item) { $value = check_plain($item['value']); $items[$delta]['safe'] = $value; @@ -474,8 +483,8 @@ function field_test_field_widget_info() { * holds the field's form values. * @param $field * The field structure. - * @param $insatnce - * the insatnce array + * @param $instance + * the instance array * @param $items * array of default values for this field * @param $delta @@ -577,6 +586,48 @@ function field_test_default_value($obj_type, $object, $field, $instance) { } /** + * Generic op to test _field_invoke behavior. + */ +function field_test_field_test_op($obj_type, $object, $field, $instance, $langcode, &$items) { + return array($langcode => md5(serialize(array($obj_type, $object, $field['field_name'], $langcode, $items)))); +} + +/** + * Generic op to test _field_invoke_multiple behavior. + */ +function field_test_field_test_op_multiple($obj_type, $objects, $field, $instances, $langcode, &$items) { + $result = array(); + foreach ($objects as $id => $object) { + $result[$id] = array($langcode => md5(serialize(array($obj_type, $object, $field['field_name'], $langcode, $items[$id])))); + } + return $result; +} + +/** + * Implement hook_field_languages(). + */ +function field_test_field_languages($obj_type, $field, &$languages) { + if ($field['settings']['test_hook_in']) { + // Add an unavailable language. + $languages[] = 'xx'; + // Remove an available language. + unset($languages[0]); + } +} + +/** + * Helper function to enable entity translations. + */ +function field_test_fieldable_info_translatable($obj_type = NULL, $translatable = NULL) { + $stored_value = &drupal_static(__FUNCTION__, array()); + if (isset($obj_type) && isset($translatable)) { + $stored_value[$obj_type] = $translatable; + _field_info_collate_types(TRUE); + } + return $stored_value; +} + +/** * Store and retrieve keyed data for later verification by unit tests. * * This function is a simple in-memory key-value store with the |