From f485fc18745baf392725d280fde5267776578cf0 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Thu, 10 Oct 2024 16:36:31 -0700 Subject: [PATCH] More tests --- .../src/Config/DecoupledConfigOverrides.php | 5 -- .../Config/DecoupledConfigOverridesTest.php | 69 +++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 modules/stanford_decoupled/tests/src/Unit/Config/DecoupledConfigOverridesTest.php diff --git a/modules/stanford_decoupled/src/Config/DecoupledConfigOverrides.php b/modules/stanford_decoupled/src/Config/DecoupledConfigOverrides.php index 032a7639..361cac4d 100644 --- a/modules/stanford_decoupled/src/Config/DecoupledConfigOverrides.php +++ b/modules/stanford_decoupled/src/Config/DecoupledConfigOverrides.php @@ -12,11 +12,6 @@ */ class DecoupledConfigOverrides implements ConfigFactoryOverrideInterface { - /** - * Config override constructor. - */ - public function __construct() {} - /** * {@inheritDoc} */ diff --git a/modules/stanford_decoupled/tests/src/Unit/Config/DecoupledConfigOverridesTest.php b/modules/stanford_decoupled/tests/src/Unit/Config/DecoupledConfigOverridesTest.php new file mode 100644 index 00000000..068327dd --- /dev/null +++ b/modules/stanford_decoupled/tests/src/Unit/Config/DecoupledConfigOverridesTest.php @@ -0,0 +1,69 @@ +createMock(QueryInterface::class); + $entity_query->method('accessCheck')->willReturnSelf(); + $entity_query->method('count')->willReturnSelf(); + $entity_query->method('execute')->willReturnReference($this->entityCount); + + $entity_storage = $this->createMock(EntityStorageInterface::class); + $entity_storage->method('getQuery')->willReturn($entity_query); + + $cache = $this->createMock(CacheBackendInterface::class); + $cache->method('get')->willReturnReference($this->cacheData); + + $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); + $entity_type_manager->method('hasDefinition') + ->willReturnReference($this->hasEntityDefinition); + $entity_type_manager->method('getStorage') + ->willReturn($entity_storage); + + $container = new ContainerBuilder(); + $container->set('cache.default', $cache); + $container->set('entity_type.manager', $entity_type_manager); + \Drupal::setContainer($container); + } + + public function testConfigOverrides() { + $overrider = new DecoupledConfigOverrides(); + $overrides = $overrider->loadOverrides(['filter.format.html']); + $this->assertEmpty($overrides); + + $this->hasEntityDefinition = TRUE; + $overrides = $overrider->loadOverrides(['filter.format.html']); + $this->assertEmpty($overrides); + + $this->entityCount = 1; + $overrides = $overrider->loadOverrides(['filter.format.html']); + $this->assertNotEmpty($overrides); + + $this->cacheData = new \stdClass(); + $this->cacheData->data = TRUE; + $overrides = $overrider->loadOverrides(['filter.format.html']); + $this->assertNotEmpty($overrides); + } + +}