ConfigFormBaseTraitTest.php in Drupal 9
File
core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php
View source
<?php
namespace Drupal\Tests\Core\Form;
use Drupal\Tests\UnitTestCase;
class ConfigFormBaseTraitTest extends UnitTestCase {
public function testConfig() {
$trait = $this
->getMockForTrait('Drupal\\Core\\Form\\ConfigFormBaseTrait');
$trait->configFactory = $this
->getConfigFactoryStub([
'editable.config' => [],
'immutable.config' => [],
]);
$trait
->expects($this
->any())
->method('getEditableConfigNames')
->willReturn([
'editable.config',
]);
$config_method = new \ReflectionMethod($trait, 'config');
$config_method
->setAccessible(TRUE);
$result = $config_method
->invoke($trait, 'editable.config');
$this
->assertInstanceOf('\\Drupal\\Core\\Config\\Config', $result);
$this
->assertNotInstanceOf('\\Drupal\\Core\\Config\\ImmutableConfig', $result);
$result = $config_method
->invoke($trait, 'immutable.config');
$this
->assertInstanceOf('\\Drupal\\Core\\Config\\ImmutableConfig', $result);
}
public function testConfigFactoryException() {
$trait = $this
->getMockForTrait('Drupal\\Core\\Form\\ConfigFormBaseTrait');
$config_method = new \ReflectionMethod($trait, 'config');
$config_method
->setAccessible(TRUE);
$this
->expectException(\LogicException::class);
$this
->expectExceptionMessage('No config factory available for ConfigFormBaseTrait');
$config_method
->invoke($trait, 'editable.config');
}
public function testConfigFactoryExceptionInvalidProperty() {
$trait = $this
->getMockForTrait('Drupal\\Core\\Form\\ConfigFormBaseTrait');
$trait->configFactory = TRUE;
$config_method = new \ReflectionMethod($trait, 'config');
$config_method
->setAccessible(TRUE);
$this
->expectException(\LogicException::class);
$this
->expectExceptionMessage('No config factory available for ConfigFormBaseTrait');
$config_method
->invoke($trait, 'editable.config');
}
}