diff --git a/Test/Unit/Model/ConfigTest.php b/Test/Unit/Model/ConfigTest.php new file mode 100644 index 0000000..464db96 --- /dev/null +++ b/Test/Unit/Model/ConfigTest.php @@ -0,0 +1,94 @@ +stateMock = $this->createMock(State::class); + $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class); + + $this->sut = new Config( + $this->stateMock, + $this->scopeConfigMock, + ); + } + + public function testIsEnabledInDeveloperMode(): void + { + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_DEVELOPER); + + $this->scopeConfigMock->expects($this->never())->method('isSetFlag'); + + $this->assertTrue( + $this->sut->isEnabled( + $this->createMock(StoreInterface::class) + ) + ); + } + + public function testIfIsEnabledBySettingTheRightConfig() + { + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_PRODUCTION); + + $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with( + 'dev/graphiql/enabled_in_production', + ScopeInterface::SCOPE_STORE, + $this->createMock(StoreInterface::class) + )->willReturn(true); + + $this->assertTrue( + $this->sut->isEnabled( + $this->createMock(StoreInterface::class) + ) + ); + } + + public function testIfIsDisabledBySettingTheRightConfig() + { + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_PRODUCTION); + + $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with( + 'dev/graphiql/enabled_in_production', + ScopeInterface::SCOPE_STORE, + $this->createMock(StoreInterface::class) + )->willReturn(false); + + $this->assertFalse( + $this->sut->isEnabled( + $this->createMock(StoreInterface::class) + ) + ); + } +}