Initial commit
This commit is contained in:
613
#pma/test/classes/config/ConfigFileTest.php
Normal file
613
#pma/test/classes/config/ConfigFileTest.php
Normal file
@ -0,0 +1,613 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for Config File Management
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\config\ConfigFile;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for Config File Management
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ConfigFileTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Any valid key that exists in config.default.php and isn't empty
|
||||
* @var string
|
||||
*/
|
||||
const SIMPLE_KEY_WITH_DEFAULT_VALUE = 'DefaultQueryTable';
|
||||
|
||||
/**
|
||||
* Object under test
|
||||
* @var ConfigFile
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Setup function for test cases
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 1;
|
||||
$this->object = new ConfigFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* TearDown function for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($_SESSION[$this->readAttribute($this->object, "_id")]);
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for new ConfigFile()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testNewObjectState()
|
||||
{
|
||||
// Check default dynamic values
|
||||
$this->assertEquals(
|
||||
"82%",
|
||||
$this->object->getDefault('fontsize')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
|
||||
// Check environment state
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$_SESSION["ConfigFile1"]
|
||||
);
|
||||
|
||||
// Validate default value used in tests
|
||||
$default_value = $this->object->getDefault(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE
|
||||
);
|
||||
$this->assertNotNull($default_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::setPersistKeys()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testPersistentKeys()
|
||||
{
|
||||
$default_simple_value = $this->object->getDefault(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE
|
||||
);
|
||||
$default_host = $this->object->getDefault('Servers/1/host');
|
||||
$default_config = array(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_simple_value,
|
||||
'Servers/1/host' => $default_host,
|
||||
'Servers/2/host' => $default_host);
|
||||
|
||||
/**
|
||||
* Case 1: set default value, key should not be persisted
|
||||
*/
|
||||
$this->object->set(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_simple_value
|
||||
);
|
||||
$this->object->set('Servers/1/host', $default_host);
|
||||
$this->object->set('Servers/2/host', $default_host);
|
||||
$this->assertEmpty($this->object->getConfig());
|
||||
|
||||
/**
|
||||
* Case 2: persistent keys should be always present in flat array,
|
||||
* even if not explicitly set (unless they are Server entries)
|
||||
*/
|
||||
$this->object->setPersistKeys(array_keys($default_config));
|
||||
$this->object->resetConfigData();
|
||||
$this->assertEmpty($this->object->getConfig());
|
||||
$this->assertEquals(
|
||||
$default_config,
|
||||
$this->object->getConfigArray()
|
||||
);
|
||||
|
||||
/**
|
||||
* Case 3: persistent keys should be always saved,
|
||||
* even if set to default values
|
||||
*/
|
||||
$this->object->set('Servers/2/host', $default_host);
|
||||
$this->assertEquals(
|
||||
array('Servers' => array(2 => array('host' => $default_host))),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::setAllowedKeys
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testAllowedKeys()
|
||||
{
|
||||
/**
|
||||
* Case 1: filter should not allow to set b
|
||||
*/
|
||||
$this->object->setAllowedKeys(array('a', 'c'));
|
||||
$this->object->set('a', 1);
|
||||
$this->object->set('b', 2);
|
||||
$this->object->set('c', 3);
|
||||
|
||||
$this->assertEquals(
|
||||
array('a' => 1, 'c' => 3),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
|
||||
/**
|
||||
* Case 2: disabling filter should allow to set b
|
||||
*/
|
||||
$this->object->setAllowedKeys(null);
|
||||
$this->object->set('b', 2);
|
||||
|
||||
$this->assertEquals(
|
||||
array('a' => 1, 'b' => 2, 'c' => 3),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::setCfgUpdateReadMapping
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testConfigReadMapping()
|
||||
{
|
||||
$this->object->setCfgUpdateReadMapping(
|
||||
array(
|
||||
'Servers/value1' => 'Servers/1/value1',
|
||||
'Servers/value2' => 'Servers/1/value2'
|
||||
)
|
||||
);
|
||||
$this->object->set('Servers/1/passthrough1', 1);
|
||||
$this->object->set('Servers/1/passthrough2', 2);
|
||||
$this->object->updateWithGlobalConfig(array('Servers/value1' => 3));
|
||||
|
||||
$this->assertEquals(
|
||||
array('Servers' => array(
|
||||
1 => array(
|
||||
'passthrough1' => 1,
|
||||
'passthrough2' => 2,
|
||||
'value1' => 3))),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
$this->assertEquals(
|
||||
3,
|
||||
$this->object->get('Servers/1/value1')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::resetConfigData
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testResetConfigData()
|
||||
{
|
||||
$this->object->set('key', 'value');
|
||||
|
||||
$this->object->resetConfigData();
|
||||
|
||||
$this->assertEmpty($this->object->getConfig());
|
||||
$this->assertEmpty($this->object->getConfigArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::setConfigData
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testSetConfigData()
|
||||
{
|
||||
$this->object->set('abc', 'should be deleted by setConfigData');
|
||||
$this->object->setConfigData(array('a' => 'b'));
|
||||
|
||||
$this->assertEquals(
|
||||
array('a' => 'b'),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array('a' => 'b'),
|
||||
$this->object->getConfigArray()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::set and ConfigFile::get
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testBasicSetUsage()
|
||||
{
|
||||
$default_host = $this->object->getDefault('Servers/1/host');
|
||||
$nondefault_host = $default_host . '.abc';
|
||||
|
||||
$this->object->set('Servers/4/host', $nondefault_host);
|
||||
$this->object->set('Servers/5/host', $default_host);
|
||||
$this->object->set('Servers/6/host', $default_host, 'Servers/6/host');
|
||||
$this->assertEquals(
|
||||
$nondefault_host,
|
||||
$this->object->get('Servers/4/host')
|
||||
);
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$this->object->get('Servers/5/host')
|
||||
);
|
||||
$this->assertEquals(
|
||||
$default_host,
|
||||
$this->object->get('Servers/6/host')
|
||||
);
|
||||
|
||||
// return default value for nonexistent keys
|
||||
$this->assertNull(
|
||||
$this->object->get('key not excist')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(1),
|
||||
$this->object->get('key not excist', array(1))
|
||||
);
|
||||
$default = new stdClass();
|
||||
$this->assertInstanceOf(
|
||||
'stdClass',
|
||||
$this->object->get('key not excist', $default)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::set - in PMA Setup
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testConfigFileSetInSetup()
|
||||
{
|
||||
$default_value = $this->object->getDefault(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE
|
||||
);
|
||||
|
||||
// default values are not written
|
||||
$this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value);
|
||||
$this->assertEmpty($this->object->getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::set - in user preferences
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testConfigFileSetInUserPreferences()
|
||||
{
|
||||
$default_value = $this->object->getDefault(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE
|
||||
);
|
||||
|
||||
// values are not written when they are the same as in config.inc.php
|
||||
$this->object = new ConfigFile(
|
||||
array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value)
|
||||
);
|
||||
$this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value);
|
||||
$this->assertEmpty($this->object->getConfig());
|
||||
|
||||
// but if config.inc.php differs from config.default.php,
|
||||
// allow to overwrite with value from config.default.php
|
||||
$config_inc_php_value = $default_value . 'suffix';
|
||||
$this->object = new ConfigFile(
|
||||
array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $config_inc_php_value)
|
||||
);
|
||||
$this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value);
|
||||
$this->assertEquals(
|
||||
array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getFlatDefaultConfig
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetFlatDefaultConfig()
|
||||
{
|
||||
$flat_default_config = $this->object->getFlatDefaultConfig();
|
||||
|
||||
$default_value = $this->object->getDefault(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE
|
||||
);
|
||||
$this->assertEquals(
|
||||
$default_value, $flat_default_config[self::SIMPLE_KEY_WITH_DEFAULT_VALUE]
|
||||
);
|
||||
|
||||
$localhost_value = $this->object->getDefault('Servers/1/host');
|
||||
$this->assertEquals(
|
||||
$localhost_value, $flat_default_config['Servers/1/host']
|
||||
);
|
||||
|
||||
$cfg = array();
|
||||
include './libraries/config.default.php';
|
||||
// verify that $cfg read from config.default.php is valid
|
||||
$this->assertGreaterThanOrEqual(100, count($cfg));
|
||||
$this->assertGreaterThanOrEqual(count($cfg), count($flat_default_config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::updateWithGlobalConfig
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testUpdateWithGlobalConfig()
|
||||
{
|
||||
$this->object->set('key', 'value');
|
||||
$this->object->set('key2', 'value');
|
||||
$this->object->updateWithGlobalConfig(array('key' => 'ABC'));
|
||||
|
||||
$this->assertEquals(
|
||||
array('key' => 'ABC', 'key2' => 'value'),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getCanonicalPath
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetCanonicalPath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"Servers/1/abcd",
|
||||
$this->object->getCanonicalPath("Servers/2/abcd")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"Servers/foo/bar",
|
||||
$this->object->getCanonicalPath("Servers/foo/bar")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getDbEntry
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDbEntry()
|
||||
{
|
||||
$cfg_db = array();
|
||||
include './libraries/config.values.php';
|
||||
// verify that $cfg_db read from config.values.php is valid
|
||||
$this->assertGreaterThanOrEqual(20, count($cfg_db));
|
||||
|
||||
$this->assertEquals(
|
||||
$cfg_db['Servers'][1]['port'],
|
||||
$this->object->getDbEntry('Servers/1/port')
|
||||
);
|
||||
$this->assertNull($this->object->getDbEntry('no such key'));
|
||||
$this->assertEquals(
|
||||
array(1),
|
||||
$this->object->getDbEntry('no such key', array(1))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getServerCount
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetServerCount()
|
||||
{
|
||||
$this->object->set('Servers/1/x', 1);
|
||||
$this->object->set('Servers/2/x', 2);
|
||||
$this->object->set('Servers/3/x', 3);
|
||||
$this->object->set('Servers/4/x', 4);
|
||||
$this->object->set('ServerDefault', 3);
|
||||
|
||||
$this->assertEquals(
|
||||
4,
|
||||
$this->object->getServerCount()
|
||||
);
|
||||
|
||||
$this->object->removeServer(2);
|
||||
$this->object->removeServer(2);
|
||||
|
||||
$this->assertEquals(
|
||||
2,
|
||||
$this->object->getServerCount()
|
||||
);
|
||||
|
||||
$this->assertLessThanOrEqual(
|
||||
2,
|
||||
$this->object->get('ServerDefault')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array('Servers' => array(1 => array('x' => 1), 2 => array('x' => 4))),
|
||||
$this->object->getConfig()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array('Servers/1/x' => 1, 'Servers/2/x' => 4),
|
||||
$this->object->getConfigArray()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getServers
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetServers()
|
||||
{
|
||||
$this->object->set('Servers/1/x', 'a');
|
||||
$this->object->set('Servers/2/x', 'b');
|
||||
|
||||
$this->assertEquals(
|
||||
array(1 => array('x' => 'a'), 2 => array('x' => 'b')),
|
||||
$this->object->getServers()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getServerDSN
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetServerDSN()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getServerDSN(1)
|
||||
);
|
||||
|
||||
$this->object->updateWithGlobalConfig(
|
||||
array(
|
||||
'Servers' => array(
|
||||
1 => array(
|
||||
"auth_type" => "config",
|
||||
"user" => "testUser",
|
||||
"connect_type" => "tcp",
|
||||
"host" => "example.com",
|
||||
"port" => "21"
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
"mysqli://testUser:***@example.com:21",
|
||||
$this->object->getServerDSN(1)
|
||||
);
|
||||
|
||||
$this->object->updateWithGlobalConfig(
|
||||
array(
|
||||
'Servers' => array(
|
||||
1 => array(
|
||||
"auth_type" => "config",
|
||||
"user" => "testUser",
|
||||
"connect_type" => "socket",
|
||||
"host" => "example.com",
|
||||
"port" => "21",
|
||||
"nopassword" => "yes",
|
||||
"socket" => "123"
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
"mysqli://testUser@123",
|
||||
$this->object->getServerDSN(1)
|
||||
);
|
||||
|
||||
$this->object->updateWithGlobalConfig(
|
||||
array(
|
||||
'Servers' => array(
|
||||
1 => array(
|
||||
"auth_type" => "config",
|
||||
"user" => "testUser",
|
||||
"connect_type" => "tcp",
|
||||
"host" => "example.com",
|
||||
"port" => "21",
|
||||
"nopassword" => "yes",
|
||||
"password" => "testPass"
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
"mysqli://testUser:***@example.com:21",
|
||||
$this->object->getServerDSN(1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getServerName
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetServerName()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getServerName(1)
|
||||
);
|
||||
|
||||
$this->object->set('Servers/1/host', 'example.com');
|
||||
$this->assertEquals(
|
||||
'example.com',
|
||||
$this->object->getServerName(1)
|
||||
);
|
||||
|
||||
$this->object->set('Servers/1/verbose', 'testData');
|
||||
$this->assertEquals(
|
||||
'testData',
|
||||
$this->object->getServerName(1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getFilePath
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetFilePath()
|
||||
{
|
||||
$this->assertNotEmpty($this->object->getFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigFile::getConfigArray
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetConfigArray()
|
||||
{
|
||||
$this->object->setPersistKeys(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE));
|
||||
$this->object->set('Array/test', array('x', 'y'));
|
||||
$default_value = $this->object->getDefault(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value,
|
||||
'Array/test' => array('x', 'y')
|
||||
),
|
||||
$this->object->getConfigArray()
|
||||
);
|
||||
}
|
||||
}
|
555
#pma/test/classes/config/FormDisplayTest.php
Normal file
555
#pma/test/classes/config/FormDisplayTest.php
Normal file
@ -0,0 +1,555 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for FormDisplay class in config folder
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\Config;
|
||||
use PMA\libraries\config\ConfigFile;
|
||||
use PMA\libraries\config\FormDisplay;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
require_once 'libraries/config/config_functions.lib.php';
|
||||
require_once 'libraries/user_preferences.lib.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA_FormDisplay class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class FormDisplayTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var FormDisplay
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$GLOBALS['PMA_Config'] = new Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new FormDisplay(new ConfigFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::__constructor
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testFormDisplayContructor()
|
||||
{
|
||||
$this->assertCount(
|
||||
5,
|
||||
$this->readAttribute($this->object, '_jsLangStrings')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::registerForm
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testRegisterForm()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\libraries\config\FormDisplay');
|
||||
|
||||
$attrForms = $reflection->getProperty('_forms');
|
||||
$attrForms->setAccessible(true);
|
||||
|
||||
$array = array(
|
||||
"Servers" => array(
|
||||
"1" => array(
|
||||
'test' => 1,
|
||||
1 => ':group:end'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->object->registerForm('pma_testform', $array, 2);
|
||||
$_forms = $attrForms->getValue($this->object);
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\config\Form',
|
||||
$_forms['pma_testform']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
"Servers/2/test" => "Servers/1/test",
|
||||
"Servers/2/:group:end:0" => "Servers/1/:group:end:0"
|
||||
),
|
||||
$this->readAttribute($this->object, '_systemPaths')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
"Servers/2/test" => "Servers-2-test",
|
||||
"Servers/2/:group:end:0" => "Servers-2-:group:end:0"
|
||||
),
|
||||
$this->readAttribute($this->object, '_translatedPaths')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::process
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testProcess()
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->object->process(true, true)
|
||||
);
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\config\FormDisplay')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('save'))
|
||||
->getMock();
|
||||
|
||||
$attrForms = new \ReflectionProperty('PMA\libraries\config\FormDisplay', '_forms');
|
||||
$attrForms->setAccessible(true);
|
||||
$attrForms->setValue($this->object, array(1, 2, 3));
|
||||
|
||||
$this->object->expects($this->once())
|
||||
->method('save')
|
||||
->with(array(0, 1, 2), false)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->process(false, false)
|
||||
);
|
||||
|
||||
$attrForms->setValue($this->object, array());
|
||||
|
||||
$this->assertFalse(
|
||||
$this->object->process(false, false)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::displayErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayErrors()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\libraries\config\FormDisplay');
|
||||
|
||||
$attrIsValidated = $reflection->getProperty('_isValidated');
|
||||
$attrIsValidated->setAccessible(true);
|
||||
$attrIsValidated->setValue($this->object, true);
|
||||
|
||||
$attrIsValidated = $reflection->getProperty('_errors');
|
||||
$attrIsValidated->setAccessible(true);
|
||||
$attrIsValidated->setValue($this->object, array());
|
||||
|
||||
$this->assertNull(
|
||||
$this->object->displayErrors()
|
||||
);
|
||||
|
||||
$arr = array(
|
||||
"Servers/1/test" => array('e1'),
|
||||
"foobar" => array('e2', 'e3')
|
||||
);
|
||||
|
||||
$sysArr = array(
|
||||
"Servers/1/test" => "Servers/1/test2"
|
||||
);
|
||||
|
||||
$attrSystemPaths = $reflection->getProperty('_systemPaths');
|
||||
$attrSystemPaths->setAccessible(true);
|
||||
$attrSystemPaths->setValue($this->object, $sysArr);
|
||||
|
||||
$attrIsValidated->setValue($this->object, $arr);
|
||||
|
||||
$GLOBALS['strConfigForm_foobar'] = 'foobar123';
|
||||
|
||||
$result = $this->object->displayErrors();
|
||||
|
||||
$this->assertEquals(
|
||||
'<dl><dt>Servers_test2_name</dt>' .
|
||||
'<dd>e1</dd></dl><dl><dt>foobar123</dt><dd>' .
|
||||
'e2</dd><dd>e3</dd></dl>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::fixErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFixErrors()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\libraries\config\FormDisplay');
|
||||
|
||||
$attrIsValidated = $reflection->getProperty('_isValidated');
|
||||
$attrIsValidated->setAccessible(true);
|
||||
$attrIsValidated->setValue($this->object, true);
|
||||
|
||||
$attrIsValidated = $reflection->getProperty('_errors');
|
||||
$attrIsValidated->setAccessible(true);
|
||||
$attrIsValidated->setValue($this->object, array());
|
||||
|
||||
$this->assertNull(
|
||||
$this->object->fixErrors()
|
||||
);
|
||||
|
||||
$arr = array(
|
||||
"Servers/1/test" => array('e1'),
|
||||
"Servers/2/test" => array('e2', 'e3'),
|
||||
"Servers/3/test" => array()
|
||||
);
|
||||
|
||||
$sysArr = array(
|
||||
"Servers/1/test" => "Servers/1/connect_type"
|
||||
);
|
||||
|
||||
$attrSystemPaths = $reflection->getProperty('_systemPaths');
|
||||
$attrSystemPaths->setAccessible(true);
|
||||
$attrSystemPaths->setValue($this->object, $sysArr);
|
||||
|
||||
$attrIsValidated->setValue($this->object, $arr);
|
||||
|
||||
$this->object->fixErrors();
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'Servers' => array(
|
||||
'1' => array(
|
||||
'test' => 'tcp'
|
||||
)
|
||||
)
|
||||
),
|
||||
$_SESSION['ConfigFile0']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::_validateSelect
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateSelect()
|
||||
{
|
||||
$attrValidateSelect = new \ReflectionMethod(
|
||||
'PMA\libraries\config\FormDisplay',
|
||||
'_validateSelect'
|
||||
);
|
||||
$attrValidateSelect->setAccessible(true);
|
||||
|
||||
$arr = array('foo' => 'var');
|
||||
$value = 'foo';
|
||||
$this->assertTrue(
|
||||
$attrValidateSelect->invokeArgs(
|
||||
$this->object,
|
||||
array(&$value, $arr)
|
||||
)
|
||||
);
|
||||
|
||||
$arr = array('' => 'foobar');
|
||||
$value = null;
|
||||
$this->assertTrue(
|
||||
$attrValidateSelect->invokeArgs(
|
||||
$this->object,
|
||||
array(&$value, $arr)
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
"string",
|
||||
gettype($value)
|
||||
);
|
||||
|
||||
$arr = array(0 => 'foobar');
|
||||
$value = 0;
|
||||
$this->assertTrue(
|
||||
$attrValidateSelect->invokeArgs(
|
||||
$this->object,
|
||||
array(&$value, $arr)
|
||||
)
|
||||
);
|
||||
|
||||
$arr = array('1' => 'foobar');
|
||||
$value = 0;
|
||||
$this->assertFalse(
|
||||
$attrValidateSelect->invokeArgs(
|
||||
$this->object,
|
||||
array(&$value, $arr)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::hasErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHasErrors()
|
||||
{
|
||||
$attrErrors = new \ReflectionProperty('PMA\libraries\config\FormDisplay', '_errors');
|
||||
$attrErrors->setAccessible(true);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->object->hasErrors()
|
||||
);
|
||||
|
||||
$attrErrors->setValue(
|
||||
$this->object,
|
||||
array(1, 2)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->hasErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::getDocLink
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetDocLink()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"./url.php?url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2F" .
|
||||
"config.html%23cfg_Servers_3_test_2_",
|
||||
$this->object->getDocLink("Servers/3/test/2/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getDocLink("Import")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getDocLink("Export")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::_getOptName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetOptName()
|
||||
{
|
||||
$method = new \ReflectionMethod('PMA\libraries\config\FormDisplay', '_getOptName');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertEquals(
|
||||
"Servers_",
|
||||
$method->invoke($this->object, "Servers/1/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"Servers_23_",
|
||||
$method->invoke($this->object, "Servers/1/23/")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::_loadUserprefsInfo
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadUserprefsInfo()
|
||||
{
|
||||
$method = new \ReflectionMethod('PMA\libraries\config\FormDisplay', '_loadUserprefsInfo');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$attrUserprefs = new \ReflectionProperty(
|
||||
'PMA\libraries\config\FormDisplay',
|
||||
'_userprefsDisallow'
|
||||
);
|
||||
|
||||
$attrUserprefs->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$attrUserprefs->getValue($this->object)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FormDisplay::_setComments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetComments()
|
||||
{
|
||||
if (! PMA_HAS_RUNKIT) {
|
||||
$this->markTestSkipped('Cannot redefine constant');
|
||||
}
|
||||
|
||||
$method = new \ReflectionMethod('PMA\libraries\config\FormDisplay', '_setComments');
|
||||
$method->setAccessible(true);
|
||||
|
||||
// recoding
|
||||
$opts = array('values' => array());
|
||||
$opts['values']['iconv'] = 'testIconv';
|
||||
$opts['values']['recode'] = 'testRecode';
|
||||
|
||||
$expect = $opts;
|
||||
|
||||
$method->invokeArgs(
|
||||
$this->object,
|
||||
array('RecodingEngine', &$opts)
|
||||
);
|
||||
|
||||
$expect['comment'] = '';
|
||||
if (!function_exists('iconv')) {
|
||||
$expect['values']['iconv'] .= " (unavailable)";
|
||||
$expect['comment'] = '"iconv" requires iconv extension';
|
||||
}
|
||||
if (!function_exists('recode_string')) {
|
||||
$expect['values']['recode'] .= " (unavailable)";
|
||||
$expect['comment'] .= ($expect['comment'] ? ", " : '') .
|
||||
'"recode" requires recode extension';
|
||||
}
|
||||
$expect['comment_warning'] = 1;
|
||||
|
||||
$this->assertEquals(
|
||||
$expect,
|
||||
$opts
|
||||
);
|
||||
|
||||
// ZipDump, GZipDump, BZipDump
|
||||
$method->invokeArgs(
|
||||
$this->object,
|
||||
array('ZipDump', &$opts)
|
||||
);
|
||||
|
||||
$comment = '';
|
||||
if (!function_exists("zip_open")) {
|
||||
$comment = 'Compressed import will not work due to missing function ' .
|
||||
'zip_open.';
|
||||
}
|
||||
if (!function_exists("gzcompress")) {
|
||||
$comment .= ($comment ? '; ' : '') . 'Compressed export will not work ' .
|
||||
'due to missing function gzcompress.';
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$comment,
|
||||
$opts['comment']
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$opts['comment_warning']
|
||||
);
|
||||
|
||||
$method->invokeArgs(
|
||||
$this->object,
|
||||
array('GZipDump', &$opts)
|
||||
);
|
||||
|
||||
$comment = '';
|
||||
if (!function_exists("gzopen")) {
|
||||
$comment = 'Compressed import will not work due to missing function ' .
|
||||
'gzopen.';
|
||||
}
|
||||
if (!function_exists("gzencode")) {
|
||||
$comment .= ($comment ? '; ' : '') . 'Compressed export will not work ' .
|
||||
'due to missing function gzencode.';
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$comment,
|
||||
$opts['comment']
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$opts['comment_warning']
|
||||
);
|
||||
|
||||
$method->invokeArgs(
|
||||
$this->object,
|
||||
array('BZipDump', &$opts)
|
||||
);
|
||||
|
||||
$comment = '';
|
||||
if (!function_exists("bzopen")) {
|
||||
$comment = 'Compressed import will not work due to missing function ' .
|
||||
'bzopen.';
|
||||
}
|
||||
if (!function_exists("bzcompress")) {
|
||||
$comment .= ($comment ? '; ' : '') . 'Compressed export will not work ' .
|
||||
'due to missing function bzcompress.';
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$comment,
|
||||
$opts['comment']
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$opts['comment_warning']
|
||||
);
|
||||
|
||||
if (defined('PMA_SETUP')) {
|
||||
runkit_constant_remove('PMA_SETUP');
|
||||
}
|
||||
|
||||
$GLOBALS['cfg']['MaxDbList'] = 10;
|
||||
$GLOBALS['cfg']['MaxTableList'] = 10;
|
||||
$GLOBALS['cfg']['QueryHistoryMax'] = 10;
|
||||
|
||||
$method->invokeArgs(
|
||||
$this->object,
|
||||
array('MaxDbList', &$opts)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"maximum 10",
|
||||
$opts['comment']
|
||||
);
|
||||
|
||||
$method->invokeArgs(
|
||||
$this->object,
|
||||
array('MaxTableList', &$opts)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"maximum 10",
|
||||
$opts['comment']
|
||||
);
|
||||
|
||||
$method->invokeArgs(
|
||||
$this->object,
|
||||
array('QueryHistoryMax', &$opts)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"maximum 10",
|
||||
$opts['comment']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
301
#pma/test/classes/config/FormTest.php
Normal file
301
#pma/test/classes/config/FormTest.php
Normal file
@ -0,0 +1,301 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for Form class in config folder
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\Config;
|
||||
use PMA\libraries\config\ConfigFile;
|
||||
use PMA\libraries\config\Form;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA_Form class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class FormTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var Form
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$GLOBALS['PMA_Config'] = new Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Form(
|
||||
'pma_form_name', array('pma_form1','pma_form2'), new ConfigFile(), 1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Form::__constructor
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testContructor()
|
||||
{
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->index
|
||||
);
|
||||
$this->assertEquals(
|
||||
'pma_form_name',
|
||||
$this->object->name
|
||||
);
|
||||
$this->assertArrayHasKey(
|
||||
'pma_form1',
|
||||
$this->object->fields
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Form::getOptionType
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetOptionType()
|
||||
{
|
||||
$attrFieldsTypes = new \ReflectionProperty('PMA\libraries\config\Form', '_fieldsTypes');
|
||||
$attrFieldsTypes->setAccessible(true);
|
||||
$attrFieldsTypes->setValue(
|
||||
$this->object,
|
||||
array("7" => "Seven")
|
||||
);
|
||||
|
||||
$this->assertNull(
|
||||
$this->object->getOptionType("123/4/5/6")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"Seven",
|
||||
$this->object->getOptionType("123/4/5/7")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Form::getOptionValueList
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetOptionValueList()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array('NHibernate C# DO', 'NHibernate XML'),
|
||||
$this->object->getOptionValueList("Export/codegen_format")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'auto' => 'auto',
|
||||
'1' => 1,
|
||||
'0' => 0
|
||||
),
|
||||
$this->object->getOptionValueList("OBGzip")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'none' => 'Nowhere',
|
||||
'left' => 'Left',
|
||||
'right' => 'Right',
|
||||
'both' => "Both"
|
||||
),
|
||||
$this->object->getOptionValueList("RowActionLinks")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Form::_readFormPathsCallback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadFormPathsCallBack()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\libraries\config\Form');
|
||||
$method = $reflection->getMethod('_readFormPathsCallback');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$array = array(
|
||||
"foo" => array(
|
||||
"bar" => array(
|
||||
'test' => 1,
|
||||
1 => ':group:end'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$method->invoke($this->object, $array, 'foo', 'pref');
|
||||
|
||||
$result = $this->object->fields;
|
||||
|
||||
$this->assertCount(
|
||||
4,
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"pma_form1",
|
||||
$result['pma_form1']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"pma_form2",
|
||||
$result['pma_form2']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"preffoo/foo/bar/test",
|
||||
$result[0]
|
||||
);
|
||||
|
||||
// needs regexp because the counter is static
|
||||
|
||||
$this->assertRegExp(
|
||||
'/^preffoo\/foo\/bar\/\:group\:end\:\d+$/',
|
||||
$result[1]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Form::readFormPaths
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadFormPaths()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\libraries\config\Form');
|
||||
$method = $reflection->getMethod('readFormPaths');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$array = array(
|
||||
"foo" => array(
|
||||
"bar" => array(
|
||||
'test' => 1,
|
||||
1 => ':group:end'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$method->invoke($this->object, $array);
|
||||
|
||||
$result = $this->object->fields;
|
||||
|
||||
$this->assertCount(
|
||||
2,
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/test",
|
||||
$result['test']
|
||||
);
|
||||
|
||||
unset($result['test']);
|
||||
|
||||
// needs regexp because the counter is static
|
||||
|
||||
$keys = array_keys($result);
|
||||
$key = $keys[0];
|
||||
|
||||
$this->assertRegexp(
|
||||
"/^\:group\:end\:(\d+)$/",
|
||||
$key
|
||||
);
|
||||
|
||||
preg_match("/^\:group\:end\:(\d+)$/", $key, $matches);
|
||||
$digit = $matches[1];
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/:group:end:" . $digit,
|
||||
$result[':group:end:' . $digit]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Form::readTypes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadTypes()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\libraries\config\Form');
|
||||
$method = $reflection->getMethod('readTypes');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->object->fields = array(
|
||||
"pma_form1" => "Servers/1/port",
|
||||
"pma_form2" => "Servers/1/connect_type",
|
||||
":group:end:0" => "preffoo/foo/bar/test",
|
||||
"1" => "preffoo/foo/bar/:group:end:0"
|
||||
);
|
||||
|
||||
$attrFieldsTypes = $reflection->getProperty('_fieldsTypes');
|
||||
$attrFieldsTypes->setAccessible(true);
|
||||
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
"pma_form1" => "integer",
|
||||
"pma_form2" => "select",
|
||||
":group:end:0" => "group",
|
||||
"1" => "NULL"
|
||||
),
|
||||
$attrFieldsTypes->getValue($this->object)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Form::loadForm
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadForm()
|
||||
{
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\config\Form')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('readFormPaths', 'readTypes'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->exactly(1))
|
||||
->method('readFormPaths')
|
||||
->with('testForm');
|
||||
|
||||
$this->object->expects($this->exactly(1))
|
||||
->method('readTypes');
|
||||
|
||||
$this->object->loadForm('pmaform', 'testForm');
|
||||
|
||||
$this->assertEquals(
|
||||
'pmaform',
|
||||
$this->object->name
|
||||
);
|
||||
}
|
||||
}
|
98
#pma/test/classes/config/PageSettingsTest.php
Normal file
98
#pma/test/classes/config/PageSettingsTest.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for Page-related settings
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\config\PageSettings;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
require_once 'libraries/config/user_preferences.forms.php';
|
||||
require_once 'libraries/config/page_settings.forms.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\config\PageSettings
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PageSettingsTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Setup tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['db'] = 'db';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test showGroup when group passed does not exist
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testShowGroupNonExistent()
|
||||
{
|
||||
$object = PageSettings::showGroup('NonExistent');
|
||||
|
||||
$this->assertEquals('', $object->getHTML());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test showGroup with a known group name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testShowGroupBrowse()
|
||||
{
|
||||
$object = PageSettings::showGroup('Browse');
|
||||
|
||||
$html = $object->getHTML();
|
||||
|
||||
// Test some sample parts
|
||||
$this->assertContains(
|
||||
'<div id="page_settings_modal">'
|
||||
. '<div class="page_settings">'
|
||||
. '<form method="post" '
|
||||
. 'action="phpunit?db=db&table=&server=1&target=&lang=en&token=token" '
|
||||
. 'class="config-form disableAjax">',
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<input type="hidden" name="submit_save" value="Browse" />',
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
"validateField('MaxRows', 'PMA_validatePositiveNumber', true);\n"
|
||||
. "validateField('RepeatCells', 'PMA_validateNonNegativeNumber', true);\n"
|
||||
. "validateField('LimitChars', 'PMA_validatePositiveNumber', true);\n",
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getNaviSettings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetNaviSettings()
|
||||
{
|
||||
$html = PageSettings::getNaviSettings();
|
||||
|
||||
// Test some sample parts
|
||||
$this->assertContains(
|
||||
'<div id="pma_navigation_settings">',
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<input type="hidden" name="submit_save" value="Navi_panel" />',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user