Mercurial > hg > cmmr2012-drupal-site
comparison core/tests/Drupal/Tests/SchemaCheckTestTrait.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests; | |
4 | |
5 use Drupal\Core\Config\TypedConfigManagerInterface; | |
6 use Drupal\Core\Config\Schema\SchemaCheckTrait; | |
7 use Drupal\Component\Utility\SafeMarkup; | |
8 | |
9 /** | |
10 * Provides a class for checking configuration schema. | |
11 */ | |
12 trait SchemaCheckTestTrait { | |
13 | |
14 use SchemaCheckTrait; | |
15 | |
16 /** | |
17 * Asserts the TypedConfigManager has a valid schema for the configuration. | |
18 * | |
19 * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config | |
20 * The TypedConfigManager. | |
21 * @param string $config_name | |
22 * The configuration name. | |
23 * @param array $config_data | |
24 * The configuration data. | |
25 */ | |
26 public function assertConfigSchema(TypedConfigManagerInterface $typed_config, $config_name, $config_data) { | |
27 $errors = $this->checkConfigSchema($typed_config, $config_name, $config_data); | |
28 if ($errors === FALSE) { | |
29 // @todo Since the use of this trait is under TestBase, it works. | |
30 // Can be fixed as part of https://www.drupal.org/node/2260053. | |
31 $this->fail(SafeMarkup::format('No schema for @config_name', ['@config_name' => $config_name])); | |
32 return; | |
33 } | |
34 elseif ($errors === TRUE) { | |
35 // @todo Since the use of this trait is under TestBase, it works. | |
36 // Can be fixed as part of https://www.drupal.org/node/2260053. | |
37 $this->pass(SafeMarkup::format('Schema found for @config_name and values comply with schema.', ['@config_name' => $config_name])); | |
38 } | |
39 else { | |
40 foreach ($errors as $key => $error) { | |
41 // @todo Since the use of this trait is under TestBase, it works. | |
42 // Can be fixed as part of https://www.drupal.org/node/2260053. | |
43 $this->fail(SafeMarkup::format('Schema key @key failed with: @error', ['@key' => $key, '@error' => $error])); | |
44 } | |
45 } | |
46 } | |
47 | |
48 /** | |
49 * Asserts configuration, specified by name, has a valid schema. | |
50 * | |
51 * @param string $config_name | |
52 * The configuration name. | |
53 */ | |
54 public function assertConfigSchemaByName($config_name) { | |
55 $config = $this->config($config_name); | |
56 $this->assertConfigSchema(\Drupal::service('config.typed'), $config->getName(), $config->get()); | |
57 } | |
58 | |
59 } |