From fe247ca5fcef266f67e0b91cdc44ab6c6d44e601 Mon Sep 17 00:00:00 2001 From: webchick Date: Thu, 30 Aug 2012 11:00:16 -0700 Subject: [PATCH] Issue #1668820 follow-up by tim.plunkett, sun: Documentation fixes and clean-ups to Configurables patch. --- core/modules/config/config.api.php | 3 ++ .../Drupal/config/ConfigStorageController.php | 4 +- .../config/Tests/ConfigConfigurableTest.php | 39 ++++++++++++------- .../tests/config_test/config_test.module | 8 ++++ .../lib/Drupal/config_test/ConfigTest.php | 15 +++++++ 5 files changed, 53 insertions(+), 16 deletions(-) diff --git a/core/modules/config/config.api.php b/core/modules/config/config.api.php index d83684c0d611..e5dba3d8e9bf 100644 --- a/core/modules/config/config.api.php +++ b/core/modules/config/config.api.php @@ -72,11 +72,14 @@ function hook_config_import_change($name, $new_config, $old_config) { $id = substr($name, strlen($entity_info['config prefix']) + 1); $config_test = entity_load('config_test', $id); + // Store the original config, and iterate through each property to store it. $config_test->original = clone $config_test; foreach ($old_config->get() as $property => $value) { $config_test->original->$property = $value; } + // Iterate through each property of the new config, copying it to the + // configurable test object. foreach ($new_config->get() as $property => $value) { $config_test->$property = $value; } diff --git a/core/modules/config/lib/Drupal/config/ConfigStorageController.php b/core/modules/config/lib/Drupal/config/ConfigStorageController.php index 57c258363435..12d62b43697d 100644 --- a/core/modules/config/lib/Drupal/config/ConfigStorageController.php +++ b/core/modules/config/lib/Drupal/config/ConfigStorageController.php @@ -137,7 +137,7 @@ class ConfigStorageController implements StorageControllerInterface { * Drupal\taxonomy\TermStorageController::buildQuery() for examples. * * @param $ids - * An array of entity IDs, or FALSE to load all entities. + * An array of entity IDs, or NULL to load all entities. * @param $revision_id * The ID of the revision to load, or FALSE if this query is asking for the * most current revision(s). @@ -149,6 +149,7 @@ class ConfigStorageController implements StorageControllerInterface { $config_class = $this->entityInfo['entity class']; $prefix = $this->entityInfo['config prefix'] . '.'; + // Load all of the configurables. if ($ids === NULL) { $names = drupal_container()->get('config.storage')->listAll($prefix); $result = array(); @@ -161,6 +162,7 @@ class ConfigStorageController implements StorageControllerInterface { else { $result = array(); foreach ($ids as $id) { + // Add the prefix to the ID to serve as the configurable name. $config = config($prefix . $id); if (!$config->isNew()) { $result[$id] = new $config_class($config->get(), $this->entityType); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigConfigurableTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigConfigurableTest.php index 08678120812b..3e73528ee01a 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigConfigurableTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigConfigurableTest.php @@ -14,6 +14,11 @@ use Drupal\simpletest\WebTestBase; */ class ConfigConfigurableTest extends WebTestBase { + /** + * Modules to enable. + * + * @var array + */ public static $modules = array('config_test'); public static function getInfo() { @@ -28,52 +33,56 @@ class ConfigConfigurableTest extends WebTestBase { * Tests basic CRUD operations through the UI. */ function testCRUD() { + $id = strtolower($this->randomName()); + $label1 = $this->randomName(); + $label2 = $this->randomName(); + $label3 = $this->randomName(); + // Create a configurable entity. - $id = 'thingie'; $edit = array( 'id' => $id, - 'label' => 'Thingie', + 'label' => $label1, ); $this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); $this->assertResponse(200); - $this->assertText('Thingie'); + $this->assertText($label1); // Update the configurable entity. $this->assertLinkByHref('admin/structure/config_test/manage/' . $id); $edit = array( - 'label' => 'Thongie', + 'label' => $label2, ); $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save'); $this->assertResponse(200); - $this->assertNoText('Thingie'); - $this->assertText('Thongie'); + $this->assertNoText($label1); + $this->assertText($label2); // Delete the configurable entity. $this->assertLinkByHref('admin/structure/config_test/manage/' . $id . '/delete'); $this->drupalPost('admin/structure/config_test/manage/' . $id . '/delete', array(), 'Delete'); $this->assertResponse(200); - $this->assertNoText('Thingie'); - $this->assertNoText('Thongie'); + $this->assertNoText($label1); + $this->assertNoText($label2); // Re-create a configurable entity. $edit = array( 'id' => $id, - 'label' => 'Thingie', + 'label' => $label1, ); $this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); $this->assertResponse(200); - $this->assertText('Thingie'); + $this->assertText($label1); // Rename the configurable entity's ID/machine name. $this->assertLinkByHref('admin/structure/config_test/manage/' . $id); - $new_id = 'zingie'; $edit = array( - 'id' => $new_id, - 'label' => 'Zingie', + 'id' => strtolower($this->randomName()), + 'label' => $label3, ); $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save'); $this->assertResponse(200); - $this->assertNoText('Thingie'); - $this->assertText('Zingie'); + $this->assertNoText($label1); + $this->assertText($label3); } + } diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index e5550d0c1f9d..5d422ad9be37 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -1,5 +1,10 @@ original = clone $config_test; foreach ($old_config->get() as $property => $value) { $config_test->original->$property = $value; } + // Iterate through each property of the new config, copying it to the + // configurable test object. foreach ($new_config->get() as $property => $value) { $config_test->$property = $value; } diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTest.php index 7431e4b24e1c..ca3550c82a5f 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTest.php @@ -14,10 +14,25 @@ use Drupal\config\ConfigurableBase; */ class ConfigTest extends ConfigurableBase { + /** + * The machine name for the configurable. + * + * @var string + */ public $id; + /** + * The UUID for the configurable. + * + * @var string + */ public $uuid; + /** + * The human-readable name of the configurable. + * + * @var string + */ public $label; /**