From 29a839062d30e97d23c4893a3d5073da5f71f3ab Mon Sep 17 00:00:00 2001 From: webchick Date: Thu, 26 Jun 2014 23:41:09 -0700 Subject: [PATCH] Issue #2293105 by vijaycs85: MigrateActionConfigSchemaTest duplicates all its code from SchemaCheckTestTrait. --- .../d6/MigrateActionConfigSchemaTest.php | 7 +- .../src/Tests/d6/MigrateConfigSchemaBase.php | 145 ------------------ 2 files changed, 6 insertions(+), 146 deletions(-) delete mode 100644 core/modules/migrate_drupal/src/Tests/d6/MigrateConfigSchemaBase.php diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateActionConfigSchemaTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateActionConfigSchemaTest.php index a0d27920b35..ee7883f8033 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateActionConfigSchemaTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateActionConfigSchemaTest.php @@ -7,12 +7,17 @@ namespace Drupal\migrate_drupal\Tests\d6; +use Drupal\config\Tests\SchemaCheckTestTrait; use Drupal\migrate\MigrateExecutable; +use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; /** * Tests the language config schema. */ -class MigrateActionConfigSchemaTest extends MigrateConfigSchemaBase { +class MigrateActionConfigSchemaTest extends MigrateDrupalTestBase { + + use SchemaCheckTestTrait; + /** * Modules to enable. * diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateConfigSchemaBase.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateConfigSchemaBase.php deleted file mode 100644 index 7af563f0a10..00000000000 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateConfigSchemaBase.php +++ /dev/null @@ -1,145 +0,0 @@ -configName = $config_name; - if (!$typed_config->hasConfigSchema($config_name)) { - $this->fail(String::format('No schema for !config_name', array('!config_name' => $config_name))); - return; - } - $definition = $typed_config->getDefinition($config_name); - $data_definition = $typed_config->buildDataDefinition($definition, $config_data); - $this->schema = $typed_config->create($data_definition, $config_data); - $this->configPass = TRUE; - foreach ($config_data as $key => $value) { - $this->checkValue($key, $value); - } - if ($this->configPass) { - $this->pass(String::format('Schema found for !config_name and values comply with schema.', array('!config_name' => $config_name))); - } - } - - /** - * Helper method to check data type. - * - * @param string $key - * A string of configuration key. - * @param mixed $value - * Value of given key. - * - * @return mixed - * Returns mixed value. - */ - protected function checkValue($key, $value) { - $element = FALSE; - try { - $element = $this->schema->get($key); - } - catch (SchemaIncompleteException $e) { - if (is_scalar($value) || $value === NULL) { - $this->fail("{$this->configName}:$key has no schema."); - } - } - // Do not check value if it is defined to be ignored. - if ($element && $element instanceof Ignore) { - return $value; - } - - if (is_scalar($value) || $value === NULL) { - $success = FALSE; - $type = gettype($value); - if ($element instanceof PrimitiveInterface) { - $success = - ($type == 'integer' && $element instanceof IntegerInterface) || - ($type == 'double' && $element instanceof FloatInterface) || - ($type == 'boolean' && $element instanceof BooleanInterface) || - ($type == 'string' && $element instanceof StringInterface) || - // Null values are allowed for all types. - ($value === NULL); - } - $class = get_class($element); - if (!$success) { - $this->fail("{$this->configName}:$key has the wrong schema. Variable type is $type and schema class is $class."); - } - } - else { - if (!$element instanceof ArrayElement) { - $this->fail("Non-scalar {$this->configName}:$key is not defined as an array type (such as mapping or sequence)."); - } - - // Go on processing so we can get errors on all levels. Any non-scalar - // value must be an array so cast to an array. - if (!is_array($value)) { - $value = (array) $value; - } - // Recurse into any nested keys. - foreach ($value as $nested_value_key => $nested_value) { - $value[$nested_value_key] = $this->checkValue($key . '.' . $nested_value_key, $nested_value); - } - } - return $value; - } - - /** - * {@inheritdoc} - */ - protected function fail($message = NULL, $group = 'Other') { - $this->configPass = FALSE; - return parent::fail($message, $group); - } - -}