SchemaCheckTraitTest.php 1.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php

/**
 * @file
 * Contains \Drupal\config\Tests\SchemaCheckTraitTest.
 */

namespace Drupal\config\Tests;

use Drupal\Core\Config\Schema\SchemaCheckTrait;
use Drupal\simpletest\KernelTestBase;


/**
15
16
17
 * Tests the functionality of SchemaCheckTrait.
 *
 * @group config
18
19
 */
class SchemaCheckTraitTest extends KernelTestBase {
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  use SchemaCheckTrait;

  /**
   * The typed config manager.
   *
   * @var \Drupal\Core\Config\TypedConfigManagerInterface
   */
  protected $typedConfig;

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('config_test', 'config_schema_test');

  /**
   * {@inheritdoc}
   */
40
  protected function setUp() {
41
42
43
44
45
46
47
48
49
50
    parent::setUp();
    $this->installConfig(array('config_test', 'config_schema_test'));
    $this->typedConfig = \Drupal::service('config.typed');
  }

  /**
   * Tests \Drupal\Core\Config\Schema\SchemaCheckTrait.
   */
  public function testTrait() {
    // Test a non existing schema.
51
    $ret = $this->checkConfigSchema($this->typedConfig, 'config_schema_test.noschema', $this->config('config_schema_test.noschema')->get());
52
53
54
    $this->assertIdentical($ret, FALSE);

    // Test an existing schema with valid data.
55
    $config_data = $this->config('config_test.types')->get();
56
57
58
    $ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
    $this->assertIdentical($ret, TRUE);

59
60
    // Add a new key, a new array and overwrite boolean with array to test the
    // error messages.
61
    $config_data = array('new_key' => 'new_value', 'new_array' => array()) + $config_data;
62
    $config_data['boolean'] = array();
63
64
    $ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
    $expected = array(
65
66
67
      'config_test.types:new_key' => 'missing schema',
      'config_test.types:new_array' => 'missing schema',
      'config_test.types:boolean' => 'non-scalar value but not defined as an array (such as mapping or sequence)',
68
    );
69
    $this->assertEqual($ret, $expected);
70
71
72
  }

}