Issue #1668820 follow-up by tim.plunkett, sun: Documentation fixes and clean-ups to Configurables patch.

8.0.x
webchick 2012-08-30 11:00:16 -07:00
parent cc204b607f
commit fe247ca5fc
5 changed files with 53 additions and 16 deletions

View File

@ -72,11 +72,14 @@ function hook_config_import_change($name, $new_config, $old_config) {
$id = substr($name, strlen($entity_info['config prefix']) + 1); $id = substr($name, strlen($entity_info['config prefix']) + 1);
$config_test = entity_load('config_test', $id); $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; $config_test->original = clone $config_test;
foreach ($old_config->get() as $property => $value) { foreach ($old_config->get() as $property => $value) {
$config_test->original->$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) { foreach ($new_config->get() as $property => $value) {
$config_test->$property = $value; $config_test->$property = $value;
} }

View File

@ -137,7 +137,7 @@ class ConfigStorageController implements StorageControllerInterface {
* Drupal\taxonomy\TermStorageController::buildQuery() for examples. * Drupal\taxonomy\TermStorageController::buildQuery() for examples.
* *
* @param $ids * @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 * @param $revision_id
* The ID of the revision to load, or FALSE if this query is asking for the * The ID of the revision to load, or FALSE if this query is asking for the
* most current revision(s). * most current revision(s).
@ -149,6 +149,7 @@ class ConfigStorageController implements StorageControllerInterface {
$config_class = $this->entityInfo['entity class']; $config_class = $this->entityInfo['entity class'];
$prefix = $this->entityInfo['config prefix'] . '.'; $prefix = $this->entityInfo['config prefix'] . '.';
// Load all of the configurables.
if ($ids === NULL) { if ($ids === NULL) {
$names = drupal_container()->get('config.storage')->listAll($prefix); $names = drupal_container()->get('config.storage')->listAll($prefix);
$result = array(); $result = array();
@ -161,6 +162,7 @@ class ConfigStorageController implements StorageControllerInterface {
else { else {
$result = array(); $result = array();
foreach ($ids as $id) { foreach ($ids as $id) {
// Add the prefix to the ID to serve as the configurable name.
$config = config($prefix . $id); $config = config($prefix . $id);
if (!$config->isNew()) { if (!$config->isNew()) {
$result[$id] = new $config_class($config->get(), $this->entityType); $result[$id] = new $config_class($config->get(), $this->entityType);

View File

@ -14,6 +14,11 @@ use Drupal\simpletest\WebTestBase;
*/ */
class ConfigConfigurableTest extends WebTestBase { class ConfigConfigurableTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('config_test'); public static $modules = array('config_test');
public static function getInfo() { public static function getInfo() {
@ -28,52 +33,56 @@ class ConfigConfigurableTest extends WebTestBase {
* Tests basic CRUD operations through the UI. * Tests basic CRUD operations through the UI.
*/ */
function testCRUD() { function testCRUD() {
$id = strtolower($this->randomName());
$label1 = $this->randomName();
$label2 = $this->randomName();
$label3 = $this->randomName();
// Create a configurable entity. // Create a configurable entity.
$id = 'thingie';
$edit = array( $edit = array(
'id' => $id, 'id' => $id,
'label' => 'Thingie', 'label' => $label1,
); );
$this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); $this->drupalPost('admin/structure/config_test/add', $edit, 'Save');
$this->assertResponse(200); $this->assertResponse(200);
$this->assertText('Thingie'); $this->assertText($label1);
// Update the configurable entity. // Update the configurable entity.
$this->assertLinkByHref('admin/structure/config_test/manage/' . $id); $this->assertLinkByHref('admin/structure/config_test/manage/' . $id);
$edit = array( $edit = array(
'label' => 'Thongie', 'label' => $label2,
); );
$this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save'); $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save');
$this->assertResponse(200); $this->assertResponse(200);
$this->assertNoText('Thingie'); $this->assertNoText($label1);
$this->assertText('Thongie'); $this->assertText($label2);
// Delete the configurable entity. // Delete the configurable entity.
$this->assertLinkByHref('admin/structure/config_test/manage/' . $id . '/delete'); $this->assertLinkByHref('admin/structure/config_test/manage/' . $id . '/delete');
$this->drupalPost('admin/structure/config_test/manage/' . $id . '/delete', array(), 'Delete'); $this->drupalPost('admin/structure/config_test/manage/' . $id . '/delete', array(), 'Delete');
$this->assertResponse(200); $this->assertResponse(200);
$this->assertNoText('Thingie'); $this->assertNoText($label1);
$this->assertNoText('Thongie'); $this->assertNoText($label2);
// Re-create a configurable entity. // Re-create a configurable entity.
$edit = array( $edit = array(
'id' => $id, 'id' => $id,
'label' => 'Thingie', 'label' => $label1,
); );
$this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); $this->drupalPost('admin/structure/config_test/add', $edit, 'Save');
$this->assertResponse(200); $this->assertResponse(200);
$this->assertText('Thingie'); $this->assertText($label1);
// Rename the configurable entity's ID/machine name. // Rename the configurable entity's ID/machine name.
$this->assertLinkByHref('admin/structure/config_test/manage/' . $id); $this->assertLinkByHref('admin/structure/config_test/manage/' . $id);
$new_id = 'zingie';
$edit = array( $edit = array(
'id' => $new_id, 'id' => strtolower($this->randomName()),
'label' => 'Zingie', 'label' => $label3,
); );
$this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save'); $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save');
$this->assertResponse(200); $this->assertResponse(200);
$this->assertNoText('Thingie'); $this->assertNoText($label1);
$this->assertText('Zingie'); $this->assertText($label3);
} }
} }

View File

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* Provides Config module hook implementations for testing purposes.
*/
use Drupal\config_test\ConfigTest; use Drupal\config_test\ConfigTest;
require_once dirname(__FILE__) . '/config_test.hooks.inc'; require_once dirname(__FILE__) . '/config_test.hooks.inc';
@ -35,11 +40,14 @@ function config_test_config_import_change($name, $new_config, $old_config) {
$id = substr($name, strlen($entity_info['config prefix']) + 1); $id = substr($name, strlen($entity_info['config prefix']) + 1);
$config_test = entity_load('config_test', $id); $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; $config_test->original = clone $config_test;
foreach ($old_config->get() as $property => $value) { foreach ($old_config->get() as $property => $value) {
$config_test->original->$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) { foreach ($new_config->get() as $property => $value) {
$config_test->$property = $value; $config_test->$property = $value;
} }

View File

@ -14,10 +14,25 @@ use Drupal\config\ConfigurableBase;
*/ */
class ConfigTest extends ConfigurableBase { class ConfigTest extends ConfigurableBase {
/**
* The machine name for the configurable.
*
* @var string
*/
public $id; public $id;
/**
* The UUID for the configurable.
*
* @var string
*/
public $uuid; public $uuid;
/**
* The human-readable name of the configurable.
*
* @var string
*/
public $label; public $label;
/** /**