PageRenderTime 50ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/test/classes/Plugins/Auth/AuthenticationConfigTest.php

http://github.com/phpmyadmin/phpmyadmin
PHP | 115 lines | 87 code | 18 blank | 10 comment | 0 complexity | b18280b4f91bcf74632a983a30cacc85 MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Tests\Plugins\Auth;
  4. use PhpMyAdmin\DatabaseInterface;
  5. use PhpMyAdmin\ErrorHandler;
  6. use PhpMyAdmin\Plugins\Auth\AuthenticationConfig;
  7. use PhpMyAdmin\Tests\AbstractTestCase;
  8. use function ob_get_clean;
  9. use function ob_start;
  10. /**
  11. * @covers \PhpMyAdmin\Plugins\Auth\AuthenticationConfig
  12. */
  13. class AuthenticationConfigTest extends AbstractTestCase
  14. {
  15. /** @var AuthenticationConfig */
  16. protected $object;
  17. /**
  18. * Configures global environment.
  19. */
  20. protected function setUp(): void
  21. {
  22. parent::setUp();
  23. parent::setLanguage();
  24. parent::setGlobalConfig();
  25. parent::setTheme();
  26. $GLOBALS['server'] = 0;
  27. $GLOBALS['db'] = 'db';
  28. $GLOBALS['table'] = 'table';
  29. $GLOBALS['PMA_PHP_SELF'] = 'index.php';
  30. $GLOBALS['token_provided'] = true;
  31. $GLOBALS['token_mismatch'] = false;
  32. $this->object = new AuthenticationConfig();
  33. }
  34. /**
  35. * tearDown for test cases
  36. */
  37. protected function tearDown(): void
  38. {
  39. parent::tearDown();
  40. unset($this->object);
  41. }
  42. public function testAuth(): void
  43. {
  44. $this->assertTrue(
  45. $this->object->showLoginForm()
  46. );
  47. }
  48. public function testAuthCheck(): void
  49. {
  50. $GLOBALS['cfg']['Server'] = [
  51. 'user' => 'username',
  52. 'password' => 'password',
  53. ];
  54. $this->assertTrue(
  55. $this->object->readCredentials()
  56. );
  57. }
  58. public function testAuthSetUser(): void
  59. {
  60. $this->assertTrue(
  61. $this->object->storeCredentials()
  62. );
  63. }
  64. public function testAuthFails(): void
  65. {
  66. $GLOBALS['errorHandler'] = new ErrorHandler();
  67. $GLOBALS['cfg']['Servers'] = [1];
  68. $GLOBALS['allowDeny_forbidden'] = false;
  69. $dbi = $this->getMockBuilder(DatabaseInterface::class)
  70. ->disableOriginalConstructor()
  71. ->getMock();
  72. $GLOBALS['dbi'] = $dbi;
  73. ob_start();
  74. $this->object->showFailure('');
  75. $html = ob_get_clean();
  76. $this->assertIsString($html);
  77. $this->assertStringContainsString(
  78. 'You probably did not create a configuration file. You might want ' .
  79. 'to use the <a href="setup/">setup script</a> to create one.',
  80. $html
  81. );
  82. $this->assertStringContainsString(
  83. '<strong>MySQL said: </strong><a href="./url.php?url=https%3A%2F%2F' .
  84. 'dev.mysql.com%2Fdoc%2Frefman%2F5.5%2Fen%2Fserver-error-reference.html"' .
  85. ' target="mysql_doc">' .
  86. '<img src="themes/dot.gif" title="Documentation" alt="Documentation" ' .
  87. 'class="icon ic_b_help"></a>',
  88. $html
  89. );
  90. $this->assertStringContainsString('Cannot connect: invalid settings.', $html);
  91. $this->assertStringContainsString(
  92. '<a href="index.php?route=/&server=0&lang=en" '
  93. . 'class="btn btn-primary mt-1 mb-1 disableAjax">Retry to connect</a>',
  94. $html
  95. );
  96. }
  97. }