createMock(ScopeConfigInterface::class); $scopeConfig->method('isSetFlag')->willReturn($enabled); $scopeConfig->method('getValue')->willReturn($allowedGroups); $httpContext = $this->createMock(HttpContext::class); $httpContext->method('getValue') ->with(CustomerContext::CONTEXT_GROUP) ->willReturn($currentGroupId); self::assertSame($expected, (new TestModeConfig($scopeConfig, $httpContext))->isRestricted()); } public static function restrictionProvider(): array { return [ 'mode disabled' => [false, null, 1, false], 'allowed group' => [true, '1,3', 3, false], 'blocked group' => [true, '1,3', 2, true], 'no groups configured' => [true, null, 1, true], ]; } public function testPopupTextUsesConfiguredValues(): void { $config = $this->createConfig([ 'esun_cart/test_mode/popup_title' => 'Private Preview', 'esun_cart/test_mode/popup_message' => 'Purchasing opens soon.', ]); self::assertSame('Private Preview', $config->getPopupTitle()); self::assertSame('Purchasing opens soon.', $config->getPopupMessage()); } public function testPopupTextFallsBackWhenValuesAreEmpty(): void { $config = $this->createConfig([ 'esun_cart/test_mode/popup_title' => ' ', 'esun_cart/test_mode/popup_message' => null, ]); self::assertSame('Test Mode', $config->getPopupTitle()); self::assertSame( 'Our website is currently in beta testing. Purchases are not available at this time.', $config->getPopupMessage() ); } /** @param array $values */ private function createConfig(array $values): TestModeConfig { $scopeConfig = $this->createMock(ScopeConfigInterface::class); $scopeConfig->method('getValue')->willReturnCallback( static fn (string $path): ?string => $values[$path] ?? null ); return new TestModeConfig($scopeConfig, $this->createMock(HttpContext::class)); } }