summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-03-26 22:08:29 -0700
committerwebchick2013-03-26 22:08:29 -0700
commit02f199f62b502fc90980d2ea28cb0dcf3b4f6839 (patch)
tree938b18ecbc05a71dde871315594d5788ca19e3c5
parent13b929b6672d0f5ac66bcea383cc671e9b452577 (diff)
Issue #1400256 by mahaprasad, David_Rothstein, amcgowanca: Tests for field info cache.
-rw-r--r--core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php26
-rw-r--r--core/modules/field/tests/modules/field_test/field_test.entity.inc11
2 files changed, 36 insertions, 1 deletions
diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
index ea6f26e..f9a1031 100644
--- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
+++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
@@ -297,7 +297,6 @@ class FieldInfoTest extends FieldUnitTestBase {
$this->assertEqual($map, $expected);
}
-
/**
* Test that the field_info settings convenience functions work.
*/
@@ -324,6 +323,31 @@ class FieldInfoTest extends FieldUnitTestBase {
}
/**
+ * Tests that the field info cache can be built correctly.
+ */
+ function testFieldInfoCache() {
+ // Create a test field and ensure it's in the array returned by
+ // field_info_fields().
+ $field_name = drupal_strtolower($this->randomName());
+ $field = array(
+ 'field_name' => $field_name,
+ 'type' => 'test_field',
+ );
+ field_create_field($field);
+ $fields = field_info_fields();
+ $this->assertTrue(isset($fields[$field_name]), 'The test field is initially found in the array returned by field_info_fields().');
+
+ // Now rebuild the field info cache, and set a variable which will cause
+ // the cache to be cleared while it's being rebuilt; see
+ // field_test_entity_info(). Ensure the test field is still in the returned
+ // array.
+ field_info_cache_clear();
+ state()->set('field_test.clear_info_cache_in_hook_entity_info', TRUE);
+ $fields = field_info_fields();
+ $this->assertTrue(isset($fields[$field_name]), 'The test field is found in the array returned by field_info_fields() even if its cache is cleared while being rebuilt.');
+ }
+
+ /**
* Test that the widget definition functions work.
*/
function testWidgetDefinition() {
diff --git a/core/modules/field/tests/modules/field_test/field_test.entity.inc b/core/modules/field/tests/modules/field_test/field_test.entity.inc
index 565ed08..5f08460 100644
--- a/core/modules/field/tests/modules/field_test/field_test.entity.inc
+++ b/core/modules/field/tests/modules/field_test/field_test.entity.inc
@@ -9,6 +9,17 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\field_test\Plugin\Core\Entity\TestEntity;
/**
+ * Implements hook_entity_info().
+ */
+function field_test_entity_info() {
+ // If requested, clear the field cache while this is being called. See
+ // Drupal\field\Tests\FieldInfoTest::testFieldInfoCache().
+ if (state()->get('field_test.clear_info_cache_in_hook_entity_info')) {
+ field_info_cache_clear();
+ }
+}
+
+/**
* Implements hook_entity_info_alter().
*/
function field_test_entity_info_alter(&$entity_info) {