_oController = oxNew(d3force_2fa::class); } /** * @test * @return void * @throws ReflectionException * @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::render */ public function testRender() { $expected = 'fixture'; Registry::getSession()->setVariable('auth', $expected); $this->callMethod( $this->_oController, 'render' ); $this->assertTrue( $this->_oController->getViewDataElement('force2FA') ); $this->assertSame( $expected, $this->getValue( $this->_oController, '_sEditObjectId' ) ); } /** * @test * @return void * @throws ReflectionException * @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::_authorize * @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::d3IsAdminForce2FA * @dataProvider authorizeDataProvider */ public function testAuthorize($expected, $isAdmin, $force2FA, $givenUserId) { /** @var d3force_2fa|MockObject $oController */ $oController = $this->getMockBuilder(d3force_2fa::class) ->onlyMethods(['isAdmin']) ->getMock(); $oController->expects($this->once())->method('isAdmin')->willReturn($isAdmin); Registry::getConfig()->setConfigParam('D3_TOTP_ADMIN_FORCE_2FA', $force2FA); Registry::getSession()->setVariable('auth', $givenUserId); $this->assertSame( $expected, $this->callMethod( $oController, '_authorize' ) ); } /** * @return array[] */ public function authorizeDataProvider(): array { return [ 'noAdmin' => [false, false, true, 'userId'], 'dont force' => [false, true, false, 'userId'], 'no user id' => [false, true, true, null], 'passed' => [true, true, true, 'userId'], ]; } /** * @test * @return void * @throws ReflectionException * @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::d3GetSessionObject */ public function testD3GetSessionObject() { $this->assertInstanceOf( Session::class, $this->callMethod( $this->_oController, 'd3GetSessionObject' ) ); } }