Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / config / tests / src / Functional / SchemaConfigListenerWebTest.php
1 <?php
2
3 namespace Drupal\Tests\config\Functional;
4
5 use Drupal\Core\Config\Schema\SchemaIncompleteException;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests the functionality of ConfigSchemaChecker in WebTestBase tests.
10  *
11  * @group config
12  */
13 class SchemaConfigListenerWebTest extends BrowserTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['config_test'];
19
20   /**
21    * Tests \Drupal\Core\Config\Development\ConfigSchemaChecker.
22    */
23   public function testConfigSchemaChecker() {
24     $this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
25
26     // Test a non-existing schema.
27     $msg = 'Expected SchemaIncompleteException thrown';
28     try {
29       $this->config('config_schema_test.schemaless')->set('foo', 'bar')->save();
30       $this->fail($msg);
31     }
32     catch (SchemaIncompleteException $e) {
33       $this->pass($msg);
34       $this->assertEqual('No schema for config_schema_test.schemaless', $e->getMessage());
35     }
36
37     // Test a valid schema.
38     $msg = 'Unexpected SchemaIncompleteException thrown';
39     $config = $this->config('config_test.types')->set('int', 10);
40     try {
41       $config->save();
42       $this->pass($msg);
43     }
44     catch (SchemaIncompleteException $e) {
45       $this->fail($msg);
46     }
47
48     // Test an invalid schema.
49     $msg = 'Expected SchemaIncompleteException thrown';
50     $config = $this->config('config_test.types')
51       ->set('foo', 'bar')
52       ->set('array', 1);
53     try {
54       $config->save();
55       $this->fail($msg);
56     }
57     catch (SchemaIncompleteException $e) {
58       $this->pass($msg);
59       $this->assertEqual('Schema errors for config_test.types with the following errors: config_test.types:array variable type is integer but applied schema class is Drupal\Core\Config\Schema\Sequence, config_test.types:foo missing schema', $e->getMessage());
60     }
61
62     // Test that the config event listener is working in the child site.
63     $this->drupalGet('config_test/schema_listener');
64     $this->assertText('No schema for config_schema_test.schemaless');
65   }
66
67 }