SchemaConfigListenerWebTest.php in Drupal 8
File
core/modules/config/tests/src/Functional/SchemaConfigListenerWebTest.php
View source
<?php
namespace Drupal\Tests\config\Functional;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\Tests\BrowserTestBase;
class SchemaConfigListenerWebTest extends BrowserTestBase {
public static $modules = [
'config_test',
];
protected $defaultTheme = 'stark';
public function testConfigSchemaChecker() {
$this
->drupalLogin($this
->drupalCreateUser([
'administer site configuration',
]));
try {
$this
->config('config_schema_test.schemaless')
->set('foo', 'bar')
->save();
$this
->fail('Expected SchemaIncompleteException thrown');
} catch (SchemaIncompleteException $e) {
$this
->assertEquals('No schema for config_schema_test.schemaless', $e
->getMessage());
}
$config = $this
->config('config_test.types')
->set('int', 10);
try {
$config
->save();
} catch (SchemaIncompleteException $e) {
$this
->fail('Unexpected SchemaIncompleteException thrown');
}
$config = $this
->config('config_test.types')
->set('foo', 'bar')
->set('array', 1);
try {
$config
->save();
$this
->fail('Expected SchemaIncompleteException thrown');
} catch (SchemaIncompleteException $e) {
$this
->assertEquals('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());
}
$this
->drupalGet('config_test/schema_listener');
$this
->assertText('No schema for config_schema_test.schemaless');
}
}