createDatabaseInterface();
$GLOBALS['server'] = 0;
$GLOBALS['db'] = 'db';
$GLOBALS['table'] = 'table';
$GLOBALS['token_provided'] = true;
$GLOBALS['token_mismatch'] = false;
$this->object = new AuthenticationConfig();
}
/**
* tearDown for test cases
*/
protected function tearDown(): void
{
parent::tearDown();
unset($this->object);
}
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuth(): void
{
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
ResponseRenderer::getInstance()->setAjax(true);
$this->expectException(ExitException::class);
$this->object->showLoginForm();
}
public function testAuthCheck(): void
{
Config::getInstance()->selectedServer = ['user' => 'username', 'password' => 'password'];
$this->assertTrue(
$this->object->readCredentials(),
);
}
public function testAuthSetUser(): void
{
$this->assertTrue(
$this->object->storeCredentials(),
);
}
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthFails(): void
{
Config::getInstance()->settings['Servers'] = [1];
$GLOBALS['allowDeny_forbidden'] = false;
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
DatabaseInterface::$instance = $dbi;
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
ob_start();
try {
$this->object->showFailure('');
} catch (Throwable $throwable) {
}
$html = ob_get_clean();
$this->assertInstanceOf(ExitException::class, $throwable);
$this->assertIsString($html);
$this->assertStringContainsString(
'You probably did not create a configuration file. You might want ' .
'to use the setup script to create one.',
$html,
);
$this->assertStringContainsString(
'MySQL said: ' .
'
',
$html,
);
$this->assertStringContainsString('Cannot connect: invalid settings.', $html);
$this->assertStringContainsString(
'Retry to connect',
$html,
);
}
}