phpmyadmin/test/classes/Config/ServerConfigChecksTest.php
William Desportes e816e45c18 phpstan level 0 (#14405)
* Fix phpdoc @return

- Fixed @return typehint

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix incorrect case on function calls

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Type hint + typo fix

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fixes

- @return fix
- @var fix
- Class names
- Throws fix
- test/classes/Plugins/Export/ExportSqlTest.php any() invoked with 1 parameter, 0 required
-  libraries/classes/Controllers/Table/TableStructureController.php Array has 2 duplicate keys with value 'columns_list'
- Call parent constructor  libraries/classes/Error.php

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Update config

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Access to an undefined property

- Access to an undefined property PhpMyAdmin\Plugins\Schema\Pdf\PdfRelationSchema::$diagram_row
- Access to an undefined property PhpMyAdmin\Plugins\Schema\Pdf\Pdf::$cMargin
- Undefined properties

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Update config

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix bootstrap-phpstan

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix typos and phpstan config

Fixes: #14399
Signed-off-by: William Desportes <williamdes@wdes.fr>
2018-06-25 20:34:46 -03:00

174 lines
4.8 KiB
PHP

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for FormDisplay class in config folder
*
* @package PhpMyAdmin-test
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Config;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\ConfigFile;
use PhpMyAdmin\Config\ServerConfigChecks;
use PhpMyAdmin\Tests\PmaTestCase;
use ReflectionProperty;
/**
* Tests for ServeConfigChecks class
*
* @package PhpMyAdmin-test
*/
class ServerConfigChecksTest extends PmaTestCase
{
/**
* @var string
*/
private $sessionID;
/**
* @throws \ReflectionException
*
* @return void
*/
protected function setUp()
{
$GLOBALS['PMA_Config'] = new Config();
$GLOBALS['cfg']['AvailableCharsets'] = [];
$GLOBALS['cfg']['ServerDefault'] = 0;
$GLOBALS['server'] = 0;
$cf = new ConfigFile();
$GLOBALS['ConfigFile'] = $cf;
$reflection = new ReflectionProperty('PhpMyAdmin\Config\ConfigFile', '_id');
$reflection->setAccessible(true);
$this->sessionID = $reflection->getValue($cf);
unset($_SESSION['messages']);
unset($_SESSION[$this->sessionID]);
}
/**
* @return void
*/
public function testManyErrors()
{
$_SESSION[$this->sessionID]['Servers'] = [
'1' => [
'host' => 'localhost',
'ssl' => false,
'auth_type' => 'config',
'user' => 'username',
'password' => 'password',
'AllowRoot' => true,
'AllowNoPassword' => true,
]
];
$_SESSION[$this->sessionID]['AllowArbitraryServer'] = true;
$_SESSION[$this->sessionID]['LoginCookieValidity'] = 5000;
$_SESSION[$this->sessionID]['LoginCookieStore'] = 4000;
$_SESSION[$this->sessionID]['SaveDir'] = true;
$_SESSION[$this->sessionID]['TempDir'] = true;
$_SESSION[$this->sessionID]['GZipDump'] = true;
$_SESSION[$this->sessionID]['BZipDump'] = true;
$_SESSION[$this->sessionID]['ZipDump'] = true;
$configChecker = $this->getMockBuilder('PhpMyAdmin\Config\ServerConfigChecks')
->setMethods(['functionExists'])
->setConstructorArgs([$GLOBALS['ConfigFile']])
->getMock();
// Configure the stub.
$configChecker->method('functionExists')->willReturn(false);
$configChecker->performConfigChecks();
$this->assertEquals(
[
'Servers/1/ssl',
'Servers/1/auth_type',
'Servers/1/AllowNoPassword',
'AllowArbitraryServer',
'LoginCookieValidity',
'SaveDir',
'TempDir',
],
array_keys($_SESSION['messages']['notice'])
);
$this->assertEquals(
[
'LoginCookieValidity',
'GZipDump',
'BZipDump',
'ZipDump_import',
'ZipDump_export',
],
array_keys($_SESSION['messages']['error'])
);
}
/**
* @return void
*/
public function testBlowfishCreate()
{
$_SESSION[$this->sessionID]['Servers'] = [
'1' => [
'host' => 'localhost',
'ssl' => true,
'auth_type' => 'cookie',
'AllowRoot' => false
]
];
$_SESSION[$this->sessionID]['AllowArbitraryServer'] = false;
$_SESSION[$this->sessionID]['LoginCookieValidity'] = -1;
$_SESSION[$this->sessionID]['LoginCookieStore'] = 0;
$_SESSION[$this->sessionID]['SaveDir'] = '';
$_SESSION[$this->sessionID]['TempDir'] = '';
$_SESSION[$this->sessionID]['GZipDump'] = false;
$_SESSION[$this->sessionID]['BZipDump'] = false;
$_SESSION[$this->sessionID]['ZipDump'] = false;
$configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
$configChecker->performConfigChecks();
$this->assertEquals(
['blowfish_secret_created'],
array_keys($_SESSION['messages']['notice'])
);
$this->assertArrayNotHasKey(
'error',
$_SESSION['messages']
);
}
/**
* @return void
*/
public function testBlowfish()
{
$_SESSION[$this->sessionID]['blowfish_secret'] = 'sec';
$_SESSION[$this->sessionID]['Servers'] = [
'1' => [
'host' => 'localhost',
'auth_type' => 'cookie'
]
];
$configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
$configChecker->performConfigChecks();
$this->assertArrayHasKey(
'blowfish_warnings2',
$_SESSION['messages']['error']
);
}
}