From a5d8a4449763850cc91fd322bb095dbce73b1a27 Mon Sep 17 00:00:00 2001 From: Mac_Weber Date: Mon, 4 Jan 2016 15:05:09 -0200 Subject: [PATCH] Issue #2641518 by Mac_Weber: Replace deprecated usage of entity_create('config_test') with a direct call to ConfigTest::create() --- core/modules/config/src/Tests/ConfigDiffTest.php | 2 +- .../config/src/Tests/ConfigEntityNormalizeTest.php | 6 +++++- core/modules/config/src/Tests/ConfigEntityStatusTest.php | 2 +- core/modules/config/src/Tests/ConfigEntityTest.php | 16 +++++++++------- .../src/Tests/ConfigImportRenameValidationTest.php | 2 +- .../src/Tests/ConfigTranslationOverviewTest.php | 2 +- .../EntityReference/EntityReferenceIntegrationTest.php | 10 ++++++++-- .../system/src/Tests/Entity/ConfigEntityQueryTest.php | 6 +++--- 8 files changed, 29 insertions(+), 17 deletions(-) diff --git a/core/modules/config/src/Tests/ConfigDiffTest.php b/core/modules/config/src/Tests/ConfigDiffTest.php index 1f32b27..6eba680 100644 --- a/core/modules/config/src/Tests/ConfigDiffTest.php +++ b/core/modules/config/src/Tests/ConfigDiffTest.php @@ -81,7 +81,7 @@ function testDiff() { // Test diffing a renamed config entity. $test_entity_id = $this->randomMachineName(); - $test_entity = entity_create('config_test', array( + $test_entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => $test_entity_id, 'label' => $this->randomMachineName(), )); diff --git a/core/modules/config/src/Tests/ConfigEntityNormalizeTest.php b/core/modules/config/src/Tests/ConfigEntityNormalizeTest.php index 7e0acef..9ab1825 100644 --- a/core/modules/config/src/Tests/ConfigEntityNormalizeTest.php +++ b/core/modules/config/src/Tests/ConfigEntityNormalizeTest.php @@ -29,7 +29,11 @@ protected function setUp() { } public function testNormalize() { - $config_entity = entity_create('config_test', array('id' => 'system', 'label' => 'foobar', 'weight' => 1)); + $config_entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( + 'id' => 'system', + 'label' => 'foobar', + 'weight' => 1, + )); $config_entity->save(); // Modify stored config entity, this is comparable with a schema change. diff --git a/core/modules/config/src/Tests/ConfigEntityStatusTest.php b/core/modules/config/src/Tests/ConfigEntityStatusTest.php index caad767..bbc4b21 100644 --- a/core/modules/config/src/Tests/ConfigEntityStatusTest.php +++ b/core/modules/config/src/Tests/ConfigEntityStatusTest.php @@ -27,7 +27,7 @@ class ConfigEntityStatusTest extends KernelTestBase { * Tests the enabling/disabling of entities. */ function testCRUD() { - $entity = entity_create('config_test', array( + $entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => strtolower($this->randomMachineName()), )); $this->assertTrue($entity->status(), 'Default status is enabled.'); diff --git a/core/modules/config/src/Tests/ConfigEntityTest.php b/core/modules/config/src/Tests/ConfigEntityTest.php index 13ab721..de094fd 100644 --- a/core/modules/config/src/Tests/ConfigEntityTest.php +++ b/core/modules/config/src/Tests/ConfigEntityTest.php @@ -81,7 +81,7 @@ function testCRUD() { } // Verify that an entity with an empty ID string is considered empty, too. - $empty_id = entity_create('config_test', array( + $empty_id = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => '', )); $this->assertIdentical($empty_id->isNew(), TRUE); @@ -94,7 +94,7 @@ function testCRUD() { } // Verify properties on a newly created entity. - $config_test = entity_create('config_test', $expected = array( + $config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create($expected = array( 'id' => $this->randomMachineName(), 'label' => $this->randomString(), 'style' => $this->randomMachineName(), @@ -146,7 +146,7 @@ function testCRUD() { // maximum allowed length, but not longer. // Test with a short ID. - $id_length_config_test = entity_create('config_test', array( + $id_length_config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => $this->randomMachineName(8), )); try { @@ -160,7 +160,7 @@ function testCRUD() { } // Test with an ID of the maximum allowed length. - $id_length_config_test = entity_create('config_test', array( + $id_length_config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => $this->randomMachineName(static::MAX_ID_LENGTH), )); try { @@ -174,7 +174,7 @@ function testCRUD() { } // Test with an ID exceeding the maximum allowed length. - $id_length_config_test = entity_create('config_test', array( + $id_length_config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => $this->randomMachineName(static::MAX_ID_LENGTH + 1), )); try { @@ -193,7 +193,7 @@ function testCRUD() { // Ensure that creating an entity with the same id as an existing one is not // possible. - $same_id = entity_create('config_test', array( + $same_id = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => $config_test->id(), )); $this->assertIdentical($same_id->isNew(), TRUE); @@ -227,7 +227,9 @@ function testCRUD() { // Test config entity prepopulation. \Drupal::state()->set('config_test.prepopulate', TRUE); - $config_test = entity_create('config_test', array('foo' => 'bar')); + $config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( + 'foo' => 'bar', + )); $this->assertEqual($config_test->get('foo'), 'baz', 'Initial value correctly populated'); } diff --git a/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php b/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php index c461f30..38fb1ea 100644 --- a/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php +++ b/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php @@ -71,7 +71,7 @@ protected function setUp() { public function testRenameValidation() { // Create a test entity. $test_entity_id = $this->randomMachineName(); - $test_entity = entity_create('config_test', array( + $test_entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => $test_entity_id, 'label' => $this->randomMachineName(), )); diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php index 13b56d5..76c4e9a 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php @@ -95,7 +95,7 @@ public function testMapperListPage() { ); foreach ($labels as $label) { - $test_entity = entity_create('config_test', array( + $test_entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'id' => $this->randomMachineName(), 'label' => $label, )); diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php index 4d678f8..c3d45e8 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php @@ -197,9 +197,15 @@ protected function assertFieldValues($entity_name, $referenced_entities) { * An array of entity objects. */ protected function getTestEntities() { - $config_entity_1 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName())); + $config_entity_1 = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( + 'id' => $this->randomMachineName(), + 'label' => $this->randomMachineName(), + )); $config_entity_1->save(); - $config_entity_2 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName())); + $config_entity_2 = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( + 'id' => $this->randomMachineName(), + 'label' => $this->randomMachineName(), + )); $config_entity_2->save(); $content_entity_1 = entity_create('entity_test', array('name' => $this->randomMachineName())); diff --git a/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php b/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php index d3b7795..1d80893 100644 --- a/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php +++ b/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php @@ -603,7 +603,7 @@ public function testLookupKeys() { $key_value = $this->container->get('keyvalue')->get(QueryFactory::CONFIG_LOOKUP_PREFIX . 'config_test'); $test_entities = []; - $entity = entity_create('config_test', array( + $entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'label' => $this->randomMachineName(), 'id' => '1', 'style' => 'test', @@ -616,7 +616,7 @@ public function testLookupKeys() { $expected[] = $entity->getConfigDependencyName(); $this->assertEqual($expected, $key_value->get('style:test')); - $entity = entity_create('config_test', array( + $entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'label' => $this->randomMachineName(), 'id' => '2', 'style' => 'test', @@ -627,7 +627,7 @@ public function testLookupKeys() { $expected[] = $entity->getConfigDependencyName(); $this->assertEqual($expected, $key_value->get('style:test')); - $entity = entity_create('config_test', array( + $entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array( 'label' => $this->randomMachineName(), 'id' => '3', 'style' => 'blah', -- 2.1.4