Initial commit
This commit is contained in:
275
#pma/test/classes/AdvisorTest.php
Normal file
275
#pma/test/classes/AdvisorTest.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for Advisor class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
use PMA\libraries\Advisor;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
/**
|
||||
* Tests behaviour of PMA_Advisor class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class AdvisorTest extends PMATestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$GLOBALS['server'] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests string escaping
|
||||
*
|
||||
* @param string $text Text to escape
|
||||
* @param string $expected Expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider escapeStrings
|
||||
*/
|
||||
public function testEscape($text, $expected)
|
||||
{
|
||||
$this->assertEquals(Advisor::escapePercent($text), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* return of escape Strings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function escapeStrings()
|
||||
{
|
||||
return array(
|
||||
array('80%', '80%%'),
|
||||
array('%s%', '%s%%'),
|
||||
array('80% foo', '80%% foo'),
|
||||
array('%s% foo', '%s%% foo'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for parseRulesFile
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParse()
|
||||
{
|
||||
$advisor = new Advisor();
|
||||
$parseResult = $advisor->parseRulesFile();
|
||||
$this->assertEquals($parseResult['errors'], array());
|
||||
}
|
||||
|
||||
/**
|
||||
* test for ADVISOR_bytime
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdvisorBytime()
|
||||
{
|
||||
$result = ADVISOR_bytime(10, 2);
|
||||
$this->assertEquals("10 per second", $result);
|
||||
|
||||
$result = ADVISOR_bytime(0.02, 2);
|
||||
$this->assertEquals("1.2 per minute", $result);
|
||||
|
||||
$result = ADVISOR_bytime(0.003, 2);
|
||||
$this->assertEquals("10.8 per hour", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for ADVISOR_timespanFormat
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdvisorTimespanFormat()
|
||||
{
|
||||
$result = ADVISOR_timespanFormat(1200);
|
||||
$this->assertEquals("0 days, 0 hours, 20 minutes and 0 seconds", $result);
|
||||
|
||||
$result = ADVISOR_timespanFormat(100);
|
||||
$this->assertEquals("0 days, 0 hours, 1 minutes and 40 seconds", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for adding rule
|
||||
*
|
||||
* @param array $rule Rule to test
|
||||
* @param array $expected Expected rendered rule in fired/errors list
|
||||
* @param string $error Expected error string (null if none error expected)
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @depends testParse
|
||||
* @dataProvider rulesProvider
|
||||
*/
|
||||
public function testAddRule($rule, $expected, $error)
|
||||
{
|
||||
$advisor = new Advisor();
|
||||
$parseResult = $advisor->parseRulesFile();
|
||||
$this->assertEquals($parseResult['errors'], array());
|
||||
$advisor->setVariable('value', 0);
|
||||
$advisor->addRule('fired', $rule);
|
||||
$runResult = $advisor->getRunResult();
|
||||
if (isset($runResult['errors']) || !is_null($error)) {
|
||||
$this->assertEquals(array($error), $runResult['errors']);
|
||||
}
|
||||
if (isset($runResult['fired']) || $expected != array()) {
|
||||
$this->assertEquals(array($expected), $runResult['fired']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* rules Provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rulesProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'justification' => 'foo',
|
||||
'name' => 'Basic',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
array(
|
||||
'justification' => 'foo',
|
||||
'id' => 'Basic',
|
||||
'name' => 'Basic',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
null,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'justification' => 'foo',
|
||||
'name' => 'Variable',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend {status_var}'
|
||||
),
|
||||
array(
|
||||
'justification' => 'foo',
|
||||
'id' => 'Variable',
|
||||
'name' => 'Variable',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend <a href="server_variables.php?' .
|
||||
'lang=en&token=token&filter=status_var">status_var</a>'
|
||||
),
|
||||
null,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'justification' => '%s foo | value',
|
||||
'name' => 'Format',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
array(
|
||||
'justification' => '0 foo',
|
||||
'id' => 'Format',
|
||||
'name' => 'Format',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
null,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'justification' => '%s% foo | value',
|
||||
'name' => 'Percent',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
array(
|
||||
'justification' => '0% foo',
|
||||
'id' => 'Percent',
|
||||
'name' => 'Percent',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
null,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'justification' => '%s% %d foo | value, value',
|
||||
'name' => 'Double',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
array(
|
||||
'justification' => '0% 0 foo',
|
||||
'id' => 'Double',
|
||||
'name' => 'Double',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
null,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'justification' => '"\'foo',
|
||||
'name' => 'Quotes',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend"\''
|
||||
),
|
||||
array(
|
||||
'justification' => '"\'foo',
|
||||
'id' => 'Quotes',
|
||||
'name' => 'Quotes',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend"\''
|
||||
),
|
||||
null,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'justification' => 'foo | fsafdsa',
|
||||
'name' => 'Failure',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend'
|
||||
),
|
||||
array(),
|
||||
'Failed formatting string for rule \'Failure\'. PHP threw ' .
|
||||
'following error: Use of undefined constant fsafdsa - ' .
|
||||
'assumed \'fsafdsa\'<br />Executed code: $value = array(fsafdsa);',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'justification' => 'Version string (%s) | value',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="https://example.com/">web</a>',
|
||||
),
|
||||
array(
|
||||
'justification' => 'Version string (0)',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="./url.php?url=https%3A%2F%2F' .
|
||||
'example.com%2F" target="_blank" rel="noopener noreferrer">web</a>',
|
||||
'id' => 'Distribution'
|
||||
),
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
205
#pma/test/classes/ConfigGeneratorTest.php
Normal file
205
#pma/test/classes/ConfigGeneratorTest.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for methods under Config file generator
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test
|
||||
*/
|
||||
use PMA\libraries\Config;
|
||||
use PMA\libraries\config\ConfigFile;
|
||||
use PMA\setup\lib\ConfigGenerator;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\setup\lib\ConfigGenerator
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ConfigGeneratorTest extends PMATestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for ConfigGenerator::getConfigFile
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetConfigFile()
|
||||
{
|
||||
unset($_SESSION['eol']);
|
||||
|
||||
$GLOBALS['PMA_Config'] = new Config();
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
$cf = new ConfigFile();
|
||||
$_SESSION['ConfigFile0'] = array('a', 'b', 'c');
|
||||
$_SESSION['ConfigFile0']['Servers'] = array(
|
||||
array(1, 2, 3)
|
||||
);
|
||||
|
||||
$cf->setPersistKeys(array("1/", 2));
|
||||
|
||||
$result = ConfigGenerator::getConfigFile($cf);
|
||||
|
||||
$this->assertContains(
|
||||
"<?php\n" .
|
||||
"/*\n" .
|
||||
" * Generated configuration file\n" .
|
||||
" * Generated by: phpMyAdmin " .
|
||||
$GLOBALS['PMA_Config']->get('PMA_VERSION') . " setup script\n",
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
"/* Servers configuration */\n" .
|
||||
'$i = 0;' . "\n\n" .
|
||||
"/* Server: localhost [0] */\n" .
|
||||
'$i++;' . "\n" .
|
||||
'$cfg[\'Servers\'][$i][\'0\'] = 1;' . "\n" .
|
||||
'$cfg[\'Servers\'][$i][\'1\'] = 2;' . "\n" .
|
||||
'$cfg[\'Servers\'][$i][\'2\'] = 3;' . "\n\n" .
|
||||
"/* End of servers configuration */\n\n",
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'?>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigGenerator::_getVarExport
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVarExport()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\setup\lib\ConfigGenerator');
|
||||
$method = $reflection->getMethod('_getVarExport');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertEquals(
|
||||
'$cfg[\'var_name\'] = 1;' . "\n",
|
||||
$method->invoke(null, 'var_name', 1, "\n")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'$cfg[\'var_name\'] = array (' .
|
||||
"\n);\n",
|
||||
$method->invoke(null, 'var_name', array(), "\n")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'$cfg[\'var_name\'] = array(1, 2, 3);' . "\n",
|
||||
$method->invoke(
|
||||
null,
|
||||
'var_name',
|
||||
array(1, 2, 3),
|
||||
"\n"
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'$cfg[\'var_name\'][\'1a\'] = \'foo\';' . "\n" .
|
||||
'$cfg[\'var_name\'][\'b\'] = \'bar\';' . "\n",
|
||||
$method->invoke(
|
||||
null,
|
||||
'var_name',
|
||||
array(
|
||||
'1a' => 'foo',
|
||||
'b' => 'bar'
|
||||
),
|
||||
"\n"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigGenerator::_isZeroBasedArray
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsZeroBasedArray()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\setup\lib\ConfigGenerator');
|
||||
$method = $reflection->getMethod('_isZeroBasedArray');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertFalse(
|
||||
$method->invoke(
|
||||
null,
|
||||
array(
|
||||
'a' => 1,
|
||||
'b' => 2
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$method->invoke(
|
||||
null,
|
||||
array(
|
||||
0 => 1,
|
||||
1 => 2,
|
||||
3 => 3,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$method->invoke(
|
||||
null,
|
||||
array()
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$method->invoke(
|
||||
null,
|
||||
array(1, 2, 3)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ConfigGenerator::_exportZeroBasedArray
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportZeroBasedArray()
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\setup\lib\ConfigGenerator');
|
||||
$method = $reflection->getMethod('_exportZeroBasedArray');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$arr = array(1, 2, 3, 4);
|
||||
|
||||
$result = $method->invoke(null, $arr, "\n");
|
||||
|
||||
$this->assertEquals(
|
||||
'array(1, 2, 3, 4)',
|
||||
$result
|
||||
);
|
||||
|
||||
$arr = array(1, 2, 3, 4, 7, 'foo');
|
||||
|
||||
$result = $method->invoke(null, $arr, "\n");
|
||||
|
||||
$this->assertEquals(
|
||||
'array(' . "\n" .
|
||||
' 1,' . "\n" .
|
||||
' 2,' . "\n" .
|
||||
' 3,' . "\n" .
|
||||
' 4,' . "\n" .
|
||||
' 7,' . "\n" .
|
||||
' \'foo\')',
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
||||
970
#pma/test/classes/ConfigTest.php
Normal file
970
#pma/test/classes/ConfigTest.php
Normal file
@@ -0,0 +1,970 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\Config class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group current
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests behaviour of PMA\libraries\Config class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ConfigTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Turn off backup globals
|
||||
*/
|
||||
protected $backupGlobals = false;
|
||||
|
||||
/**
|
||||
* @var PMA\libraries\Config
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* @var object to test file permission
|
||||
*/
|
||||
protected $permTestObj;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new PMA\libraries\Config;
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['is_git_revision'] = true;
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config(CONFIG_FILE);
|
||||
$GLOBALS['cfg']['ProxyUrl'] = '';
|
||||
|
||||
//for testing file permissions
|
||||
$this->permTestObj = new PMA\libraries\Config("./config.sample.inc.php");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
unset($this->permTestObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for CheckSystem
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testCheckSystem()
|
||||
{
|
||||
$this->object->checkSystem();
|
||||
|
||||
$this->assertNotNull($this->object->get('PMA_VERSION'));
|
||||
$this->assertNotEmpty($this->object->get('PMA_THEME_VERSION'));
|
||||
$this->assertNotEmpty($this->object->get('PMA_THEME_GENERATION'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for GetFontsizeForm
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFontsizeForm()
|
||||
{
|
||||
$this->assertContains(
|
||||
'<form name="form_fontsize_selection" id="form_fontsize_selection"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<label for="select_fontsize">',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
|
||||
//test getFontsizeOptions for "em" unit
|
||||
$fontsize = $GLOBALS['PMA_Config']->get('fontsize');
|
||||
$GLOBALS['PMA_Config']->set('fontsize', '');
|
||||
$_COOKIE['pma_fontsize'] = "10em";
|
||||
$this->assertContains(
|
||||
'<option value="7em"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
$this->assertContains(
|
||||
'<option value="8em"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
|
||||
//test getFontsizeOptions for "pt" unit
|
||||
$_COOKIE['pma_fontsize'] = "10pt";
|
||||
$this->assertContains(
|
||||
'<option value="2pt"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
$this->assertContains(
|
||||
'<option value="4pt"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
|
||||
//test getFontsizeOptions for "px" unit
|
||||
$_COOKIE['pma_fontsize'] = "10px";
|
||||
$this->assertContains(
|
||||
'<option value="5px"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
$this->assertContains(
|
||||
'<option value="6px"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
|
||||
//test getFontsizeOptions for unknown unit
|
||||
$_COOKIE['pma_fontsize'] = "10abc";
|
||||
$this->assertContains(
|
||||
'<option value="7abc"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
$this->assertContains(
|
||||
'<option value="8abc"',
|
||||
PMA\libraries\Config::getFontsizeForm()
|
||||
);
|
||||
unset($_COOKIE['pma_fontsize']);
|
||||
//rollback the fontsize setting
|
||||
$GLOBALS['PMA_Config']->set('fontsize', $fontsize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checkOutputCompression
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckOutputCompression()
|
||||
{
|
||||
|
||||
$this->object->set('OBGzip', 'auto');
|
||||
|
||||
$this->object->set('PMA_USR_BROWSER_AGENT', 'IE');
|
||||
$this->object->set('PMA_USR_BROWSER_VER', 6);
|
||||
$this->object->checkOutputCompression();
|
||||
$this->assertFalse($this->object->get("OBGzip"));
|
||||
|
||||
$this->object->set('OBGzip', 'auto');
|
||||
$this->object->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
|
||||
$this->object->set('PMA_USR_BROWSER_VER', 5);
|
||||
$this->object->checkOutputCompression();
|
||||
$this->assertTrue($this->object->get("OBGzip"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests client parsing code.
|
||||
*
|
||||
* @param string $agent User agent string
|
||||
* @param string $os Expected parsed OS (or null if none)
|
||||
* @param string $browser Expected parsed browser (or null if none)
|
||||
* @param string $version Expected browser version (or null if none)
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider userAgentProvider
|
||||
*/
|
||||
public function testCheckClient($agent, $os, $browser = null, $version = null)
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = $agent;
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals($os, $this->object->get('PMA_USR_OS'));
|
||||
if ($os != null) {
|
||||
$this->assertEquals(
|
||||
$browser,
|
||||
$this->object->get('PMA_USR_BROWSER_AGENT')
|
||||
);
|
||||
}
|
||||
if ($version != null) {
|
||||
$this->assertEquals(
|
||||
$version,
|
||||
$this->object->get('PMA_USR_BROWSER_VER')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* user Agent Provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function userAgentProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00',
|
||||
'Linux',
|
||||
'OPERA',
|
||||
'9.80',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/'
|
||||
. '528.16 OmniWeb/622.8.0.112941',
|
||||
'Mac',
|
||||
'OMNIWEB',
|
||||
'622',
|
||||
),
|
||||
array(
|
||||
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)',
|
||||
'Win',
|
||||
'IE',
|
||||
'8.0',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
|
||||
'Win',
|
||||
'IE',
|
||||
'9.0',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; '
|
||||
. 'Trident/6.0)',
|
||||
'Win',
|
||||
'IE',
|
||||
'10.0',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; '
|
||||
. '.NET4.0C; rv:11.0) like Gecko',
|
||||
'Win',
|
||||
'IE',
|
||||
'11.0',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; '
|
||||
. '.NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; '
|
||||
. '.NET CLR 3.0.30729; InfoPath.3; rv:11.0) like Gecko',
|
||||
'Win',
|
||||
'IE',
|
||||
'11.0',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, '
|
||||
. 'like Gecko) Chrome/25.0.1364.172 Safari/537.22',
|
||||
'Win',
|
||||
'CHROME',
|
||||
'25.0.1364.172',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (Unknown; U; Unix BSD/SYSV system; C -) '
|
||||
. 'AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.2',
|
||||
'Unix',
|
||||
'SAFARI',
|
||||
'5.0.419',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.9b) Gecko/20031208',
|
||||
'Win',
|
||||
'GECKO',
|
||||
'1.9',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (compatible; Konqueror/4.5; NetBSD 5.0.2; X11; '
|
||||
. 'amd64; en_US) KHTML/4.5.4 (like Gecko)',
|
||||
'Other',
|
||||
'KONQUEROR',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0',
|
||||
'Linux',
|
||||
'FIREFOX',
|
||||
'5.0',
|
||||
),
|
||||
array(
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 '
|
||||
. 'Firefox/12.0',
|
||||
'Linux',
|
||||
'FIREFOX',
|
||||
'12.0',
|
||||
),
|
||||
/**
|
||||
* @todo Is this version really expected?
|
||||
*/
|
||||
array(
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.4+ (KHTML, like G'
|
||||
. 'ecko) Version/5.0 Safari/535.4+ SUSE/12.1 (3.2.1) Epiphany/3.2.1',
|
||||
'Linux',
|
||||
'SAFARI',
|
||||
'5.0',
|
||||
),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test for CheckGd2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckGd2()
|
||||
{
|
||||
$prevIsGb2Val = $this->object->get('PMA_IS_GD2');
|
||||
|
||||
$this->object->set('GD2Available', 'yes');
|
||||
$this->object->checkGd2();
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_GD2'));
|
||||
|
||||
$this->object->set('GD2Available', 'no');
|
||||
$this->object->checkGd2();
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_GD2'));
|
||||
|
||||
$this->object->set('GD2Available', $prevIsGb2Val);
|
||||
|
||||
if (!@function_exists('imagecreatetruecolor')) {
|
||||
$this->object->checkGd2();
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->get('PMA_IS_GD2'),
|
||||
'imagecreatetruecolor does not exist, PMA_IS_GD2 should be 0'
|
||||
);
|
||||
}
|
||||
|
||||
if (@function_exists('gd_info')) {
|
||||
$this->object->checkGd2();
|
||||
$gd_nfo = gd_info();
|
||||
if (mb_strstr($gd_nfo["GD Version"], '2.')) {
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->get('PMA_IS_GD2'),
|
||||
'GD Version >= 2, PMA_IS_GD2 should be 1'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->get('PMA_IS_GD2'),
|
||||
'GD Version < 2, PMA_IS_GD2 should be 0'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get GD version string from phpinfo output */
|
||||
ob_start();
|
||||
phpinfo(INFO_MODULES); /* Only modules */
|
||||
$a = strip_tags(ob_get_contents());
|
||||
ob_end_clean();
|
||||
|
||||
if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
|
||||
if (mb_strstr($v, '2.')) {
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->get('PMA_IS_GD2'),
|
||||
'PMA_IS_GD2 should be 1'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->get('PMA_IS_GD2'),
|
||||
'PMA_IS_GD2 should be 0'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Web server detection test
|
||||
*
|
||||
* @param string $server Server identification
|
||||
* @param boolean $iis Whether server should be detected as IIS
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider serverNames
|
||||
*/
|
||||
public function testCheckWebServer($server, $iis)
|
||||
{
|
||||
$_SERVER['SERVER_SOFTWARE'] = $server;
|
||||
$this->object->checkWebServer();
|
||||
$this->assertEquals($iis, $this->object->get('PMA_IS_IIS'));
|
||||
unset($_SERVER['SERVER_SOFTWARE']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return server names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function serverNames()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
"Microsoft-IIS 7.0",
|
||||
1,
|
||||
),
|
||||
array(
|
||||
"Apache/2.2.17",
|
||||
0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test for CheckWebServerOs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckWebServerOs()
|
||||
{
|
||||
$this->object->checkWebServerOs();
|
||||
|
||||
if (defined('PHP_OS')) {
|
||||
if (stristr(PHP_OS, 'darwin')) {
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS'));
|
||||
} elseif (stristr(PHP_OS, 'win')) {
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'));
|
||||
} elseif (stristr(PHP_OS, 'OS/2')) {
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'));
|
||||
} elseif (stristr(PHP_OS, 'Linux')) {
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS'));
|
||||
} else {
|
||||
$this->markTestIncomplete('Not known PHP_OS: ' . PHP_OS);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS'));
|
||||
|
||||
define('PHP_OS', 'Windows');
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests loading of default values
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group large
|
||||
*/
|
||||
public function testLoadDefaults()
|
||||
{
|
||||
$prevDefaultSource = $this->object->default_source;
|
||||
|
||||
$this->object->default_source = 'unexisted.file.php';
|
||||
$this->assertFalse($this->object->loadDefaults());
|
||||
|
||||
$this->object->default_source = $prevDefaultSource;
|
||||
|
||||
include $this->object->default_source;
|
||||
|
||||
$loadedConf = $cfg;
|
||||
unset($cfg);
|
||||
|
||||
$this->assertTrue($this->object->loadDefaults());
|
||||
|
||||
$this->assertEquals(
|
||||
$this->object->default_source_mtime,
|
||||
filemtime($prevDefaultSource)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$loadedConf['Servers'][1],
|
||||
$this->object->default_server
|
||||
);
|
||||
|
||||
unset($loadedConf['Servers']);
|
||||
|
||||
$this->assertEquals($loadedConf, $this->object->default);
|
||||
|
||||
$expectedSettings = array_replace_recursive(
|
||||
$this->object->settings,
|
||||
$loadedConf
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedSettings,
|
||||
$this->object->settings,
|
||||
'Settings loaded wrong'
|
||||
);
|
||||
|
||||
$this->assertFalse($this->object->error_config_default_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for CheckConfigSource
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckConfigSource()
|
||||
{
|
||||
$this->object->setSource('unexisted.config.php');
|
||||
$this->assertFalse($this->object->checkConfigSource());
|
||||
$this->assertEquals(0, $this->object->source_mtime);
|
||||
|
||||
$this->object->setSource('libraries/config.default.php');
|
||||
|
||||
$this->assertNotEmpty($this->object->getSource());
|
||||
$this->assertTrue($this->object->checkConfigSource());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting and setting config values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetAndSet()
|
||||
{
|
||||
$this->assertNull($this->object->get("unresisting_setting"));
|
||||
|
||||
$this->object->set('test_setting', 'test_value');
|
||||
|
||||
$this->assertEquals('test_value', $this->object->get('test_setting'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting configuration source
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSetSource()
|
||||
{
|
||||
echo $this->object->getSource();
|
||||
|
||||
$this->assertEmpty($this->object->getSource(), "Source is null by default");
|
||||
|
||||
$this->object->setSource("config.sample.inc.php");
|
||||
|
||||
$this->assertEquals(
|
||||
"config.sample.inc.php",
|
||||
$this->object->getSource(),
|
||||
"Cant set new source"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for CheckCollationConnection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckCollationConnection()
|
||||
{
|
||||
$_REQUEST['collation_connection'] = 'utf-8';
|
||||
$this->object->checkCollationConnection();
|
||||
|
||||
$this->assertEquals(
|
||||
$_REQUEST['collation_connection'],
|
||||
$this->object->get('collation_connection')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for IsHttp
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider httpsParams
|
||||
*/
|
||||
public function testIsHttps($scheme, $https, $uri, $lb, $front, $proto, $port, $expected)
|
||||
{
|
||||
$_SERVER['HTTP_SCHEME'] = $scheme;
|
||||
$_SERVER['HTTPS'] = $https;
|
||||
$_SERVER['REQUEST_URI'] = $uri;
|
||||
$_SERVER['HTTP_HTTPS_FROM_LB'] = $lb;
|
||||
$_SERVER['HTTP_FRONT_END_HTTPS'] = $front;
|
||||
$_SERVER['HTTP_X_FORWARDED_PROTO'] = $proto;
|
||||
$_SERVER['SERVER_PORT'] = $port;
|
||||
|
||||
$this->object->set('is_https', null);
|
||||
$this->assertEquals($expected, $this->object->isHttps());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for https detection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function httpsParams()
|
||||
{
|
||||
return array(
|
||||
array('http', '', '', '', '', 'http', 80, false),
|
||||
array('http', '', 'http://', '', '', 'http', 80, false),
|
||||
array('http', '', '', '', '', 'http', 443, true),
|
||||
array('http', '', '', '', '', 'https', 80, true),
|
||||
array('http', '', '', '', 'on', 'http', 80, true),
|
||||
array('http', '', '', 'on', '', 'http', 80, true),
|
||||
array('http', '', 'https://', '', '', 'http', 80, true),
|
||||
array('http', 'on', '', '', '', 'http', 80, true),
|
||||
array('https', '', '', '', '', 'http', 80, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for backward compatibility globals
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @depends testCheckSystem
|
||||
* @depends testCheckWebServer
|
||||
* @depends testLoadDefaults
|
||||
*
|
||||
* @group large
|
||||
*/
|
||||
public function testEnableBc()
|
||||
{
|
||||
$this->object->enableBc();
|
||||
|
||||
$defines = array(
|
||||
'PMA_VERSION',
|
||||
'PMA_THEME_VERSION',
|
||||
'PMA_THEME_GENERATION',
|
||||
'PMA_IS_WINDOWS',
|
||||
'PMA_IS_IIS',
|
||||
'PMA_IS_GD2',
|
||||
'PMA_USR_OS',
|
||||
'PMA_USR_BROWSER_VER',
|
||||
'PMA_USR_BROWSER_AGENT'
|
||||
);
|
||||
|
||||
foreach ($defines as $define) {
|
||||
$this->assertTrue(defined($define));
|
||||
$this->assertEquals(constant($define), $this->object->get($define));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getting root path
|
||||
*
|
||||
* @param string $request The request URL used for phpMyAdmin
|
||||
* @param string $absolute The absolute URL used for phpMyAdmin
|
||||
* @param string $expected Expected root path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider rootUris
|
||||
*/
|
||||
public function testGetRootPath($request, $absolute, $expected)
|
||||
{
|
||||
$GLOBALS['PMA_PHP_SELF'] = $request;
|
||||
$this->object->set('PmaAbsoluteUri', $absolute);
|
||||
$this->assertEquals($expected, $this->object->getRootPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetRootPath
|
||||
*
|
||||
* @return array data for testGetRootPath
|
||||
*/
|
||||
public function rootUris()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
'/',
|
||||
),
|
||||
array(
|
||||
'/',
|
||||
'',
|
||||
'/',
|
||||
),
|
||||
array(
|
||||
'/index.php',
|
||||
'',
|
||||
'/',
|
||||
),
|
||||
array(
|
||||
'\\index.php',
|
||||
'',
|
||||
'/',
|
||||
),
|
||||
array(
|
||||
'\\',
|
||||
'',
|
||||
'/',
|
||||
),
|
||||
array(
|
||||
'\\path\\to\\index.php',
|
||||
'',
|
||||
'/path/to/',
|
||||
),
|
||||
array(
|
||||
'/foo/bar/phpmyadmin/index.php',
|
||||
'',
|
||||
'/foo/bar/phpmyadmin/',
|
||||
),
|
||||
array(
|
||||
'/foo/bar/phpmyadmin/',
|
||||
'',
|
||||
'/foo/bar/phpmyadmin/',
|
||||
),
|
||||
array(
|
||||
'https://example.net/baz/phpmyadmin/',
|
||||
'',
|
||||
'/baz/phpmyadmin/',
|
||||
),
|
||||
array(
|
||||
'http://example.net/baz/phpmyadmin/',
|
||||
'',
|
||||
'/baz/phpmyadmin/',
|
||||
),
|
||||
array(
|
||||
'http://example.net/phpmyadmin/',
|
||||
'',
|
||||
'/phpmyadmin/',
|
||||
),
|
||||
array(
|
||||
'http://example.net/',
|
||||
'',
|
||||
'/',
|
||||
),
|
||||
array(
|
||||
'http://example.net/',
|
||||
'http://example.net/phpmyadmin/',
|
||||
'/phpmyadmin/',
|
||||
),
|
||||
array(
|
||||
'http://example.net/',
|
||||
'http://example.net/phpmyadmin',
|
||||
'/phpmyadmin/',
|
||||
),
|
||||
array(
|
||||
'http://example.net/',
|
||||
'/phpmyadmin2',
|
||||
'/phpmyadmin2/',
|
||||
),
|
||||
array(
|
||||
'http://example.net/',
|
||||
'/phpmyadmin3/',
|
||||
'/phpmyadmin3/',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests loading of config file
|
||||
*
|
||||
* @param string $source File name of config to load
|
||||
* @param boolean $result Expected result of loading
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider configPaths
|
||||
*/
|
||||
public function testLoad($source, $result)
|
||||
{
|
||||
if ($result) {
|
||||
$this->assertTrue($this->object->load($source));
|
||||
} else {
|
||||
$this->assertFalse($this->object->load($source));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return of config Paths
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function configPaths()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'./test/test_data/config.inc.php',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'./test/test_data/config-nonexisting.inc.php',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'./libraries/config.default.php',
|
||||
true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for loading user preferences
|
||||
*
|
||||
* @return void
|
||||
* @todo Test actually preferences loading
|
||||
*/
|
||||
public function testLoadUserPreferences()
|
||||
{
|
||||
$this->assertNull($this->object->loadUserPreferences());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setting user config value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetUserValue()
|
||||
{
|
||||
$this->object->setUserValue(null, 'lang', 'cs', 'en');
|
||||
$this->object->setUserValue("TEST_COOKIE_USER_VAL", '', 'cfg_val_1');
|
||||
$this->assertEquals(
|
||||
$this->object->getUserValue("TEST_COOKIE_USER_VAL", 'fail'),
|
||||
'cfg_val_1'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getting user config value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetUserValue()
|
||||
{
|
||||
$this->assertEquals($this->object->getUserValue('test_val', 'val'), 'val');
|
||||
}
|
||||
|
||||
/**
|
||||
* Should test getting unique value for theme
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetThemeUniqueValue()
|
||||
{
|
||||
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
|
||||
$partial_sum = (
|
||||
PHPUnit_Framework_Assert::readAttribute($this->object, 'source_mtime') +
|
||||
PHPUnit_Framework_Assert::readAttribute(
|
||||
$this->object,
|
||||
'default_source_mtime'
|
||||
) +
|
||||
$this->object->get('user_preferences_mtime') +
|
||||
$_SESSION['PMA_Theme']->mtime_info +
|
||||
$_SESSION['PMA_Theme']->filesize_info
|
||||
);
|
||||
|
||||
$this->object->set('fontsize', 10);
|
||||
$this->assertEquals(10 + $partial_sum, $this->object->getThemeUniqueValue());
|
||||
$this->object->set('fontsize', null);
|
||||
|
||||
$_COOKIE['pma_fontsize'] = 20;
|
||||
$this->assertEquals(20 + $partial_sum, $this->object->getThemeUniqueValue());
|
||||
unset($_COOKIE['pma_fontsize']);
|
||||
|
||||
$this->assertEquals($partial_sum, $this->object->getThemeUniqueValue());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Should test checking of config permissions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckPermissions()
|
||||
{
|
||||
//load file permissions for the current permissions file
|
||||
$perms = @fileperms($this->object->getSource());
|
||||
//testing for permissions for no configuration file
|
||||
$this->assertFalse(!($perms === false) && ($perms & 2));
|
||||
|
||||
//load file permissions for the current permissions file
|
||||
$perms = @fileperms($this->permTestObj->getSource());
|
||||
//testing for permissions
|
||||
$this->assertFalse(!($perms === false) && ($perms & 2));
|
||||
|
||||
//if the above assertion is false then applying further assertions
|
||||
if (!($perms === false) && ($perms & 2)) {
|
||||
$this->assertFalse($this->permTestObj->get('PMA_IS_WINDOWS') == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for setting cookies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetCookie()
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->object->setCookie(
|
||||
'TEST_DEF_COOKIE',
|
||||
'test_def_123',
|
||||
'test_def_123'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->setCookie(
|
||||
'TEST_CONFIG_COOKIE',
|
||||
'test_val_123',
|
||||
null,
|
||||
3600
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->setCookie(
|
||||
'TEST_CONFIG_COOKIE',
|
||||
'',
|
||||
'default_val'
|
||||
)
|
||||
);
|
||||
|
||||
$_COOKIE['TEST_MANUAL_COOKIE'] = 'some_test_val';
|
||||
$this->assertTrue(
|
||||
$this->object->setCookie(
|
||||
'TEST_MANUAL_COOKIE',
|
||||
'other',
|
||||
'other'
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for isGitRevision
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsGitRevision()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->isGitRevision()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Check HTTP
|
||||
*
|
||||
* @group medium
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckHTTP()
|
||||
{
|
||||
if (! function_exists('curl_init')) {
|
||||
$this->markTestSkipped('Missing curl extension!');
|
||||
}
|
||||
$this->assertTrue(
|
||||
$this->object->checkHTTP("https://www.phpmyadmin.net/test/data")
|
||||
);
|
||||
$this->assertContains(
|
||||
"TEST DATA",
|
||||
$this->object->checkHTTP("https://www.phpmyadmin.net/test/data", true)
|
||||
);
|
||||
$this->assertFalse(
|
||||
$this->object->checkHTTP("https://www.phpmyadmin.net/test/nothing")
|
||||
);
|
||||
// Use rate limit API as it's not subject to rate limiting
|
||||
$this->assertContains(
|
||||
'"resources"',
|
||||
$this->object->checkHTTP("https://api.github.com/rate_limit", true)
|
||||
);
|
||||
}
|
||||
}
|
||||
115
#pma/test/classes/DatabaseInterfaceTest.php
Normal file
115
#pma/test/classes/DatabaseInterfaceTest.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for faked database access
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests basic functionality of dummy dbi driver
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class DatabaseInterfaceTest extends PMATestCase
|
||||
{
|
||||
|
||||
private $_dbi;
|
||||
|
||||
/**
|
||||
* Configures test parameters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
//$extension = new PMA\libraries\dbi\DBIDummy();
|
||||
$extension = $this->getMockBuilder('PMA\libraries\dbi\DBIDummy')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$extension->expects($this->any())
|
||||
->method('realQuery')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$meta1 = new FieldMeta();
|
||||
$meta1->table = "meta1_table";
|
||||
$meta1->name = "meta1_name";
|
||||
|
||||
$meta2 = new FieldMeta();
|
||||
$meta2->table = "meta2_table";
|
||||
$meta2->name = "meta2_name";
|
||||
|
||||
$extension->expects($this->any())
|
||||
->method('getFieldsMeta')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
$meta1, $meta2
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->_dbi = new PMA\libraries\DatabaseInterface($extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for DBI::getColumnMapFromSql() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testPMAGetColumnMap()
|
||||
{
|
||||
$sql_query = "PMA_sql_query";
|
||||
$view_columns = array(
|
||||
"view_columns1", "view_columns2"
|
||||
);
|
||||
|
||||
$column_map = $this->_dbi->getColumnMapFromSql(
|
||||
$sql_query, $view_columns
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'table_name' => 'meta1_table',
|
||||
'refering_column' => 'meta1_name',
|
||||
'real_column' => 'view_columns1'
|
||||
),
|
||||
$column_map[0]
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'table_name' => 'meta2_table',
|
||||
'refering_column' => 'meta2_name',
|
||||
'real_column' => 'view_columns2'
|
||||
),
|
||||
$column_map[1]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for DBI::getSystemDatabase() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetSystemDatabase()
|
||||
{
|
||||
$sd = $this->_dbi->getSystemDatabase();
|
||||
$this->assertInstanceOf('PMA\libraries\SystemDatabase', $sd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* class for Table Field Meta
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class FieldMeta
|
||||
{
|
||||
public $table;
|
||||
public $name;
|
||||
}
|
||||
543
#pma/test/classes/DbQbeTest.php
Normal file
543
#pma/test/classes/DbQbeTest.php
Normal file
@@ -0,0 +1,543 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for DbQbe.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
use PMA\libraries\DbQbe;
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\DbQbe class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class DbQbeTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new DbQbe('pma_test');
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['db'] = 'pma_test';
|
||||
//mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$create_table = 'CREATE TABLE `table1` ('
|
||||
. '`id` int(11) NOT NULL,'
|
||||
. '`value` int(11) NOT NULL,'
|
||||
. 'PRIMARY KEY (`id`,`value`),'
|
||||
. 'KEY `value` (`value`)'
|
||||
. ') ENGINE=InnoDB DEFAULT CHARSET=latin1';
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fetchValue')
|
||||
->with('SHOW CREATE TABLE `pma_test`.`table1`', 0, 1)
|
||||
->will($this->returnValue($create_table));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('getTableIndexes')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call protected functions by setting visibility to public.
|
||||
*
|
||||
* @param string $name method name
|
||||
* @param array $params parameters for the invocation
|
||||
*
|
||||
* @return the output from the protected method.
|
||||
*/
|
||||
private function _callProtectedFunction($name, $params)
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\DbQbe');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($this->object, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getSortSelectCell
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSortSelectCell()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<td class="center"><select style="width: 12ex" name="criteriaSort[1]" '
|
||||
. 'size="1"><option value=""> </option><option value="ASC">'
|
||||
. 'Ascending</option><option value="DESC">Descending</option>'
|
||||
. '</select></td>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getSortSelectCell',
|
||||
array(1)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getSortRow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSortRow()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<tr class="even noclick"><th>Sort:</th><td class="center">'
|
||||
. '<select style="width: 12ex" name="criteriaSort[0]" size="1">'
|
||||
. '<option value=""> </option><option value="ASC">Ascending'
|
||||
. '</option><option value="DESC">Descending</option></select></td>'
|
||||
. '<td class="center"><select style="width: 12ex" '
|
||||
. 'name="criteriaSort[1]" size="1"><option value=""> </option>'
|
||||
. '<option value="ASC">Ascending</option><option value="DESC">'
|
||||
. 'Descending</option></select></td><td class="center">'
|
||||
. '<select style="width: 12ex" name="criteriaSort[2]" size="1">'
|
||||
. '<option value=""> </option><option value="ASC">Ascending'
|
||||
. '</option><option value="DESC">Descending</option></select></td></tr>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getSortRow',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getShowRow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetShowRow()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<tr class="odd noclick"><th>Show:</th><td class="center"><input type'
|
||||
. '="checkbox" name="criteriaShow[0]" /></td><td class="center">'
|
||||
. '<input type="checkbox" name="criteriaShow[1]" /></td><td '
|
||||
. 'class="center"><input type="checkbox" name="criteriaShow[2]" />'
|
||||
. '</td></tr>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getShowRow',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getCriteriaInputboxRow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCriteriaInputboxRow()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<tr class="even noclick"><th>Criteria:</th><td class="center">'
|
||||
. '<input type="hidden" name="prev_criteria[0]" value="" />'
|
||||
. '<input type="text" name="criteria[0]" value="" class="textfield" '
|
||||
. 'style="width: 12ex" size="20" /></td><td class="center">'
|
||||
. '<input type="hidden" name="prev_criteria[1]" value="" />'
|
||||
. '<input type="text" name="criteria[1]" value="" class="textfield" '
|
||||
. 'style="width: 12ex" size="20" /></td><td class="center">'
|
||||
. '<input type="hidden" name="prev_criteria[2]" value="" />'
|
||||
. '<input type="text" name="criteria[2]" value="" class="textfield" '
|
||||
. 'style="width: 12ex" size="20" /></td></tr>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getCriteriaInputboxRow',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getFootersOptions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFootersOptions()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<div class="floatleft">Add/Delete criteria rows:<select size="1" '
|
||||
. 'name="criteriaRowAdd"><option value="-3">-3</option><option '
|
||||
. 'value="-2">-2</option><option value="-1">-1</option><option '
|
||||
. 'value="0" selected="selected">0</option><option value="1">1'
|
||||
. '</option><option value="2">2</option><option value="3">3</option>'
|
||||
. '</select></div>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getFootersOptions',
|
||||
array('row')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getTableFooters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTableFooters()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<fieldset class="tblFooters"><div class="floatleft">Add/Delete criteria'
|
||||
. ' rows:<select size="1" name="criteriaRowAdd"><option value="-3">-3'
|
||||
. '</option><option value="-2">-2</option><option value="-1">-1</option>'
|
||||
. '<option value="0" selected="selected">0</option><option value="1">1'
|
||||
. '</option><option value="2">2</option><option value="3">3</option>'
|
||||
. '</select></div><div class="floatleft">Add/Delete columns:<select '
|
||||
. 'size="1" name="criteriaColumnAdd"><option value="-3">-3</option>'
|
||||
. '<option value="-2">-2</option><option value="-1">-1</option>'
|
||||
. '<option value="0" selected="selected">0</option><option value="1">1'
|
||||
. '</option><option value="2">2</option><option value="3">3</option>'
|
||||
. '</select></div><div class="floatleft"><input type="submit" '
|
||||
. 'name="modify"value="Update Query" /></div></fieldset>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getTableFooters',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getAndOrColCell
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetAndOrColCell()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<td class="center"><strong>Or:</strong><input type="radio" '
|
||||
. 'name="criteriaAndOrColumn[1]" value="or" /> <strong>And:'
|
||||
. '</strong><input type="radio" name="criteriaAndOrColumn[1]" value='
|
||||
. '"and" /><br />Ins<input type="checkbox" name="criteriaColumnInsert'
|
||||
. '[1]" /> Del<input type="checkbox" '
|
||||
. 'name="criteriaColumnDelete[1]" /></td>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getAndOrColCell',
|
||||
array(1)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getModifyColumnsRow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetModifyColumnsRow()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<tr class="even noclick"><th>Modify:</th><td class="center"><strong>'
|
||||
. 'Or:</strong><input type="radio" name="criteriaAndOrColumn[0]" value'
|
||||
. '="or" /> <strong>And:</strong><input type="radio" name='
|
||||
. '"criteriaAndOrColumn[0]" value="and" checked="checked" /><br />Ins'
|
||||
. '<input type="checkbox" name="criteriaColumnInsert[0]" /> '
|
||||
. 'Del<input type="checkbox" name="criteriaColumnDelete[0]" /></td><td '
|
||||
. 'class="center"><strong>Or:</strong><input type="radio" name="'
|
||||
. 'criteriaAndOrColumn[1]" value="or" /> <strong>And:'
|
||||
. '</strong><input type="radio" name="criteriaAndOrColumn[1]" value='
|
||||
. '"and" checked="checked" /><br />Ins<input type="checkbox" name='
|
||||
. '"criteriaColumnInsert[1]" /> Del<input type="checkbox" '
|
||||
. 'name="criteriaColumnDelete[1]" /></td><td class="center"><br />Ins'
|
||||
. '<input type="checkbox" name="criteriaColumnInsert[2]" /> '
|
||||
. 'Del<input type="checkbox" name="criteriaColumnDelete[2]" /></td>'
|
||||
. '</tr>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getModifyColumnsRow',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getInsDelAndOrCell
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInsDelAndOrCell()
|
||||
{
|
||||
$GLOBALS['cell_align_right'] = 'cellAlign';
|
||||
$this->assertEquals(
|
||||
'<td class="cellAlign nowrap"><!-- Row controls --><table class="nospac'
|
||||
. 'ing nopadding"><tr><td class="cellAlign nowrap"><small>Ins:</small>'
|
||||
. '<input type="checkbox" name="criteriaRowInsert[3]" /></td><td '
|
||||
. 'class="cellAlign"><strong>And:</strong></td><td><input type="radio" '
|
||||
. 'name="criteriaAndOrRow[3]" value="and" /></td></tr><tr><td class="'
|
||||
. 'cellAlign nowrap"><small>Del:</small><input type="checkbox" '
|
||||
. 'name="criteriaRowDelete[3]" /></td><td class="cellAlign"><strong>'
|
||||
. 'Or:</strong></td><td><input type="radio" name="criteriaAndOrRow[3]" '
|
||||
. 'value="or" checked="checked" /></td></tr></table></td>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getInsDelAndOrCell',
|
||||
array(3, array('and' => '', 'or' => ' checked="checked"'))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getInputboxRow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInputboxRow()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<td class="center"><input type="text" name="Or2[0]" value="" class='
|
||||
. '"textfield" style="width: 12ex" size="20" /></td><td class="center">'
|
||||
. '<input type="text" name="Or2[1]" value="" class="textfield" '
|
||||
. 'style="width: 12ex" size="20" /></td><td class="center"><input '
|
||||
. 'type="text" name="Or2[2]" value="" class="textfield" style="width: '
|
||||
. '12ex" size="20" /></td>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getInputboxRow',
|
||||
array(2)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getInsDelAndOrCriteriaRows
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInsDelAndOrCriteriaRows()
|
||||
{
|
||||
$GLOBALS['cell_align_right'] = 'cellAlign';
|
||||
$this->assertEquals(
|
||||
'<tr class="odd noclick"><td class="cellAlign nowrap"><!-- Row controls'
|
||||
. ' --><table class="nospacing nopadding"><tr><td class="cellAlign '
|
||||
. 'nowrap"><small>Ins:</small><input type="checkbox" name="'
|
||||
. 'criteriaRowInsert[0]" /></td><td class="cellAlign"><strong>And:'
|
||||
. '</strong></td><td><input type="radio" name="criteriaAndOrRow[0]" '
|
||||
. 'value="and" /></td></tr><tr><td class="cellAlign nowrap"><small>Del:'
|
||||
. '</small><input type="checkbox" name="criteriaRowDelete[0]" /></td>'
|
||||
. '<td class="cellAlign"><strong>Or:</strong></td><td><input type='
|
||||
. '"radio" name="criteriaAndOrRow[0]" value="or" checked="checked" />'
|
||||
. '</td></tr></table></td><td class="center"><input type="text" '
|
||||
. 'name="Or0[0]" value="" class="textfield" style="width: 12ex" '
|
||||
. 'size="20" /></td><td class="center"><input type="text" name="Or0[1]" '
|
||||
. 'value="" class="textfield" style="width: 12ex" size="20" /></td><td '
|
||||
. 'class="center"><input type="text" name="Or0[2]" value="" class='
|
||||
. '"textfield" style="width: 12ex" size="20" /></td></tr>',
|
||||
$this->_callProtectedFunction(
|
||||
'_getInsDelAndOrCriteriaRows',
|
||||
array(2,3)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getSelectClause
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSelectClause()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->_callProtectedFunction(
|
||||
'_getSelectClause',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getWhereClause
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetWhereClause()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->_callProtectedFunction(
|
||||
'_getWhereClause',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getOrderByClause
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetOrderByClause()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->_callProtectedFunction(
|
||||
'_getOrderByClause',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getIndexes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetIndexes()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'unique' => array(),
|
||||
'index' => array()
|
||||
),
|
||||
$this->_callProtectedFunction(
|
||||
'_getIndexes',
|
||||
array(
|
||||
array('`table1`','table2'),
|
||||
array('column1', 'column2', 'column3'),
|
||||
array('column2')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getLeftJoinColumnCandidates
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLeftJoinColumnCandidates()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
0 => 'column2'
|
||||
),
|
||||
$this->_callProtectedFunction(
|
||||
'_getLeftJoinColumnCandidates',
|
||||
array(
|
||||
array('`table1`','table2'),
|
||||
array('column1', 'column2', 'column3'),
|
||||
array('column2')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getMasterTable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMasterTable()
|
||||
{
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->_callProtectedFunction(
|
||||
'_getMasterTable',
|
||||
array(
|
||||
array('table1','table2'),
|
||||
array('column1', 'column2', 'column3'),
|
||||
array('column2'),
|
||||
array('qbe_test')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getWhereClauseTablesAndColumns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetWhereClauseTablesAndColumns()
|
||||
{
|
||||
$_POST['criteriaColumn'] = array(
|
||||
'table1.id',
|
||||
'table1.value',
|
||||
'table1.name',
|
||||
'table1.deleted'
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'where_clause_tables' => array(),
|
||||
'where_clause_columns' => array()
|
||||
),
|
||||
$this->_callProtectedFunction(
|
||||
'_getWhereClauseTablesAndColumns',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getFromClause
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFromClause()
|
||||
{
|
||||
$_POST['criteriaColumn'] = array(
|
||||
'table1.id',
|
||||
'table1.value',
|
||||
'table1.name',
|
||||
'table1.deleted'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'`table1`',
|
||||
$this->_callProtectedFunction(
|
||||
'_getFromClause',
|
||||
array(array('`table1`.`id`'))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getSQLQuery
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSQLQuery()
|
||||
{
|
||||
$_POST['criteriaColumn'] = array(
|
||||
'table1.id',
|
||||
'table1.value',
|
||||
'table1.name',
|
||||
'table1.deleted'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'FROM `table1`
|
||||
',
|
||||
$this->_callProtectedFunction(
|
||||
'_getSQLQuery',
|
||||
array(array('`table1`.`id`'))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
271
#pma/test/classes/DbSearchTest.php
Normal file
271
#pma/test/classes/DbSearchTest.php
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for DbSearch.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
use PMA\libraries\DbSearch;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
/**
|
||||
* Tests for database search.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class DbSearchTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new DbSearch('pma_test');
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['db'] = 'pma';
|
||||
$GLOBALS['collation_connection'] = 'utf-8';
|
||||
|
||||
//mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('getColumns')
|
||||
->with('pma', 'table1')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call protected functions by setting visibility to public.
|
||||
*
|
||||
* @param string $name method name
|
||||
* @param array $params parameters for the invocation
|
||||
*
|
||||
* @return the output from the protected method.
|
||||
*/
|
||||
private function _callProtectedFunction($name, $params)
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\DbSearch');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($this->object, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getSearchSqls
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSearchSqls()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array (
|
||||
'select_columns' => 'SELECT * FROM `pma`.`table1` WHERE FALSE',
|
||||
'select_count' => 'SELECT COUNT(*) AS `count` FROM `pma`.`table1` ' .
|
||||
'WHERE FALSE',
|
||||
'delete' => 'DELETE FROM `pma`.`table1` WHERE FALSE'
|
||||
),
|
||||
$this->_callProtectedFunction(
|
||||
'_getSearchSqls',
|
||||
array('table1')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getSearchResults
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSearchResults()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<br /><table class="data"><caption class="tblHeaders">Search results '
|
||||
. 'for "<i></i>" :</caption></table>',
|
||||
$this->object->getSearchResults()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getResultsRow
|
||||
*
|
||||
* @param string $each_table Tables on which search is to be performed
|
||||
* @param array $newsearchsqls Contains SQL queries
|
||||
* @param bool $odd_row For displaying contrasting table rows
|
||||
* @param string $output Expected HTML output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForTestGetResultsRow
|
||||
*/
|
||||
public function testGetResultsRow(
|
||||
$each_table, $newsearchsqls, $odd_row, $output
|
||||
) {
|
||||
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->_callProtectedFunction(
|
||||
'_getResultsRow',
|
||||
array($each_table, $newsearchsqls, $odd_row, 2)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetResultRow
|
||||
*
|
||||
* @return array provider for testGetResultsRow
|
||||
*/
|
||||
public function providerForTestGetResultsRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'table1',
|
||||
array(
|
||||
'SELECT * FROM `pma`.`table1` WHERE FALSE',
|
||||
'SELECT COUNT(*) AS `count` FROM `pma`.`table1` WHERE FALSE',
|
||||
'select_count' => 2,
|
||||
'select_columns' => 'column1',
|
||||
'delete' => 'column2'
|
||||
),
|
||||
true,
|
||||
'<tr class="noclick odd"><td>2 matches in <strong>table1</strong>'
|
||||
. '</td><td><a name="browse_search" class="ajax browse_results" '
|
||||
. 'href="sql.php?db=pma&table'
|
||||
. '=table1&goto=db_sql.php&pos=0&is_js_confirmed=0&'
|
||||
. 'server=0&lang=en&'
|
||||
. 'collation_connection=utf-8&token=token" '
|
||||
. 'data-browse-sql="column1" data-table-name="table1" '
|
||||
. '>Browse</a></td><td>'
|
||||
. '<a name="delete_search" class="ajax delete_results" href'
|
||||
. '="sql.php?db=pma&table=table1&goto=db_sql.php&pos=0'
|
||||
. '&is_js_confirmed=0&server=0&'
|
||||
. 'lang=en&collation_connection=utf-8&token=token" '
|
||||
. 'data-delete-sql="column2" '
|
||||
. 'data-table-name="table1" '
|
||||
. '>Delete</a></td></tr>'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getSelectionForm
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSelectionForm()
|
||||
{
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['pmaThemeImage'] = 'themes/dot.gif';
|
||||
$this->assertEquals(
|
||||
'<a id="db_search"></a><form id="db_search_form" class="ajax lock-page" '
|
||||
. 'method="post" action="db_search.php" name="db_search">'
|
||||
. '<input type="hidden" name="db" value="pma" />'
|
||||
. '<input type="hidden" name="lang" value="en" />'
|
||||
. '<input type="hidden" name="collation_connection" value="utf-8" />'
|
||||
. '<input type="hidden" name="token" value="token" />'
|
||||
. '<fieldset><legend>Search in database</legend><table class='
|
||||
. '"formlayout"><tr><td>Words or values to search for (wildcard: "%"):'
|
||||
. '</td><td><input type="text" name="criteriaSearchString" size="60" '
|
||||
. 'value="" /></td></tr><tr><td class="right vtop">Find:</td><td><input '
|
||||
. 'type="radio" name="criteriaSearchType" id="criteriaSearchType_1" '
|
||||
. 'value="1" checked="checked" />' . "\n"
|
||||
. '<label for="criteriaSearchType_1">at least one of the words<span '
|
||||
. 'class="pma_hint"><img src="themes/dot.gifb_help.png" title="" alt="" '
|
||||
. '/><span class="hide">Words are separated by a space character (" ").'
|
||||
. '</span></span></label><br />' . "\n"
|
||||
. '<input type="radio" name="criteriaSearchType" id="criteriaSearchType'
|
||||
. '_2" value="2" />' . "\n"
|
||||
. '<label for="criteriaSearchType_2">all words<span class="pma_hint">'
|
||||
. '<img src="themes/dot.gifb_help.png" title="" alt="" /><span class'
|
||||
. '="hide">Words are separated by a space character (" ").</span></span>'
|
||||
. '</label><br />' . "\n"
|
||||
. '<input type="radio" name="criteriaSearchType" id="criteriaSearchType'
|
||||
. '_3" value="3" />' . "\n"
|
||||
. '<label for="criteriaSearchType_3">the exact phrase</label><br />'
|
||||
. "\n" . '<input type="radio" name="criteriaSearchType" id="criteria'
|
||||
. 'SearchType_4" value="4" />' . "\n"
|
||||
. '<label for="criteriaSearchType_4">as regular expression <a href='
|
||||
. '"./url.php?url=https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen'
|
||||
. '%2Fregexp.html" target='
|
||||
. '"mysql_doc"><img src="themes/dot.gifb_help.png" title="Documentation"'
|
||||
. ' alt="Documentation" /></a></label><br />' . "\n"
|
||||
. '</td></tr><tr><td class="right vtop">Inside tables:</td>'
|
||||
. '<td rowspan="2"><select name="criteriaTables[]" size="6" '
|
||||
. 'multiple="multiple"><option value="table1">table1</option>'
|
||||
. '<option value="table2">table2</option></select></td></tr><tr>'
|
||||
. '<td class="right vbottom"><a href="#" onclick="setSelectOptions'
|
||||
. '(\'db_search\', \'criteriaTables[]\', true); return false;">Select '
|
||||
. 'all</a> / <a href="#" onclick="setSelectOptions'
|
||||
. '(\'db_search\', \'criteriaTables[]\', false); return false;">Unselect'
|
||||
. ' all</a></td></tr><tr><td class="right">Inside column:</td><td>'
|
||||
. '<input type="text" name="criteriaColumnName" size="60"value="" />'
|
||||
. '</td></tr></table></fieldset><fieldset class="tblFooters"><input '
|
||||
. 'type="submit" name="submit_search" value="Go" id="buttonGo" />'
|
||||
. '</fieldset></form><div id="togglesearchformdiv">'
|
||||
. '<a id="togglesearchformlink"></a></div>',
|
||||
$this->object->getSelectionForm()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getResultDivs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetResultDivs()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<!-- These two table-image and table-link elements display the '
|
||||
. 'table name in browse search results --><div id="table-info">'
|
||||
. '<a class="item" id="table-link" ></a></div><div id="browse-results">'
|
||||
. '<!-- this browse-results div is used to load the browse and delete '
|
||||
. 'results in the db search --></div><br class="clearfloat" />'
|
||||
. '<div id="sqlqueryform"><!-- this sqlqueryform div is used to load the'
|
||||
. ' delete form in the db search --></div><!-- toggle query box link-->'
|
||||
. '<a id="togglequerybox"></a>',
|
||||
$this->_callProtectedFunction(
|
||||
'getResultDivs',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
1608
#pma/test/classes/DisplayResultsTest.php
Normal file
1608
#pma/test/classes/DisplayResultsTest.php
Normal file
File diff suppressed because it is too large
Load Diff
308
#pma/test/classes/ErrorHandlerTest.php
Normal file
308
#pma/test/classes/ErrorHandlerTest.php
Normal file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for ErrorHandler
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\ErrorHandler class.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ErrorHandlerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new PMA\libraries\ErrorHandler();
|
||||
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call protected functions by setting visibility to public.
|
||||
*
|
||||
* @param string $name method name
|
||||
* @param array $params parameters for the invocation
|
||||
*
|
||||
* @return the output from the protected method.
|
||||
*/
|
||||
private function _callProtectedFunction($name, $params)
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\ErrorHandler');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($this->object, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testHandleError
|
||||
*
|
||||
* @return array data for testHandleError
|
||||
*/
|
||||
public function providerForTestHandleError()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
E_RECOVERABLE_ERROR,
|
||||
'Compile Error',
|
||||
'error.txt',
|
||||
12,
|
||||
'Compile Error',
|
||||
'',
|
||||
),
|
||||
array(
|
||||
E_USER_NOTICE,
|
||||
'User notice',
|
||||
'error.txt',
|
||||
12,
|
||||
'User notice',
|
||||
'User notice',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getDispErrors when PHP errors are not shown
|
||||
*
|
||||
* @param integer $errno error number
|
||||
* @param string $errstr error string
|
||||
* @param string $errfile error file
|
||||
* @param integer $errline error line
|
||||
* @param string $output_show expected output if showing of errors is
|
||||
* enabled
|
||||
* @param string $output_hide expected output if showing of errors is
|
||||
* disabled and 'sendErrorReports' is set to 'never'
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForTestHandleError
|
||||
*/
|
||||
public function testGetDispErrorsForDisplayFalse(
|
||||
$errno, $errstr, $errfile, $errline, $output_show, $output_hide
|
||||
) {
|
||||
// TODO: Add other test cases for all combination of 'sendErrorReports'
|
||||
$GLOBALS['cfg']['SendErrorReports'] = 'never';
|
||||
|
||||
$this->object->handleError($errno, $errstr, $errfile, $errline);
|
||||
|
||||
$output = $this->object->getDispErrors();
|
||||
|
||||
if ($output_hide == '') {
|
||||
$this->assertEquals('', $output);
|
||||
} else {
|
||||
$this->assertContains($output_hide, $output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getDispErrors when PHP errors are shown
|
||||
*
|
||||
* @param integer $errno error number
|
||||
* @param string $errstr error string
|
||||
* @param string $errfile error file
|
||||
* @param integer $errline error line
|
||||
* @param string $output_show expected output if showing of errors is
|
||||
* enabled
|
||||
* @param string $output_hide expected output if showing of errors is
|
||||
* disabled
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForTestHandleError
|
||||
*/
|
||||
public function testGetDispErrorsForDisplayTrue(
|
||||
$errno, $errstr, $errfile, $errline, $output_show, $output_hide
|
||||
) {
|
||||
$this->object->handleError($errno, $errstr, $errfile, $errline);
|
||||
|
||||
$this->assertContains(
|
||||
$output_show,
|
||||
$this->object->getDispErrors()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checkSavedErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckSavedErrors()
|
||||
{
|
||||
|
||||
$_SESSION['errors'] = array();
|
||||
|
||||
$this->_callProtectedFunction(
|
||||
'checkSavedErrors',
|
||||
array()
|
||||
);
|
||||
$this->assertTrue(!isset($_SESSION['errors']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for countErrors
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testCountErrors()
|
||||
{
|
||||
$this->object->addError(
|
||||
'Compile Error', E_WARNING, 'error.txt', 15
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->countErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for sliceErrors
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testSliceErrors()
|
||||
{
|
||||
$this->object->addError(
|
||||
'Compile Error', E_WARNING, 'error.txt', 15
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->countErrors()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->sliceErrors(1)
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->countErrors()
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count($this->object->sliceErrors(0))
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->countErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for countUserErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCountUserErrors()
|
||||
{
|
||||
$this->object->addError(
|
||||
'Compile Error', E_WARNING, 'error.txt', 15
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->countUserErrors()
|
||||
);
|
||||
$this->object->addError(
|
||||
'Compile Error', E_USER_WARNING, 'error.txt', 15
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->countUserErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for hasUserErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHasUserErrors()
|
||||
{
|
||||
$this->assertFalse($this->object->hasUserErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for hasErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHasErrors()
|
||||
{
|
||||
$this->assertFalse($this->object->hasErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for countDisplayErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCountDisplayErrorsForDisplayTrue()
|
||||
{
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->countDisplayErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for countDisplayErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCountDisplayErrorsForDisplayFalse()
|
||||
{
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->countDisplayErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for hasDisplayErrors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHasDisplayErrors()
|
||||
{
|
||||
$this->assertFalse($this->object->hasDisplayErrors());
|
||||
}
|
||||
}
|
||||
190
#pma/test/classes/ErrorTest.php
Normal file
190
#pma/test/classes/ErrorTest.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for Error.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Error class testing.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ErrorTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new PMA\libraries\Error('2', 'Compile Error', 'error.txt', 15);
|
||||
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setBacktrace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetBacktrace()
|
||||
{
|
||||
$bt = array(array('file'=>'bt1','line'=>2, 'function'=>'bar', 'args'=>array('foo'=>$this)));
|
||||
$this->object->setBacktrace($bt);
|
||||
$bt[0]['args']['foo'] = '<Class:ErrorTest>';
|
||||
$this->assertEquals($bt, $this->object->getBacktrace());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setLine
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLine()
|
||||
{
|
||||
$this->object->setLine(15);
|
||||
$this->assertEquals(15, $this->object->getLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setFile
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider filePathProvider
|
||||
*/
|
||||
public function testSetFile($file, $expected)
|
||||
{
|
||||
$this->object->setFile($file);
|
||||
$this->assertEquals($expected, $this->object->getFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for setFile
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filePathProvider()
|
||||
{
|
||||
return array(
|
||||
array('./ChangeLog', './ChangeLog'),
|
||||
array(__FILE__, './test/classes/ErrorTest.php'),
|
||||
array('./NONEXISTING', 'NONEXISTING'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getHash
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHash()
|
||||
{
|
||||
$this->assertEquals(
|
||||
1,
|
||||
preg_match('/^([a-z0-9]*)$/', $this->object->getHash())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getBacktraceDisplay
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetBacktraceDisplay()
|
||||
{
|
||||
$this->assertContains(
|
||||
'PHPUnit_Framework_TestResult->run(<Class:ErrorTest>)<br />',
|
||||
$this->object->getBacktraceDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getDisplay
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetDisplay()
|
||||
{
|
||||
$this->assertContains(
|
||||
'<div class="error"><strong>Warning</strong>',
|
||||
$this->object->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getHtmlTitle
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHtmlTitle()
|
||||
{
|
||||
$this->assertEquals('Warning: Compile Error', $this->object->getHtmlTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getTitle
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTitle()
|
||||
{
|
||||
$this->assertEquals('Warning: Compile Error', $this->object->getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getBacktrace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetBacktrace()
|
||||
{
|
||||
$bt = array(
|
||||
array('file'=>'bt1','line'=>2, 'function'=>'bar', 'args'=>array('foo'=>1)),
|
||||
array('file'=>'bt2','line'=>2, 'function'=>'bar', 'args'=>array('foo'=>2)),
|
||||
array('file'=>'bt3','line'=>2, 'function'=>'bar', 'args'=>array('foo'=>3)),
|
||||
array('file'=>'bt4','line'=>2, 'function'=>'bar', 'args'=>array('foo'=>4)),
|
||||
);
|
||||
|
||||
$this->object->setBacktrace($bt);
|
||||
|
||||
// case: full backtrace
|
||||
$this->assertEquals(4, count($this->object->getBacktrace()));
|
||||
|
||||
// case: first 2 frames
|
||||
$this->assertEquals(2, count($this->object->getBacktrace(2)));
|
||||
}
|
||||
}
|
||||
71
#pma/test/classes/FileTest.php
Normal file
71
#pma/test/classes/FileTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\File class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\File class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class FileTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Setup function for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['charset_conversion'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\File::getCompression
|
||||
*
|
||||
* @param string $file file string
|
||||
* @param string $mime expected mime
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider compressedFiles
|
||||
*/
|
||||
public function testMIME($file, $mime)
|
||||
{
|
||||
$arr = new PMA\libraries\File($file);
|
||||
$this->assertEquals($mime, $arr->getCompression());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\File::getContent
|
||||
*
|
||||
* @param string $file file string
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider compressedFiles
|
||||
*/
|
||||
public function testBinaryContent($file)
|
||||
{
|
||||
$data = '0x' . bin2hex(file_get_contents($file));
|
||||
$file = new PMA\libraries\File($file);
|
||||
$this->assertEquals($data, $file->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for tests
|
||||
*
|
||||
* @return array Test data
|
||||
*/
|
||||
public function compressedFiles()
|
||||
{
|
||||
return array(
|
||||
array('./test/test_data/test.gz', 'application/gzip'),
|
||||
array('./test/test_data/test.bz2', 'application/bzip2'),
|
||||
array('./test/test_data/test.zip', 'application/zip'),
|
||||
);
|
||||
}
|
||||
}
|
||||
262
#pma/test/classes/FontTest.php
Normal file
262
#pma/test/classes/FontTest.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\Font class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\Font class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class FontTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Test getStringWidth with different characters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetStringWidth()
|
||||
{
|
||||
// empty string
|
||||
$this->assertEquals(
|
||||
0,
|
||||
PMA\libraries\Font::getStringWidth("", "arial", "10")
|
||||
);
|
||||
|
||||
// empty string
|
||||
$this->assertEquals(
|
||||
3,
|
||||
PMA\libraries\Font::getStringWidth(" ", "arial", "10")
|
||||
);
|
||||
|
||||
// string "a"
|
||||
$this->assertEquals(
|
||||
6,
|
||||
PMA\libraries\Font::getStringWidth("a", "arial", "10")
|
||||
);
|
||||
|
||||
// string "aa"
|
||||
$this->assertEquals(
|
||||
12,
|
||||
PMA\libraries\Font::getStringWidth("aa", "arial", "10")
|
||||
);
|
||||
|
||||
// string "i"
|
||||
$this->assertEquals(
|
||||
3,
|
||||
PMA\libraries\Font::getStringWidth("i", "arial", "10")
|
||||
);
|
||||
|
||||
// string "f"
|
||||
$this->assertEquals(
|
||||
3,
|
||||
PMA\libraries\Font::getStringWidth("f", "arial", "10")
|
||||
);
|
||||
|
||||
// string "t"
|
||||
$this->assertEquals(
|
||||
3,
|
||||
PMA\libraries\Font::getStringWidth("t", "arial", "10")
|
||||
);
|
||||
|
||||
// string "if"
|
||||
$this->assertEquals(
|
||||
5,
|
||||
PMA\libraries\Font::getStringWidth("if", "arial", "10")
|
||||
);
|
||||
|
||||
// string "it"
|
||||
$this->assertEquals(
|
||||
6,
|
||||
PMA\libraries\Font::getStringWidth("it", "arial", "10")
|
||||
);
|
||||
|
||||
// string "r"
|
||||
$this->assertEquals(
|
||||
4,
|
||||
PMA\libraries\Font::getStringWidth("r", "arial", "10")
|
||||
);
|
||||
|
||||
// string "1"
|
||||
$this->assertEquals(
|
||||
5,
|
||||
PMA\libraries\Font::getStringWidth("1", "arial", "10")
|
||||
);
|
||||
|
||||
// string "c"
|
||||
$this->assertEquals(
|
||||
5,
|
||||
PMA\libraries\Font::getStringWidth("c", "arial", "10")
|
||||
);
|
||||
|
||||
// string "F"
|
||||
$this->assertEquals(
|
||||
7,
|
||||
PMA\libraries\Font::getStringWidth("F", "arial", "10")
|
||||
);
|
||||
|
||||
// string "A"
|
||||
$this->assertEquals(
|
||||
7,
|
||||
PMA\libraries\Font::getStringWidth("A", "arial", "10")
|
||||
);
|
||||
|
||||
// string "w"
|
||||
$this->assertEquals(
|
||||
8,
|
||||
PMA\libraries\Font::getStringWidth("w", "arial", "10")
|
||||
);
|
||||
|
||||
// string "G"
|
||||
$this->assertEquals(
|
||||
8,
|
||||
PMA\libraries\Font::getStringWidth("G", "arial", "10")
|
||||
);
|
||||
|
||||
// string "m"
|
||||
$this->assertEquals(
|
||||
9,
|
||||
PMA\libraries\Font::getStringWidth("m", "arial", "10")
|
||||
);
|
||||
|
||||
// string "W"
|
||||
$this->assertEquals(
|
||||
10,
|
||||
PMA\libraries\Font::getStringWidth("W", "arial", "10")
|
||||
);
|
||||
|
||||
// string "$"
|
||||
$this->assertEquals(
|
||||
3,
|
||||
PMA\libraries\Font::getStringWidth("$", "arial", "10")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getStringWidth with different fonts.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetStringWidthFont()
|
||||
{
|
||||
// string "phpMyAdmin", with Arial 10
|
||||
$this->assertEquals(
|
||||
59,
|
||||
PMA\libraries\Font::getStringWidth("phpMyAdmin", "arial", "10")
|
||||
);
|
||||
|
||||
// string "phpMyAdmin", with No font
|
||||
$this->assertEquals(
|
||||
59,
|
||||
PMA\libraries\Font::getStringWidth("phpMyAdmin", "", "10")
|
||||
);
|
||||
|
||||
// string "phpMyAdmin", with Times 10
|
||||
$this->assertEquals(
|
||||
55,
|
||||
PMA\libraries\Font::getStringWidth("phpMyAdmin", "times", "10")
|
||||
);
|
||||
|
||||
// string "phpMyAdmin", with Broadway 10
|
||||
$this->assertEquals(
|
||||
73,
|
||||
PMA\libraries\Font::getStringWidth("phpMyAdmin", "broadway", "10")
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getStringWidth with different font sizes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetStringWidthSize()
|
||||
{
|
||||
// string "phpMyAdmin", with font size 0
|
||||
$this->assertEquals(
|
||||
0,
|
||||
PMA\libraries\Font::getStringWidth("phpMyAdmin", "arial", "0")
|
||||
);
|
||||
|
||||
// string "phpMyAdmin", with Arial 10
|
||||
$this->assertEquals(
|
||||
59,
|
||||
PMA\libraries\Font::getStringWidth("phpMyAdmin", "arial", "10")
|
||||
);
|
||||
|
||||
// string "phpMyAdmin", with Arial 11
|
||||
$this->assertEquals(
|
||||
65,
|
||||
PMA\libraries\Font::getStringWidth("phpMyAdmin", "arial", "11")
|
||||
);
|
||||
|
||||
// string "phpMyAdmin", with Arial 20
|
||||
$this->assertEquals(
|
||||
118,
|
||||
PMA\libraries\Font::getStringWidth("phpMyAdmin", "arial", "20")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getStringWidth with a custom charList.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetStringWidthCharLists()
|
||||
{
|
||||
// string "a", with invalid charlist (= string)
|
||||
$this->assertEquals(
|
||||
6,
|
||||
PMA\libraries\Font::getStringWidth("a", "arial", "10", "list")
|
||||
);
|
||||
|
||||
// string "a", with invalid charlist (= array without proper structure)
|
||||
$this->assertEquals(
|
||||
6,
|
||||
PMA\libraries\Font::getStringWidth("a", "arial", "10", array("list"))
|
||||
);
|
||||
|
||||
// string "a", with invalid charlist (= array without proper structure :
|
||||
// modifier is missing
|
||||
$this->assertEquals(
|
||||
6,
|
||||
PMA\libraries\Font::getStringWidth(
|
||||
"a", "arial", "10",
|
||||
array(array("chars" => "a"))
|
||||
)
|
||||
);
|
||||
|
||||
// string "a", with invalid charlist (= array without proper structure :
|
||||
// chars is missing
|
||||
$this->assertEquals(
|
||||
6,
|
||||
PMA\libraries\Font::getStringWidth(
|
||||
"a", "arial", "10",
|
||||
array(array("modifier" => 0.61))
|
||||
)
|
||||
);
|
||||
|
||||
// string "a", with invalid charlist (= array without proper structure :
|
||||
// chars is not an array
|
||||
$this->assertEquals(
|
||||
6,
|
||||
PMA\libraries\Font::getStringWidth(
|
||||
"a", "arial", "10",
|
||||
array(array("chars" => "a", "modifier" => 0.61))
|
||||
)
|
||||
);
|
||||
|
||||
// string "a", with valid charlist
|
||||
$this->assertEquals(
|
||||
7,
|
||||
PMA\libraries\Font::getStringWidth(
|
||||
"a", "arial", "10",
|
||||
array(array("chars" => array("a"), "modifier" => 0.61))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
277
#pma/test/classes/FooterTest.php
Normal file
277
#pma/test/classes/FooterTest.php
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for Footer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for Footer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class FooterTest extends PMATestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array store private attributes of PMA\libraries\Footer
|
||||
*/
|
||||
public $privates = array();
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$_SERVER['SCRIPT_NAME'] = 'index.php';
|
||||
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
|
||||
$GLOBALS['db'] = '';
|
||||
$GLOBALS['table'] = '';
|
||||
$GLOBALS['text_dir'] = 'ltr';
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['collation_connection'] = 'utf8_general_ci';
|
||||
$GLOBALS['cfg']['Server']['verbose'] = 'verbose host';
|
||||
$GLOBALS['server'] = '1';
|
||||
$_GET['reload_left_frame'] = '1';
|
||||
$GLOBALS['focus_querywindow'] = 'main_pane_left';
|
||||
$this->object = new PMA\libraries\Footer();
|
||||
unset($GLOBALS['error_message']);
|
||||
unset($GLOBALS['sql_query']);
|
||||
$GLOBALS['error_handler'] = new PMA\libraries\ErrorHandler();
|
||||
unset($_POST);
|
||||
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call private functions by setting visibility to public.
|
||||
*
|
||||
* @param string $name method name
|
||||
* @param array $params parameters for the invocation
|
||||
*
|
||||
* @return the output from the private method.
|
||||
*/
|
||||
private function _callPrivateFunction($name, $params)
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\Footer');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($this->object, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getDebugMessage
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetDebugMessage()
|
||||
{
|
||||
$GLOBALS['cfg']['DBG']['sql'] = true;
|
||||
$_SESSION['debug']['queries'] = array(
|
||||
array(
|
||||
'count' => 1,
|
||||
'time' => 0.2,
|
||||
'query' => 'SELECT * FROM `pma_bookmark` WHERE 1',
|
||||
),
|
||||
array(
|
||||
'count' => 1,
|
||||
'time' => 2.5,
|
||||
'query' => 'SELECT * FROM `db` WHERE 1',
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"queries":[{"count":1,"time":0.2,"query":"SELECT * FROM `pma_bookmark` WHERE 1"},'
|
||||
. '{"count":1,"time":2.5,"query":"SELECT * FROM `db` WHERE 1"}]}',
|
||||
$this->object->getDebugMessage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _removeRecursion
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRemoveRecursion()
|
||||
{
|
||||
$object = (object) array();
|
||||
$object->child = (object) array();
|
||||
$object->child->parent = $object;
|
||||
|
||||
$this->_callPrivateFunction(
|
||||
'_removeRecursion',
|
||||
array(
|
||||
&$object
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"child":{"parent":"***RECURSION***"}}',
|
||||
json_encode($object)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getSelfLink
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSelfLink()
|
||||
{
|
||||
|
||||
$GLOBALS['cfg']['TabsMode'] = 'text';
|
||||
$GLOBALS['cfg']['ServerDefault'] = 1;
|
||||
|
||||
$this->assertEquals(
|
||||
'<div id="selflink" class="print_ignore"><a href="index.php?db=&'
|
||||
. 'table=&server=1&target=&lang=en&collation_connection='
|
||||
. 'utf8_general_ci&token=token" title="Open new phpMyAdmin window" '
|
||||
. 'target="_blank" rel="noopener noreferrer">Open new phpMyAdmin window</a></div>',
|
||||
$this->_callPrivateFunction(
|
||||
'_getSelfLink',
|
||||
array(
|
||||
$this->object->getSelfUrl()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getSelfLink
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSelfLinkWithImage()
|
||||
{
|
||||
|
||||
$GLOBALS['cfg']['TabsMode'] = 'icons';
|
||||
$GLOBALS['cfg']['ServerDefault'] = 1;
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
|
||||
$this->assertEquals(
|
||||
'<div id="selflink" class="print_ignore"><a href="index.php?db=&'
|
||||
. 'table=&server=1&target=&lang=en&collation_connection='
|
||||
. 'utf8_general_ci&token=token" title="Open new phpMyAdmin window" '
|
||||
. 'target="_blank" rel="noopener noreferrer"><img src="imagewindow-new.png" title="Open new '
|
||||
. 'phpMyAdmin window" alt="Open new phpMyAdmin window" /></a></div>',
|
||||
$this->_callPrivateFunction(
|
||||
'_getSelfLink',
|
||||
array(
|
||||
$this->object->getSelfUrl()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for disable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisable()
|
||||
{
|
||||
$footer = new PMA\libraries\Footer();
|
||||
$footer->disable();
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$footer->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for footer when ajax enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAjax()
|
||||
{
|
||||
$footer = new PMA\libraries\Footer();
|
||||
$footer->setAjax(true);
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$footer->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for footer get Scripts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetScripts()
|
||||
{
|
||||
$footer = new PMA\libraries\Footer();
|
||||
$this->assertContains(
|
||||
'<script data-cfasync="false" type="text/javascript">',
|
||||
$footer->getScripts()->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for displaying footer
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testDisplay()
|
||||
{
|
||||
$footer = new PMA\libraries\Footer();
|
||||
$this->assertContains(
|
||||
'Open new phpMyAdmin window',
|
||||
$footer->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for minimal footer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMinimal()
|
||||
{
|
||||
$footer = new PMA\libraries\Footer();
|
||||
$footer->setMinimal();
|
||||
$this->assertEquals(
|
||||
'</div></body></html>',
|
||||
$footer->getDisplay()
|
||||
);
|
||||
}
|
||||
}
|
||||
178
#pma/test/classes/HeaderTest.php
Normal file
178
#pma/test/classes/HeaderTest.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\Header class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\Header class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class HeaderTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
if (!defined('PMA_IS_WINDOWS')) {
|
||||
define('PMA_IS_WINDOWS', false);
|
||||
}
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['message'] = 'phpmyadminmessage';
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
|
||||
$GLOBALS['server'] = 'server';
|
||||
$GLOBALS['db'] = 'pma_test';
|
||||
$GLOBALS['table'] = 'table1';
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['verbose'] = 'verbose host';
|
||||
$GLOBALS['cfg']['Server']['pmadb'] = '';
|
||||
$GLOBALS['cfg']['Server']['user'] = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for disable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisable()
|
||||
{
|
||||
$header = new PMA\libraries\Header();
|
||||
$header->disable();
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$header->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Set BodyId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetBodyId()
|
||||
{
|
||||
$header = new PMA\libraries\Header();
|
||||
$header->setBodyId('PMA_header_id');
|
||||
$this->assertContains(
|
||||
'PMA_header_id',
|
||||
$header->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for print view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintView()
|
||||
{
|
||||
$header = new PMA\libraries\Header();
|
||||
$header->enablePrintView();
|
||||
$this->assertContains(
|
||||
'Print view',
|
||||
$header->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Get JsParams
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetJsParams()
|
||||
{
|
||||
$header = new PMA\libraries\Header();
|
||||
$this->assertArrayHasKey(
|
||||
'common_query',
|
||||
$header->getJsParams()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Get JsParamsCode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetJsParamsCode()
|
||||
{
|
||||
$header = new PMA\libraries\Header();
|
||||
$this->assertContains(
|
||||
'PMA_commonParams.setAll',
|
||||
$header->getJsParamsCode()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Get Message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMessage()
|
||||
{
|
||||
$header = new PMA\libraries\Header();
|
||||
$this->assertContains(
|
||||
'phpmyadminmessage',
|
||||
$header->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Disable Warnings
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testDisableWarnings()
|
||||
{
|
||||
$header = new PMA\libraries\Header();
|
||||
$header->disableWarnings();
|
||||
$this->assertAttributeEquals(
|
||||
false,
|
||||
'_warningsEnabled',
|
||||
$header
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests private method _getWarnings when warnings are disabled
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetWarningsWithWarningsDisabled()
|
||||
{
|
||||
$method = new ReflectionMethod(
|
||||
'PMA\libraries\Header', '_getWarnings'
|
||||
);
|
||||
$method->setAccessible(true);
|
||||
|
||||
$header = new PMA\libraries\Header();
|
||||
$header->disableWarnings();
|
||||
$this->assertEmpty($method->invoke($header));
|
||||
}
|
||||
}
|
||||
198
#pma/test/classes/IndexTest.php
Normal file
198
#pma/test/classes/IndexTest.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for Index class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test for Index class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class IndexTest extends PMATestCase
|
||||
{
|
||||
private $_params = array();
|
||||
|
||||
/**
|
||||
* Configures parameters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$this->_params['Schema'] = "PMA_Schema";
|
||||
$this->_params['Table'] = "PMA_Table";
|
||||
$this->_params['Key_name'] = "PMA_Key_name";
|
||||
$this->_params['Index_choice'] = "PMA_Index_choice";
|
||||
$this->_params['Comment'] = "PMA_Comment";
|
||||
$this->_params['Index_comment'] = "PMA_Index_comment";
|
||||
$this->_params['Non_unique'] = "PMA_Non_unique";
|
||||
$this->_params['Packed'] = "PMA_Packed";
|
||||
|
||||
//test add columns
|
||||
$column1 = array("Column_name"=>"column1","Seq_in_index"=>"index1",
|
||||
"Collation"=>"Collation1","Cardinality"=>"Cardinality1",
|
||||
"Null"=>"null1"
|
||||
);
|
||||
$column2 = array("Column_name"=>"column2","Seq_in_index"=>"index2",
|
||||
"Collation"=>"Collation2","Cardinality"=>"Cardinality2",
|
||||
"Null"=>"null2"
|
||||
);
|
||||
$column3 = array("Column_name"=>"column3","Seq_in_index"=>"index3",
|
||||
"Collation"=>"Collation3","Cardinality"=>"Cardinality3",
|
||||
"Null"=>"null3"
|
||||
);
|
||||
$this->_params['columns'][] = $column1;
|
||||
$this->_params['columns'][] = $column2;
|
||||
$this->_params['columns'][] = $column3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$index = new PMA\libraries\Index($this->_params);
|
||||
$this->assertEquals(
|
||||
'PMA_Index_comment',
|
||||
$index->getComment()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PMA_Comment',
|
||||
$index->getRemarks()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PMA_Index_choice',
|
||||
$index->getChoice()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PMA_Packed',
|
||||
$index->getPacked()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PMA_Non_unique',
|
||||
$index->getNonUnique()
|
||||
);
|
||||
$this->assertContains(
|
||||
'PMA_Comment',
|
||||
$index->getComments()
|
||||
);
|
||||
$this->assertContains(
|
||||
'PMA_Index_comment',
|
||||
$index->getComments()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PMA_Index_choice',
|
||||
$index->getChoice()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getIndexChoices
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetIndexChoices()
|
||||
{
|
||||
$index_choices = PMA\libraries\Index::getIndexChoices();
|
||||
$this->assertEquals(
|
||||
5,
|
||||
count($index_choices)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PRIMARY,INDEX,UNIQUE,SPATIAL,FULLTEXT',
|
||||
implode(",", $index_choices)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for isUnique
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsUniquer()
|
||||
{
|
||||
$this->_params['Non_unique'] = "0";
|
||||
$index = new PMA\libraries\Index($this->_params);
|
||||
$this->assertTrue(
|
||||
$index->isUnique()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'Yes',
|
||||
$index->isUnique(true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for add Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddColumns()
|
||||
{
|
||||
$index = new PMA\libraries\Index();
|
||||
$index->addColumns($this->_params['columns']);
|
||||
$this->assertTrue($index->hasColumn("column1"));
|
||||
$this->assertTrue($index->hasColumn("column2"));
|
||||
$this->assertTrue($index->hasColumn("column3"));
|
||||
$this->assertEquals(
|
||||
3,
|
||||
$index->getColumnCount()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get Name & set Name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testName()
|
||||
{
|
||||
$index = new PMA\libraries\Index();
|
||||
$index->setName('PMA_name');
|
||||
$this->assertEquals(
|
||||
'PMA_name',
|
||||
$index->getName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\Index_Column
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testColumns()
|
||||
{
|
||||
$index = new PMA\libraries\Index();
|
||||
$index->addColumns($this->_params['columns']);
|
||||
|
||||
$index_columns = $index->getColumns();
|
||||
$index_column = $index_columns['column1'];
|
||||
$this->assertEquals(
|
||||
'column1',
|
||||
$index_column->getName()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'index1',
|
||||
$index_column->getSeqInIndex()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'Collation1',
|
||||
$index_column->getCollation()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'Cardinality1',
|
||||
$index_column->getCardinality()
|
||||
);
|
||||
}
|
||||
}
|
||||
235
#pma/test/classes/LanguageTest.php
Normal file
235
#pma/test/classes/LanguageTest.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for Advisor class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\LanguageManager;
|
||||
|
||||
/**
|
||||
* Tests behaviour of PMA_Advisor class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class LanguageTest extends PMATestCase
|
||||
{
|
||||
private $manager;
|
||||
|
||||
/**
|
||||
* Setup for Language tests.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$loc = LOCALE_PATH . '/cs/LC_MESSAGES/phpmyadmin.mo';
|
||||
if (! is_readable($loc)) {
|
||||
$this->markTestSkipped('Missing compiled locales.');
|
||||
}
|
||||
$this->manager = new LanguageManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test language filtering
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAvailable()
|
||||
{
|
||||
$GLOBALS['cfg']['FilterLanguages'] = 'cs';
|
||||
|
||||
$langs = $this->manager->availableLocales();
|
||||
|
||||
$this->assertEquals(1, count($langs));
|
||||
$this->assertContains('cs', $langs);
|
||||
$GLOBALS['cfg']['FilterLanguages'] = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test no language filtering
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAllAvailable()
|
||||
{
|
||||
$GLOBALS['cfg']['FilterLanguages'] = '';
|
||||
|
||||
$langs = $this->manager->availableLocales();
|
||||
|
||||
$this->assertContains('cs', $langs);
|
||||
$this->assertContains('en', $langs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether listing locales works
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testList()
|
||||
{
|
||||
$langs = $this->manager->listLocaleDir();
|
||||
$this->assertContains('cs', $langs);
|
||||
$this->assertContains('en', $langs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getting available languages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLanguages()
|
||||
{
|
||||
$langs = $this->manager->availableLanguages();
|
||||
$this->assertGreaterThan(1, count($langs));
|
||||
|
||||
/* Ensure we have name for every language */
|
||||
foreach($langs as $lang) {
|
||||
$this->assertNotEquals($lang->getCode(), strtolower($lang->getEnglishName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for MySQL locales
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMySQLLocale()
|
||||
{
|
||||
$czech = $this->manager->getLanguage('cs');
|
||||
$this->assertEquals('cs_CZ', $czech->getMySQLLocale());
|
||||
|
||||
$korani = $this->manager->getLanguage('ckb');
|
||||
$this->assertEquals('', $korani->getMySQLLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getting available sorted languages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSortedLanguages()
|
||||
{
|
||||
$langs = $this->manager->sortedLanguages();
|
||||
$this->assertGreaterThan(1, count($langs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting language by code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
$lang = $this->manager->getLanguage('cs');
|
||||
$this->assertNotEquals(false, $lang);
|
||||
$this->assertEquals('Czech', $lang->getEnglishName());
|
||||
$this->assertEquals('Čeština', $lang->getNativeName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test language selection
|
||||
*
|
||||
* @param string $lang Value for forced language
|
||||
* @param string $post Value for language in POST
|
||||
* @param string $get Value for language in GET
|
||||
* @param string $cookie Value for language in COOKIE
|
||||
* @param string $accept Value for HTTP Accept-Language header
|
||||
* @param string $agent Value for HTTP User-Agent header
|
||||
* @param string $default Value for default language
|
||||
* @param string $expect Expected language name
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider selectDataProvider
|
||||
*/
|
||||
public function testSelect($lang, $post, $get, $cookie, $accept, $agent, $default, $expect)
|
||||
{
|
||||
$GLOBALS['cfg']['Lang'] = $lang;
|
||||
$_POST['lang'] = $post;
|
||||
$_GET['lang'] = $get;
|
||||
$_COOKIE['pma_lang'] = $cookie;
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = $accept;
|
||||
$_SERVER['HTTP_USER_AGENT'] = $agent;
|
||||
$GLOBALS['cfg']['DefaultLang'] = $default;
|
||||
|
||||
$lang = $this->manager->selectLanguage();
|
||||
|
||||
$this->assertEquals($expect, $lang->getEnglishName());
|
||||
|
||||
$GLOBALS['cfg']['Lang'] = '';
|
||||
$_POST['lang'] = '';
|
||||
$_GET['lang'] = '';
|
||||
$_COOKIE['pma_lang'] = '';
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = '';
|
||||
$_SERVER['HTTP_USER_AGENT'] = '';
|
||||
$GLOBALS['cfg']['DefaultLang'] = 'en';
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for language selection test.
|
||||
*
|
||||
* @return array Test parameters.
|
||||
*/
|
||||
public function selectDataProvider()
|
||||
{
|
||||
return array(
|
||||
array('cs', 'en', '', '' ,'' ,'', '', 'Czech'),
|
||||
array('', 'cs', '', '' ,'' ,'', '', 'Czech'),
|
||||
array('', 'cs', 'en', '' ,'' ,'', '', 'Czech'),
|
||||
array('', '', 'cs', '' ,'' ,'', '', 'Czech'),
|
||||
array('', '', '', '' ,'cs,en-US;q=0.7,en;q=0.3' ,'', '', 'Czech'),
|
||||
array(
|
||||
'', '', '', '', '',
|
||||
'Mozilla/5.0 (Linux; U; Android 2.2.2; tr-tr; GM FOX)',
|
||||
'', 'Turkish'
|
||||
),
|
||||
array('', '', '', '' ,'' ,'', 'cs', 'Czech'),
|
||||
array('', '', '', '' ,'' ,'', '', 'English'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setting and parsing locales
|
||||
*
|
||||
* @param string $locale locale name
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group large
|
||||
* @dataProvider listLocales
|
||||
*/
|
||||
public function testGettext($locale)
|
||||
{
|
||||
/* We should be able to set the language */
|
||||
$this->manager->getLanguage($locale)->activate();
|
||||
|
||||
/* Grab some texts */
|
||||
$this->assertContains('%s', _ngettext('%s table', '%s tables', 10));
|
||||
$this->assertContains('%s', _ngettext('%s table', '%s tables', 1));
|
||||
|
||||
$this->assertEquals(
|
||||
$locale,
|
||||
$this->manager->getCurrentLanguage()->getCode()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider to generate list of available locales.
|
||||
*
|
||||
* @return array with arrays of available locales
|
||||
*/
|
||||
public function listLocales()
|
||||
{
|
||||
$ret = array();
|
||||
foreach (LanguageManager::getInstance()->availableLanguages() as $language) {
|
||||
$ret[] = array($language->getCode());
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
142
#pma/test/classes/LinterTest.php
Normal file
142
#pma/test/classes/LinterTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for Linter.php.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\Linter;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\Linter
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class LinterTest extends PMATestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Linter::getLines
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLines()
|
||||
{
|
||||
$this->assertEquals(array(0), Linter::getLines(''));
|
||||
$this->assertEquals(array(0, 2), Linter::getLines("a\nb"));
|
||||
$this->assertEquals(array(0, 4, 7), Linter::getLines("abc\nde\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Linter::findLineNumberAndColumn
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFindLineNumberAndColumn()
|
||||
{
|
||||
// Let the analyzed string be:
|
||||
// ^abc$
|
||||
// ^de$
|
||||
// ^$
|
||||
//
|
||||
// Where `^` is the beginning of the line and `$` the end of the line.
|
||||
//
|
||||
// Positions of each character (by line):
|
||||
// ( a, 0), ( b, 1), ( c, 2), (\n, 3),
|
||||
// ( d, 4), ( e, 5), (\n, 6),
|
||||
// (\n, 7).
|
||||
$this->assertEquals(
|
||||
array(1, 0),
|
||||
Linter::findLineNumberAndColumn(array(0, 4, 7), 4)
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(1, 1),
|
||||
Linter::findLineNumberAndColumn(array(0, 4, 7), 5)
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(1, 2),
|
||||
Linter::findLineNumberAndColumn(array(0, 4, 7), 6)
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(2, 0),
|
||||
Linter::findLineNumberAndColumn(array(0, 4, 7), 7)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Linter::lint
|
||||
*
|
||||
* @dataProvider testLintProvider
|
||||
*
|
||||
* @param array $expected The expected result.
|
||||
* @param string $query The query to be analyzed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLint($expected, $query)
|
||||
{
|
||||
$this->assertEquals($expected, Linter::lint($query));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for `testLint`.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function testLintProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(),
|
||||
'',
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
'SELECT * FROM tbl'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'message' => 'Unrecognized data type. (near ' .
|
||||
'<code>IN</code>)',
|
||||
'fromLine' => 0,
|
||||
'fromColumn' => 22,
|
||||
'toLine' => 0,
|
||||
'toColumn' => 24,
|
||||
'severity' => 'error',
|
||||
),
|
||||
array(
|
||||
'message' => 'A closing bracket was expected. (near ' .
|
||||
'<code>IN</code>)',
|
||||
'fromLine' => 0,
|
||||
'fromColumn' => 22,
|
||||
'toLine' => 0,
|
||||
'toColumn' => 24,
|
||||
'severity' => 'error',
|
||||
)
|
||||
),
|
||||
'CREATE TABLE tbl ( id IN'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'message' => 'Linting is disabled for this query because ' .
|
||||
'it exceeds the maximum length.',
|
||||
'fromLine' => 0,
|
||||
'fromColumn' => 0,
|
||||
'toLine' => 0,
|
||||
'toColumn' => 0,
|
||||
'severity' => 'warning',
|
||||
)
|
||||
),
|
||||
str_repeat(";", 10001)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
126
#pma/test/classes/ListDatabaseTest.php
Normal file
126
#pma/test/classes/ListDatabaseTest.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for ListDatabase class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\ListDatabase;
|
||||
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for ListDatabase class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ListDatabaseTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['only_db'] = array('single\\_db');
|
||||
$this->object = new ListDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call protected functions by setting visibility to public.
|
||||
*
|
||||
* @param string $name method name
|
||||
* @param array $params parameters for the invocation
|
||||
*
|
||||
* @return the output from the protected method.
|
||||
*/
|
||||
private function _callProtectedFunction($name, $params)
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\ListDatabase');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($this->object, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ListDatabase::getEmpty
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEmpty()
|
||||
{
|
||||
$arr = new ListDatabase;
|
||||
$this->assertEquals('', $arr->getEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ListDatabase::exists
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExists()
|
||||
{
|
||||
$arr = new ListDatabase;
|
||||
$this->assertEquals(true, $arr->exists('single_db'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ListDatabase::getHtmlOptions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHtmlOptions()
|
||||
{
|
||||
$arr = new ListDatabase;
|
||||
$this->assertEquals(
|
||||
'<option value="single_db">single_db</option>' . "\n",
|
||||
$arr->getHtmlOptions()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checkHideDatabase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckHideDatabase()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['hide_db'] = 'single\\_db';
|
||||
$this->assertEquals(
|
||||
$this->_callProtectedFunction(
|
||||
'checkHideDatabase',
|
||||
array()
|
||||
),
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getDefault
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetDefault()
|
||||
{
|
||||
$GLOBALS['db'] = '';
|
||||
$this->assertEquals(
|
||||
$this->object->getDefault(),
|
||||
''
|
||||
);
|
||||
|
||||
$GLOBALS['db'] = 'mysql';
|
||||
$this->assertEquals(
|
||||
$this->object->getDefault(),
|
||||
'mysql'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
121
#pma/test/classes/MenuTest.php
Normal file
121
#pma/test/classes/MenuTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for Menu class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\Menu;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test for Menu class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class MenuTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
if (!defined('PMA_IS_WINDOWS')) {
|
||||
define('PMA_IS_WINDOWS', false);
|
||||
}
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['Server']['verbose'] = 'verbose host';
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
|
||||
$GLOBALS['server'] = 'server';
|
||||
$GLOBALS['db'] = 'pma_test';
|
||||
$GLOBALS['table'] = 'table1';
|
||||
}
|
||||
|
||||
/**
|
||||
* Server menu test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testServer()
|
||||
{
|
||||
$menu = new Menu('server', '', '');
|
||||
$this->assertContains(
|
||||
'floating_menubar',
|
||||
$menu->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Database menu test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testDatabase()
|
||||
{
|
||||
$menu = new Menu('server', 'pma_test', '');
|
||||
$this->assertContains(
|
||||
'floating_menubar',
|
||||
$menu->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Table menu test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testTable()
|
||||
{
|
||||
$menu = new Menu('server', 'pma_test', 'table1');
|
||||
$this->assertContains(
|
||||
'floating_menubar',
|
||||
$menu->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Table menu display test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testTableDisplay()
|
||||
{
|
||||
$menu = new Menu('server', 'pma_test', '');
|
||||
$this->expectOutputString(
|
||||
$menu->getDisplay()
|
||||
);
|
||||
$menu->display();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Table menu setTable test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSetTable()
|
||||
{
|
||||
$menu = new Menu('server', 'pma_test', '');
|
||||
$menu->setTable('table1');
|
||||
$this->assertContains(
|
||||
'table1',
|
||||
$menu->getDisplay()
|
||||
);
|
||||
}
|
||||
}
|
||||
693
#pma/test/classes/MessageTest.php
Normal file
693
#pma/test/classes/MessageTest.php
Normal file
@@ -0,0 +1,693 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for Message class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test for Message class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class MessageTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var PMA\libraries\Message
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new PMA\libraries\Message;
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* to String casting test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testToString()
|
||||
{
|
||||
$this->object->setMessage('test<&>', true);
|
||||
$this->assertEquals('test<&>', (string)$this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* test success method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSuccess()
|
||||
{
|
||||
$this->object = new PMA\libraries\Message('test<&>', PMA\libraries\Message::SUCCESS);
|
||||
$this->assertEquals($this->object, PMA\libraries\Message::success('test<&>'));
|
||||
$this->assertEquals(
|
||||
'Your SQL query has been executed successfully.',
|
||||
PMA\libraries\Message::success()->getString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test error method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testError()
|
||||
{
|
||||
$this->object = new PMA\libraries\Message('test<&>', PMA\libraries\Message::ERROR);
|
||||
$this->assertEquals($this->object, PMA\libraries\Message::error('test<&>'));
|
||||
$this->assertEquals('Error', PMA\libraries\Message::error()->getString());
|
||||
}
|
||||
|
||||
/**
|
||||
* test notice method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNotice()
|
||||
{
|
||||
$this->object = new PMA\libraries\Message('test<&>', PMA\libraries\Message::NOTICE);
|
||||
$this->assertEquals($this->object, PMA\libraries\Message::notice('test<&>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test rawError method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRawError()
|
||||
{
|
||||
$this->object = new PMA\libraries\Message('', PMA\libraries\Message::ERROR);
|
||||
$this->object->setMessage('test<&>');
|
||||
$this->object->setBBCode(false);
|
||||
|
||||
$this->assertEquals($this->object, PMA\libraries\Message::rawError('test<&>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test rawNotice method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRawNotice()
|
||||
{
|
||||
$this->object = new PMA\libraries\Message('', PMA\libraries\Message::NOTICE);
|
||||
$this->object->setMessage('test<&>');
|
||||
$this->object->setBBCode(false);
|
||||
|
||||
$this->assertEquals($this->object, PMA\libraries\Message::rawNotice('test<&>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test rawSuccess method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRawSuccess()
|
||||
{
|
||||
$this->object = new PMA\libraries\Message('', PMA\libraries\Message::SUCCESS);
|
||||
$this->object->setMessage('test<&>');
|
||||
$this->object->setBBCode(false);
|
||||
|
||||
$this->assertEquals($this->object, PMA\libraries\Message::rawSuccess('test<&>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testing isSuccess method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsSuccess()
|
||||
{
|
||||
$this->assertFalse($this->object->isSuccess());
|
||||
$this->assertTrue($this->object->isSuccess(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* testing isNotice method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsNotice()
|
||||
{
|
||||
$this->assertTrue($this->object->isNotice());
|
||||
$this->object->isError(true);
|
||||
$this->assertFalse($this->object->isNotice());
|
||||
$this->assertTrue($this->object->isNotice(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* testing isError method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsError()
|
||||
{
|
||||
$this->assertFalse($this->object->isError());
|
||||
$this->assertTrue($this->object->isError(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* testing setter of message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetMessage()
|
||||
{
|
||||
$this->object->setMessage('test&<>', false);
|
||||
$this->assertEquals('test&<>', $this->object->getMessage());
|
||||
$this->object->setMessage('test&<>', true);
|
||||
$this->assertEquals('test&<>', $this->object->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* testing setter of string
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetString()
|
||||
{
|
||||
$this->object->setString('test&<>', false);
|
||||
$this->assertEquals('test&<>', $this->object->getString());
|
||||
$this->object->setString('test&<>', true);
|
||||
$this->assertEquals('test&<>', $this->object->getString());
|
||||
}
|
||||
|
||||
/**
|
||||
* testing add param method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddParam()
|
||||
{
|
||||
$this->object->addParam(PMA\libraries\Message::notice('test'));
|
||||
$this->assertEquals(
|
||||
array(PMA\libraries\Message::notice('test')),
|
||||
$this->object->getParams()
|
||||
);
|
||||
$this->object->addParam('test', true);
|
||||
$this->assertEquals(
|
||||
array(PMA\libraries\Message::notice('test'), 'test'),
|
||||
$this->object->getParams()
|
||||
);
|
||||
$this->object->addParam('test', false);
|
||||
$this->assertEquals(
|
||||
array(PMA\libraries\Message::notice('test'), 'test', PMA\libraries\Message::notice('test')),
|
||||
$this->object->getParams()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testing add string method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddString()
|
||||
{
|
||||
$this->object->addString('test', '*');
|
||||
$this->assertEquals(
|
||||
array('*', PMA\libraries\Message::notice('test')),
|
||||
$this->object->getAddedMessages()
|
||||
);
|
||||
$this->object->addString('test', '');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'*',
|
||||
PMA\libraries\Message::notice('test'),
|
||||
'',
|
||||
PMA\libraries\Message::notice('test')
|
||||
),
|
||||
$this->object->getAddedMessages()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testing add message method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddMessage()
|
||||
{
|
||||
$this->object->addMessage('test', '');
|
||||
$this->assertEquals(
|
||||
array(PMA\libraries\Message::rawNotice('test')),
|
||||
$this->object->getAddedMessages()
|
||||
);
|
||||
$this->object->addMessage('test');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
PMA\libraries\Message::rawNotice('test'),
|
||||
' ',
|
||||
PMA\libraries\Message::rawNotice('test')
|
||||
),
|
||||
$this->object->getAddedMessages()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testing add messages method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddMessages()
|
||||
{
|
||||
$messages = array();
|
||||
$messages[] = "Test1";
|
||||
$messages[] = new PMA\libraries\Message("PMA_Test2", PMA\libraries\Message::ERROR);
|
||||
$messages[] = "Test3";
|
||||
$this->object->addMessages($messages, '');
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
PMA\libraries\Message::rawNotice('Test1'),
|
||||
PMA\libraries\Message::error("PMA_Test2"),
|
||||
PMA\libraries\Message::rawNotice('Test3')
|
||||
),
|
||||
$this->object->getAddedMessages()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testing setter of params
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetParams()
|
||||
{
|
||||
$this->object->setParams('test&<>');
|
||||
$this->assertEquals('test&<>', $this->object->getParams());
|
||||
$this->object->setParams('test&<>', true);
|
||||
$this->assertEquals('test&<>', $this->object->getParams());
|
||||
}
|
||||
|
||||
/**
|
||||
* testing sanitize method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSanitize()
|
||||
{
|
||||
$this->object->setString('test&string<>', false);
|
||||
$this->assertEquals(
|
||||
'test&string<>',
|
||||
PMA\libraries\Message::sanitize($this->object)
|
||||
);
|
||||
$this->assertEquals(
|
||||
array('test&string<>', 'test&string<>'),
|
||||
PMA\libraries\Message::sanitize(array($this->object, $this->object))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testDecodeBB
|
||||
*
|
||||
* @return array Test data
|
||||
*/
|
||||
public function decodeBBDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'[em]test[/em][em]aa[em/][em]test[/em]',
|
||||
'<em>test</em><em>aa[em/]<em>test</em>'
|
||||
),
|
||||
array(
|
||||
'[strong]test[/strong][strong]test[/strong]',
|
||||
'<strong>test</strong><strong>test</strong>'
|
||||
),
|
||||
array(
|
||||
'[code]test[/code][code]test[/code]',
|
||||
'<code>test</code><code>test</code>'
|
||||
),
|
||||
array(
|
||||
'[kbd]test[/kbd][br][sup]test[/sup]',
|
||||
'<kbd>test</kbd><br /><sup>test</sup>'
|
||||
),
|
||||
array(
|
||||
'[a@https://example.com/@Documentation]link[/a]',
|
||||
'<a href="./url.php?url=https%3A%2F%2Fexample.com%2F"'
|
||||
. ' target="Documentation">link</a>'
|
||||
),
|
||||
array(
|
||||
'[a@./non-existing@Documentation]link[/a]',
|
||||
'[a@./non-existing@Documentation]link</a>'
|
||||
),
|
||||
array(
|
||||
'[doc@foo]link[/doc]',
|
||||
'<a href="./url.php?url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2F'
|
||||
. 'latest%2Fsetup.html%23foo" '
|
||||
. 'target="documentation">link</a>'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testing decodeBB method
|
||||
*
|
||||
* @param string $actual BB code string
|
||||
* @param string $expected Expected decoded string
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider decodeBBDataProvider
|
||||
*/
|
||||
public function testDecodeBB($actual, $expected)
|
||||
{
|
||||
unset($GLOBALS['server']);
|
||||
unset($GLOBALS['collation_connection']);
|
||||
$this->assertEquals($expected, PMA\libraries\Message::decodeBB($actual));
|
||||
}
|
||||
|
||||
/**
|
||||
* testing format method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFormat()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'test string',
|
||||
PMA\libraries\Message::format('test string')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test string',
|
||||
PMA\libraries\Message::format('test string', 'a')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test string',
|
||||
PMA\libraries\Message::format('test string', array())
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test string',
|
||||
PMA\libraries\Message::format('%s string', array('test'))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* testing getHash method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHash()
|
||||
{
|
||||
$this->object->setString('<&>test', false);
|
||||
$this->object->setMessage('<&>test', false);
|
||||
$this->assertEquals(
|
||||
md5(PMA\libraries\Message::NOTICE . '<&>test<&>test'),
|
||||
$this->object->getHash()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* getMessage test - with empty message and with non-empty string -
|
||||
* not key in globals additional params are defined
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMessageWithoutMessageWithStringWithParams()
|
||||
{
|
||||
$this->object->setMessage('');
|
||||
$this->object->setString('test string %s %s');
|
||||
$this->object->addParam('test param 1');
|
||||
$this->object->addParam('test param 2');
|
||||
$this->assertEquals(
|
||||
'test string test param 1 test param 2',
|
||||
$this->object->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* getMessage test - with empty message and with empty string
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMessageWithoutMessageWithEmptyString()
|
||||
{
|
||||
$this->object->setMessage('');
|
||||
$this->object->setString('');
|
||||
$this->assertEquals('', $this->object->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* getMessage test - with empty message and with string, which is key to GLOBALS
|
||||
* additional messages are defined
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMessageWithoutMessageWithGlobalStringWithAddMessages()
|
||||
{
|
||||
$GLOBALS['key'] = 'test message';
|
||||
$this->object->setMessage('');
|
||||
$this->object->setString('key');
|
||||
$this->object->addMessage('test message 2', ' - ');
|
||||
$this->object->addMessage('test message 3', '&');
|
||||
$this->assertEquals(
|
||||
'test message - test message 2&test message 3',
|
||||
$this->object->getMessage()
|
||||
);
|
||||
unset($GLOBALS['key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* getMessage test - message is defined
|
||||
* message with BBCode defined
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMessageWithMessageWithBBCode()
|
||||
{
|
||||
$this->object->setMessage('[kbd]test[/kbd] [doc@cfg_Example]test[/doc]');
|
||||
$this->assertEquals(
|
||||
'<kbd>test</kbd> <a href="./url.php?url=https%3A%2F%2Fdocs.phpmyadmin.'
|
||||
. 'net%2Fen%2Flatest%2Fconfig.html%23cfg_Example"'
|
||||
. ' target="documentation">test</a>',
|
||||
$this->object->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* getLevel test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLevel()
|
||||
{
|
||||
$this->assertEquals('notice', $this->object->getLevel());
|
||||
$this->object->setNumber(PMA\libraries\Message::SUCCESS);
|
||||
$this->assertEquals('success', $this->object->getLevel());
|
||||
$this->object->setNumber(PMA\libraries\Message::ERROR);
|
||||
$this->assertEquals('error', $this->object->getLevel());
|
||||
}
|
||||
|
||||
/**
|
||||
* testing display method (output string and _is_displayed variable)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplay()
|
||||
{
|
||||
$this->assertFalse($this->object->isDisplayed());
|
||||
$this->object->setMessage('Test Message');
|
||||
|
||||
$this->expectOutputString(
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" /> '
|
||||
. 'Test Message</div>'
|
||||
);
|
||||
$this->object->display();
|
||||
|
||||
$this->assertTrue($this->object->isDisplayed());
|
||||
}
|
||||
|
||||
/**
|
||||
* getDisplay test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetDisplay()
|
||||
{
|
||||
$this->object->setMessage('Test Message');
|
||||
$this->assertEquals(
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" /> '
|
||||
. 'Test Message</div>',
|
||||
$this->object->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* isDisplayed test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsDisplayed()
|
||||
{
|
||||
$this->assertFalse($this->object->isDisplayed(false));
|
||||
$this->assertTrue($this->object->isDisplayed(true));
|
||||
$this->assertTrue($this->object->isDisplayed(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testAffectedRows
|
||||
*
|
||||
* @return array Test-data
|
||||
*/
|
||||
public function providerAffectedRows()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
1,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 1 row affected.</div>'
|
||||
),
|
||||
array(
|
||||
2,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 2 rows affected.</div>'
|
||||
),
|
||||
array(
|
||||
10000,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 10000 rows affected.</div>'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getMessageForAffectedRows() method
|
||||
*
|
||||
* @param int $rows Number of rows
|
||||
* @param string $output Expected string
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerAffectedRows
|
||||
*/
|
||||
public function testAffectedRows($rows, $output)
|
||||
{
|
||||
$this->object = new PMA\libraries\Message();
|
||||
$msg = $this->object->getMessageForAffectedRows($rows);
|
||||
echo $this->object->addMessage($msg);
|
||||
$this->expectOutputString($output);
|
||||
$this->object->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testInsertedRows
|
||||
*
|
||||
* @return array Test-data
|
||||
*/
|
||||
public function providerInsertedRows()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
1,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 1 row inserted.</div>'
|
||||
),
|
||||
array(
|
||||
2,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 2 rows inserted.</div>'
|
||||
),
|
||||
array(
|
||||
100000,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 100000 rows inserted.</div>'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getMessageForInsertedRows() method
|
||||
*
|
||||
* @param int $rows Number of rows
|
||||
* @param string $output Expected string
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerInsertedRows
|
||||
*/
|
||||
public function testInsertedRows($rows, $output)
|
||||
{
|
||||
$this->object = new PMA\libraries\Message();
|
||||
$msg = $this->object->getMessageForInsertedRows($rows);
|
||||
echo $this->object->addMessage($msg);
|
||||
$this->expectOutputString($output);
|
||||
$this->object->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testDeletedRows
|
||||
*
|
||||
* @return array Test-data
|
||||
*/
|
||||
public function providerDeletedRows()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
1,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 1 row deleted.</div>'
|
||||
),
|
||||
array(
|
||||
2,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 2 rows deleted.</div>'
|
||||
),
|
||||
array(
|
||||
500000,
|
||||
'<div class="notice"><img src="theme/s_notice.png" title="" alt="" '
|
||||
. '/> 500000 rows deleted.</div>'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getMessageForDeletedRows() method
|
||||
*
|
||||
* @param int $rows Number of rows
|
||||
* @param string $output Expected string
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerDeletedRows
|
||||
*/
|
||||
public function testDeletedRows($rows, $output)
|
||||
{
|
||||
$this->object = new PMA\libraries\Message();
|
||||
$msg = $this->object->getMessageForDeletedRows($rows);
|
||||
echo $this->object->addMessage($msg);
|
||||
$this->expectOutputString($output);
|
||||
$this->object->display();
|
||||
}
|
||||
}
|
||||
82
#pma/test/classes/PDFTest.php
Normal file
82
#pma/test/classes/PDFTest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PDF class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\PDF;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PDF class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PDFTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PDF::getPDFData
|
||||
*
|
||||
* @group large
|
||||
* @return void
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
$arr = new PDF();
|
||||
$this->assertContains('PDF', $arr->getPDFData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PDF::getPDFData
|
||||
*
|
||||
* @group large
|
||||
* @return void
|
||||
*/
|
||||
public function testAlias()
|
||||
{
|
||||
$arr = new PDF();
|
||||
$arr->SetAlias('{00}', '32');
|
||||
$this->assertContains('PDF', $arr->getPDFData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PDF::getPDFData
|
||||
*
|
||||
* @group large
|
||||
* @return void
|
||||
*/
|
||||
public function testDocument()
|
||||
{
|
||||
$pdf = new PDF();
|
||||
$pdf->SetTitle('Title');
|
||||
$pdf->Open();
|
||||
$pdf->SetAutoPageBreak('auto');
|
||||
$pdf->Addpage();
|
||||
$pdf->SetFont(PDF::PMA_PDF_FONT, 'B', 14);
|
||||
$pdf->Cell(0, 6, 'Cell', 'B', 1, 'C');
|
||||
$pdf->Ln();
|
||||
$pdf->Addpage();
|
||||
$pdf->Bookmark('Bookmark');
|
||||
$pdf->SetMargins(0, 0);
|
||||
$pdf->SetDrawColor(200, 200, 200);
|
||||
$pdf->line(0, 0, 100, 100);
|
||||
$this->assertContains('PDF', $pdf->getPDFData());
|
||||
}
|
||||
}
|
||||
244
#pma/test/classes/ScriptsTest.php
Normal file
244
#pma/test/classes/ScriptsTest.php
Normal file
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for Script.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\Scripts;
|
||||
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for Script.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ScriptsTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new Scripts();
|
||||
if (! defined('PMA_USR_BROWSER_AGENT')) {
|
||||
define('PMA_USR_BROWSER_AGENT', 'MOZILLA');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call private functions by setting visibility to public.
|
||||
*
|
||||
* @param string $name method name
|
||||
* @param array $params parameters for the invocation
|
||||
*
|
||||
* @return the output from the private method.
|
||||
*/
|
||||
private function _callPrivateFunction($name, $params)
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\Scripts');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($this->object, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _includeFile
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testIncludeFile()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<script data-cfasync="false" type="text/javascript" '
|
||||
. 'src="js/get_scripts.js.php?'
|
||||
. 'scripts%5B%5D=common.js&v=' . PMA_VERSION . '"></script>',
|
||||
$this->_callPrivateFunction(
|
||||
'_includeFiles',
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'has_onload' => false,
|
||||
'filename' => 'common.js',
|
||||
'conditional_ie' => false
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getDisplay
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetDisplay()
|
||||
{
|
||||
|
||||
$this->object->addFile('common.js');
|
||||
|
||||
$this->assertRegExp(
|
||||
'@<script data-cfasync="false" type="text/javascript" '
|
||||
. 'src="js/get_scripts.js.php\\?'
|
||||
. 'scripts%5B%5D=common.js&v=' . PMA_VERSION . '"></script>'
|
||||
. '<script data-cfasync="false" type="text/'
|
||||
. 'javascript">// <!\\[CDATA\\[' . "\n"
|
||||
. 'AJAX.scriptHandler.add\\("common.js",1\\);' . "\n"
|
||||
. '\\$\\(function\\(\\) \\{AJAX.fireOnload\\("common.js"\\);\\}\\);'
|
||||
. "\n"
|
||||
. '// ]]></script>@',
|
||||
$this->object->getDisplay()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test for addCode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddCode()
|
||||
{
|
||||
|
||||
$this->object->addCode('alert(\'CodeAdded\');');
|
||||
|
||||
$this->assertEquals(
|
||||
'<script data-cfasync="false" type="text/javascript">// <![CDATA[
|
||||
alert(\'CodeAdded\');
|
||||
AJAX.scriptHandler;
|
||||
$(function() {});
|
||||
// ]]></script>',
|
||||
$this->object->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for getFiles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFiles()
|
||||
{
|
||||
// codemirror's onload event is blacklisted
|
||||
$this->object->addFile('codemirror/lib/codemirror.js');
|
||||
|
||||
$this->object->addFile('common.js');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array('name' => 'codemirror/lib/codemirror.js', 'fire' => 0),
|
||||
array('name' => 'common.js', 'fire' => 1)
|
||||
),
|
||||
$this->object->getFiles()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for addFile
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddFile()
|
||||
{
|
||||
// Assert empty _files property of
|
||||
// Scripts
|
||||
$this->assertAttributeEquals(
|
||||
array(),
|
||||
'_files',
|
||||
$this->object
|
||||
);
|
||||
|
||||
// Add one script file
|
||||
$file = 'common.js';
|
||||
$hash = 'd7716810d825f4b55d18727c3ccb24e6';
|
||||
$_files = array(
|
||||
$hash => array(
|
||||
'has_onload' => 1,
|
||||
'filename' => 'common.js',
|
||||
'conditional_ie' => false,
|
||||
'before_statics' => false
|
||||
)
|
||||
);
|
||||
$this->object->addFile($file);
|
||||
$this->assertAttributeEquals(
|
||||
$_files,
|
||||
'_files',
|
||||
$this->object
|
||||
);
|
||||
|
||||
// Add same script file again w/
|
||||
// conditional_ie true
|
||||
$this->object->addFile($file, true);
|
||||
// No change in _files as file was already added
|
||||
$this->assertAttributeEquals(
|
||||
$_files,
|
||||
'_files',
|
||||
$this->object
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for addFiles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddFiles()
|
||||
{
|
||||
$filenames = array(
|
||||
'common.js',
|
||||
'sql.js',
|
||||
'common.js',
|
||||
);
|
||||
$_files = array(
|
||||
'd7716810d825f4b55d18727c3ccb24e6' => array(
|
||||
'has_onload' => 1,
|
||||
'filename' => 'common.js',
|
||||
'conditional_ie' => true,
|
||||
'before_statics' => false
|
||||
),
|
||||
'347a57484fcd6ea6d8a125e6e1d31f78' => array(
|
||||
'has_onload' => 1,
|
||||
'filename' => 'sql.js',
|
||||
'conditional_ie' => true,
|
||||
'before_statics' => false
|
||||
),
|
||||
);
|
||||
$this->object->addFiles($filenames, true);
|
||||
$this->assertAttributeEquals(
|
||||
$_files,
|
||||
'_files',
|
||||
$this->object
|
||||
);
|
||||
}
|
||||
}
|
||||
136
#pma/test/classes/ServerStatusDataTest.php
Normal file
136
#pma/test/classes/ServerStatusDataTest.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for ServerStatusData class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\ServerStatusData;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test for ServerStatusData class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ServerStatusDataTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
|
||||
$GLOBALS['cfg']['Server']['host'] = "::1";
|
||||
$GLOBALS['replication_info']['master']['status'] = true;
|
||||
$GLOBALS['replication_info']['slave']['status'] = true;
|
||||
$GLOBALS['replication_types'] = array();
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
//this data is needed when ServerStatusData constructs
|
||||
$server_status = array(
|
||||
"Aborted_clients" => "0",
|
||||
"Aborted_connects" => "0",
|
||||
"Com_delete_multi" => "0",
|
||||
"Com_create_function" => "0",
|
||||
"Com_empty_query" => 3,
|
||||
"Key_blocks_used" => 2,
|
||||
"Key_writes" => true,
|
||||
"Key_reads" => true,
|
||||
"Key_write_requests" => 5,
|
||||
"Key_read_requests" => 1,
|
||||
"Threads_created" => true,
|
||||
"Connections" => 2,
|
||||
);
|
||||
|
||||
$server_variables= array(
|
||||
"auto_increment_increment" => "1",
|
||||
"auto_increment_offset" => "1",
|
||||
"automatic_sp_privileges" => "ON",
|
||||
"back_log" => "50",
|
||||
"big_tables" => "OFF",
|
||||
"key_buffer_size" => 10,
|
||||
);
|
||||
|
||||
$fetchResult = array(
|
||||
array(
|
||||
"SHOW GLOBAL STATUS",
|
||||
0,
|
||||
1,
|
||||
null,
|
||||
0,
|
||||
$server_status
|
||||
),
|
||||
array(
|
||||
"SHOW GLOBAL VARIABLES",
|
||||
0,
|
||||
1,
|
||||
null,
|
||||
0,
|
||||
$server_variables
|
||||
),
|
||||
array(
|
||||
"SELECT concat('Com_', variable_name), variable_value "
|
||||
. "FROM data_dictionary.GLOBAL_STATEMENTS",
|
||||
0,
|
||||
1,
|
||||
null,
|
||||
0,
|
||||
$server_status
|
||||
),
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())->method('fetchResult')
|
||||
->will($this->returnValueMap($fetchResult));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object = new ServerStatusData();
|
||||
}
|
||||
|
||||
/**
|
||||
* tests getMenuHtml()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetMenuHtml()
|
||||
{
|
||||
$html = $this->object->getMenuHtml();
|
||||
|
||||
$this->assertContains('Server', $html);
|
||||
$this->assertContains('server_status.php', $html);
|
||||
|
||||
$this->assertContains('Processes', $html);
|
||||
$this->assertContains('server_status_processes.php', $html);
|
||||
|
||||
$this->assertContains('Query statistics', $html);
|
||||
$this->assertContains('server_status_queries.php', $html);
|
||||
|
||||
$this->assertContains('All status variables', $html);
|
||||
$this->assertContains('server_status_variables.php', $html);
|
||||
|
||||
$this->assertContains('Monitor', $html);
|
||||
$this->assertContains('server_status_monitor.php', $html);
|
||||
|
||||
$this->assertContains('Advisor', $html);
|
||||
$this->assertContains('server_status_advisor.php', $html);
|
||||
}
|
||||
}
|
||||
311
#pma/test/classes/StorageEngineTest.php
Normal file
311
#pma/test/classes/StorageEngineTest.php
Normal file
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for StorageEngine.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\StorageEngine;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
|
||||
/**
|
||||
* Tests for StorageEngine.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class StorageEngineTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 1;
|
||||
$this->object = $this->getMockForAbstractClass(
|
||||
'PMA\libraries\StorageEngine', array('dummy')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getStorageEngines
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetStorageEngines()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'dummy' => array(
|
||||
'Engine' => 'dummy',
|
||||
'Support' => 'YES',
|
||||
'Comment' => 'dummy comment',
|
||||
),
|
||||
'dummy2' => array(
|
||||
'Engine' => 'dummy2',
|
||||
'Support' => 'NO',
|
||||
'Comment' => 'dummy2 comment',
|
||||
),
|
||||
'FEDERATED' => array(
|
||||
'Engine' => 'FEDERATED',
|
||||
'Support' => 'NO',
|
||||
'Comment' => 'Federated MySQL storage engine'
|
||||
),
|
||||
),
|
||||
$this->object->getStorageEngines()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getHtmlSelect
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetHtmlSelect()
|
||||
{
|
||||
$html = $this->object->getHtmlSelect();
|
||||
|
||||
$this->assertContains(
|
||||
'<option value="dummy" title="dummy comment">',
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for StorageEngine::getEngine
|
||||
*
|
||||
* @param string $expectedClass Class that should be selected
|
||||
* @param string $engineName Engine name
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerGetEngine
|
||||
*/
|
||||
public function testGetEngine($expectedClass, $engineName)
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
$expectedClass, StorageEngine::getEngine($engineName)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for testGetEngine
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerGetEngine()
|
||||
{
|
||||
return array(
|
||||
array('PMA\libraries\StorageEngine', 'unknown engine'),
|
||||
array('PMA\libraries\engines\Bdb', 'Bdb'),
|
||||
array('PMA\libraries\engines\Berkeleydb', 'Berkeleydb'),
|
||||
array('PMA\libraries\engines\Binlog', 'Binlog'),
|
||||
array('PMA\libraries\engines\Innobase', 'Innobase'),
|
||||
array('PMA\libraries\engines\Innodb', 'Innodb'),
|
||||
array('PMA\libraries\engines\Memory', 'Memory'),
|
||||
array('PMA\libraries\engines\Merge', 'Merge'),
|
||||
array('PMA\libraries\engines\Mrg_Myisam', 'Mrg_Myisam'),
|
||||
array('PMA\libraries\engines\Myisam', 'Myisam'),
|
||||
array('PMA\libraries\engines\Ndbcluster', 'Ndbcluster'),
|
||||
array('PMA\libraries\engines\Pbxt', 'Pbxt'),
|
||||
array('PMA\libraries\engines\Performance_Schema', 'Performance_Schema'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for isValid
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsValid()
|
||||
{
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->isValid('PBMS')
|
||||
);
|
||||
$this->assertTrue(
|
||||
$this->object->isValid('dummy')
|
||||
);
|
||||
$this->assertTrue(
|
||||
$this->object->isValid('dummy2')
|
||||
);
|
||||
$this->assertFalse(
|
||||
$this->object->isValid('invalid')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPage()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getPage('Foo')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getInfoPages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInfoPages()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->getInfoPages()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariablesLikePattern
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariablesLikePattern()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getVariablesLikePattern()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getMysqlHelpPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMysqlHelpPage()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
'dummy-storage-engine',
|
||||
$this->object->getMysqlHelpPage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariables()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->getVariables()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getSupportInformationMessage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSupportInformationMessage()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'dummy is available on this MySQL server.',
|
||||
$this->object->getSupportInformationMessage()
|
||||
);
|
||||
|
||||
$this->object->support = 1;
|
||||
$this->assertEquals(
|
||||
'dummy has been disabled for this MySQL server.',
|
||||
$this->object->getSupportInformationMessage()
|
||||
);
|
||||
|
||||
$this->object->support = 2;
|
||||
$this->assertEquals(
|
||||
'dummy is available on this MySQL server.',
|
||||
$this->object->getSupportInformationMessage()
|
||||
);
|
||||
|
||||
$this->object->support = 3;
|
||||
$this->assertEquals(
|
||||
'dummy is the default storage engine on this MySQL server.',
|
||||
$this->object->getSupportInformationMessage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getComment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetComment()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
'dummy comment',
|
||||
$this->object->getComment()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getTitle
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTitle()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
'dummy',
|
||||
$this->object->getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for resolveTypeSize
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testResolveTypeSize()
|
||||
{
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
0 => 12,
|
||||
1 => 'B'
|
||||
),
|
||||
$this->object->resolveTypeSize(12)
|
||||
);
|
||||
}
|
||||
}
|
||||
123
#pma/test/classes/SystemDatabaseTest.php
Normal file
123
#pma/test/classes/SystemDatabaseTest.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for libraries/SystemDatabase.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for libraries/SystemDatabase.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class SystemDatabaseTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Setup function for test cases
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
/**
|
||||
* SET these to avoid undefine d index error
|
||||
*/
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['Server']['pmadb'] = '';
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('tryQuery')
|
||||
->will($this->returnValue('executeResult2'));
|
||||
|
||||
//_SESSION
|
||||
$_SESSION['relation'][$GLOBALS['server']] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'table_coords' => "table_name",
|
||||
'displaywork' => 'displaywork',
|
||||
'db' => "information_schema",
|
||||
'table_info' => 'table_info',
|
||||
'relwork' => 'relwork',
|
||||
'commwork' => 'commwork',
|
||||
'pdfwork' => 'pdfwork',
|
||||
'column_info' => 'column_info',
|
||||
'relation' => 'relation',
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'table_name' => "table_name",
|
||||
'column_name' => "column_name",
|
||||
'comment' => "comment",
|
||||
'mimetype' => "mimetype",
|
||||
'transformation' => "transformation",
|
||||
'transformation_options' => "transformation_options",
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->sysDb = new PMA\libraries\SystemDatabase($dbi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for PMA_getExistingTransformationData() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testPMAGetExistingTransformationData()
|
||||
{
|
||||
$db = "PMA_db";
|
||||
$ret = $this->sysDb->getExistingTransformationData($db);
|
||||
|
||||
//validate that is the same as $GLOBALS['dbi']->tryQuery
|
||||
$this->assertEquals(
|
||||
'executeResult2',
|
||||
$ret
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for PMA_getNewTransformationDataSql() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testPMAGetNewTransformationDataSql()
|
||||
{
|
||||
$db = "PMA_db";
|
||||
$pma_transformation_data = array();
|
||||
$column_map = array(
|
||||
array(
|
||||
"table_name" => "table_name",
|
||||
"refering_column" => "column_name"
|
||||
)
|
||||
);
|
||||
$view_name = "view_name";
|
||||
|
||||
$ret = $this->sysDb->getNewTransformationDataSql(
|
||||
$pma_transformation_data, $column_map, $view_name, $db
|
||||
);
|
||||
|
||||
$sql = "INSERT INTO `information_schema`.`column_info` "
|
||||
. "(`db_name`, `table_name`, `column_name`, `comment`, `mimetype`, "
|
||||
. "`transformation`, `transformation_options`) VALUES "
|
||||
. "('PMA_db', 'view_name', 'column_name', 'comment', 'mimetype', "
|
||||
. "'transformation', 'transformation_options')";
|
||||
|
||||
$this->assertEquals(
|
||||
$sql,
|
||||
$ret
|
||||
);
|
||||
}
|
||||
}
|
||||
1240
#pma/test/classes/TableTest.php
Normal file
1240
#pma/test/classes/TableTest.php
Normal file
File diff suppressed because it is too large
Load Diff
85
#pma/test/classes/TemplateTest.php
Normal file
85
#pma/test/classes/TemplateTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\Template class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\Template class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TemplateTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Test for set function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSet()
|
||||
{
|
||||
$template = PMA\libraries\Template::get('test/add_data');
|
||||
$template->set('variable1', 'value1');
|
||||
$template->set(
|
||||
array(
|
||||
'variable2' => 'value2'
|
||||
)
|
||||
);
|
||||
$result = $template->render();
|
||||
$this->assertContains('value1', $result);
|
||||
$this->assertContains('value2', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setHelper
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetHelper()
|
||||
{
|
||||
$template = PMA\libraries\Template::get('test/set_helper');
|
||||
$template->setHelper('hello', function ($string) {
|
||||
return 'hello ' . $string;
|
||||
});
|
||||
$template->set(
|
||||
array(
|
||||
'variable' => 'world'
|
||||
)
|
||||
);
|
||||
$this->assertEquals('hello world', $template->render());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for render
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testStaticRender()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'static content',
|
||||
PMA\libraries\Template::get('test/static')->render()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for render
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicRender()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'value',
|
||||
PMA\libraries\Template::get('test/echo')->render(
|
||||
array(
|
||||
'variable' => 'value'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
165
#pma/test/classes/ThemeManagerTest.php
Normal file
165
#pma/test/classes/ThemeManagerTest.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for ThemeManager class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\ThemeManager;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for ThemeManager class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ThemeManagerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['cfg']['ThemePath'] = './themes';
|
||||
$GLOBALS['cfg']['ThemePerServer'] = false;
|
||||
$GLOBALS['cfg']['ThemeDefault'] = 'pmahomme';
|
||||
$GLOBALS['cfg']['ServerDefault'] = 0;
|
||||
$GLOBALS['server'] = 99;
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
|
||||
$GLOBALS['collation_connection'] = 'utf8_general_ci';
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$cfg['dbi'] = $dbi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ThemeManager::getThemeCookieName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCookieName()
|
||||
{
|
||||
$tm = new ThemeManager();
|
||||
$this->assertEquals('pma_theme', $tm->getThemeCookieName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ThemeManager::getThemeCookieName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPerServerCookieName()
|
||||
{
|
||||
$tm = new ThemeManager();
|
||||
$tm->setThemePerServer(true);
|
||||
$this->assertEquals('pma_theme-99', $tm->getThemeCookieName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ThemeManager::getHtmlSelectBox
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHtmlSelectBox()
|
||||
{
|
||||
$tm = new ThemeManager();
|
||||
$this->assertContains(
|
||||
'<option value="pmahomme" selected="selected">',
|
||||
$tm->getHtmlSelectBox()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setThemeCookie
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetThemeCookie()
|
||||
{
|
||||
$tm = new ThemeManager();
|
||||
$this->assertTrue(
|
||||
$tm->setThemeCookie()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checkConfig
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckConfig()
|
||||
{
|
||||
$tm = new ThemeManager();
|
||||
$this->assertNull(
|
||||
$tm->checkConfig()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for makeBc
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeBc()
|
||||
{
|
||||
$tm = new ThemeManager();
|
||||
$this->assertNull(
|
||||
$tm->makeBc()
|
||||
);
|
||||
$this->assertEquals($GLOBALS['theme'], 'pmahomme');
|
||||
$this->assertEquals($GLOBALS['pmaThemePath'], './themes/pmahomme');
|
||||
$this->assertEquals($GLOBALS['pmaThemeImage'], './themes/pmahomme/img/');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getPrintPreviews
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPrintPreviews()
|
||||
{
|
||||
$tm = new ThemeManager();
|
||||
$this->assertEquals(
|
||||
'<div class="theme_preview"><h2>Original (2.9) </h2><p><a class='
|
||||
. '"take_theme" name="original" href="index.php?set_theme=original'
|
||||
. '&server=99&lang=en&collation_connection=utf8_general_ci'
|
||||
. '&token=token"><img src="./themes/original/screen.png" border="1" '
|
||||
. 'alt="Original" title="Original" /><br />[ <strong>take it</strong> ]'
|
||||
. '</a></p></div><div class="theme_preview"><h2>pmahomme (1.1) </h2><p>'
|
||||
. '<a class="take_theme" name="pmahomme" href="index.php?set_theme='
|
||||
. 'pmahomme&server=99&lang=en&collation_connection=utf8_'
|
||||
. 'general_ci&token=token"><img src="./themes/pmahomme/screen.png" '
|
||||
. 'border="1" alt="pmahomme" title="pmahomme" /><br />[ <strong>take it'
|
||||
. '</strong> ]</a></p></div>',
|
||||
$tm->getPrintPreviews()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getFallBackTheme
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFallBackTheme()
|
||||
{
|
||||
$tm = new ThemeManager();
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\Theme',
|
||||
$tm->getFallBackTheme()
|
||||
);
|
||||
}
|
||||
}
|
||||
420
#pma/test/classes/ThemeTest.php
Normal file
420
#pma/test/classes/ThemeTest.php
Normal file
@@ -0,0 +1,420 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test class for Theme.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test class for Theme.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ThemeTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var Theme
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new Theme();
|
||||
$_SESSION['PMA_Theme'] = $this->object;
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['text_dir'] = 'ltr';
|
||||
include 'themes/pmahomme/layout.inc.php';
|
||||
$GLOBALS['server'] = '99';
|
||||
$GLOBALS['collation_connection'] = 'utf-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::loadInfo
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testCheckImgPathNotExisted()
|
||||
{
|
||||
$this->object->setPath('path/to/nowhere');
|
||||
$this->assertFalse($this->object->loadInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::loadInfo
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckImgPathIncorrect()
|
||||
{
|
||||
$this->object->setPath('./test/classes/_data/incorrect_theme');
|
||||
$this->assertFalse(
|
||||
$this->object->loadInfo(),
|
||||
'Theme name is not properly set'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::getName, getVersion
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckImgPathFull()
|
||||
{
|
||||
$this->object->setPath('./test/classes/_data/gen_version_info');
|
||||
$this->assertTrue($this->object->loadInfo());
|
||||
$this->assertEquals('Test Theme', $this->object->getName());
|
||||
$this->assertEquals('2.0.3', $this->object->getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::loadInfo
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadInfo()
|
||||
{
|
||||
$this->object->setPath('./themes/original');
|
||||
$infofile = $this->object->getPath() . '/info.inc.php';
|
||||
$this->assertTrue($this->object->loadInfo());
|
||||
|
||||
$this->assertEquals(
|
||||
filemtime($infofile),
|
||||
$this->object->mtime_info
|
||||
);
|
||||
|
||||
$this->object->setPath('./themes/original');
|
||||
$this->object->mtime_info = filemtime($infofile);
|
||||
$this->assertTrue($this->object->loadInfo());
|
||||
$this->assertEquals('Original', $this->object->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::load
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
$newTheme = Theme::load('./themes/original');
|
||||
$this->assertNotNull($newTheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::loadCss
|
||||
*
|
||||
* @param string $theme Path to theme files
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider listThemes
|
||||
*/
|
||||
public function testLoadCss($theme)
|
||||
{
|
||||
$newTheme = Theme::load($theme);
|
||||
ob_start();
|
||||
$ret = $newTheme->loadCss();
|
||||
$out = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertTrue($ret);
|
||||
$this->assertContains('FILE: navigation.css.php', $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for Theme::loadCss test
|
||||
*
|
||||
* @return array with theme paths
|
||||
*/
|
||||
public function listThemes()
|
||||
{
|
||||
return array(
|
||||
array('./themes/original'),
|
||||
array('./themes/pmahomme/'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::load
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadNotExisted()
|
||||
{
|
||||
$this->assertFalse(Theme::load('/path/to/nowhere'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fir Theme::checkImgPath
|
||||
*
|
||||
* @return void
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
*/
|
||||
public function testCheckImgPathBad()
|
||||
{
|
||||
$GLOBALS['cfg']['ThemePath'] = 'nowhere';
|
||||
$this->object->setPath('path/to/nowhere');
|
||||
|
||||
$this->assertFalse($this->object->checkImgPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::checkImgPath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckImgPath()
|
||||
{
|
||||
$this->object->setPath('./themes/original');
|
||||
$this->assertTrue($this->object->checkImgPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::checkImgPath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckImgPathGlobals()
|
||||
{
|
||||
$this->object->setPath('/this/is/wrong/path');
|
||||
$GLOBALS['cfg']['ThemePath'] = 'themes';
|
||||
$this->assertTrue($this->object->checkImgPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::checkImgPath
|
||||
*
|
||||
* @return void
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
*/
|
||||
public function testCheckImgPathGlobalsWrongPath()
|
||||
{
|
||||
$prevThemePath = $GLOBALS['cfg']['ThemePath'];
|
||||
$GLOBALS['cfg']['ThemePath'] = 'no_themes';
|
||||
|
||||
$this->object->setPath('/this/is/wrong/path');
|
||||
$this->object->checkImgPath();
|
||||
|
||||
$GLOBALS['cfg']['ThemePath'] = $prevThemePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::getPath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSetPath()
|
||||
{
|
||||
$this->assertEmpty($this->object->getPath());
|
||||
$this->object->setPath('./themes/original');
|
||||
|
||||
$this->assertEquals('./themes/original', $this->object->getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::loadInfo
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLayoutFile()
|
||||
{
|
||||
$this->assertContains('layout.inc.php', $this->object->getLayoutFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::checkVersion
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @depends testLoadInfo
|
||||
*/
|
||||
public function testGetSetCheckVersion()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'0.0.0.0',
|
||||
$this->object->getVersion(),
|
||||
'Version 0.0.0.0 by default'
|
||||
);
|
||||
|
||||
$this->object->setVersion("1.2.3.4");
|
||||
$this->assertEquals('1.2.3.4', $this->object->getVersion());
|
||||
|
||||
$this->assertFalse($this->object->checkVersion("0.0.1.1"));
|
||||
$this->assertTrue($this->object->checkVersion("2.0.1.1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::getName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSetName()
|
||||
{
|
||||
$this->assertEmpty($this->object->getName(), 'Name is empty by default');
|
||||
$this->object->setName('New Theme Name');
|
||||
|
||||
$this->assertEquals('New Theme Name', $this->object->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::getId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSetId()
|
||||
{
|
||||
$this->assertEmpty($this->object->getId(), 'ID is empty by default');
|
||||
$this->object->setId('NewID');
|
||||
|
||||
$this->assertEquals('NewID', $this->object->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Theme::getImgPath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSetImgPath()
|
||||
{
|
||||
$this->assertEmpty(
|
||||
$this->object->getImgPath(),
|
||||
'ImgPath is empty by default'
|
||||
);
|
||||
$this->object->setImgPath('/new/path');
|
||||
|
||||
$this->assertEquals('/new/path', $this->object->getImgPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getPrintPreview().
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintPreview()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getPrintPreview(),
|
||||
'<div class="theme_preview"><h2> (0.0.0.0) </h2><p><a class="take_'
|
||||
. 'theme" name="" href="index.php?set_theme=&server=99&lang=en'
|
||||
. '&collation_connection=utf-8'
|
||||
. '&token=token">No preview available.[ <strong>take it</strong> ]'
|
||||
. '</a></p></div>'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getCssIEClearFilter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCssIEClearFilter()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getCssIEClearFilter(),
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getFontSize
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFontSize()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getFontSize(),
|
||||
'82%'
|
||||
);
|
||||
|
||||
$GLOBALS['PMA_Config']->set('fontsize', '12px');
|
||||
$this->assertEquals(
|
||||
$this->object->getFontSize(),
|
||||
'12px'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getCssGradient
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testgetCssGradient()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getCssGradient('12345', '54321'),
|
||||
'background-image: url(./themes/svg_gradient.php?from=12345&to=54321);'
|
||||
. "\n" . 'background-size: 100% 100%;'
|
||||
. "\n" . 'background: -webkit-gradient(linear, left top, left bottom, '
|
||||
. 'from(#12345), to(#54321));'
|
||||
. "\n" . 'background: -webkit-linear-gradient(top, #12345, #54321);'
|
||||
. "\n" . 'background: -moz-linear-gradient(top, #12345, #54321);'
|
||||
. "\n" . 'background: -ms-linear-gradient(top, #12345, #54321);'
|
||||
. "\n" . 'background: -o-linear-gradient(top, #12345, #54321);'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getImgPath
|
||||
*
|
||||
* @param string $file file name for image
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForGetImgPath
|
||||
*/
|
||||
public function testGetImgPath($file, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getImgPath($file),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for testGetImgPath
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerForGetImgPath()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
null,
|
||||
''
|
||||
),
|
||||
array(
|
||||
'screen.png',
|
||||
'./themes/pmahomme/img/screen.png'
|
||||
),
|
||||
array(
|
||||
'arrow_ltr.png',
|
||||
'./themes/pmahomme/img/arrow_ltr.png'
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
926
#pma/test/classes/TrackerTest.php
Normal file
926
#pma/test/classes/TrackerTest.php
Normal file
@@ -0,0 +1,926 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\Tracker
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\Tracker;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\Tracker
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TrackerTest extends PMATestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup function for test cases
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
/**
|
||||
* SET these to avoid undefined index error
|
||||
*/
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['Server']['tracking_add_drop_table'] = '';
|
||||
$GLOBALS['cfg']['Server']['tracking_add_drop_view'] = '';
|
||||
$GLOBALS['cfg']['Server']['tracking_add_drop_database'] = '';
|
||||
$GLOBALS['cfg']['Server']['tracking_default_statements'] = '';
|
||||
$GLOBALS['cfg']['Server']['tracking_version_auto_create'] = '';
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$_SESSION['relation'][$GLOBALS['server']] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'db' => 'pmadb',
|
||||
'tracking' => 'tracking'
|
||||
);
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$cfg['dbi'] = $dbi;
|
||||
}
|
||||
/**
|
||||
* Test for Tracker::enable
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testEnabled()
|
||||
{
|
||||
Tracker::enable();
|
||||
$this->assertTrue(
|
||||
PHPUnit_Framework_Assert::readAttribute('PMA\libraries\Tracker', 'enabled')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::isActive()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testIsActive()
|
||||
{
|
||||
$attr = new \ReflectionProperty('PMA\libraries\Tracker', 'enabled');
|
||||
$attr->setAccessible(true);
|
||||
$attr->setValue(false);
|
||||
|
||||
$this->assertFalse(
|
||||
Tracker::isActive()
|
||||
);
|
||||
|
||||
Tracker::enable();
|
||||
|
||||
$_SESSION['relation'][$GLOBALS['server']] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'trackingwork' => false
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
Tracker::isActive()
|
||||
);
|
||||
|
||||
$_SESSION['relation'][$GLOBALS['server']] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'trackingwork' => true,
|
||||
'db' => 'pmadb',
|
||||
'tracking' => 'tracking'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
Tracker::isActive()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::getTableName()
|
||||
*
|
||||
* @param string $string String to test against
|
||||
* @param string $expected Expected Table Name
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
* @dataProvider getTableNameData
|
||||
*/
|
||||
public function testGetTableName($string, $expected)
|
||||
{
|
||||
$reflection = new \ReflectionClass('PMA\libraries\Tracker');
|
||||
$method = $reflection->getMethod("getTableName");
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$method->invokeArgs(null, array($string))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data Provider for testGetTableName
|
||||
*
|
||||
* @return array Test data
|
||||
*
|
||||
*/
|
||||
public function getTableNameData()
|
||||
{
|
||||
return array(
|
||||
array("`tbl`;", "tbl"),
|
||||
array(" `pma.table` ", "table"),
|
||||
array(" `pma.table\nfoobar` ", "table")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::isTracked()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testIsTracked()
|
||||
{
|
||||
$attr = new \ReflectionProperty('PMA\libraries\Tracker', 'enabled');
|
||||
$attr->setAccessible(true);
|
||||
$attr->setValue(false);
|
||||
|
||||
$this->assertFalse(
|
||||
Tracker::isTracked("", "")
|
||||
);
|
||||
|
||||
Tracker::enable();
|
||||
|
||||
$_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'] = PMA_VERSION;
|
||||
$_SESSION['relation'][$GLOBALS['server']]['trackingwork'] = false;
|
||||
|
||||
$this->assertFalse(
|
||||
Tracker::isTracked("", "")
|
||||
);
|
||||
|
||||
$_SESSION['relation'][$GLOBALS['server']]['trackingwork'] = true;
|
||||
|
||||
$this->assertTrue(
|
||||
Tracker::isTracked("pma_test_db", "pma_test_table")
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
Tracker::isTracked("pma_test_db", "pma_test_table2")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::getLogComment()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetLogComment()
|
||||
{
|
||||
if (!setupForTestsUsingDate()) {
|
||||
$this->markTestSkipped("Cannot override internal function date()");
|
||||
}
|
||||
|
||||
$date = date('Y-m-d H:i:s');
|
||||
$GLOBALS['cfg']['Server']['user'] = "pma_test_user";
|
||||
|
||||
$this->assertEquals(
|
||||
"# log $date pma_test_user\n",
|
||||
Tracker::getLogComment()
|
||||
);
|
||||
|
||||
tearDownForTestsUsingDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::createVersion()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testCreateVersion()
|
||||
{
|
||||
if (!setupForTestsUsingDate()) {
|
||||
$this->markTestSkipped("Cannot override internal function date()");
|
||||
}
|
||||
|
||||
$GLOBALS['cfg']['Server']['tracking_add_drop_table'] = true;
|
||||
$GLOBALS['cfg']['Server']['tracking_add_drop_view'] = true;
|
||||
$GLOBALS['cfg']['Server']['user'] = "pma_test_user";
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/**
|
||||
* set up mock objects
|
||||
* passing null to with() for an argument is equivalent
|
||||
* to passing $this->anything()
|
||||
*/
|
||||
|
||||
$getColumnsResult = array(
|
||||
array(
|
||||
'Field' => 'field1',
|
||||
'Type' => 'int(11)',
|
||||
'Key' => 'PRI'
|
||||
),
|
||||
array(
|
||||
'Field' => 'field2',
|
||||
'Type' => 'text',
|
||||
'Key' => ''
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->once())->method('getColumns')
|
||||
->with('pma_test', 'pma_tbl')
|
||||
->will($this->returnValue($getColumnsResult));
|
||||
|
||||
$getIndexesResult = array(
|
||||
array(
|
||||
'Table' => 'pma_tbl',
|
||||
'Field' => 'field1',
|
||||
'Key' => 'PRIMARY'
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->once())->method('getTableIndexes')
|
||||
->with('pma_test', 'pma_tbl')
|
||||
->will($this->returnValue($getIndexesResult));
|
||||
|
||||
$tableStatusArray = array(
|
||||
array(
|
||||
'Name' => 'pma_tbl',
|
||||
'Rows' => '1',
|
||||
'Create_time' => '2013-02-22 02:04:04',
|
||||
'Update_time' => '2013-02-22 21:46:48'
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->any())->method('tryQuery')
|
||||
->with($this->equalTo("SHOW CREATE TABLE `pma_test`.`pma_tbl`"))
|
||||
->will(
|
||||
$this->returnValue(
|
||||
"CREATE TABLE `pma_test`.`pma_tbl` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`username` text NOT NULL
|
||||
)"
|
||||
)
|
||||
);
|
||||
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
$expectedMainQuery = "/*NOTRACK*/" .
|
||||
"\nINSERT INTO `pmadb`.`tracking` (db_name, table_name, version, date_created, date_updated," .
|
||||
" schema_snapshot, schema_sql, data_sql, tracking ) values (
|
||||
'pma_test',
|
||||
'pma_tbl',
|
||||
'1',
|
||||
'" . $date . "',
|
||||
'" . $date . "',
|
||||
'a:2:{s:7:\"COLUMNS\";a:2:{" .
|
||||
"i:0;a:3:{s:5:\"Field\";s:6:\"field1\";s:4:\"Type\";s:7:\"int(11)\";" .
|
||||
"s:3:\"Key\";s:3:\"PRI\";}" .
|
||||
"i:1;a:3:{s:5:\"Field\";s:6:\"field2\";s:4:\"Type\";s:4:\"text\";" .
|
||||
"s:3:\"Key\";s:0:\"\";}}" .
|
||||
"s:7:\"INDEXES\";a:1:{" .
|
||||
"i:0;a:3:{s:5:\"Table\";s:7:\"pma_tbl\";s:5:\"Field\";s:6:\"field1\";" .
|
||||
"s:3:\"Key\";s:7:\"PRIMARY\";}}}',
|
||||
'# log " . $date . " pma_test_user" .
|
||||
"\nDROP VIEW IF EXISTS `pma_tbl`;" .
|
||||
"\n# log " . $date . " pma_test_user" .
|
||||
"\n\n;" .
|
||||
"\n',
|
||||
'" .
|
||||
"\n',
|
||||
'11' )";
|
||||
|
||||
$GLOBALS['controllink'] = null;
|
||||
|
||||
$queryResults = array(
|
||||
array(
|
||||
"SHOW TABLE STATUS FROM `pma_test` LIKE 'pma_tbl'",
|
||||
null,
|
||||
1,
|
||||
true,
|
||||
$tableStatusArray
|
||||
),
|
||||
array(
|
||||
$expectedMainQuery,
|
||||
null,
|
||||
0,
|
||||
false,
|
||||
'executed'
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())->method('query')
|
||||
->will($this->returnValueMap($queryResults));
|
||||
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$this->assertEquals(
|
||||
'executed',
|
||||
Tracker::createVersion('pma_test', 'pma_tbl', '1', '11', true)
|
||||
);
|
||||
|
||||
tearDownForTestsUsingDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::deleteTracking()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testDeleteTracking()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$sql_query = "/*NOTRACK*/\n"
|
||||
. "DELETE FROM `pmadb`.`tracking`"
|
||||
. " WHERE `db_name` = 'testdb'"
|
||||
. " AND `table_name` = 'testtable'";
|
||||
|
||||
$dbi->expects($this->exactly(1))
|
||||
->method('query')
|
||||
->with($sql_query)
|
||||
->will($this->returnValue('executed'));
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$this->assertEquals(
|
||||
Tracker::deleteTracking("testdb", "testtable"),
|
||||
'executed'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::createDatabaseVersion()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testCreateDatabaseVersion()
|
||||
{
|
||||
if (!setupForTestsUsingDate()) {
|
||||
$this->markTestSkipped("Cannot override internal function date()");
|
||||
}
|
||||
|
||||
$GLOBALS['cfg']['Server']['tracking_add_drop_table'] = true;
|
||||
$GLOBALS['cfg']['Server']['tracking_add_drop_view'] = true;
|
||||
$GLOBALS['cfg']['Server']['user'] = "pma_test_user";
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
$expectedMainQuery = "/*NOTRACK*/" .
|
||||
"\nINSERT INTO `pmadb`.`tracking` (db_name, table_name, version, date_created, date_updated," .
|
||||
" schema_snapshot, schema_sql, data_sql, tracking ) values (
|
||||
'pma_test',
|
||||
'',
|
||||
'1',
|
||||
'" . $date . "',
|
||||
'" . $date . "',
|
||||
'',
|
||||
'# log " . $date . " pma_test_user" .
|
||||
"\nSHOW DATABASES',
|
||||
'" .
|
||||
"\n',
|
||||
'CREATE DATABASE,ALTER DATABASE,DROP DATABASE' )";
|
||||
|
||||
$GLOBALS['controllink'] = null;
|
||||
|
||||
$dbi->expects($this->exactly(1))
|
||||
->method('query')
|
||||
->with($expectedMainQuery, null, 0, false)
|
||||
->will($this->returnValue("executed"));
|
||||
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$this->assertEquals(
|
||||
'executed',
|
||||
Tracker::createDatabaseVersion('pma_test', '1', 'SHOW DATABASES')
|
||||
);
|
||||
|
||||
tearDownForTestsUsingDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::changeTracking(). This test is also invoked by two
|
||||
* other tests: testActivateTracking() and testDeactivateTracking()
|
||||
*
|
||||
* @param string $dbname Database name
|
||||
* @param string $tablename Table name
|
||||
* @param string $version Version
|
||||
* @param string $new_state State to change to
|
||||
* @param string $type Type of test
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @test
|
||||
*
|
||||
*/
|
||||
public function testChangeTracking($dbname = 'pma_db', $tablename = 'pma_tbl',
|
||||
$version = '0.1', $new_state = '1', $type = null
|
||||
) {
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$sql_query = " UPDATE `pmadb`.`tracking` SET `tracking_active` = " .
|
||||
"'" . $new_state . "' " .
|
||||
" WHERE `db_name` = '" . $dbname . "' " .
|
||||
" AND `table_name` = '" . $tablename . "' " .
|
||||
" AND `version` = '" . $version . "' ";
|
||||
|
||||
$GLOBALS['controllink'] = null;
|
||||
|
||||
$dbi->expects($this->exactly(1))
|
||||
->method('query')
|
||||
->with($sql_query, null, 0, false)
|
||||
->will($this->returnValue("executed"));
|
||||
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
if ($type == null) {
|
||||
$method = new \ReflectionMethod('PMA\libraries\Tracker', '_changeTracking');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke(
|
||||
null,
|
||||
$dbname,
|
||||
$tablename,
|
||||
$version,
|
||||
$new_state
|
||||
);
|
||||
} elseif ($type == "activate") {
|
||||
$result = Tracker::activateTracking($dbname, $tablename, $version);
|
||||
} elseif ($type == "deactivate") {
|
||||
$result = Tracker::deactivateTracking($dbname, $tablename, $version);
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
'executed',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::testChangeTrackingData()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testChangeTrackingData()
|
||||
{
|
||||
if (!setupForTestsUsingDate()) {
|
||||
$this->markTestSkipped("Cannot override internal function date()");
|
||||
}
|
||||
|
||||
$this->assertFalse(
|
||||
Tracker::changeTrackingData("", "", "", "", "")
|
||||
);
|
||||
|
||||
$GLOBALS['controllink'] = null;
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$sql_query_1 = " UPDATE `pmadb`.`tracking`" .
|
||||
" SET `schema_sql` = '# new_data_processed' " .
|
||||
" WHERE `db_name` = 'pma_db' " .
|
||||
" AND `table_name` = 'pma_table' " .
|
||||
" AND `version` = '1.0' ";
|
||||
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
$new_data = array(
|
||||
array(
|
||||
'username' => 'user1',
|
||||
'statement' => 'test_statement1'
|
||||
),
|
||||
array(
|
||||
'username' => 'user2',
|
||||
'statement' => 'test_statement2'
|
||||
)
|
||||
);
|
||||
|
||||
$sql_query_2 = " UPDATE `pmadb`.`tracking`" .
|
||||
" SET `data_sql` = '# log $date user1test_statement1\n" .
|
||||
"# log $date user2test_statement2\n' " .
|
||||
" WHERE `db_name` = 'pma_db' " .
|
||||
" AND `table_name` = 'pma_table' " .
|
||||
" AND `version` = '1.0' ";
|
||||
|
||||
$dbi->method('query')
|
||||
->will(
|
||||
$this->returnValueMap(
|
||||
array(
|
||||
array($sql_query_1, null, 0, false, "executed_1"),
|
||||
array($sql_query_2, null, 0, false, "executed_2")
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
Tracker::changeTrackingData(
|
||||
'pma_db',
|
||||
'pma_table',
|
||||
'1.0',
|
||||
'DDL',
|
||||
"# new_data_processed"
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
Tracker::changeTrackingData(
|
||||
'pma_db',
|
||||
'pma_table',
|
||||
'1.0',
|
||||
'DML',
|
||||
$new_data
|
||||
)
|
||||
);
|
||||
|
||||
tearDownForTestsUsingDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::activateTracking()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testActivateTracking()
|
||||
{
|
||||
$this->testChangeTracking('pma_db', 'pma_tbl', '0.1', 1, 'activate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::deactivateTracking()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testDeactivateTracking()
|
||||
{
|
||||
$this->testChangeTracking('pma_db', 'pma_tbl', '0.1', '0', 'deactivate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_Tracker::getTrackedData()
|
||||
*
|
||||
* @param array $fetchArrayReturn Value to be returned by mocked fetchArray
|
||||
* @param array $expectedArray Expected array
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
* @dataProvider getTrackedDataProvider
|
||||
*/
|
||||
public function testGetTrackedData($fetchArrayReturn, $expectedArray)
|
||||
{
|
||||
$GLOBALS['controllink'] = null;
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->will($this->returnValue("executed_1"));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('fetchAssoc')
|
||||
->with("executed_1")
|
||||
->will($this->returnValue($fetchArrayReturn));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('escapeString')
|
||||
->will(
|
||||
$this->returnValueMap(
|
||||
array(
|
||||
array("pma'db", "pma\'db"),
|
||||
array("pma'table", "pma\'table"),
|
||||
array("1.0", "1.0"),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$result = Tracker::getTrackedData("pma'db", "pma'table", "1.0");
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedArray,
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetTrackedData
|
||||
*
|
||||
* @return array Test data
|
||||
*/
|
||||
public function getTrackedDataProvider()
|
||||
{
|
||||
$fetchArrayReturn = array(
|
||||
array(
|
||||
"schema_sql" => "# log 20-03-2013 23:33:58 user1\nstat1" .
|
||||
"# log 20-03-2013 23:39:58 user2\n",
|
||||
"data_sql" => "# log ",
|
||||
"schema_snapshot" => "dataschema",
|
||||
"tracking" => "SELECT, DELETE"
|
||||
)
|
||||
);
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'date_from' => '20-03-2013 23:33:58',
|
||||
'date_to' => '20-03-2013 23:39:58',
|
||||
'ddlog' => array(
|
||||
array(
|
||||
'date' => '20-03-2013 23:33:58',
|
||||
'username' => 'user1',
|
||||
'statement' => "\nstat1"
|
||||
),
|
||||
array(
|
||||
'date' => '20-03-2013 23:39:58',
|
||||
'username' => 'user2',
|
||||
'statement' => ""
|
||||
)
|
||||
),
|
||||
'dmlog' => array(),
|
||||
"schema_snapshot" => "dataschema",
|
||||
"tracking" => "SELECT, DELETE"
|
||||
)
|
||||
);
|
||||
|
||||
$fetchArrayReturn[1] = array(
|
||||
"schema_sql" => "# log 20-03-2012 23:33:58 user1\n" .
|
||||
"# log 20-03-2012 23:39:58 user2\n",
|
||||
"data_sql" => "# log 20-03-2013 23:33:58 user3\n" .
|
||||
"# log 20-03-2013 23:39:58 user4\n",
|
||||
"schema_snapshot" => "dataschema",
|
||||
"tracking" => "SELECT, DELETE"
|
||||
);
|
||||
|
||||
$data[1] = array(
|
||||
'date_from' => '20-03-2012 23:33:58',
|
||||
'date_to' => '20-03-2013 23:39:58',
|
||||
'ddlog' => array(
|
||||
array(
|
||||
'date' => '20-03-2012 23:33:58',
|
||||
'username' => 'user1',
|
||||
'statement' => ""
|
||||
),
|
||||
array(
|
||||
'date' => '20-03-2012 23:39:58',
|
||||
'username' => 'user2',
|
||||
'statement' => ""
|
||||
)
|
||||
),
|
||||
'dmlog' => array(
|
||||
array(
|
||||
'date' => '20-03-2013 23:33:58',
|
||||
'username' => 'user3',
|
||||
'statement' => ""
|
||||
),
|
||||
array(
|
||||
'date' => '20-03-2013 23:39:58',
|
||||
'username' => 'user4',
|
||||
'statement' => ""
|
||||
)
|
||||
),
|
||||
"schema_snapshot" => "dataschema",
|
||||
"tracking" => "SELECT, DELETE"
|
||||
);
|
||||
return array(
|
||||
array($fetchArrayReturn[0], $data[0]),
|
||||
array($fetchArrayReturn[1], $data[1])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Tracker::parseQuery
|
||||
*
|
||||
* @param string $query Query to parse
|
||||
* @param string $type Expected type
|
||||
* @param string $identifier Expected identifier
|
||||
* @param string $tablename Expected tablename
|
||||
* @param string $db Expected dbname
|
||||
* @param string $tablename_after_rename Expected name after rename
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @test
|
||||
* @dataProvider parseQueryData
|
||||
*/
|
||||
public function testParseQuery($query, $type, $identifier, $tablename,
|
||||
$db = null, $tablename_after_rename = null
|
||||
) {
|
||||
$result = Tracker::parseQuery($query);
|
||||
|
||||
$this->assertEquals(
|
||||
$type,
|
||||
$result['type']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$identifier,
|
||||
$result['identifier']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$tablename,
|
||||
$result['tablename']
|
||||
);
|
||||
|
||||
if ($db) {
|
||||
$this->assertEquals(
|
||||
$db,
|
||||
$GLOBALS['db']
|
||||
);
|
||||
}
|
||||
|
||||
if ($tablename_after_rename) {
|
||||
$this->assertEquals(
|
||||
$result['tablename_after_rename'],
|
||||
$tablename_after_rename
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testParseQuery
|
||||
*
|
||||
* @return array Test data
|
||||
*/
|
||||
public function parseQueryData()
|
||||
{
|
||||
$query = array();
|
||||
/** TODO: Should test fail when USE is in conjunction with * identifiers?
|
||||
$query[] = array(
|
||||
" - USE db1;\n- CREATE VIEW db1.v AS SELECT * FROM t;",
|
||||
"DDL",
|
||||
"CREATE VIEW",
|
||||
"v",
|
||||
"db1"
|
||||
);
|
||||
*/
|
||||
$query[] = array(
|
||||
"- CREATE VIEW v AS SELECT * FROM t;",
|
||||
"DDL",
|
||||
"CREATE VIEW",
|
||||
"v",
|
||||
);
|
||||
$query[] = array(
|
||||
"- ALTER VIEW db1.v AS SELECT col1, col2, col3, col4 FROM t",
|
||||
"DDL",
|
||||
"ALTER VIEW",
|
||||
"v"
|
||||
);
|
||||
$query[] = array(
|
||||
"- DROP VIEW db1.v;",
|
||||
"DDL",
|
||||
"DROP VIEW",
|
||||
"v"
|
||||
);
|
||||
$query[] = array(
|
||||
"- DROP VIEW IF EXISTS db1.v;",
|
||||
"DDL",
|
||||
"DROP VIEW",
|
||||
"v"
|
||||
);
|
||||
$query[] = array(
|
||||
"- CREATE DATABASE db1; -",
|
||||
"DDL",
|
||||
"CREATE DATABASE",
|
||||
"",
|
||||
"db1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- ALTER DATABASE db1; -",
|
||||
"DDL",
|
||||
"ALTER DATABASE",
|
||||
""
|
||||
);
|
||||
$query[] = array(
|
||||
"- DROP DATABASE db1; -",
|
||||
"DDL",
|
||||
"DROP DATABASE",
|
||||
"",
|
||||
"db1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- CREATE TABLE db1.t1 (c1 INT);",
|
||||
"DDL",
|
||||
"CREATE TABLE",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- ALTER TABLE db1.t1 ADD c2 TEXT;",
|
||||
"DDL",
|
||||
"ALTER TABLE",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- DROP TABLE db1.t1",
|
||||
"DDL",
|
||||
"DROP TABLE",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- DROP TABLE IF EXISTS db1.t1",
|
||||
"DDL",
|
||||
"DROP TABLE",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- CREATE INDEX ind ON db1.t1 (c2(10));",
|
||||
"DDL",
|
||||
"CREATE INDEX",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- CREATE UNIQUE INDEX ind ON db1.t1 (c2(10));",
|
||||
"DDL",
|
||||
"CREATE INDEX",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- CREATE SPATIAL INDEX ind ON db1.t1 (c2(10));",
|
||||
"DDL",
|
||||
"CREATE INDEX",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- DROP INDEX ind ON db1.t1;",
|
||||
"DDL",
|
||||
"DROP INDEX",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- RENAME TABLE db1.t1 TO db1.t2",
|
||||
"DDL",
|
||||
"RENAME TABLE",
|
||||
"t1",
|
||||
"",
|
||||
"t2"
|
||||
);
|
||||
$query[] = array(
|
||||
"- UPDATE db1.t1 SET a = 2",
|
||||
"DML",
|
||||
"UPDATE",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- INSERT INTO db1.t1 (a, b, c) VALUES(1, 2, 3)",
|
||||
"DML",
|
||||
"INSERT",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- DELETE FROM db1.t1",
|
||||
"DML",
|
||||
"DELETE",
|
||||
"t1"
|
||||
);
|
||||
$query[] = array(
|
||||
"- TRUNCATE db1.t1",
|
||||
"DML",
|
||||
"TRUNCATE",
|
||||
"t1"
|
||||
);
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
432
#pma/test/classes/TypesMySQLTest.php
Normal file
432
#pma/test/classes/TypesMySQLTest.php
Normal file
@@ -0,0 +1,432 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for Types.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\TypesMySQL;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Testcase for MySQL types handling.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TypesMySQLTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var PMA\libraries\Types
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new TypesMySQL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getTypeDescription
|
||||
*
|
||||
* @param string $type The data type to get a description.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForTestGetTypeDescription
|
||||
*/
|
||||
public function testGetTypeDescription($type)
|
||||
{
|
||||
$this->assertNotEquals(
|
||||
'',
|
||||
$this->object->getTypeDescription($type)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getTypeDescription with unknown value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetUnknownTypeDescription()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getTypeDescription('UNKNOWN')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for testGetTypeDescription
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerForTestGetTypeDescription()
|
||||
{
|
||||
return array(
|
||||
array('TINYINT'),
|
||||
array('SMALLINT'),
|
||||
array('MEDIUMINT'),
|
||||
array('INT'),
|
||||
array('BIGINT'),
|
||||
array('DECIMAL'),
|
||||
array('FLOAT'),
|
||||
array('DOUBLE'),
|
||||
array('REAL'),
|
||||
array('BIT'),
|
||||
array('BOOLEAN'),
|
||||
array('SERIAL'),
|
||||
array('DATE'),
|
||||
array('DATETIME'),
|
||||
array('TIMESTAMP'),
|
||||
array('TIME'),
|
||||
array('YEAR'),
|
||||
array('CHAR'),
|
||||
array('VARCHAR'),
|
||||
array('TINYTEXT'),
|
||||
array('TEXT'),
|
||||
array('MEDIUMTEXT'),
|
||||
array('LONGTEXT'),
|
||||
array('BINARY'),
|
||||
array('VARBINARY'),
|
||||
array('TINYBLOB'),
|
||||
array('MEDIUMBLOB'),
|
||||
array('BLOB'),
|
||||
array('LONGBLOB'),
|
||||
array('ENUM'),
|
||||
array('SET'),
|
||||
array('GEOMETRY'),
|
||||
array('POINT'),
|
||||
array('LINESTRING'),
|
||||
array('POLYGON'),
|
||||
array('MULTIPOINT'),
|
||||
array('MULTILINESTRING'),
|
||||
array('MULTIPOLYGON'),
|
||||
array('GEOMETRYCOLLECTION'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getTypeClass
|
||||
*
|
||||
* @param string $type Type to check
|
||||
* @param string $output Expected result
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerFortTestGetTypeClass
|
||||
*/
|
||||
public function testGetTypeClass($type, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->getTypeClass($type)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for type testing
|
||||
*
|
||||
* @return array for testing type detection
|
||||
*/
|
||||
public function providerFortTestGetTypeClass()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'SERIAL',
|
||||
'NUMBER'
|
||||
),
|
||||
array(
|
||||
'YEAR',
|
||||
'DATE'
|
||||
),
|
||||
array(
|
||||
'GEOMETRYCOLLECTION',
|
||||
'SPATIAL'
|
||||
),
|
||||
array(
|
||||
'SET',
|
||||
'CHAR'
|
||||
),
|
||||
array(
|
||||
'UNKNOWN',
|
||||
''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getFunctionsClass
|
||||
*
|
||||
* @param string $class The class to get function list.
|
||||
* @param array $output Expected function list
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerFortTestGetFunctionsClass
|
||||
*/
|
||||
public function testGetFunctionsClass($class, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->getFunctionsClass($class)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testing function lists
|
||||
*
|
||||
* @return array with test data
|
||||
*/
|
||||
public function providerFortTestGetFunctionsClass()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'CHAR',
|
||||
array(
|
||||
'AES_DECRYPT',
|
||||
'AES_ENCRYPT',
|
||||
'BIN',
|
||||
'CHAR',
|
||||
'COMPRESS',
|
||||
'CURRENT_USER',
|
||||
'DATABASE',
|
||||
'DAYNAME',
|
||||
'DES_DECRYPT',
|
||||
'DES_ENCRYPT',
|
||||
'ENCRYPT',
|
||||
'HEX',
|
||||
'INET6_NTOA',
|
||||
'INET_NTOA',
|
||||
'LOAD_FILE',
|
||||
'LOWER',
|
||||
'LTRIM',
|
||||
'MD5',
|
||||
'MONTHNAME',
|
||||
'OLD_PASSWORD',
|
||||
'PASSWORD',
|
||||
'QUOTE',
|
||||
'REVERSE',
|
||||
'RTRIM',
|
||||
'SHA1',
|
||||
'SOUNDEX',
|
||||
'SPACE',
|
||||
'TRIM',
|
||||
'UNCOMPRESS',
|
||||
'UNHEX',
|
||||
'UPPER',
|
||||
'USER',
|
||||
'UUID',
|
||||
'VERSION',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'DATE',
|
||||
array(
|
||||
'CURRENT_DATE',
|
||||
'CURRENT_TIME',
|
||||
'DATE',
|
||||
'FROM_DAYS',
|
||||
'FROM_UNIXTIME',
|
||||
'LAST_DAY',
|
||||
'NOW',
|
||||
'SEC_TO_TIME',
|
||||
'SYSDATE',
|
||||
'TIME',
|
||||
'TIMESTAMP',
|
||||
'UTC_DATE',
|
||||
'UTC_TIME',
|
||||
'UTC_TIMESTAMP',
|
||||
'YEAR',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'SPATIAL',
|
||||
array(
|
||||
'GeomFromText',
|
||||
'GeomFromWKB',
|
||||
|
||||
'GeomCollFromText',
|
||||
'LineFromText',
|
||||
'MLineFromText',
|
||||
'PointFromText',
|
||||
'MPointFromText',
|
||||
'PolyFromText',
|
||||
'MPolyFromText',
|
||||
|
||||
'GeomCollFromWKB',
|
||||
'LineFromWKB',
|
||||
'MLineFromWKB',
|
||||
'PointFromWKB',
|
||||
'MPointFromWKB',
|
||||
'PolyFromWKB',
|
||||
'MPolyFromWKB',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'NUMBER',
|
||||
array(
|
||||
'0' => 'ABS',
|
||||
'1' => 'ACOS',
|
||||
'2' => 'ASCII',
|
||||
'3' => 'ASIN',
|
||||
'4' => 'ATAN',
|
||||
'5' => 'BIT_LENGTH',
|
||||
'6' => 'BIT_COUNT',
|
||||
'7' => 'CEILING',
|
||||
'8' => 'CHAR_LENGTH',
|
||||
'9' => 'CONNECTION_ID',
|
||||
'10' => 'COS',
|
||||
'11' => 'COT',
|
||||
'12' => 'CRC32',
|
||||
'13' => 'DAYOFMONTH',
|
||||
'14' => 'DAYOFWEEK',
|
||||
'15' => 'DAYOFYEAR',
|
||||
'16' => 'DEGREES',
|
||||
'17' => 'EXP',
|
||||
'18' => 'FLOOR',
|
||||
'19' => 'HOUR',
|
||||
'20' => 'INET6_ATON',
|
||||
'21' => 'INET_ATON',
|
||||
'22' => 'LENGTH',
|
||||
'23' => 'LN',
|
||||
'24' => 'LOG',
|
||||
'25' => 'LOG2',
|
||||
'26' => 'LOG10',
|
||||
'27' => 'MICROSECOND',
|
||||
'28' => 'MINUTE',
|
||||
'29' => 'MONTH',
|
||||
'30' => 'OCT',
|
||||
'31' => 'ORD',
|
||||
'32' => 'PI',
|
||||
'33' => 'QUARTER',
|
||||
'34' => 'RADIANS',
|
||||
'35' => 'RAND',
|
||||
'36' => 'ROUND',
|
||||
'37' => 'SECOND',
|
||||
'38' => 'SIGN',
|
||||
'39' => 'SIN',
|
||||
'40' => 'SQRT',
|
||||
'41' => 'TAN',
|
||||
'42' => 'TO_DAYS',
|
||||
'43' => 'TO_SECONDS',
|
||||
'44' => 'TIME_TO_SEC',
|
||||
'45' => 'UNCOMPRESSED_LENGTH',
|
||||
'46' => 'UNIX_TIMESTAMP',
|
||||
'47' => 'UUID_SHORT',
|
||||
'48' => 'WEEK',
|
||||
'49' => 'WEEKDAY',
|
||||
'50' => 'WEEKOFYEAR',
|
||||
'51' => 'YEARWEEK'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'UNKNOWN',
|
||||
array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getAttributes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetAttributes()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'',
|
||||
'BINARY',
|
||||
'UNSIGNED',
|
||||
'UNSIGNED ZEROFILL',
|
||||
'on update CURRENT_TIMESTAMP',
|
||||
),
|
||||
$this->object->getAttributes()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getColumns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetColumns()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
0 => 'INT',
|
||||
1 => 'VARCHAR',
|
||||
2 => 'TEXT',
|
||||
3 => 'DATE',
|
||||
'Numeric' => array (
|
||||
'TINYINT',
|
||||
'SMALLINT',
|
||||
'MEDIUMINT',
|
||||
'INT',
|
||||
'BIGINT',
|
||||
'-',
|
||||
'DECIMAL',
|
||||
'FLOAT',
|
||||
'DOUBLE',
|
||||
'REAL',
|
||||
'-',
|
||||
'BIT',
|
||||
'BOOLEAN',
|
||||
'SERIAL',
|
||||
),
|
||||
'Date and time' => array (
|
||||
'DATE',
|
||||
'DATETIME',
|
||||
'TIMESTAMP',
|
||||
'TIME',
|
||||
'YEAR',
|
||||
),
|
||||
'String' => array (
|
||||
'CHAR',
|
||||
'VARCHAR',
|
||||
'-',
|
||||
'TINYTEXT',
|
||||
'TEXT',
|
||||
'MEDIUMTEXT',
|
||||
'LONGTEXT',
|
||||
'-',
|
||||
'BINARY',
|
||||
'VARBINARY',
|
||||
'-',
|
||||
'TINYBLOB',
|
||||
'MEDIUMBLOB',
|
||||
'BLOB',
|
||||
'LONGBLOB',
|
||||
'-',
|
||||
'ENUM',
|
||||
'SET',
|
||||
),
|
||||
'Spatial' => array (
|
||||
'GEOMETRY',
|
||||
'POINT',
|
||||
'LINESTRING',
|
||||
'POLYGON',
|
||||
'MULTIPOINT',
|
||||
'MULTILINESTRING',
|
||||
'MULTIPOLYGON',
|
||||
'GEOMETRYCOLLECTION',
|
||||
),
|
||||
'JSON' => array(
|
||||
'JSON'
|
||||
)
|
||||
),
|
||||
$this->object->getColumns()
|
||||
);
|
||||
}
|
||||
}
|
||||
338
#pma/test/classes/TypesTest.php
Normal file
338
#pma/test/classes/TypesTest.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for Types.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\Types;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test class for Types.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TypesTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var Types
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new Types();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for isUnaryOperator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUnary()
|
||||
{
|
||||
$this->assertTrue($this->object->isUnaryOperator('IS NULL'));
|
||||
$this->assertFalse($this->object->isUnaryOperator('='));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getUnaryOperators
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetUnaryOperators()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'IS NULL',
|
||||
'IS NOT NULL',
|
||||
"= ''",
|
||||
"!= ''",
|
||||
),
|
||||
$this->object->getUnaryOperators()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getNullOperators
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetNullOperators()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'IS NULL',
|
||||
'IS NOT NULL',
|
||||
),
|
||||
$this->object->getNullOperators()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getEnumOperators
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEnumOperators()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'=',
|
||||
'!=',
|
||||
),
|
||||
$this->object->getEnumOperators()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getTextOperators
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testgetTextOperators()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'LIKE',
|
||||
'LIKE %...%',
|
||||
'NOT LIKE',
|
||||
'=',
|
||||
'!=',
|
||||
'REGEXP',
|
||||
'REGEXP ^...$',
|
||||
'NOT REGEXP',
|
||||
"= ''",
|
||||
"!= ''",
|
||||
'IN (...)',
|
||||
'NOT IN (...)',
|
||||
'BETWEEN',
|
||||
'NOT BETWEEN',
|
||||
),
|
||||
$this->object->getTextOperators()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getNumberOperators
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetNumberOperators()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'=',
|
||||
'>',
|
||||
'>=',
|
||||
'<',
|
||||
'<=',
|
||||
'!=',
|
||||
'LIKE',
|
||||
'LIKE %...%',
|
||||
'NOT LIKE',
|
||||
'IN (...)',
|
||||
'NOT IN (...)',
|
||||
'BETWEEN',
|
||||
'NOT BETWEEN',
|
||||
),
|
||||
$this->object->getNumberOperators()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getting type operators
|
||||
*
|
||||
* @param string $type Type of field
|
||||
* @param boolean $null Whether field can be NULL
|
||||
* @param string $output Expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForGetTypeOperators
|
||||
*/
|
||||
public function testGetTypeOperators($type, $null, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->getTypeOperators($type, $null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGetTypeOperators
|
||||
*
|
||||
* @return data for testGetTypeOperators
|
||||
*/
|
||||
public function providerForGetTypeOperators()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'enum',
|
||||
false,
|
||||
array(
|
||||
'=',
|
||||
'!=',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'CHAR',
|
||||
true,
|
||||
array(
|
||||
'=',
|
||||
'>',
|
||||
'>=',
|
||||
'<',
|
||||
'<=',
|
||||
'!=',
|
||||
'LIKE',
|
||||
'LIKE %...%',
|
||||
'NOT LIKE',
|
||||
'IN (...)',
|
||||
'NOT IN (...)',
|
||||
'BETWEEN',
|
||||
'NOT BETWEEN',
|
||||
'IS NULL',
|
||||
'IS NOT NULL',
|
||||
),
|
||||
array(
|
||||
'int',
|
||||
false,
|
||||
array(
|
||||
'=',
|
||||
'!=',
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getTypeOperatorsHtml
|
||||
*
|
||||
* @param string $type Type of field
|
||||
* @param boolean $null Whether field can be NULL
|
||||
* @param string $selectedOperator Option to be selected
|
||||
* @param string $output Expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForTestGetTypeOperatorsHtml
|
||||
*/
|
||||
public function testGetTypeOperatorsHtml(
|
||||
$type, $null, $selectedOperator, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->getTypeOperatorsHtml($type, $null, $selectedOperator)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for testGetTypeOperatorsHtml
|
||||
*
|
||||
* @return test data for getTypeOperatorsHtml
|
||||
*/
|
||||
public function providerForTestGetTypeOperatorsHtml()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'enum',
|
||||
false,
|
||||
'=',
|
||||
'<option value="=" selected="selected">=</option>'
|
||||
. '<option value="!=">!=</option>'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getTypeDescription
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTypeDescription()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getTypeDescription('enum')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getFunctionsClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFunctionsClass()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->getFunctionsClass('enum')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getFunctions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFunctions()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->getFunctions('enum')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getAllFunctions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetAllFunctions()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->getAllFunctions()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getAttributes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetAttributes()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->getAttributes()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getColumns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetColumns()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'INT',
|
||||
'VARCHAR',
|
||||
'TEXT',
|
||||
'DATE',
|
||||
),
|
||||
$this->object->getColumns()
|
||||
);
|
||||
}
|
||||
}
|
||||
119
#pma/test/classes/UtilTest.php
Normal file
119
#pma/test/classes/UtilTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\Util class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\Util class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class UtilTest extends PMATestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for createGISData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateGISData()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"abc",
|
||||
PMA\libraries\Util::createGISData("abc")
|
||||
);
|
||||
$this->assertEquals(
|
||||
"GeomFromText('POINT()',10)",
|
||||
PMA\libraries\Util::createGISData("'POINT()',10")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getGISFunctions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetGISFunctions()
|
||||
{
|
||||
$funcs = PMA\libraries\Util::getGISFunctions();
|
||||
$this->assertArrayHasKey(
|
||||
'Dimension',
|
||||
$funcs
|
||||
);
|
||||
$this->assertArrayHasKey(
|
||||
'GeometryType',
|
||||
$funcs
|
||||
);
|
||||
$this->assertArrayHasKey(
|
||||
'MBRDisjoint',
|
||||
$funcs
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Page Selector
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPageSelector()
|
||||
{
|
||||
$this->assertContains(
|
||||
'<select class="pageselector ajax" name="pma" >',
|
||||
PMA\libraries\Util::pageselector("pma", 3)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for isForeignKeyCheck
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsForeignKeyCheck()
|
||||
{
|
||||
$GLOBALS['server'] = 1;
|
||||
|
||||
$GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'enable';
|
||||
$this->assertEquals(
|
||||
true,
|
||||
PMA\libraries\Util::isForeignKeyCheck()
|
||||
);
|
||||
|
||||
$GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'disable';
|
||||
$this->assertEquals(
|
||||
false,
|
||||
PMA\libraries\Util::isForeignKeyCheck()
|
||||
);
|
||||
|
||||
$GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'default';
|
||||
$this->assertEquals(
|
||||
true,
|
||||
PMA\libraries\Util::isForeignKeyCheck()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for isForeignKeySupported
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsForeignKeySupported()
|
||||
{
|
||||
$GLOBALS['server'] = 1;
|
||||
|
||||
$this->assertTrue(
|
||||
PMA\libraries\Util::isForeignKeySupported('innodb')
|
||||
);
|
||||
$this->assertFalse(
|
||||
PMA\libraries\Util::isForeignKeySupported('myisam')
|
||||
);
|
||||
$this->assertTrue(
|
||||
PMA\libraries\Util::isForeignKeySupported('ndb')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
261
#pma/test/classes/VersionInformationTest.php
Normal file
261
#pma/test/classes/VersionInformationTest.php
Normal file
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for methods in PMA\libraries\VersionInformation class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\VersionInformation;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for methods in PMA\libraries\VersionInformation class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class VersionInformationTest extends PMATestCase
|
||||
{
|
||||
private $_releases;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_releases = array();
|
||||
|
||||
$release = new stdClass();
|
||||
$release->date = "2015-09-08";
|
||||
$release->php_versions = ">=5.3,<7.1";
|
||||
$release->version = "4.4.14.1";
|
||||
$release->mysql_versions = ">=5.5";
|
||||
$this->_releases[] = $release;
|
||||
|
||||
$release = new stdClass();
|
||||
$release->date = "2015-09-09";
|
||||
$release->php_versions = ">=5.3,<7.0";
|
||||
$release->version = "4.4.13.3";
|
||||
$release->mysql_versions = ">=5.5";
|
||||
$this->_releases[] = $release;
|
||||
|
||||
$release = new stdClass();
|
||||
$release->date = "2015-05-13";
|
||||
$release->php_versions = ">=5.2,<5.3";
|
||||
$release->version = "4.0.10.10";
|
||||
$release->mysql_versions = ">=5.0";
|
||||
$this->_releases[] = $release;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test version checking
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group large
|
||||
*/
|
||||
public function testGetLatestVersion()
|
||||
{
|
||||
$GLOBALS['cfg']['ProxyUrl'] = PROXY_URL;
|
||||
$GLOBALS['cfg']['ProxyUser'] = PROXY_USER;
|
||||
$GLOBALS['cfg']['ProxyPass'] = PROXY_PASS;
|
||||
$GLOBALS['cfg']['VersionCheck'] = true;
|
||||
$versionInformation = new VersionInformation();
|
||||
$version = $versionInformation->getLatestVersion();
|
||||
$this->assertNotEmpty($version->version);
|
||||
$this->assertNotEmpty($version->date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test version to int conversion.
|
||||
*
|
||||
* @param string $version Version string
|
||||
* @param int $numeric Integer matching version
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider dataVersions
|
||||
*/
|
||||
public function testVersionToInt($version, $numeric)
|
||||
{
|
||||
$versionInformation = new VersionInformation();
|
||||
$this->assertEquals(
|
||||
$numeric,
|
||||
$versionInformation->versionToInt($version)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Data provider for version parsing
|
||||
*
|
||||
* @return array with test data
|
||||
*/
|
||||
public function dataVersions()
|
||||
{
|
||||
return array(
|
||||
array('1.0.0', 1000050),
|
||||
array('2.0.0.2-dev', 2000002),
|
||||
array('3.4.2.1', 3040251),
|
||||
array('3.4.2-dev3', 3040203),
|
||||
array('3.4.2-dev', 3040200),
|
||||
array('3.4.2-pl', 3040260),
|
||||
array('3.4.2-pl3', 3040263),
|
||||
array('4.4.2-rc22', 4040252),
|
||||
array('4.4.2-rc', 4040230),
|
||||
array('4.4.22-beta22', 4042242),
|
||||
array('4.4.22-beta', 4042220),
|
||||
array('4.4.21-alpha22', 4042132),
|
||||
array('4.4.20-alpha', 4042010),
|
||||
array('4.40.20-alpha-dev', 4402010),
|
||||
array('4.4a', 4000050),
|
||||
array('4.4.4-test', 4040400),
|
||||
array('4.1.0', 4010050),
|
||||
array('4.0.1.3', 4000153),
|
||||
array('4.1-dev', 4010000),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getLatestCompatibleVersion() when there is only one server confgiured
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLatestCompatibleVersionWithSingleServer()
|
||||
{
|
||||
$GLOBALS['cfg']['Servers'] = array(
|
||||
array()
|
||||
);
|
||||
|
||||
$mockVersionInfo = $this->getMockBuilder('PMA\libraries\VersionInformation')
|
||||
->setMethods(array('evaluateVersionCondition'))
|
||||
->getMock();
|
||||
|
||||
$mockVersionInfo->expects($this->at(0))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('PHP', '>=5.3')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$mockVersionInfo->expects($this->at(1))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('PHP', '<7.1')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$mockVersionInfo->expects($this->at(2))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('MySQL', '>=5.5')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$compatible = $mockVersionInfo
|
||||
->getLatestCompatibleVersion($this->_releases);
|
||||
$this->assertEquals('4.4.14.1', $compatible['version']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getLatestCompatibleVersion() when there are multiple servers configured
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLaestCompatibleVersionWithMultipleServers()
|
||||
{
|
||||
$GLOBALS['cfg']['Servers'] = array(
|
||||
array(),
|
||||
array()
|
||||
);
|
||||
|
||||
$mockVersionInfo = $this->getMockBuilder('PMA\libraries\VersionInformation')
|
||||
->setMethods(array('evaluateVersionCondition'))
|
||||
->getMock();
|
||||
|
||||
$mockVersionInfo->expects($this->at(0))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('PHP', '>=5.3')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$mockVersionInfo->expects($this->at(1))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('PHP', '<7.1')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$compatible = $mockVersionInfo
|
||||
->getLatestCompatibleVersion($this->_releases);
|
||||
$this->assertEquals('4.4.14.1', $compatible['version']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getLatestCompatibleVersion() with an old PHP version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLaestCompatibleVersionWithOldPHPVersion()
|
||||
{
|
||||
$GLOBALS['cfg']['Servers'] = array(
|
||||
array(),
|
||||
array()
|
||||
);
|
||||
|
||||
$mockVersionInfo = $this->getMockBuilder('PMA\libraries\VersionInformation')
|
||||
->setMethods(array('evaluateVersionCondition'))
|
||||
->getMock();
|
||||
|
||||
$mockVersionInfo->expects($this->at(0))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('PHP', '>=5.3')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$mockVersionInfo->expects($this->at(1))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('PHP', '>=5.3')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$mockVersionInfo->expects($this->at(2))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('PHP', '>=5.2')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$mockVersionInfo->expects($this->at(3))
|
||||
->method('evaluateVersionCondition')
|
||||
->with('PHP', '<5.3')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$compatible = $mockVersionInfo
|
||||
->getLatestCompatibleVersion($this->_releases);
|
||||
$this->assertEquals('4.0.10.10', $compatible['version']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests evaluateVersionCondition() method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEvaluateVersionCondition()
|
||||
{
|
||||
$mockVersionInfo = $this->getMockBuilder('PMA\libraries\VersionInformation')
|
||||
->setMethods(array('getPHPVersion'))
|
||||
->getMock();
|
||||
|
||||
$mockVersionInfo->expects($this->any())
|
||||
->method('getPHPVersion')
|
||||
->will($this->returnValue('5.2.4'));
|
||||
|
||||
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '<=5.3'));
|
||||
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '<5.3'));
|
||||
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '>=5.2'));
|
||||
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '>5.2'));
|
||||
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '!=5.3'));
|
||||
|
||||
$this->assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '<=5.2'));
|
||||
$this->assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '<5.2'));
|
||||
$this->assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '>=7.0'));
|
||||
$this->assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '>7.0'));
|
||||
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '!=5.2'));
|
||||
}
|
||||
}
|
||||
123
#pma/test/classes/ZipFileTest.php
Normal file
123
#pma/test/classes/ZipFileTest.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests PMA\libraries\ZipFile
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\ZipFile;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\ZipFile
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ZipFileTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new ZipFile();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setDoWrite
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetDoWrite()
|
||||
{
|
||||
$this->object->setDoWrite();
|
||||
$this->assertTrue($this->object->doWrite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for unix2DosTime
|
||||
*
|
||||
* @param int $unixTime UNIX timestamp
|
||||
* @param int $output DOS timestamp
|
||||
*
|
||||
* @dataProvider providerForTestUnix2DosTime
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUnix2DosTime($unixTime, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->unix2DosTime($unixTime),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for testUnix2DosTime
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerForTestUnix2DosTime()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
123456,
|
||||
2162688
|
||||
),
|
||||
array(
|
||||
234232,
|
||||
2162688
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for addFile
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddFile()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->addFile('This is test content for the file', 'Test file'),
|
||||
''
|
||||
);
|
||||
$this->assertTrue(!empty($this->object->ctrl_dir));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFile()
|
||||
{
|
||||
$file = $this->object->file();
|
||||
$this->assertTrue(
|
||||
!empty($file)
|
||||
);
|
||||
}
|
||||
}
|
||||
10
#pma/test/classes/_data/gen_version_info/info.inc.php
Normal file
10
#pma/test/classes/_data/gen_version_info/info.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Full information about theme, including $theme_generation and $theme_version
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
$theme_name = 'Test Theme';
|
||||
$theme_generation = "2";
|
||||
$theme_version = "0.3";
|
||||
10
#pma/test/classes/_data/incorrect_theme/info.inc.php
Normal file
10
#pma/test/classes/_data/incorrect_theme/info.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Incorrect theme information file.
|
||||
* Full name is not specified
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
$theme_full_version = '1.0';
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* DatabaseStructureController_Test class
|
||||
*
|
||||
* this class is for testing DatabaseStructureController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\controllers\database\DatabaseStructureController;
|
||||
use PMA\libraries\di\Container;
|
||||
use PMA\libraries\Table;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/libraries/stubs/ResponseStub.php';
|
||||
|
||||
/**
|
||||
* DatabaseStructureController_Test class
|
||||
*
|
||||
* this class is for testing DatabaseStructureController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class DatabaseStructureControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var \PMA\Test\Stubs\Response
|
||||
*/
|
||||
private $_response;
|
||||
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
$_REQUEST['pos'] = 3;
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['table'] = "table";
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
|
||||
if (!defined('PMA_USR_BROWSER_AGENT')) {
|
||||
define('PMA_USR_BROWSER_AGENT', 'Other');
|
||||
}
|
||||
|
||||
$table = $this->getMockBuilder('PMA\libraries\Table')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
// Expect the table will have 6 rows
|
||||
$table->expects($this->any())->method('getRealRowCountTable')
|
||||
->will($this->returnValue(6));
|
||||
$table->expects($this->any())->method('countRecords')
|
||||
->will($this->returnValue(6));
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())->method('getTable')
|
||||
->will($this->returnValue($table));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('db', 'db');
|
||||
$container->set('table', 'table');
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$this->_response = new \PMA\Test\Stubs\Response();
|
||||
$container->set('PMA\libraries\Response', $this->_response);
|
||||
$container->alias('response', 'PMA\libraries\Response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getValuesForInnodbTable()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetValuesForInnodbTable()
|
||||
{
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('db', 'db');
|
||||
$container->set('table', 'table');
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$response = new \PMA\Test\Stubs\Response();
|
||||
$container->set('PMA\libraries\Response', $response);
|
||||
$container->alias('response', 'PMA\libraries\Response');
|
||||
|
||||
$class = new ReflectionClass('PMA\libraries\controllers\database\DatabaseStructureController');
|
||||
$method = $class->getMethod('getValuesForInnodbTable');
|
||||
$method->setAccessible(true);
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
// Showing statistics
|
||||
$property = $class->getProperty('_is_show_stats');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, true);
|
||||
|
||||
$GLOBALS['cfg']['MaxExactCount'] = 10;
|
||||
$current_table = array(
|
||||
'ENGINE' => 'InnoDB',
|
||||
'TABLE_ROWS' => 5,
|
||||
'Data_length' => 16384,
|
||||
'Index_length' => 0,
|
||||
'TABLE_NAME' => 'table'
|
||||
);
|
||||
list($current_table,,, $sum_size)
|
||||
= $method->invokeArgs($ctrl, array($current_table, 10));
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$current_table['COUNTED']
|
||||
);
|
||||
$this->assertEquals(
|
||||
6,
|
||||
$current_table['TABLE_ROWS']
|
||||
);
|
||||
$this->assertEquals(
|
||||
16394,
|
||||
$sum_size
|
||||
);
|
||||
|
||||
$current_table['ENGINE'] = 'MYISAM';
|
||||
list($current_table,,, $sum_size)
|
||||
= $method->invokeArgs($ctrl, array($current_table, 10));
|
||||
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$current_table['COUNTED']
|
||||
);
|
||||
$this->assertEquals(
|
||||
16394,
|
||||
$sum_size
|
||||
);
|
||||
// Not showing statistics
|
||||
$is_show_stats = false;
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
|
||||
$current_table['ENGINE'] = 'InnoDB';
|
||||
list($current_table,,, $sum_size)
|
||||
= $method->invokeArgs($ctrl, array($current_table, 10));
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$current_table['COUNTED']
|
||||
);
|
||||
$this->assertEquals(
|
||||
10,
|
||||
$sum_size
|
||||
);
|
||||
|
||||
$current_table['ENGINE'] = 'MYISAM';
|
||||
list($current_table,,, $sum_size)
|
||||
= $method->invokeArgs($ctrl, array($current_table, 10));
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$current_table['COUNTED']
|
||||
);
|
||||
$this->assertEquals(
|
||||
10,
|
||||
$sum_size
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the getValuesForAriaTable()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetValuesForAriaTable()
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\controllers\database\DatabaseStructureController');
|
||||
$method = $class->getMethod('getValuesForAriaTable');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
// Showing statistics
|
||||
$property = $class->getProperty('_is_show_stats');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, true);
|
||||
$property = $class->getProperty('_db_is_system_schema');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, true);
|
||||
|
||||
$current_table = array(
|
||||
'Data_length' => 16384,
|
||||
'Index_length' => 0,
|
||||
'Name' => 'table',
|
||||
'Data_free' => 300,
|
||||
);
|
||||
list($current_table,,,,, $overhead_size, $sum_size)
|
||||
= $method->invokeArgs($ctrl, array($current_table, 0, 0, 0, 0, 0, 0,));
|
||||
$this->assertEquals(
|
||||
6,
|
||||
$current_table['Rows']
|
||||
);
|
||||
$this->assertEquals(
|
||||
16384,
|
||||
$sum_size
|
||||
);
|
||||
$this->assertEquals(
|
||||
300,
|
||||
$overhead_size
|
||||
);
|
||||
|
||||
unset($current_table['Data_free']);
|
||||
list($current_table,,,,, $overhead_size,)
|
||||
= $method->invokeArgs($ctrl, array($current_table, 0, 0, 0, 0, 0, 0,));
|
||||
$this->assertEquals(0, $overhead_size);
|
||||
|
||||
$is_show_stats = false;
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
list($current_table,,,,,, $sum_size)
|
||||
= $method->invokeArgs($ctrl, array($current_table, 0, 0, 0, 0, 0, 0));
|
||||
$this->assertEquals(0, $sum_size);
|
||||
|
||||
$db_is_system_schema = false;
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
list($current_table,,,,,,)
|
||||
= $method->invokeArgs($ctrl, array($current_table, 0, 0, 0, 0, 0, 0,));
|
||||
$this->assertArrayNotHasKey('Row', $current_table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for hasTable()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testHasTable()
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\controllers\database\DatabaseStructureController');
|
||||
$method = $class->getMethod('hasTable');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
|
||||
// When parameter $db is empty
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$method->invokeArgs($ctrl, array(array(), 'table'))
|
||||
);
|
||||
|
||||
// Correct parameter
|
||||
$tables = array(
|
||||
'db.table'
|
||||
);
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$method->invokeArgs($ctrl, array($tables, 'table'))
|
||||
);
|
||||
|
||||
// Table not in database
|
||||
$tables = array(
|
||||
'db.tab1e'
|
||||
);
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$method->invokeArgs($ctrl, array($tables, 'table'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for checkFavoriteTable()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testCheckFavoriteTable()
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\controllers\database\DatabaseStructureController');
|
||||
$method = $class->getMethod('checkFavoriteTable');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
|
||||
$_SESSION['tmpval']['favorite_tables'][$GLOBALS['server']] = array(
|
||||
array('db' => 'db', 'table' => 'table')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$method->invokeArgs($ctrl, array(''))
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$method->invokeArgs($ctrl, array('table'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for synchronizeFavoriteTables()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testSynchronizeFavoriteTables()
|
||||
{
|
||||
$fav_instance = $this->getMockBuilder('PMA\libraries\RecentFavoriteTable')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$fav_instance->expects($this->at(1))->method('getTables')
|
||||
->will($this->returnValue(array()));
|
||||
$fav_instance->expects($this->at(2))
|
||||
->method('getTables')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
array('db' => 'db', 'table' => 'table'),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$class = new ReflectionClass('PMA\libraries\controllers\database\DatabaseStructureController');
|
||||
$method = $class->getMethod('synchronizeFavoriteTables');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
|
||||
// The user hash for test
|
||||
$user = 'abcdefg';
|
||||
$favorite_table = array(
|
||||
$user => array(
|
||||
array('db' => 'db', 'table' => 'table')
|
||||
),
|
||||
);
|
||||
|
||||
$method->invokeArgs($ctrl, array($fav_instance, $user, $favorite_table));
|
||||
$json = $this->_response->getJSONResult();
|
||||
|
||||
$this->assertEquals(json_encode($favorite_table), $json['favorite_tables']);
|
||||
$this->assertArrayHasKey('list', $json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for handleRealRowCountRequestAction()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testHandleRealRowCountRequestAction()
|
||||
{
|
||||
$_REQUEST['table'] = 'table';
|
||||
|
||||
$ctrl = new DatabaseStructureController(
|
||||
$GLOBALS['db'], null
|
||||
);
|
||||
// Showing statistics
|
||||
$class = new ReflectionClass('PMA\libraries\controllers\database\DatabaseStructureController');
|
||||
$property = $class->getProperty('_tables');
|
||||
$property->setAccessible(true);
|
||||
|
||||
$ctrl->handleRealRowCountRequestAction();
|
||||
$json = $this->_response->getJSONResult();
|
||||
$this->assertEquals(
|
||||
6,
|
||||
$json['real_row_count']
|
||||
);
|
||||
|
||||
// Fall into another branch
|
||||
$_REQUEST['real_row_count_all'] = 'abc';
|
||||
$property->setValue(
|
||||
$ctrl,
|
||||
array(
|
||||
array(
|
||||
'TABLE_NAME' => 'table'
|
||||
)
|
||||
)
|
||||
);
|
||||
$ctrl->handleRealRowCountRequestAction();
|
||||
$json = $this->_response->getJSONResult();
|
||||
|
||||
$expected_result = array(
|
||||
array(
|
||||
'table' => 'table',
|
||||
'row_count' => 6
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
json_encode($expected_result),
|
||||
$json['real_row_count_all']
|
||||
);
|
||||
}
|
||||
}
|
||||
284
#pma/test/classes/controllers/ServerBinlogControllerTest.php
Normal file
284
#pma/test/classes/controllers/ServerBinlogControllerTest.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds ServerBinlogControllerTest
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\Theme;
|
||||
use PMA\libraries\controllers\server\ServerBinlogController;
|
||||
use PMA\libraries\di\Container;
|
||||
use PMA\libraries\Util;
|
||||
|
||||
require_once 'test/PMATestCase.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
|
||||
/**
|
||||
* Tests for ServerCollationsController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ServerBinlogControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
$_REQUEST['pos'] = 3;
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['cfg']['MaxRows'] = 10;
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['ServerDefault'] = "server";
|
||||
$GLOBALS['cfg']['RememberSorting'] = true;
|
||||
$GLOBALS['cfg']['SQP'] = array();
|
||||
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
|
||||
$GLOBALS['cfg']['ShowSQL'] = true;
|
||||
$GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
|
||||
$GLOBALS['cfg']['LimitChars'] = 100;
|
||||
|
||||
$GLOBALS['table'] = "table";
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
|
||||
Util::cacheSet('profiling_supported', true);
|
||||
|
||||
$binary_log_file_names = array();
|
||||
$binary_log_file_names[] = array("Log_name"=>"index1", "File_size"=>100);
|
||||
$binary_log_file_names[] = array("Log_name"=>"index2", "File_size"=>200);
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())->method('fetchResult')
|
||||
->will($this->returnValue($binary_log_file_names));
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $dbi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _getLogSelector
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLogSelector()
|
||||
{
|
||||
$url_params = array();
|
||||
$url_params['log'] = "log";
|
||||
$url_params['dontlimitchars'] = 1;
|
||||
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerBinlogController');
|
||||
$method = $class->getMethod('_getLogSelector');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$ctrl = new ServerBinlogController();
|
||||
$html = $method->invoke(
|
||||
$ctrl,
|
||||
$url_params
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'Select binary log to view',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<option value="index1" selected="selected">',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<option value="index2">',
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _getLogInfo
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetLogInfo()
|
||||
{
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerBinlogController');
|
||||
$method = $class->getMethod('_getLogInfo');
|
||||
$method->setAccessible(true);
|
||||
$ctrl = new ServerBinlogController();
|
||||
|
||||
//Mock DBI
|
||||
$container = Container::getDefaultContainer();
|
||||
$dbi = $container->get('dbi');
|
||||
|
||||
//expects return value
|
||||
$result = array(
|
||||
array(
|
||||
"SHOW BINLOG EVENTS IN 'index1' LIMIT 3, 10",
|
||||
null,
|
||||
1,
|
||||
true,
|
||||
array("log1"=>"logd")
|
||||
),
|
||||
array(
|
||||
array("log2"=>"logb"),
|
||||
null,
|
||||
0,
|
||||
false,
|
||||
'executed'
|
||||
)
|
||||
);
|
||||
$value = array(
|
||||
'Info' => "index1_Info",
|
||||
'Log_name' => "index1_Log_name",
|
||||
'Pos' => "index1_Pos",
|
||||
'Event_type' => "index1_Event_type",
|
||||
'End_log_pos' => "index1_End_log_pos",
|
||||
'Server_id' => "index1_Server_id",
|
||||
);
|
||||
$count = 3;
|
||||
|
||||
//expects functions
|
||||
$dbi->expects($this->once())->method('query')
|
||||
->will($this->returnValue($result));
|
||||
|
||||
$dbi->expects($this->once())->method('numRows')
|
||||
->will($this->returnValue($count));
|
||||
|
||||
$dbi->expects($this->at(0))->method('fetchAssoc')
|
||||
->will($this->returnValue($value));
|
||||
|
||||
$dbi->expects($this->at(1))->method('fetchAssoc')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$container->set('dbi', $dbi);
|
||||
|
||||
//Call the test function
|
||||
$url_params = array();
|
||||
$url_params['log'] = "log";
|
||||
$url_params['dontlimitchars'] = 1;
|
||||
$html = $method->invoke($ctrl, $url_params);
|
||||
|
||||
//validate 1: the sql has been executed
|
||||
$this->assertContains(
|
||||
'Your SQL query has been executed successfully',
|
||||
$html
|
||||
);
|
||||
//validate 2: SQL
|
||||
$this->assertContains(
|
||||
"SHOW BINLOG EVENTS IN 'index1' LIMIT 3, 10",
|
||||
$html
|
||||
);
|
||||
//validate 3: BINLOG HTML
|
||||
$this->assertContains(
|
||||
'<table id="binlogTable">',
|
||||
$html
|
||||
);
|
||||
//validate 4: PMA_getNavigationRow is right
|
||||
$urlNavigation = 'server_binlog.php?log=log&dontlimitchars=1&'
|
||||
. 'pos=3&server=1&';
|
||||
$this->assertContains(
|
||||
$urlNavigation,
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'title="Previous"',
|
||||
$html
|
||||
);
|
||||
//validate 5: Log Item
|
||||
$this->assertContains(
|
||||
'Log name',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'Position',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'Event type',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'Server ID',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'Original position',
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _getAllLogItemInfo
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetAllLogItemInfo()
|
||||
{
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerBinlogController');
|
||||
$method = $class->getMethod('_getAllLogItemInfo');
|
||||
$method->setAccessible(true);
|
||||
$ctrl = new ServerBinlogController();
|
||||
|
||||
//Mock DBI
|
||||
$container = Container::getDefaultContainer();
|
||||
$dbi = $container->get('dbi');
|
||||
|
||||
$fetchAssoc = array(
|
||||
'Info' => 'Info',
|
||||
'Log_name' => 'Log_name',
|
||||
'Pos' => 'Pos',
|
||||
'Event_type' => 'Event_type',
|
||||
'Server_id' => 'Server_id',
|
||||
'Orig_log_pos' => 'Orig_log_pos',
|
||||
'End_log_pos' => 'End_log_pos',
|
||||
);
|
||||
$dbi->expects($this->at(0))->method('fetchAssoc')
|
||||
->will($this->returnValue($fetchAssoc));
|
||||
$dbi->expects($this->at(1))->method('fetchAssoc')
|
||||
->will($this->returnValue(false));
|
||||
$container->set('dbi', $dbi);
|
||||
|
||||
$GLOBALS['cfg']['LimitChars'] = 2;
|
||||
|
||||
$result = array();
|
||||
$dontlimitchars = ";";
|
||||
$html = $method->invoke($ctrl, $result, $dontlimitchars);
|
||||
|
||||
$value = $fetchAssoc;
|
||||
$this->assertContains(
|
||||
$value['Log_name'],
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
$value['Pos'],
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
$value['Event_type'],
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
$value['Server_id'],
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
$value['Orig_log_pos'],
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
htmlspecialchars($value['Info']),
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
151
#pma/test/classes/controllers/ServerCollationsControllerTest.php
Normal file
151
#pma/test/classes/controllers/ServerCollationsControllerTest.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds ServerCollationsControllerTest class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
//$GLOBALS
|
||||
use PMA\libraries\Theme;
|
||||
use PMA\libraries\controllers\server\ServerCollationsController;
|
||||
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['is_superuser'] = false;
|
||||
$GLOBALS['cfg']['ServerDefault'] = 1;
|
||||
$GLOBALS['url_query'] = "url_query";
|
||||
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
|
||||
$GLOBALS['lang'] = "en";
|
||||
$GLOBALS['text_dir'] = "text_dir";
|
||||
$GLOBALS['cfg']['Server'] = array(
|
||||
'DisableIS' => false
|
||||
);
|
||||
//$_SESSION
|
||||
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/server_common.inc.php';
|
||||
require_once 'libraries/mysql_charsets.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for ServerCollationsController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ServerCollationsControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
$_REQUEST['pos'] = 3;
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['is_ajax_request'] = true;
|
||||
$GLOBALS['table'] = "table";
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getHtmlForCharsets
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPMAGetHtmlForCharsets()
|
||||
{
|
||||
$mysql_charsets = array("armscii8", "ascii", "big5", "binary");
|
||||
$mysql_collations = array(
|
||||
"armscii8" => array("armscii8"),
|
||||
"ascii" => array("ascii"),
|
||||
"big5" => array("big5"),
|
||||
"binary" => array("binary"),
|
||||
);
|
||||
$mysql_charsets_descriptions = array(
|
||||
"armscii8" => "PMA_armscii8_general_ci",
|
||||
"ascii" => "PMA_ascii_general_ci",
|
||||
"big5" => "PMA_big5_general_ci",
|
||||
"binary" => "PMA_binary_general_ci",
|
||||
);
|
||||
$mysql_default_collations = array(
|
||||
"armscii8" => "armscii8",
|
||||
"ascii" => "ascii",
|
||||
"big5" => "big5",
|
||||
"binary" => "binary",
|
||||
);
|
||||
$mysql_collations_available = array(
|
||||
"armscii8" => true,
|
||||
"ascii" => true,
|
||||
"big5" => true,
|
||||
"binary" => true,
|
||||
);
|
||||
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerCollationsController');
|
||||
$method = $class->getMethod('_getHtmlForCharsets');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$ctrl = new ServerCollationsController();
|
||||
$html = $method->invoke(
|
||||
$ctrl,
|
||||
$mysql_charsets,
|
||||
$mysql_collations,
|
||||
$mysql_charsets_descriptions,
|
||||
$mysql_default_collations,
|
||||
$mysql_collations_available
|
||||
);
|
||||
|
||||
//validate 1: Charset HTML
|
||||
$this->assertContains(
|
||||
'<div id="div_mysql_charset_collations">',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
__('Collation'),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
__('Description'),
|
||||
$html
|
||||
);
|
||||
//validate 2: Charset Item
|
||||
$this->assertContains(
|
||||
'<i>PMA_armscii8_general_ci</i>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<td>armscii8</td>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<i>PMA_ascii_general_ci</i>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<td>ascii</td>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<i>PMA_big5_general_ci</i>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<td>big5</td>',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
324
#pma/test/classes/controllers/ServerDatabasesControllerTest.php
Normal file
324
#pma/test/classes/controllers/ServerDatabasesControllerTest.php
Normal file
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds ServerDatabasesControllerTest class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\di\Container;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/mysql_charsets.lib.php';
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
|
||||
require_once 'test/libraries/stubs/ResponseStub.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for ServerDatabasesController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
class ServerDatabasesControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
$_REQUEST['pos'] = 3;
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['is_superuser'] = true;
|
||||
|
||||
$GLOBALS['table'] = "table";
|
||||
$GLOBALS['replication_info']['master']['status'] = false;
|
||||
$GLOBALS['replication_info']['slave']['status'] = false;
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$GLOBALS['text_dir'] = "text_dir";
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['server'] = 1;
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$this->response = new \PMA\Test\Stubs\Response();
|
||||
$container->set('PMA\libraries\Response', $this->response);
|
||||
$container->alias('response', 'PMA\libraries\Response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _getHtmlForDatabases
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetHtmlForDatabase()
|
||||
{
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerDatabasesController');
|
||||
$method = $class->getMethod('_getHtmlForDatabases');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory('PMA\libraries\controllers\server\ServerDatabasesController');
|
||||
$container->alias(
|
||||
'ServerDatabasesController', 'PMA\libraries\controllers\server\ServerDatabasesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerDatabasesController');
|
||||
|
||||
//Call the test function
|
||||
$databases = array(
|
||||
array("SCHEMA_NAME" => "pma_bookmark"),
|
||||
array("SCHEMA_NAME" => "information_schema"),
|
||||
array("SCHEMA_NAME" => "mysql"),
|
||||
array("SCHEMA_NAME" => "performance_schema"),
|
||||
array("SCHEMA_NAME" => "phpmyadmin")
|
||||
);
|
||||
$property = $class->getProperty('_databases');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, $databases);
|
||||
|
||||
$property = $class->getProperty('_database_count');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, 5);
|
||||
|
||||
$property = $class->getProperty('_pos');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, 0);
|
||||
|
||||
$property = $class->getProperty('_dbstats');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, 0);
|
||||
|
||||
$property = $class->getProperty('_sort_by');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, 'SCHEMA_NAME');
|
||||
|
||||
$property = $class->getProperty('_sort_order');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($ctrl, 'asc');
|
||||
|
||||
$replication_types = array("master", "slave");
|
||||
|
||||
$html = $method->invoke($ctrl, $replication_types);
|
||||
|
||||
//validate 1: General info
|
||||
$this->assertContains(
|
||||
'<div id="tableslistcontainer">',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 2:ajax Form
|
||||
$this->assertContains(
|
||||
'<form class="ajax" action="server_databases.php" ',
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<table id="tabledatabases" class="data">',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 3: PMA_getHtmlForColumnOrderWithSort
|
||||
$this->assertContains(
|
||||
'<a href="server_databases.php',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'sort_by=SCHEMA_NAME',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 4: PMA_getHtmlAndColumnOrderForDatabaseList
|
||||
$this->assertRegExp(
|
||||
'/title="pma_bookmark"[[:space:]]*value="pma_bookmark"/',
|
||||
$html
|
||||
);
|
||||
$this->assertRegExp(
|
||||
'/title="information_schema"[[:space:]]*value="information_schema"/',
|
||||
$html
|
||||
);
|
||||
$this->assertRegExp(
|
||||
'/title="performance_schema"[[:space:]]*value="performance_schema"/',
|
||||
$html
|
||||
);
|
||||
$this->assertRegExp(
|
||||
'/title="phpmyadmin"[[:space:]]*value="phpmyadmin"/',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 5: PMA_getHtmlForTableFooter
|
||||
$this->assertContains(
|
||||
'Total: <span id="databases_count">5</span>',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 6: PMA_getHtmlForTableFooterButtons
|
||||
$this->assertContains(
|
||||
'Check all',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 7: PMA_getHtmlForNoticeEnableStatistics
|
||||
$this->assertContains(
|
||||
'Note: Enabling the database statistics here might cause heavy traffic',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'Enable statistics',
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _setSortDetails()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetSortDetails()
|
||||
{
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerDatabasesController');
|
||||
$method = $class->getMethod('_setSortDetails');
|
||||
$method->setAccessible(true);
|
||||
$propertySortBy = $class->getProperty('_sort_by');
|
||||
$propertySortBy->setAccessible(true);
|
||||
$propertySortOrder = $class->getProperty('_sort_order');
|
||||
$propertySortOrder->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory('PMA\libraries\controllers\server\ServerDatabasesController');
|
||||
$container->alias(
|
||||
'ServerDatabasesController', 'PMA\libraries\controllers\server\ServerDatabasesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerDatabasesController');
|
||||
|
||||
//$_REQUEST['sort_by'] and $_REQUEST['sort_order'] are empty
|
||||
$method->invoke($ctrl, array("master", "slave"));
|
||||
$this->assertEquals(
|
||||
'SCHEMA_NAME',
|
||||
$propertySortBy->getValue($ctrl)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'asc',
|
||||
$propertySortOrder->getValue($ctrl)
|
||||
);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory('PMA\libraries\controllers\server\ServerDatabasesController');
|
||||
$container->alias(
|
||||
'ServerDatabasesController', 'PMA\libraries\controllers\server\ServerDatabasesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerDatabasesController');
|
||||
|
||||
// $_REQUEST['sort_by'] = 'DEFAULT_COLLATION_NAME'
|
||||
// and $_REQUEST['sort_order'] is not 'desc'
|
||||
$_REQUEST['sort_by'] = 'DEFAULT_COLLATION_NAME';
|
||||
$_REQUEST['sort_order'] = 'abc';
|
||||
$method->invoke($ctrl);
|
||||
$this->assertEquals(
|
||||
'DEFAULT_COLLATION_NAME',
|
||||
$propertySortBy->getValue($ctrl)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'asc',
|
||||
$propertySortOrder->getValue($ctrl)
|
||||
);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory('PMA\libraries\controllers\server\ServerDatabasesController');
|
||||
$container->alias(
|
||||
'ServerDatabasesController', 'PMA\libraries\controllers\server\ServerDatabasesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerDatabasesController');
|
||||
|
||||
// $_REQUEST['sort_by'] = 'DEFAULT_COLLATION_NAME'
|
||||
// and $_REQUEST['sort_order'] is 'desc'
|
||||
$_REQUEST['sort_by'] = 'DEFAULT_COLLATION_NAME';
|
||||
$_REQUEST['sort_order'] = 'desc';
|
||||
$method->invoke($ctrl);
|
||||
$this->assertEquals(
|
||||
'DEFAULT_COLLATION_NAME',
|
||||
$propertySortBy->getValue($ctrl)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'desc',
|
||||
$propertySortOrder->getValue($ctrl)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _getColumnOrder()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetColumnOrder()
|
||||
{
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerDatabasesController');
|
||||
$method = $class->getMethod('_getColumnOrder');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory('PMA\libraries\controllers\server\ServerDatabasesController');
|
||||
$container->alias(
|
||||
'ServerDatabasesController', 'PMA\libraries\controllers\server\ServerDatabasesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerDatabasesController');
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'DEFAULT_COLLATION_NAME' => array(
|
||||
'disp_name' => __('Collation'),
|
||||
'description_function' => 'PMA_getCollationDescr',
|
||||
'format' => 'string',
|
||||
'footer' => 'utf8_general_ci'
|
||||
),
|
||||
'SCHEMA_TABLES' => array(
|
||||
'disp_name' => __('Tables'),
|
||||
'format' => 'number',
|
||||
'footer' => 0
|
||||
),
|
||||
'SCHEMA_TABLE_ROWS' => array(
|
||||
'disp_name' => __('Rows'),
|
||||
'format' => 'number',
|
||||
'footer' => 0
|
||||
),
|
||||
'SCHEMA_DATA_LENGTH' => array(
|
||||
'disp_name' => __('Data'),
|
||||
'format' => 'byte',
|
||||
'footer' => 0
|
||||
),
|
||||
'SCHEMA_INDEX_LENGTH' => array(
|
||||
'disp_name' => __('Indexes'),
|
||||
'format' => 'byte',
|
||||
'footer' => 0
|
||||
),
|
||||
'SCHEMA_LENGTH' => array(
|
||||
'disp_name' => __('Total'),
|
||||
'format' => 'byte',
|
||||
'footer' => 0
|
||||
),
|
||||
'SCHEMA_DATA_FREE' => array(
|
||||
'disp_name' => __('Overhead'),
|
||||
'format' => 'byte',
|
||||
'footer' => 0
|
||||
)
|
||||
),
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
}
|
||||
}
|
||||
170
#pma/test/classes/controllers/ServerEnginesControllerTest.php
Normal file
170
#pma/test/classes/controllers/ServerEnginesControllerTest.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds ServerEnginesControllerTest class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\StorageEngine;
|
||||
use PMA\libraries\Theme;
|
||||
use PMA\libraries\controllers\server\ServerEnginesController;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for ServerEnginesController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ServerEnginesControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
$_REQUEST['pos'] = 3;
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['table'] = "table";
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _getHtmlForAllServerEngines() method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHtmlForAllServerEngines()
|
||||
{
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerEnginesController');
|
||||
$method = $class->getMethod('_getHtmlForAllServerEngines');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$ctrl = new ServerEnginesController();
|
||||
$html = $method->invoke($ctrl);
|
||||
|
||||
//validate 1: Item header
|
||||
$this->assertContains(
|
||||
'<th>Storage Engine</th>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<th>Description</th>',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 2: FEDERATED
|
||||
$this->assertContains(
|
||||
'<td>Federated MySQL storage engine</td>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'FEDERATED',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'server_engines.php?engine=FEDERATED',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 3: dummy
|
||||
$this->assertContains(
|
||||
'<td>dummy comment</td>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'dummy',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'server_engines.php?engine=dummy',
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _getHtmlForServerEngine() method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHtmlForServerEngine()
|
||||
{
|
||||
$_REQUEST['engine'] = "Pbxt";
|
||||
$_REQUEST['page'] = "page";
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerEnginesController');
|
||||
$method = $class->getMethod('_getHtmlForServerEngine');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$engine_plugin = StorageEngine::getEngine("Pbxt");
|
||||
$ctrl = new ServerEnginesController();
|
||||
$html = $method->invoke($ctrl, $engine_plugin);
|
||||
|
||||
//validate 1: Engine title
|
||||
$this->assertContains(
|
||||
htmlspecialchars($engine_plugin->getTitle()),
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 2: Engine Mysql Help Page
|
||||
$this->assertContains(
|
||||
PMA\libraries\Util::showMySQLDocu($engine_plugin->getMysqlHelpPage()),
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 3: Engine Comment
|
||||
$this->assertContains(
|
||||
htmlspecialchars($engine_plugin->getComment()),
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 4: Engine Info Pages
|
||||
$this->assertContains(
|
||||
__('Variables'),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA_URL_getCommon(
|
||||
array('engine' => $_REQUEST['engine'], 'page' => "Documentation")
|
||||
),
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 5: other items
|
||||
$this->assertContains(
|
||||
PMA_URL_getCommon(array('engine' => $_REQUEST['engine'])),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
$engine_plugin->getSupportInformationMessage(),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'There is no detailed status information available for this '
|
||||
. 'storage engine.',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
139
#pma/test/classes/controllers/ServerPluginsControllerTest.php
Normal file
139
#pma/test/classes/controllers/ServerPluginsControllerTest.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds ServerPluginsControllerTest class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\Theme;
|
||||
use PMA\libraries\controllers\server\ServerPluginsController;
|
||||
use PMA\libraries\di\Container;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for ServerPluginsController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ServerPluginsControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
$_REQUEST['pos'] = 3;
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['table'] = "table";
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getPluginsHtml() method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPMAGetPluginAndModuleInfo()
|
||||
{
|
||||
/**
|
||||
* Prepare plugin list
|
||||
*/
|
||||
$row = array();
|
||||
$row["plugin_name"] = "plugin_name1";
|
||||
$row["plugin_type"] = "plugin_type1";
|
||||
$row["plugin_type_version"] = "plugin_version1";
|
||||
$row["plugin_author"] = "plugin_author1";
|
||||
$row["plugin_license"] = "plugin_license1";
|
||||
$row["plugin_description"] = "plugin_description1";
|
||||
$row["is_active"] = true;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->will($this->returnValue(true));
|
||||
$dbi->expects($this->at(1))
|
||||
->method('fetchAssoc')
|
||||
->will($this->returnValue($row));
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fetchAssoc')
|
||||
->will($this->returnValue(false));
|
||||
$dbi->expects($this->once())
|
||||
->method('freeResult')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $dbi);
|
||||
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerPluginsController');
|
||||
$method = $class->getMethod('_getPluginsHtml');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$ctrl = new ServerPluginsController();
|
||||
$html = $method->invoke($ctrl);
|
||||
|
||||
//validate 1:Items
|
||||
$this->assertContains(
|
||||
'<th>Plugin</th>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<th>Description</th>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<th>Version</th>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<th>Author</th>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<th>License</th>',
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 2: one Item HTML
|
||||
$this->assertContains(
|
||||
'plugin_name1',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<td>plugin_description1</td>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<td>plugin_version1</td>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<td>plugin_author1</td>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<td>plugin_license1</td>',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
320
#pma/test/classes/controllers/ServerVariablesControllerTest.php
Normal file
320
#pma/test/classes/controllers/ServerVariablesControllerTest.php
Normal file
@@ -0,0 +1,320 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds ServerVariablesControllerTest class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\di\Container;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/libraries/stubs/ResponseStub.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
|
||||
/**
|
||||
* Tests for ServerVariablesController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ServerVariablesControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var \PMA\Test\Stubs\Response
|
||||
*/
|
||||
private $_response;
|
||||
|
||||
/**
|
||||
* Test for setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
$_REQUEST['pos'] = 3;
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['table'] = "table";
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
//this data is needed when ServerStatusData constructs
|
||||
$server_session_variable = array(
|
||||
"auto_increment_increment" => "1",
|
||||
"auto_increment_offset" => "13",
|
||||
"automatic_sp_privileges" => "ON",
|
||||
"back_log" => "50",
|
||||
"big_tables" => "OFF",
|
||||
);
|
||||
|
||||
$server_global_variables = array(
|
||||
"auto_increment_increment" => "0",
|
||||
"auto_increment_offset" => "12"
|
||||
);
|
||||
|
||||
$fetchResult = array(
|
||||
array(
|
||||
"SHOW SESSION VARIABLES;",
|
||||
0,
|
||||
1,
|
||||
null,
|
||||
0,
|
||||
$server_session_variable
|
||||
),
|
||||
array(
|
||||
"SHOW GLOBAL VARIABLES;",
|
||||
0,
|
||||
1,
|
||||
null,
|
||||
0,
|
||||
$server_global_variables
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())->method('fetchResult')
|
||||
->will($this->returnValueMap($fetchResult));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$this->_response = new \PMA\Test\Stubs\Response();
|
||||
$container->set('PMA\libraries\Response', $this->_response);
|
||||
$container->alias('response', 'PMA\libraries\Response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _formatVariable()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFormatVariable()
|
||||
{
|
||||
$class = new ReflectionClass(
|
||||
'\PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$method = $class->getMethod('_formatVariable');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory(
|
||||
'PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$container->alias(
|
||||
'ServerVariablesController',
|
||||
'PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerVariablesController');
|
||||
|
||||
//Call the test function
|
||||
$name_for_value_byte = "binlog_cache_size";
|
||||
$name_for_value_not_byte = "auto_increment_increment";
|
||||
$name_for_value_not_num = "PMA_key";
|
||||
|
||||
//name is_numeric and the value type is byte
|
||||
$this->assertEquals(
|
||||
'<abbr title="3">3 B</abbr>',
|
||||
$method->invoke($ctrl, $name_for_value_byte, "3")
|
||||
);
|
||||
|
||||
//name is_numeric and the value type is not byte
|
||||
$this->assertEquals(
|
||||
'3',
|
||||
$method->invoke($ctrl, $name_for_value_not_byte, "3")
|
||||
);
|
||||
|
||||
//value is not a number
|
||||
$this->assertEquals(
|
||||
'value',
|
||||
$method->invoke($ctrl, $name_for_value_not_num, "value")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getHtmlForLinkTemplates()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHtmlForLinkTemplates()
|
||||
{
|
||||
$class = new ReflectionClass(
|
||||
'\PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$method = $class->getMethod('_getHtmlForLinkTemplates');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory(
|
||||
'PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$container->alias(
|
||||
'ServerVariablesController',
|
||||
'PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerVariablesController');
|
||||
|
||||
//Call the test function
|
||||
$html = $method->invoke($ctrl);
|
||||
$url = 'server_variables.php' . PMA_URL_getCommon(array());
|
||||
|
||||
//validate 1: URL
|
||||
$this->assertContains(
|
||||
$url,
|
||||
$html
|
||||
);
|
||||
//validate 2: images
|
||||
$this->assertContains(
|
||||
PMA\libraries\Util::getIcon('b_save.png', __('Save')),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA\libraries\Util::getIcon('b_close.png', __('Cancel')),
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getHtmlForServerVariables()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPMAGetHtmlForServerVariables()
|
||||
{
|
||||
|
||||
$class = new ReflectionClass(
|
||||
'\PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$method = $class->getMethod('_getHtmlForServerVariables');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory(
|
||||
'PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$container->alias(
|
||||
'ServerVariablesController',
|
||||
'PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerVariablesController');
|
||||
|
||||
$_REQUEST['filter'] = "auto-commit";
|
||||
$serverVarsSession
|
||||
= $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1);
|
||||
$serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1);
|
||||
|
||||
$html = $method->invoke($ctrl, $serverVars, $serverVarsSession);
|
||||
|
||||
//validate 1: Filters
|
||||
$this->assertContains(
|
||||
'<legend>' . __('Filters') . '</legend>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
__('Containing the word:'),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
$_REQUEST['filter'],
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 2: Server Variables
|
||||
$this->assertContains(
|
||||
'<table id="serverVariables" class="data filteredData noclick">',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
__('Variable'),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
__('Global value'),
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getHtmlForServerVariablesItems()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHtmlForServerVariablesItems()
|
||||
{
|
||||
$class = new ReflectionClass(
|
||||
'\PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$method = $class->getMethod('_getHtmlForServerVariablesItems');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory(
|
||||
'PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$container->alias(
|
||||
'ServerVariablesController',
|
||||
'PMA\libraries\controllers\server\ServerVariablesController'
|
||||
);
|
||||
$ctrl = $container->get('ServerVariablesController');
|
||||
|
||||
$serverVarsSession
|
||||
= $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1);
|
||||
$serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1);
|
||||
|
||||
$html = $method->invoke($ctrl, $serverVars, $serverVarsSession);
|
||||
|
||||
//validate 1: variable: auto_increment_increment
|
||||
$name = "auto_increment_increment";
|
||||
$value = htmlspecialchars(str_replace('_', ' ', $name));
|
||||
$this->assertContains(
|
||||
$value,
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 2: variable: auto_increment_offset
|
||||
$name = "auto_increment_offset";
|
||||
$value = htmlspecialchars(str_replace('_', ' ', $name));
|
||||
$this->assertContains(
|
||||
$value,
|
||||
$html
|
||||
);
|
||||
|
||||
$formatVariable = $class->getMethod('_formatVariable');
|
||||
$formatVariable->setAccessible(true);
|
||||
|
||||
$value = $formatVariable->invoke($ctrl, $name, "12");
|
||||
$this->assertContains(
|
||||
$value,
|
||||
$html
|
||||
);
|
||||
|
||||
//validate 3: variables
|
||||
$this->assertContains(
|
||||
__('Session value'),
|
||||
$html
|
||||
);
|
||||
|
||||
$value = $formatVariable->invoke($ctrl, $name, "13");
|
||||
$this->assertContains(
|
||||
$value,
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
224
#pma/test/classes/controllers/TableIndexesControllerTest.php
Normal file
224
#pma/test/classes/controllers/TableIndexesControllerTest.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for libraries/controllers/TableIndexesController.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\controllers\table\TableIndexesController;
|
||||
use PMA\libraries\di\Container;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'test/libraries/stubs/ResponseStub.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for libraries/controllers/TableIndexesController.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TableIndexesControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Setup function for test cases
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
/**
|
||||
* SET these to avoid undefined index error
|
||||
*/
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['Server']['pmadb'] = '';
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$GLOBALS['url_params'] = array(
|
||||
'db' => 'db',
|
||||
'server' => 1
|
||||
);
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$indexs = array(
|
||||
array(
|
||||
"Schema" => "Schema1",
|
||||
"Key_name"=>"Key_name1",
|
||||
"Column_name"=>"Column_name1"
|
||||
),
|
||||
array(
|
||||
"Schema" => "Schema2",
|
||||
"Key_name"=>"Key_name2",
|
||||
"Column_name"=>"Column_name2"
|
||||
),
|
||||
array(
|
||||
"Schema" => "Schema3",
|
||||
"Key_name"=>"Key_name3",
|
||||
"Column_name"=>"Column_name3"
|
||||
),
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())->method('getTableIndexes')
|
||||
->will($this->returnValue($indexs));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for doSaveDataAction() method
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testDoSaveDataAction()
|
||||
{
|
||||
$sql_query = 'ALTER TABLE `db`.`table` DROP PRIMARY KEY, ADD UNIQUE ;';
|
||||
|
||||
$table = $this->getMockBuilder('PMA\libraries\Table')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$table->expects($this->any())->method('getSqlQueryForIndexCreateOrEdit')
|
||||
->will($this->returnValue($sql_query));
|
||||
|
||||
$GLOBALS['dbi']->expects($this->any())->method('getTable')
|
||||
->will($this->returnValue($table));
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('db', 'db');
|
||||
$container->set('table', 'table');
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$response = new \PMA\Test\Stubs\Response();
|
||||
$container->set('PMA\libraries\Response', $response);
|
||||
$container->alias('response', 'PMA\libraries\Response');
|
||||
|
||||
$ctrl = new TableIndexesController(null);
|
||||
|
||||
// Preview SQL
|
||||
$_REQUEST['preview_sql'] = true;
|
||||
$ctrl->doSaveDataAction();
|
||||
$jsonArray = $response->getJSONResult();
|
||||
$this->assertArrayHasKey('sql_data', $jsonArray);
|
||||
$this->assertContains(
|
||||
$sql_query,
|
||||
$jsonArray['sql_data']
|
||||
);
|
||||
|
||||
// Alter success
|
||||
$response->clear();
|
||||
unset($_REQUEST['preview_sql']);
|
||||
$GLOBALS['is_ajax_request'] = true;
|
||||
$ctrl->doSaveDataAction();
|
||||
$jsonArray = $response->getJSONResult();
|
||||
$this->assertArrayHasKey('index_table', $jsonArray);
|
||||
$this->assertArrayHasKey('message', $jsonArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for displayFormAction()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testDisplayFormAction()
|
||||
{
|
||||
$table = $this->getMockBuilder('PMA\libraries\Table')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$table->expects($this->any())->method('getStatusInfo')
|
||||
->will($this->returnValue(""));
|
||||
$table->expects($this->any())->method('isView')
|
||||
->will($this->returnValue(false));
|
||||
$table->expects($this->any())->method('getNameAndTypeOfTheColumns')
|
||||
->will($this->returnValue(array("field_name" => "field_type")));
|
||||
|
||||
$GLOBALS['dbi']->expects($this->any())->method('getTable')
|
||||
->will($this->returnValue($table));
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('db', 'db');
|
||||
$container->set('table', 'table');
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$response = new \PMA\Test\Stubs\Response();
|
||||
$container->set('PMA\libraries\Response', $response);
|
||||
$container->alias('response', 'PMA\libraries\Response');
|
||||
$index = new PMA\libraries\Index();
|
||||
|
||||
$ctrl = new TableIndexesController($index);
|
||||
|
||||
$_REQUEST['create_index'] = true;
|
||||
$_REQUEST['added_fields'] = 3;
|
||||
$ctrl->displayFormAction();
|
||||
$html = $response->getHTMLResult();
|
||||
|
||||
//PMA_URL_getHiddenInputs
|
||||
$this->assertContains(
|
||||
PMA_URL_getHiddenInputs(
|
||||
array(
|
||||
'db' => 'db',
|
||||
'table' => 'table',
|
||||
'create_index' => 1,
|
||||
)
|
||||
),
|
||||
$html
|
||||
);
|
||||
|
||||
$doc_html = PMA\libraries\Util::showHint(
|
||||
PMA\libraries\Message::notice(
|
||||
__(
|
||||
'"PRIMARY" <b>must</b> be the name of'
|
||||
. ' and <b>only of</b> a primary key!'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertContains(
|
||||
$doc_html,
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
PMA\libraries\Util::showMySQLDocu('ALTER_TABLE'),
|
||||
$html
|
||||
);
|
||||
|
||||
// generateIndexSelector
|
||||
$this->assertContains(
|
||||
$index->generateIndexChoiceSelector(false),
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
sprintf(__('Add %s column(s) to index'), 1),
|
||||
$html
|
||||
);
|
||||
|
||||
//$field_name & $field_type
|
||||
$this->assertContains(
|
||||
"field_name",
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
"field_type",
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
277
#pma/test/classes/controllers/TableRelationControllerTest.php
Normal file
277
#pma/test/classes/controllers/TableRelationControllerTest.php
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for libraries/controllers/TableRelationController.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\di\Container;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'test/libraries/stubs/ResponseStub.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for libraries/controllers/TableRelationController.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TableRelationControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var \PMA\Test\Stubs\Response
|
||||
*/
|
||||
private $_response;
|
||||
|
||||
/**
|
||||
* Configures environment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
|
||||
$_REQUEST['foreignDb'] = 'db';
|
||||
$_REQUEST['foreignTable'] = 'table';
|
||||
|
||||
$GLOBALS['dblist'] = new DataBasePMAMockForTblRelation();
|
||||
$GLOBALS['dblist']->databases = new DataBaseMockForTblRelation();
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('db', 'db');
|
||||
$container->set('table', 'table');
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$this->_response = new \PMA\Test\Stubs\Response();
|
||||
$container->set('PMA\libraries\Response', $this->_response);
|
||||
$container->alias('response', 'PMA\libraries\Response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getDropdownValueForTableAction()
|
||||
*
|
||||
* Case one: this case is for the situation when the target
|
||||
* table is a view.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDropdownValueForTableActionIsView()
|
||||
{
|
||||
$viewColumns = array(
|
||||
'viewCol', 'viewCol2', 'viewCol3'
|
||||
);
|
||||
$tableMock = $this->getMockBuilder('PMA\libraries\Table')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
// Test the situation when the table is a view
|
||||
$tableMock->expects($this->any())->method('isView')
|
||||
->will($this->returnValue(true));
|
||||
$tableMock->expects($this->any())->method('getColumns')
|
||||
->will($this->returnValue($viewColumns));
|
||||
|
||||
$GLOBALS['dbi']->expects($this->any())->method('getTable')
|
||||
->will($this->returnValue($tableMock));
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableRelationController');
|
||||
$container->alias(
|
||||
'TableRelationController',
|
||||
'PMA\libraries\controllers\table\TableRelationController'
|
||||
);
|
||||
/**
|
||||
* @var PMA\libraries\controllers\table\TableRelationController
|
||||
*/
|
||||
$ctrl = $container->get('TableRelationController');
|
||||
|
||||
$ctrl->getDropdownValueForTableAction();
|
||||
$json = $this->_response->getJSONResult();
|
||||
$this->assertEquals(
|
||||
$viewColumns,
|
||||
$json['columns']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getDropdownValueForTableAction()
|
||||
*
|
||||
* Case one: this case is for the situation when the target
|
||||
* table is not a view (real tabletable).
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDropdownValueForTableActionNotView()
|
||||
{
|
||||
$indexedColumns = array(
|
||||
'primaryTableCol'
|
||||
);
|
||||
$tableMock = $this->getMockBuilder('PMA\libraries\Table')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
// Test the situation when the table is a view
|
||||
$tableMock->expects($this->any())->method('isView')
|
||||
->will($this->returnValue(false));
|
||||
$tableMock->expects($this->any())->method('getIndexedColumns')
|
||||
->will($this->returnValue($indexedColumns));
|
||||
|
||||
$GLOBALS['dbi']->expects($this->any())->method('getTable')
|
||||
->will($this->returnValue($tableMock));
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableRelationController');
|
||||
$container->alias(
|
||||
'TableRelationController',
|
||||
'PMA\libraries\controllers\table\TableRelationController'
|
||||
);
|
||||
$ctrl = $container->get('TableRelationController');
|
||||
|
||||
$ctrl->getDropdownValueForTableAction();
|
||||
$json = $this->_response->getJSONResult();
|
||||
$this->assertEquals(
|
||||
$indexedColumns,
|
||||
$json['columns']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getDropdownValueForDbAction()
|
||||
*
|
||||
* Case one: foreign
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDropdownValueForDbActionOne()
|
||||
{
|
||||
$GLOBALS['dbi']->expects($this->any())
|
||||
->method('fetchArray')
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () {
|
||||
static $count = 0;
|
||||
if ($count == 0) {
|
||||
$count++;
|
||||
return array('Engine' => 'InnoDB', 'Name' => 'table',);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableRelationController');
|
||||
$container->alias(
|
||||
'TableRelationController',
|
||||
'PMA\libraries\controllers\table\TableRelationController'
|
||||
);
|
||||
$ctrl = $container->get(
|
||||
'TableRelationController',
|
||||
array('tbl_storage_engine' => 'INNODB')
|
||||
);
|
||||
|
||||
$_REQUEST['foreign'] = 'true';
|
||||
$ctrl->getDropdownValueForDbAction();
|
||||
$json = $this->_response->getJSONResult();
|
||||
$this->assertEquals(
|
||||
array('table'),
|
||||
$json['tables']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getDropdownValueForDbAction()
|
||||
*
|
||||
* Case two: not foreign
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDropdownValueForDbActionTwo()
|
||||
{
|
||||
$GLOBALS['dbi']->expects($this->any())
|
||||
->method('fetchArray')
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () {
|
||||
static $count = 0;
|
||||
if ($count == 0) {
|
||||
$count++;
|
||||
return array('table');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableRelationController');
|
||||
$container->alias(
|
||||
'TableRelationController',
|
||||
'PMA\libraries\controllers\table\TableRelationController'
|
||||
);
|
||||
$ctrl = $container->get(
|
||||
'TableRelationController',
|
||||
array('tbl_storage_engine' => 'INNODB',)
|
||||
);
|
||||
|
||||
$_REQUEST['foreign'] = 'false';
|
||||
$ctrl->getDropdownValueForDbAction();
|
||||
$json = $this->_response->getJSONResult();
|
||||
$this->assertEquals(
|
||||
array('table'),
|
||||
$json['tables']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock class for DataBasePMAMock
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
Class DataBasePMAMockForTblRelation
|
||||
{
|
||||
var $databases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock class for DataBaseMock
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
Class DataBaseMockForTblRelation
|
||||
{
|
||||
/**
|
||||
* mock function to return table is existed
|
||||
*
|
||||
* @param string $name table name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function exists($name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
383
#pma/test/classes/controllers/TableSearchControllerTest.php
Normal file
383
#pma/test/classes/controllers/TableSearchControllerTest.php
Normal file
@@ -0,0 +1,383 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA_TableSearch
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\controllers\table\TableSearchController;
|
||||
use PMA\libraries\di\Container;
|
||||
use PMA\libraries\Theme;
|
||||
use PMA\libraries\TypesMySQL;
|
||||
|
||||
require_once 'test/libraries/stubs/ResponseStub.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA_TableSearch
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TableSearchControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var PMA\Test\Stubs\Response
|
||||
*/
|
||||
private $_response;
|
||||
|
||||
/**
|
||||
* Setup function for test cases
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
/**
|
||||
* SET these to avoid undefined index error
|
||||
*/
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$_POST['zoom_submit'] = 'zoom';
|
||||
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
|
||||
$GLOBALS['pmaThemeImage'] = 'themes/dot.gif';
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
$GLOBALS['cfgRelation'] = PMA_getRelationsParam();
|
||||
$GLOBALS['PMA_Types'] = new TypesMySQL();
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$columns =array(
|
||||
array(
|
||||
'Field' => 'Field1',
|
||||
'Type' => 'Type1',
|
||||
'Null' => 'Null1',
|
||||
'Collation' => 'Collation1',
|
||||
),
|
||||
array(
|
||||
'Field' => 'Field2',
|
||||
'Type' => 'Type2',
|
||||
'Null' => 'Null2',
|
||||
'Collation' => 'Collation2',
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->any())->method('getColumns')
|
||||
->will($this->returnValue($columns));
|
||||
|
||||
$show_create_table = "CREATE TABLE `pma_bookmark` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`dbase` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
|
||||
`user` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
|
||||
`label` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '',
|
||||
`query` text COLLATE utf8_bin NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `foreign_field` (`foreign_db`,`foreign_table`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin "
|
||||
. "COMMENT='Bookmarks'";
|
||||
|
||||
$dbi->expects($this->any())->method('fetchValue')
|
||||
->will($this->returnValue($show_create_table));
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->_response = new PMA\Test\Stubs\Response();
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('db', 'PMA');
|
||||
$container->set('table', 'PMA_BookMark');
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->set('response', $this->_response);
|
||||
$container->set('searchType', 'replace');
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown function for test cases
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for replace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReplace()
|
||||
{
|
||||
$tableSearch = new TableSearchController("zoom", null);
|
||||
$columnIndex = 0;
|
||||
$find = "Field";
|
||||
$replaceWith = "Column";
|
||||
$useRegex = false;
|
||||
$charSet = "UTF-8";
|
||||
$tableSearch->replace(
|
||||
$columnIndex, $find, $replaceWith, $useRegex, $charSet
|
||||
);
|
||||
|
||||
$sql_query = $GLOBALS['sql_query'];
|
||||
$result = "UPDATE `PMA_BookMark` SET `Field1` = "
|
||||
. "REPLACE(`Field1`, 'Field', 'Column') "
|
||||
. "WHERE `Field1` LIKE '%Field%' COLLATE UTF-8_bin";
|
||||
$this->assertEquals(
|
||||
$result,
|
||||
$sql_query
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for buildSqlQuery
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildSqlQuery()
|
||||
{
|
||||
$_POST['distinct'] = true;
|
||||
$_POST['zoom_submit'] = true;
|
||||
$_POST['table'] = "PMA";
|
||||
$_POST['orderByColumn'] = "name";
|
||||
$_POST['order'] = "asc";
|
||||
$_POST['customWhereClause'] = "name='pma'";
|
||||
|
||||
$class = new ReflectionClass('PMA\libraries\controllers\table\TableSearchController');
|
||||
$method = $class->getMethod('_buildSqlQuery');
|
||||
$method->setAccessible(true);
|
||||
$tableSearch = new TableSearchController("zoom", null);
|
||||
|
||||
$sql = $method->invoke($tableSearch);
|
||||
$result = "SELECT DISTINCT * FROM `PMA` WHERE name='pma' "
|
||||
. "ORDER BY `name` asc";
|
||||
|
||||
$this->assertEquals(
|
||||
$result,
|
||||
$sql
|
||||
);
|
||||
|
||||
unset($_POST['customWhereClause']);
|
||||
$sql = $method->invoke($tableSearch);
|
||||
$result = "SELECT DISTINCT * FROM `PMA` ORDER BY `name` asc";
|
||||
$this->assertEquals(
|
||||
$result,
|
||||
$sql
|
||||
);
|
||||
|
||||
$_POST['criteriaValues'] = array(
|
||||
'value1',
|
||||
'value2',
|
||||
'value3',
|
||||
'value4',
|
||||
'value5',
|
||||
'value6',
|
||||
'value7,value8'
|
||||
);
|
||||
$_POST['criteriaColumnNames'] = array(
|
||||
'name',
|
||||
'id',
|
||||
'index',
|
||||
'index2',
|
||||
'index3',
|
||||
'index4',
|
||||
'index5',
|
||||
);
|
||||
$_POST['criteriaColumnTypes'] = array(
|
||||
'varchar',
|
||||
'int',
|
||||
'enum',
|
||||
'type1',
|
||||
'type2',
|
||||
'type3',
|
||||
'type4'
|
||||
);
|
||||
$_POST['criteriaColumnCollations'] = array(
|
||||
"char1",
|
||||
"char2",
|
||||
"char3",
|
||||
"char4",
|
||||
"char5",
|
||||
"char6",
|
||||
"char7",
|
||||
);
|
||||
$_POST['criteriaColumnOperators'] = array(
|
||||
"!=",
|
||||
">",
|
||||
"IS NULL",
|
||||
"LIKE %...%",
|
||||
"REGEXP ^...$",
|
||||
"IN (...)",
|
||||
"BETWEEN"
|
||||
);
|
||||
|
||||
$sql = $method->invoke($tableSearch);
|
||||
$result = "SELECT DISTINCT * FROM `PMA` WHERE `name` != 'value1'"
|
||||
. " AND `id` > value2 AND `index` IS NULL AND `index2` LIKE '%value4%'"
|
||||
. " AND `index3` REGEXP ^value5$ AND `index4` IN (value6) AND `index5`"
|
||||
. " BETWEEN value7 AND value8 ORDER BY `name` asc";
|
||||
$this->assertEquals(
|
||||
$result,
|
||||
$sql
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getColumnMinMax()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetColumnMinMax()
|
||||
{
|
||||
$GLOBALS['dbi']->expects($this->any())->method('fetchSingleRow')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableSearchController');
|
||||
$container->alias(
|
||||
'TableSearchController', 'PMA\libraries\controllers\table\TableSearchController'
|
||||
);
|
||||
$ctrl = $container->get('TableSearchController');
|
||||
|
||||
$result = $ctrl->getColumnMinMax('column');
|
||||
$expected = 'SELECT MIN(`column`) AS `min`, '
|
||||
. 'MAX(`column`) AS `max` '
|
||||
. 'FROM `PMA`.`PMA_BookMark`';
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for _generateWhereClause()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGenerateWhereClause()
|
||||
{
|
||||
$types = $this->getMockBuilder('PMA\libraries\Types')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$types->expects($this->any())->method('isUnaryOperator')
|
||||
->will($this->returnValue(false));
|
||||
$GLOBALS['PMA_Types'] = $types;
|
||||
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\Table\TableSearchController');
|
||||
$method = $class->getMethod('_generateWhereClause');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->factory('\PMA\libraries\controllers\Table\TableSearchController');
|
||||
$container->alias(
|
||||
'TableSearchController', 'PMA\libraries\controllers\table\TableSearchController'
|
||||
);
|
||||
$ctrl = $container->get('TableSearchController');
|
||||
|
||||
$_POST['customWhereClause'] = '`table` = \'PMA_BookMark\'';
|
||||
$result = $method->invoke($ctrl);
|
||||
$this->assertEquals(
|
||||
' WHERE `table` = \'PMA_BookMark\'',
|
||||
$result
|
||||
);
|
||||
|
||||
unset($_POST['customWhereClause']);
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
|
||||
$_POST['criteriaColumnNames'] = array(
|
||||
'b', 'a'
|
||||
);
|
||||
$_POST['criteriaColumnOperators'] = array(
|
||||
'<=', '='
|
||||
);
|
||||
$_POST['criteriaValues'] = array(
|
||||
'10', '2'
|
||||
);
|
||||
$_POST['criteriaColumnTypes'] = array(
|
||||
'int(11)', 'int(11)'
|
||||
);
|
||||
$result = $method->invoke($ctrl);
|
||||
$this->assertEquals(
|
||||
' WHERE `b` <= 10 AND `a` = 2',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getDataRowAction()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDataRowAction()
|
||||
{
|
||||
$meta_one = new stdClass();
|
||||
$meta_one->type = 'int';
|
||||
$meta_one->length = 11;
|
||||
$meta_two = new stdClass();
|
||||
$meta_two->length = 11;
|
||||
$meta_two->type = 'int';
|
||||
$fields_meta = array(
|
||||
$meta_one, $meta_two
|
||||
);
|
||||
$GLOBALS['dbi']->expects($this->any())->method('getFieldsMeta')
|
||||
->will($this->returnValue($fields_meta));
|
||||
|
||||
$GLOBALS['dbi']->expects($this->any())->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () {
|
||||
static $count = 0;
|
||||
if ($count == 0) {
|
||||
$count++;
|
||||
|
||||
return array(
|
||||
'col1' => 1,
|
||||
'col2' => 2,
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('\PMA\libraries\controllers\Table\TableSearchController');
|
||||
$container->alias(
|
||||
'TableSearchController', 'PMA\libraries\controllers\table\TableSearchController'
|
||||
);
|
||||
$ctrl = $container->get('TableSearchController');
|
||||
|
||||
$_REQUEST['db'] = 'PMA';
|
||||
$_REQUEST['table'] = 'PMA_BookMark';
|
||||
$_REQUEST['where_clause'] = '`col1` = 1';
|
||||
$expected = array(
|
||||
'col1' => 1,
|
||||
'col2' => 2
|
||||
);
|
||||
$ctrl->getDataRowAction();
|
||||
|
||||
$json = $this->_response->getJSONResult();
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$json['row_info']
|
||||
);
|
||||
}
|
||||
}
|
||||
345
#pma/test/classes/controllers/TableStructureControllerTest.php
Normal file
345
#pma/test/classes/controllers/TableStructureControllerTest.php
Normal file
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* TableStructureController_Test class
|
||||
*
|
||||
* this class is for testing TableStructureController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\di\Container;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/libraries/stubs/ResponseStub.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* TableStructureController_Test class
|
||||
*
|
||||
* this class is for testing TableStructureController class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TableStructureControllerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var \PMA\Test\Stubs\Response
|
||||
*/
|
||||
private $_response;
|
||||
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
$_REQUEST['pos'] = 3;
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['table'] = "table";
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
|
||||
$table = $this->getMockBuilder('PMA\libraries\Table')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())->method('getTable')
|
||||
->will($this->returnValue($table));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('db', 'db');
|
||||
$container->set('table', 'table');
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$this->_response = new \PMA\Test\Stubs\Response();
|
||||
$container->set('PMA\libraries\Response', $this->_response);
|
||||
$container->alias('response', 'PMA\libraries\Response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getKeyForTablePrimary()
|
||||
*
|
||||
* Case one: there are no primary key in the table
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetKeyForTablePrimaryOne()
|
||||
{
|
||||
$GLOBALS['dbi']->expects($this->any())->method('fetchAssoc')
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\table\TableStructureController');
|
||||
$method = $class->getMethod('getKeyForTablePrimary');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableStructureController');
|
||||
$container->alias(
|
||||
'TableStructureController', 'PMA\libraries\controllers\table\TableStructureController'
|
||||
);
|
||||
$ctrl = $container->get('TableStructureController');
|
||||
// No primary key in db.table2
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getKeyForTablePrimary()
|
||||
*
|
||||
* Case two: there are a primary key in the table
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetKeyForTablePrimaryTwo()
|
||||
{
|
||||
$GLOBALS['dbi']->expects($this->any())
|
||||
->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () {
|
||||
static $callCount = 0;
|
||||
if ($callCount == 0) {
|
||||
$callCount++;
|
||||
|
||||
return array(
|
||||
'Key_name' => 'PRIMARY',
|
||||
'Column_name' => 'column',
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\table\TableStructureController');
|
||||
$method = $class->getMethod('getKeyForTablePrimary');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableStructureController');
|
||||
$container->alias(
|
||||
'TableStructureController', 'PMA\libraries\controllers\table\TableStructureController'
|
||||
);
|
||||
$ctrl = $container->get('TableStructureController');
|
||||
// With db.table, it has a primary key `column`
|
||||
$this->assertEquals(
|
||||
'column, ',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for adjustColumnPrivileges()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testAdjustColumnPrivileges()
|
||||
{
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\table\TableStructureController');
|
||||
$method = $class->getMethod('adjustColumnPrivileges');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableStructureController');
|
||||
$container->alias(
|
||||
'TableStructureController', 'PMA\libraries\controllers\table\TableStructureController'
|
||||
);
|
||||
$ctrl = $container->get('TableStructureController');
|
||||
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$method->invokeArgs($ctrl, array(null))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getMultipleFieldCommandType()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetMultipleFieldCommandType()
|
||||
{
|
||||
$class = new ReflectionClass('\PMA\libraries\controllers\table\TableStructureController');
|
||||
$method = $class->getMethod('getMultipleFieldCommandType');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $GLOBALS['dbi']);
|
||||
$container->factory('PMA\libraries\controllers\table\TableStructureController');
|
||||
$container->alias(
|
||||
'TableStructureController', 'PMA\libraries\controllers\table\TableStructureController'
|
||||
);
|
||||
$ctrl = $container->get('TableStructureController');
|
||||
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
|
||||
$_REQUEST['submit_mult_drop_x'] = true;
|
||||
$this->assertEquals(
|
||||
'drop',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
unset($_REQUEST['submit_mult_drop_x']);
|
||||
|
||||
$_REQUEST['submit_mult'] = 'create';
|
||||
$this->assertEquals(
|
||||
'create',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
unset($_REQUEST['submit_mult']);
|
||||
|
||||
$_REQUEST['mult_btn'] = __('Yes');
|
||||
$this->assertEquals(
|
||||
'row_delete',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
|
||||
$_REQUEST['selected'] = array('a', 'b');
|
||||
$method->invoke($ctrl);
|
||||
$this->assertEquals(
|
||||
$_REQUEST['selected'],
|
||||
$_REQUEST['selected_fld']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getDataForSubmitMult()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testPMAGetDataForSubmitMult()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())
|
||||
->method('query')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$class = new ReflectionClass('PMA\libraries\controllers\table\TableStructureController');
|
||||
$method = $class->getMethod('getDataForSubmitMult');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$container = Container::getDefaultContainer();
|
||||
$container->set('dbi', $dbi);
|
||||
$container->factory('PMA\libraries\controllers\table\TableStructureController');
|
||||
$container->alias(
|
||||
'TableStructureController', 'PMA\libraries\controllers\table\TableStructureController'
|
||||
);
|
||||
$ctrl = $container->get('TableStructureController');
|
||||
|
||||
$submit_mult = "index";
|
||||
$db = "PMA_db";
|
||||
$table = "PMA_table";
|
||||
$selected = array(
|
||||
"table1", "table2"
|
||||
);
|
||||
$action = 'db_delete_row';
|
||||
|
||||
list($what, $query_type, $is_unset_submit_mult, $mult_btn, $centralColsError)
|
||||
= $method->invokeArgs(
|
||||
$ctrl,
|
||||
array($submit_mult, $db, $table, $selected, $action)
|
||||
);
|
||||
|
||||
//validate 1: $what
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$what
|
||||
);
|
||||
|
||||
//validate 2: $query_type
|
||||
$this->assertEquals(
|
||||
'index_fld',
|
||||
$query_type
|
||||
);
|
||||
|
||||
//validate 3: $is_unset_submit_mult
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$is_unset_submit_mult
|
||||
);
|
||||
|
||||
//validate 4:
|
||||
$this->assertEquals(
|
||||
__('Yes'),
|
||||
$mult_btn
|
||||
);
|
||||
|
||||
//validate 5: $centralColsError
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$centralColsError
|
||||
);
|
||||
|
||||
$submit_mult = "unique";
|
||||
|
||||
list($what, $query_type, $is_unset_submit_mult, $mult_btn, $centralColsError)
|
||||
= $method->invokeArgs(
|
||||
$ctrl,
|
||||
array($submit_mult, $db, $table, $selected, $action)
|
||||
);
|
||||
|
||||
//validate 1: $what
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$what
|
||||
);
|
||||
|
||||
//validate 2: $query_type
|
||||
$this->assertEquals(
|
||||
'unique_fld',
|
||||
$query_type
|
||||
);
|
||||
|
||||
//validate 3: $is_unset_submit_mult
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$is_unset_submit_mult
|
||||
);
|
||||
|
||||
//validate 4: $mult_btn
|
||||
$this->assertEquals(
|
||||
__('Yes'),
|
||||
$mult_btn
|
||||
);
|
||||
|
||||
//validate 5: $centralColsError
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$centralColsError
|
||||
);
|
||||
}
|
||||
}
|
||||
331
#pma/test/classes/dbi/DBIMysqlTest.php
Normal file
331
#pma/test/classes/dbi/DBIMysqlTest.php
Normal file
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\dbi\DBIMysql class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\dbi\DBIMysql;
|
||||
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\dbi\DBIMysql class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class DBIMysqlTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
if (! extension_loaded('mysql')) {
|
||||
$this->markTestSkipped('The MySQL extension is not available.');
|
||||
}
|
||||
$GLOBALS['cfg']['Server']['ssl'] = true;
|
||||
$GLOBALS['cfg']['Server']['compress'] = true;
|
||||
$this->object = new DBIMysql();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for realMultiQuery
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testRealMultiQuery()
|
||||
{
|
||||
//PHP's 'mysql' extension does not support multi_queries
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$this->object->realMultiQuery(null, "select * from PMA")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for mysql related functions, using runkit_function_redefine
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testMysqlDBI()
|
||||
{
|
||||
if (! PMA_HAS_RUNKIT || ! $GLOBALS['runkit_internal_override']) {
|
||||
$this->markTestSkipped("Cannot redefine function");
|
||||
}
|
||||
//FOR UT, we just test the right mysql client API is called
|
||||
runkit_function_redefine('mysql_pconnect', '', 'return "mysql_pconnect";');
|
||||
runkit_function_redefine('mysql_connect', '', 'return "mysql_connect";');
|
||||
runkit_function_redefine('mysql_query', '', 'return "mysql_query";');
|
||||
runkit_function_redefine(
|
||||
'mysql_fetch_array', '', 'return "mysql_fetch_array";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysql_data_seek', '', 'return "mysql_data_seek";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysql_get_host_info', '', 'return "mysql_get_host_info";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysql_get_proto_info', '', 'return "mysql_get_proto_info";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysql_field_flags', '', 'return "mysql_field_flags";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysql_field_name', '', 'return "mysql_field_name";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysql_field_len', '', 'return "mysql_field_len";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysql_num_fields', '', 'return "mysql_num_fields";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysql_affected_rows', '', 'return "mysql_affected_rows";'
|
||||
);
|
||||
|
||||
//test for fieldFlags
|
||||
$result = array("table1", "table2");
|
||||
$ret = $this->object->numFields($result);
|
||||
$this->assertEquals(
|
||||
'mysql_num_fields',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fetchRow
|
||||
$result = array("table1", "table2");
|
||||
$ret = $this->object->fetchRow($result);
|
||||
$this->assertEquals(
|
||||
'mysql_fetch_array',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fetchRow
|
||||
$result = array("table1", "table2");
|
||||
$ret = $this->object->fetchAssoc($result);
|
||||
$this->assertEquals(
|
||||
'mysql_fetch_array',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for affectedRows
|
||||
$link = "PMA_link";
|
||||
$get_from_cache = false;
|
||||
$ret = $this->object->affectedRows($link, $get_from_cache);
|
||||
$this->assertEquals(
|
||||
"mysql_affected_rows",
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for connect
|
||||
$user = 'PMA_user';
|
||||
$password = 'PMA_password';
|
||||
$is_controluser = false;
|
||||
$server = array(
|
||||
'port' => 8080,
|
||||
'socket' => 123,
|
||||
'host' => 'locahost',
|
||||
);
|
||||
$auxiliary_connection = true;
|
||||
|
||||
//test for connect
|
||||
$ret = $this->object->connect(
|
||||
$user, $password, $is_controluser,
|
||||
$server, $auxiliary_connection
|
||||
);
|
||||
$this->assertEquals(
|
||||
'mysql_connect',
|
||||
$ret
|
||||
);
|
||||
|
||||
$GLOBALS['cfg']['PersistentConnections'] = true;
|
||||
$ret = $this->object->connect(
|
||||
$user, $password, $is_controluser,
|
||||
$server, $auxiliary_connection
|
||||
);
|
||||
$this->assertEquals(
|
||||
'mysql_pconnect',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for realQuery
|
||||
$query = 'select * from DBI';
|
||||
$link = $ret;
|
||||
$options = 0;
|
||||
$ret = $this->object->realQuery($query, $link, $options);
|
||||
$this->assertEquals(
|
||||
'mysql_query',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fetchArray
|
||||
$result = $ret;
|
||||
$ret = $this->object->fetchArray($result);
|
||||
$this->assertEquals(
|
||||
'mysql_fetch_array',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for dataSeek
|
||||
$result = $ret;
|
||||
$offset = 12;
|
||||
$ret = $this->object->dataSeek($result, $offset);
|
||||
$this->assertEquals(
|
||||
'mysql_data_seek',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for getHostInfo
|
||||
$ret = $this->object->getHostInfo($ret);
|
||||
$this->assertEquals(
|
||||
'mysql_get_host_info',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for getProtoInfo
|
||||
$ret = $this->object->getProtoInfo($ret);
|
||||
$this->assertEquals(
|
||||
'mysql_get_proto_info',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fieldLen
|
||||
$ret = $this->object->fieldLen($ret, $offset);
|
||||
$this->assertEquals(
|
||||
'mysql_field_len',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fieldName
|
||||
$ret = $this->object->fieldName($ret, $offset);
|
||||
$this->assertEquals(
|
||||
'mysql_field_name',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fieldFlags
|
||||
$ret = $this->object->fieldFlags($ret, $offset);
|
||||
$this->assertEquals(
|
||||
'mysql_field_flags',
|
||||
$ret
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for selectDb
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testSelectDb()
|
||||
{
|
||||
$this->markTestIncomplete('Not testing anything');
|
||||
//$link is empty
|
||||
$GLOBALS['userlink'] = null;
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$this->object->selectDb("PMA", null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for moreResults
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testMoreResults()
|
||||
{
|
||||
//PHP's 'mysql' extension does not support multi_queries
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$this->object->moreResults(null)
|
||||
);
|
||||
//PHP's 'mysql' extension does not support multi_queries
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$this->object->nextResult(null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getClientInfo
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetClientInfo()
|
||||
{
|
||||
$this->assertEquals(
|
||||
mysql_get_client_info(),
|
||||
$this->object->getClientInfo()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for numRows
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testNumRows()
|
||||
{
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$this->object->numRows(true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for storeResult
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testStoreResult()
|
||||
{
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$this->object->storeResult(null)
|
||||
);
|
||||
}
|
||||
}
|
||||
249
#pma/test/classes/dbi/DBIMysqliTest.php
Normal file
249
#pma/test/classes/dbi/DBIMysqliTest.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\dbi\DBIMysqli class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PMA\libraries\dbi\DBIMysqli;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\dbi\DBIMysqli class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class DBIMysqliTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['ssl'] = false;
|
||||
$GLOBALS['cfg']['Server']['compress'] = true;
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$this->object = new DBIMysqli();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for mysqli related functions, using runkit_function_redefine
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testMysqliDBI()
|
||||
{
|
||||
if (! PMA_HAS_RUNKIT) {
|
||||
$this->markTestSkipped("Cannot redefine function");
|
||||
}
|
||||
|
||||
//FOR UT, we just test the right mysql client API is called
|
||||
runkit_function_redefine(
|
||||
'mysqli_real_connect', '', 'return "mysqli_real_connect";'
|
||||
);
|
||||
runkit_function_redefine('mysqli_init', '', 'return "mysqli_init";');
|
||||
runkit_function_redefine('mysqli_options', '', 'return "mysqli_options";');
|
||||
runkit_function_redefine('mysqli_query', '', 'return "mysqli_query";');
|
||||
runkit_function_redefine(
|
||||
'mysqli_multi_query', '', 'return "mysqli_multi_query";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysqli_fetch_array', '', 'return "mysqli_fetch_array";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysqli_data_seek', '', 'return "mysqli_data_seek";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysqli_more_results', '', 'return "mysqli_more_results";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysqli_next_result', '', 'return "mysqli_next_result";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysqli_get_host_info', '', 'return "mysqli_get_host_info";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysqli_get_proto_info', '', 'return "mysqli_get_proto_info";'
|
||||
);
|
||||
runkit_function_redefine(
|
||||
'mysqli_get_client_info', '', 'return "mysqli_get_client_info";'
|
||||
);
|
||||
|
||||
$user = 'PMA_user';
|
||||
$password = 'PMA_password';
|
||||
$is_controluser = false;
|
||||
$server = array(
|
||||
'port' => 8080,
|
||||
'socket' => 123,
|
||||
'host' => 'locahost',
|
||||
);
|
||||
$auxiliary_connection = true;
|
||||
|
||||
//test for connect
|
||||
$ret = $this->object->connect(
|
||||
$user, $password, $is_controluser,
|
||||
$server, $auxiliary_connection
|
||||
);
|
||||
$this->assertEquals(
|
||||
'mysqli_init',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for realQuery
|
||||
$query = 'select * from DBI';
|
||||
$link = $ret;
|
||||
$options = 0;
|
||||
$ret = $this->object->realQuery($query, $link, $options);
|
||||
$this->assertEquals(
|
||||
'mysqli_query',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for realMultiQuery
|
||||
$ret = $this->object->realMultiQuery($link, $query);
|
||||
$this->assertEquals(
|
||||
'mysqli_multi_query',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fetchArray
|
||||
$result = $ret;
|
||||
$ret = $this->object->fetchArray($result);
|
||||
$this->assertEquals(
|
||||
'mysqli_fetch_array',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fetchAssoc
|
||||
$result = $ret;
|
||||
$ret = $this->object->fetchAssoc($result);
|
||||
$this->assertEquals(
|
||||
'mysqli_fetch_array',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for fetchRow
|
||||
$result = $ret;
|
||||
$ret = $this->object->fetchRow($result);
|
||||
$this->assertEquals(
|
||||
'mysqli_fetch_array',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for dataSeek
|
||||
$result = $ret;
|
||||
$offset = 10;
|
||||
$ret = $this->object->dataSeek($result, $offset);
|
||||
$this->assertEquals(
|
||||
'mysqli_data_seek',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for moreResults
|
||||
$link = $ret;
|
||||
$ret = $this->object->moreResults($link);
|
||||
$this->assertEquals(
|
||||
'mysqli_more_results',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for nextResult
|
||||
$link = $ret;
|
||||
$ret = $this->object->nextResult($link);
|
||||
$this->assertEquals(
|
||||
'mysqli_next_result',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for getHostInfo
|
||||
$link = $ret;
|
||||
$ret = $this->object->getHostInfo($link);
|
||||
$this->assertEquals(
|
||||
'mysqli_get_host_info',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for getProtoInfo
|
||||
$link = $ret;
|
||||
$ret = $this->object->getProtoInfo($link);
|
||||
$this->assertEquals(
|
||||
'mysqli_get_proto_info',
|
||||
$ret
|
||||
);
|
||||
|
||||
//test for getClientInfo
|
||||
$ret = $this->object->getClientInfo();
|
||||
$this->assertEquals(
|
||||
'mysqli_get_client_info',
|
||||
$ret
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for selectDb
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testSelectDb()
|
||||
{
|
||||
$this->markTestIncomplete('Not testing anything');
|
||||
//$link is empty
|
||||
$GLOBALS['userlink'] = null;
|
||||
$this->assertEquals(
|
||||
false,
|
||||
$this->object->selectDb("PMA", null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for numRows
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testNumRows()
|
||||
{
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->numRows(true)
|
||||
);
|
||||
}
|
||||
}
|
||||
128
#pma/test/classes/engines/BdbTest.php
Normal file
128
#pma/test/classes/engines/BdbTest.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Bdb
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\engines\Bdb;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Bdb
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class BdbTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Bdb('bdb');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariables()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getVariables(),
|
||||
array(
|
||||
'version_bdb' => array(
|
||||
'title' => __('Version information'),
|
||||
),
|
||||
'bdb_cache_size' => array(
|
||||
'type' => 1,
|
||||
),
|
||||
'bdb_home' => array(
|
||||
),
|
||||
'bdb_log_buffer_size' => array(
|
||||
'type' => 1,
|
||||
),
|
||||
'bdb_logdir' => array(
|
||||
),
|
||||
'bdb_max_lock' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'bdb_shared_data' => array(
|
||||
),
|
||||
'bdb_tmpdir' => array(
|
||||
),
|
||||
'bdb_data_direct' => array(
|
||||
),
|
||||
'bdb_lock_detect' => array(
|
||||
),
|
||||
'bdb_log_direct' => array(
|
||||
),
|
||||
'bdb_no_recover' => array(
|
||||
),
|
||||
'bdb_no_sync' => array(
|
||||
),
|
||||
'skip_sync_bdb_logs' => array(
|
||||
),
|
||||
'sync_bdb_logs' => array(
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariablesLikePattern
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariablesLikePattern()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getVariablesLikePattern(),
|
||||
'%bdb%'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getMysqlHelpPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMysqlHelpPage()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getMysqlHelpPage(),
|
||||
'bdb'
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
67
#pma/test/classes/engines/BinlogTest.php
Normal file
67
#pma/test/classes/engines/BinlogTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA_StorageEngine_binlog
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\engines\Binlog;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Binlog
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class BinlogTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Binlog('binlog');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for getMysqlHelpPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMysqlHelpPage()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getMysqlHelpPage(),
|
||||
'binary-log'
|
||||
);
|
||||
}
|
||||
}
|
||||
367
#pma/test/classes/engines/InnodbTest.php
Normal file
367
#pma/test/classes/engines/InnodbTest.php
Normal file
@@ -0,0 +1,367 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA_StorageEngine_innodb
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\engines\Innodb;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Innodb
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class InnodbTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Innodb('innodb');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariables()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'innodb_data_home_dir' => array(
|
||||
'title' => __('Data home directory'),
|
||||
'desc' => __('The common part of the directory path for all InnoDB data files.'),
|
||||
),
|
||||
'innodb_data_file_path' => array(
|
||||
'title' => __('Data files'),
|
||||
),
|
||||
'innodb_autoextend_increment' => array(
|
||||
'title' => __('Autoextend increment'),
|
||||
'desc' => __('The increment size for extending the size of an autoextending tablespace when it becomes full.'),
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_buffer_pool_size' => array(
|
||||
'title' => __('Buffer pool size'),
|
||||
'desc' => __('The size of the memory buffer InnoDB uses to cache data and indexes of its tables.'),
|
||||
'type' => 1,
|
||||
),
|
||||
'innodb_additional_mem_pool_size' => array(
|
||||
'title' => 'innodb_additional_mem_pool_size',
|
||||
'type' => 1,
|
||||
),
|
||||
'innodb_buffer_pool_awe_mem_mb' => array(
|
||||
'type' => 1,
|
||||
),
|
||||
'innodb_checksums' => array(
|
||||
),
|
||||
'innodb_commit_concurrency' => array(
|
||||
),
|
||||
'innodb_concurrency_tickets' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_doublewrite' => array(
|
||||
),
|
||||
'innodb_fast_shutdown' => array(
|
||||
),
|
||||
'innodb_file_io_threads' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_file_per_table' => array(
|
||||
),
|
||||
'innodb_flush_log_at_trx_commit' => array(
|
||||
),
|
||||
'innodb_flush_method' => array(
|
||||
),
|
||||
'innodb_force_recovery' => array(
|
||||
),
|
||||
'innodb_lock_wait_timeout' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_locks_unsafe_for_binlog' => array(
|
||||
),
|
||||
'innodb_log_arch_dir' => array(
|
||||
),
|
||||
'innodb_log_archive' => array(
|
||||
),
|
||||
'innodb_log_buffer_size' => array(
|
||||
'type' => 1,
|
||||
),
|
||||
'innodb_log_file_size' => array(
|
||||
'type' => 1,
|
||||
),
|
||||
'innodb_log_files_in_group' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_log_group_home_dir' => array(
|
||||
),
|
||||
'innodb_max_dirty_pages_pct' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_max_purge_lag' => array(
|
||||
),
|
||||
'innodb_mirrored_log_groups' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_open_files' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_support_xa' => array(
|
||||
),
|
||||
'innodb_sync_spin_loops' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_table_locks' => array(
|
||||
'type' => 3,
|
||||
),
|
||||
'innodb_thread_concurrency' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
'innodb_thread_sleep_delay' => array(
|
||||
'type' => 2,
|
||||
),
|
||||
),
|
||||
$this->object->getVariables()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariablesLikePattern
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariablesLikePattern()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'innodb\\_%',
|
||||
$this->object->getVariablesLikePattern()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getInfoPages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInfoPages()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->getInfoPages()
|
||||
);
|
||||
$this->object->support = 2;
|
||||
$this->assertEquals(
|
||||
array (
|
||||
'Bufferpool' => 'Buffer Pool',
|
||||
'Status' => 'InnoDB Status'
|
||||
),
|
||||
$this->object->getInfoPages()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getPageBufferpool
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPageBufferpool()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<table class="data" id="table_innodb_bufferpool_usage">
|
||||
<caption class="tblHeaders">
|
||||
Buffer Pool Usage
|
||||
</caption>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="2">
|
||||
Total
|
||||
: 4,096 pages / 65,536 KiB
|
||||
</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<th>Free pages</th>
|
||||
<td class="value">0</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<th>Dirty pages</th>
|
||||
<td class="value">0</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<th>Pages containing data</th>
|
||||
<td class="value">0
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<th>Pages to be flushed</th>
|
||||
<td class="value">0
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<th>Busy pages</th>
|
||||
<td class="value">0
|
||||
</td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<table class="data" id="table_innodb_bufferpool_activity">
|
||||
<caption class="tblHeaders">
|
||||
Buffer Pool Activity
|
||||
</caption>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<th>Read requests</th>
|
||||
<td class="value">64
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<th>Write requests</th>
|
||||
<td class="value">64
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<th>Read misses</th>
|
||||
<td class="value">32
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<th>Write waits</th>
|
||||
<td class="value">0
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<th>Read misses in %</th>
|
||||
<td class="value">50 %
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<th>Write waits in %</th>
|
||||
<td class="value">0 %
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
',
|
||||
$this->object->getPageBufferpool()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getPageStatus
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPageStatus()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<pre id="pre_innodb_status">' . "\n" . "\n" . '</pre>' . "\n",
|
||||
$this->object->getPageStatus()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPage()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$this->object->getPage('Status')
|
||||
);
|
||||
$this->object->support = 2;
|
||||
$this->assertEquals(
|
||||
'<pre id="pre_innodb_status">' . "\n" . "\n" . '</pre>' . "\n",
|
||||
$this->object->getPage('Status')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getMysqlHelpPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMysqlHelpPage()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'innodb-storage-engine',
|
||||
$this->object->getMysqlHelpPage()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getInnodbPluginVersion
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInnodbPluginVersion()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'1.1.8',
|
||||
$this->object->getInnodbPluginVersion()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for supportsFilePerTable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSupportsFilePerTable()
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->object->supportsFilePerTable()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getInnodbFileFormat
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInnodbFileFormat()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'Antelope',
|
||||
$this->object->getInnodbFileFormat()
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
70
#pma/test/classes/engines/MemoryTest.php
Normal file
70
#pma/test/classes/engines/MemoryTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA_StorageEngine_memory
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\engines\Memory;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Memory
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class MemoryTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Memory('memory');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariables()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getVariables(),
|
||||
array(
|
||||
'max_heap_table_size' => array(
|
||||
'type' => 1,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
67
#pma/test/classes/engines/Mrg_MyisamTest.php
Normal file
67
#pma/test/classes/engines/Mrg_MyisamTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Mrg_Myisam
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\engines\Mrg_Myisam;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Mrg_Myisam
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class Mrg_MyisamTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Mrg_Myisam('mrg_myisam');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getMysqlHelpPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMysqlHelpPage()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getMysqlHelpPage(),
|
||||
'merge-storage-engine'
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
107
#pma/test/classes/engines/MyisamTest.php
Normal file
107
#pma/test/classes/engines/MyisamTest.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA_StorageEngine_myisam
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\engines\Myisam;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Myisam
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class MyisamTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Myisam('myisam');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariables()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getVariables(),
|
||||
array(
|
||||
'myisam_data_pointer_size' => array(
|
||||
'title' => __('Data pointer size'),
|
||||
'desc' => __('The default pointer size in bytes, to be used by CREATE TABLE for MyISAM tables when no MAX_ROWS option is specified.'),
|
||||
'type' => 1,
|
||||
),
|
||||
'myisam_recover_options' => array(
|
||||
'title' => __('Automatic recovery mode'),
|
||||
'desc' => __('The mode for automatic recovery of crashed MyISAM tables, as set via the --myisam-recover server startup option.'),
|
||||
),
|
||||
'myisam_max_sort_file_size' => array(
|
||||
'title' => __('Maximum size for temporary sort files'),
|
||||
'desc' => __('The maximum size of the temporary file MySQL is allowed to use while re-creating a MyISAM index (during REPAIR TABLE, ALTER TABLE, or LOAD DATA INFILE).'),
|
||||
'type' => 1,
|
||||
),
|
||||
'myisam_max_extra_sort_file_size' => array(
|
||||
'title' => __('Maximum size for temporary files on index creation'),
|
||||
'desc' => __('If the temporary file used for fast MyISAM index creation would be larger than using the key cache by the amount specified here, prefer the key cache method.'),
|
||||
'type' => 1,
|
||||
),
|
||||
'myisam_repair_threads' => array(
|
||||
'title' => __('Repair threads'),
|
||||
'desc' => __('If this value is greater than 1, MyISAM table indexes are created in parallel (each index in its own thread) during the repair by sorting process.'),
|
||||
'type' => 2,
|
||||
),
|
||||
'myisam_sort_buffer_size' => array(
|
||||
'title' => __('Sort buffer size'),
|
||||
'desc' => __('The buffer that is allocated when sorting MyISAM indexes during a REPAIR TABLE or when creating indexes with CREATE INDEX or ALTER TABLE.'),
|
||||
'type' => 1,
|
||||
),
|
||||
'myisam_stats_method' => array(
|
||||
),
|
||||
'delay_key_write' => array(
|
||||
),
|
||||
'bulk_insert_buffer_size' => array(
|
||||
'type' => 1,
|
||||
),
|
||||
'skip_external_locking' => array(
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
96
#pma/test/classes/engines/NdbclusterTest.php
Normal file
96
#pma/test/classes/engines/NdbclusterTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA_StorageEngine_ndbcluster
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\engines\Ndbcluster;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Ndbcluster
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NdbclusterTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Ndbcluster('nbdcluster');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariables()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getVariables(),
|
||||
array(
|
||||
'ndb_connectstring' => array(
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariablesLikePattern
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariablesLikePattern()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getVariablesLikePattern(),
|
||||
'ndb\\_%'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getMysqlHelpPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMysqlHelpPage()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getMysqlHelpPage(),
|
||||
'ndbcluster'
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
266
#pma/test/classes/engines/PbxtTest.php
Normal file
266
#pma/test/classes/engines/PbxtTest.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA_StorageEngine_pbxt
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
use PMA\libraries\engines\Pbxt;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\engines\Pbxt;
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PbxtTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new Pbxt('pbxt');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVariables()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getVariables(),
|
||||
array(
|
||||
'pbxt_index_cache_size' => array(
|
||||
'title' => __('Index cache size'),
|
||||
'desc' => __(
|
||||
'This is the amount of memory allocated to the'
|
||||
. ' index cache. Default value is 32MB. The memory'
|
||||
. ' allocated here is used only for caching index pages.'
|
||||
),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_record_cache_size' => array(
|
||||
'title' => __('Record cache size'),
|
||||
'desc' => __(
|
||||
'This is the amount of memory allocated to the'
|
||||
. ' record cache used to cache table data. The default'
|
||||
. ' value is 32MB. This memory is used to cache changes to'
|
||||
. ' the handle data (.xtd) and row pointer (.xtr) files.'
|
||||
),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_log_cache_size' => array(
|
||||
'title' => __('Log cache size'),
|
||||
'desc' => __(
|
||||
'The amount of memory allocated to the'
|
||||
. ' transaction log cache used to cache on transaction log'
|
||||
. ' data. The default is 16MB.'
|
||||
),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_log_file_threshold' => array(
|
||||
'title' => __('Log file threshold'),
|
||||
'desc' => __(
|
||||
'The size of a transaction log before rollover,'
|
||||
. ' and a new log is created. The default value is 16MB.'
|
||||
),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_transaction_buffer_size' => array(
|
||||
'title' => __('Transaction buffer size'),
|
||||
'desc' => __(
|
||||
'The size of the global transaction log buffer'
|
||||
. ' (the engine allocates 2 buffers of this size).'
|
||||
. ' The default is 1MB.'
|
||||
),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_checkpoint_frequency' => array(
|
||||
'title' => __('Checkpoint frequency'),
|
||||
'desc' => __(
|
||||
'The amount of data written to the transaction'
|
||||
. ' log before a checkpoint is performed.'
|
||||
. ' The default value is 24MB.'
|
||||
),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_data_log_threshold' => array(
|
||||
'title' => __('Data log threshold'),
|
||||
'desc' => __(
|
||||
'The maximum size of a data log file. The default'
|
||||
. ' value is 64MB. PBXT can create a maximum of 32000 data'
|
||||
. ' logs, which are used by all tables. So the value of'
|
||||
. ' this variable can be increased to increase the total'
|
||||
. ' amount of data that can be stored in the database.'
|
||||
),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_garbage_threshold' => array(
|
||||
'title' => __('Garbage threshold'),
|
||||
'desc' => __(
|
||||
'The percentage of garbage in a data log file'
|
||||
. ' before it is compacted. This is a value between 1 and'
|
||||
. ' 99. The default is 50.'
|
||||
),
|
||||
'type' => 2
|
||||
),
|
||||
'pbxt_log_buffer_size' => array(
|
||||
'title' => __('Log buffer size'),
|
||||
'desc' => __(
|
||||
'The size of the buffer used when writing a data'
|
||||
. ' log. The default is 256MB. The engine allocates one'
|
||||
. ' buffer per thread, but only if the thread is required'
|
||||
. ' to write a data log.'
|
||||
),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_data_file_grow_size' => array(
|
||||
'title' => __('Data file grow size'),
|
||||
'desc' => __('The grow size of the handle data (.xtd) files.'),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_row_file_grow_size' => array(
|
||||
'title' => __('Row file grow size'),
|
||||
'desc' => __('The grow size of the row pointer (.xtr) files.'),
|
||||
'type' => 1
|
||||
),
|
||||
'pbxt_log_file_count' => array(
|
||||
'title' => __('Log file count'),
|
||||
'desc' => __(
|
||||
'This is the number of transaction log files'
|
||||
. ' (pbxt/system/xlog*.xt) the system will maintain. If the'
|
||||
. ' number of logs exceeds this value then old logs will be'
|
||||
. ' deleted, otherwise they are renamed and given the next'
|
||||
. ' highest number.'
|
||||
),
|
||||
'type' => 2
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for resolveTypeSize
|
||||
*
|
||||
* @param string $formatted_size the size expression (for example 8MB)
|
||||
* @param string $output Expected output
|
||||
*
|
||||
* @dataProvider providerFortTestResolveTypeSize
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testResolveTypeSize($formatted_size, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->resolveTypeSize($formatted_size),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for testResolveTypeSize
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerFortTestResolveTypeSize()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'8MB',
|
||||
array (
|
||||
0 => '8,192',
|
||||
1 => 'KiB'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'10mb',
|
||||
array (
|
||||
0 => '-1',
|
||||
1 => 'B'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'A4',
|
||||
array (
|
||||
0 => '0',
|
||||
1 => 'B'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getInfoPages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInfoPages()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getInfoPages(),
|
||||
array(
|
||||
'Documentation' => 'Documentation'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPage()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->getPage('Documentation'),
|
||||
'<p>'
|
||||
. sprintf(
|
||||
__(
|
||||
'Documentation and further information about PBXT'
|
||||
. ' can be found on the %sPrimeBase XT Home Page%s.'
|
||||
),
|
||||
'<a href="' . PMA_linkURL('https://mariadb.com/kb/en/mariadb/about-pbxt/')
|
||||
. '" rel="noopener noreferrer" target="_blank">',
|
||||
'</a>'
|
||||
)
|
||||
. '</p>' . "\n"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->object->getPage('NonExistMethod'),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
70
#pma/test/classes/gis/GISFactoryTest.php
Normal file
70
#pma/test/classes/gis/GISFactoryTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISFactory
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\gis\GISFactory;
|
||||
|
||||
/**
|
||||
* Test class for PMA\libraries\gis\GISFactory
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISFactoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test factory method
|
||||
*
|
||||
* @param string $type geometry type
|
||||
* @param object $geom geometry object
|
||||
*
|
||||
* @dataProvider providerForTestFactory
|
||||
* @return void
|
||||
*/
|
||||
public function testFactory($type, $geom)
|
||||
{
|
||||
$this->assertInstanceOf($geom, GISFactory::factory($type));
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testFactory
|
||||
*
|
||||
* @return data for testFactory
|
||||
*/
|
||||
public function providerForTestFactory()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOLYGON',
|
||||
'PMA\libraries\gis\GISMultipolygon'
|
||||
),
|
||||
array(
|
||||
'POLYGON',
|
||||
'PMA\libraries\gis\GISPolygon'
|
||||
),
|
||||
array(
|
||||
'MULTILINESTRING',
|
||||
'PMA\libraries\gis\GISMultilinestring'
|
||||
),
|
||||
array(
|
||||
'LINESTRING',
|
||||
'PMA\libraries\gis\GISLinestring'
|
||||
),
|
||||
array(
|
||||
'MULTIPOINT',
|
||||
'PMA\libraries\gis\GISMultipoint'
|
||||
),
|
||||
array(
|
||||
'POINT',
|
||||
'PMA\libraries\gis\GISPoint'
|
||||
),
|
||||
array(
|
||||
'GEOMETRYCOLLECTION',
|
||||
'PMA\libraries\gis\GISGeometrycollection'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
70
#pma/test/classes/gis/GISGeomTest.php
Normal file
70
#pma/test/classes/gis/GISGeomTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Abstract parent class for all PMA_GIS_<Geom_type> test classes
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract parent class for all GIS<Geom_type> test classes
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
abstract class GISGeomTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* test generateParams method
|
||||
*
|
||||
* @param string $wkt point in WKT form
|
||||
* @param int $index index
|
||||
* @param array $params expected output array
|
||||
*
|
||||
* @dataProvider providerForTestGenerateParams
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateParams($wkt, $index, $params)
|
||||
{
|
||||
if ($index == null) {
|
||||
$this->assertEquals(
|
||||
$params,
|
||||
$this->object->generateParams($wkt)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$params,
|
||||
$this->object->generateParams($wkt, $index)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test scaleRow method
|
||||
*
|
||||
* @param string $spatial spatial data of a row
|
||||
* @param array $min_max expected results
|
||||
*
|
||||
* @dataProvider providerForTestScaleRow
|
||||
* @return void
|
||||
*/
|
||||
public function testScaleRow($spatial, $min_max)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$min_max,
|
||||
$this->object->scaleRow($spatial)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether content is a valid image.
|
||||
*
|
||||
* @param object $object Image
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertImage($object)
|
||||
{
|
||||
$this->assertGreaterThan(0, imagesx($object));
|
||||
}
|
||||
}
|
||||
340
#pma/test/classes/gis/GISGeometryTest.php
Normal file
340
#pma/test/classes/gis/GISGeometryTest.php
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISGeometry
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\gis\GISGeometry class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISGeometryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = $this->getMockForAbstractClass('PMA\libraries\gis\GISGeometry');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call protected functions by making the visibility to public.
|
||||
*
|
||||
* @param string $name method name
|
||||
* @param array $params parameters for the invocation
|
||||
*
|
||||
* @return the output from the protected method.
|
||||
*/
|
||||
private function _callProtectedFunction($name, $params)
|
||||
{
|
||||
$class = new ReflectionClass('PMA\libraries\gis\GISGeometry');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($this->object, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* tests setMinMax method
|
||||
*
|
||||
* @param string $point_set Point set
|
||||
* @param array $min_max Existing min, max values
|
||||
* @param array $output Expected output array
|
||||
*
|
||||
* @dataProvider providerForTestSetMinMax
|
||||
* @return void
|
||||
*/
|
||||
public function testSetMinMax($point_set, $min_max, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->_callProtectedFunction(
|
||||
'setMinMax',
|
||||
array($point_set, $min_max)
|
||||
),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testSetMinMax
|
||||
*
|
||||
* @return data for testSetMinMax
|
||||
*/
|
||||
public function providerForTestSetMinMax()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'12 35,48 75,69 23,25 45,14 53,35 78',
|
||||
array(),
|
||||
array(
|
||||
'minX' => 12,
|
||||
'maxX' => 69,
|
||||
'minY' => 23,
|
||||
'maxY' => 78
|
||||
)
|
||||
),
|
||||
array(
|
||||
'12 35,48 75,69 23,25 45,14 53,35 78',
|
||||
array(
|
||||
'minX' => 2,
|
||||
'maxX' => 29,
|
||||
'minY' => 23,
|
||||
'maxY' => 128
|
||||
),
|
||||
array(
|
||||
'minX' => 2,
|
||||
'maxX' => 69,
|
||||
'minY' => 23,
|
||||
'maxY' => 128
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* tests generateParams method
|
||||
*
|
||||
* @param string $value Geometry data
|
||||
* @param string $output Expected output
|
||||
*
|
||||
* @dataProvider providerForTestGenerateParams
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateParams($value, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->_callProtectedFunction(
|
||||
'generateParams',
|
||||
array($value)
|
||||
),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateParams
|
||||
*
|
||||
* @return data for testGenerateParams
|
||||
*/
|
||||
public function providerForTestGenerateParams()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
"'MULTIPOINT(125 50,156 25,178 43,175 80)',125",
|
||||
array(
|
||||
'srid' => '125',
|
||||
'wkt' => 'MULTIPOINT(125 50,156 25,178 43,175 80)',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'MULTIPOINT(125 50,156 25,178 43,175 80)',
|
||||
array(
|
||||
'srid' => '0',
|
||||
'wkt' => 'MULTIPOINT(125 50,156 25,178 43,175 80)',
|
||||
),
|
||||
),
|
||||
array(
|
||||
"foo",
|
||||
array(
|
||||
'srid' => '0',
|
||||
'wkt' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* tests extractPoints method
|
||||
*
|
||||
* @param string $point_set String of comma separated points
|
||||
* @param array $scale_data Data related to scaling
|
||||
* @param boolean $linear If true, as a 1D array, else as a 2D array
|
||||
* @param array $output Expected output
|
||||
*
|
||||
* @dataProvider providerForTestExtractPoints
|
||||
* @return void
|
||||
*/
|
||||
public function testExtractPoints($point_set, $scale_data, $linear, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->_callProtectedFunction(
|
||||
'extractPoints',
|
||||
array($point_set, $scale_data, $linear)
|
||||
),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testExtractPoints
|
||||
*
|
||||
* @return data for testExtractPoints
|
||||
*/
|
||||
public function providerForTestExtractPoints()
|
||||
{
|
||||
return array(
|
||||
// with no scale data
|
||||
array(
|
||||
'12 35,48 75,69 23',
|
||||
null,
|
||||
false,
|
||||
array(
|
||||
0 => array(12, 35),
|
||||
1 => array(48, 75),
|
||||
2 => array(69, 23),
|
||||
),
|
||||
),
|
||||
// with scale data
|
||||
array(
|
||||
'12 35,48 75,69 23',
|
||||
array(
|
||||
'x' => 5,
|
||||
'y' => 5,
|
||||
'scale' => 2,
|
||||
'height' => 200,
|
||||
),
|
||||
false,
|
||||
array(
|
||||
0 => array(14, 140),
|
||||
1 => array(86, 60),
|
||||
2 => array(128, 164),
|
||||
),
|
||||
),
|
||||
// linear output
|
||||
array(
|
||||
'12 35,48 75,69 23',
|
||||
null,
|
||||
true,
|
||||
array(12, 35, 48, 75, 69, 23),
|
||||
),
|
||||
// if a single part of a coordinate is empty
|
||||
array(
|
||||
'12 35,48 75,69 ',
|
||||
null,
|
||||
false,
|
||||
array(
|
||||
0 => array(12, 35),
|
||||
1 => array(48, 75),
|
||||
2 => array('', ''),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for getBoundsForOl() method
|
||||
*
|
||||
* @param string $srid spatial reference ID
|
||||
* @param array $scale_data data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForTestGetBoundsForOl
|
||||
*/
|
||||
public function testGetBoundsForOl($srid, $scale_data, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->_callProtectedFunction(
|
||||
'getBoundsForOl',
|
||||
array($srid, $scale_data)
|
||||
),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGetBoundsForOl() test case
|
||||
*
|
||||
* @return array test data for the testGetBoundsForOl() test case
|
||||
*/
|
||||
public function providerForTestGetBoundsForOl()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
4326,
|
||||
array(
|
||||
'minX' => '0',
|
||||
'minY' => '0',
|
||||
'maxX' => '1',
|
||||
'maxY' => '1',
|
||||
),
|
||||
'bound = new OpenLayers.Bounds(); '
|
||||
. 'bound.extend(new OpenLayers.LonLat(0, 0).transform('
|
||||
. 'new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject())); '
|
||||
. 'bound.extend(new OpenLayers.LonLat(1, 1).transform('
|
||||
. 'new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject()));'
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for getPolygonArrayForOpenLayers() method
|
||||
*
|
||||
* @param array $polygons x and y coordinate pairs for each polygon
|
||||
* @param string $srid spatial reference id
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForTestGetPolygonArrayForOpenLayers
|
||||
*/
|
||||
public function testGetPolygonArrayForOpenLayers($polygons, $srid, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->_callProtectedFunction(
|
||||
'getPolygonArrayForOpenLayers',
|
||||
array($polygons, $srid)
|
||||
),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGetPolygonArrayForOpenLayers() test case
|
||||
*
|
||||
* @return array test data for testGetPolygonArrayForOpenLayers() test case
|
||||
*/
|
||||
public function providerForTestGetPolygonArrayForOpenLayers()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('Triangle'),
|
||||
4326,
|
||||
'new Array('
|
||||
. 'new OpenLayers.Geometry.Polygon('
|
||||
. 'new Array('
|
||||
. 'new OpenLayers.Geometry.LinearRing('
|
||||
. 'new Array('
|
||||
. '(new OpenLayers.Geometry.Point(,)).transform('
|
||||
. 'new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject()))))))'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
405
#pma/test/classes/gis/GISGeometrycollectionTest.php
Normal file
405
#pma/test/classes/gis/GISGeometrycollectionTest.php
Normal file
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISGeometry
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\gis\GISGeometrycollection;
|
||||
|
||||
require_once 'libraries/tcpdf/tcpdf.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\gis\GISGeometrycollection class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISGeometryCollectionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = GISGeometrycollection::singleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for scaleRow
|
||||
*
|
||||
* @param string $spatial string to parse
|
||||
* @param array $output expected parsed output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForScaleRow
|
||||
*/
|
||||
public function testScaleRow($spatial, $output)
|
||||
{
|
||||
$this->assertEquals($output, $this->object->scaleRow($spatial));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testScaleRow() test case
|
||||
*
|
||||
* @return array test data for testScaleRow() test case
|
||||
*/
|
||||
public function providerForScaleRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
|
||||
. '(20 30,35 32,30 20,20 30)))',
|
||||
array(
|
||||
'maxX' => 45.0,
|
||||
'minX' => 10.0,
|
||||
'maxY' => 45.0,
|
||||
'minY' => 10.0
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for generateWkt
|
||||
*
|
||||
* @param array $gis_data array of GIS data
|
||||
* @param integer $index index in $gis_data
|
||||
* @param string $empty empty parameter
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForGenerateWkt
|
||||
*/
|
||||
public function testGenerateWkt($gis_data, $index, $empty, $output)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->generateWkt($gis_data, $index, $empty)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGenerateWkt() test case
|
||||
*
|
||||
* @return array test data for testGenerateWkt() test case
|
||||
*/
|
||||
public function providerForGenerateWkt()
|
||||
{
|
||||
$temp1 = array(
|
||||
0 => array(
|
||||
'gis_type' => 'LINESTRING',
|
||||
'LINESTRING' => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array('x' => 5.02, 'y' => 8.45),
|
||||
1 => array('x' => 6.14, 'y' => 0.15)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$temp1,
|
||||
0,
|
||||
null,
|
||||
'GEOMETRYCOLLECTION(LINESTRING(5.02 8.45,6.14 0.15))'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for generateParams
|
||||
*
|
||||
* @param string $value string to parse
|
||||
* @param array $output expected parsed output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForGenerateParams
|
||||
*/
|
||||
public function testGenerateParams($value, $output)
|
||||
{
|
||||
$this->assertEquals($output, $this->object->generateParams($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGenerateParams() test case
|
||||
*
|
||||
* @return array test data for testGenerateParams() test case
|
||||
*/
|
||||
public function providerForGenerateParams()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'GEOMETRYCOLLECTION(LINESTRING(5.02 8.45,6.14 0.15))',
|
||||
array(
|
||||
'srid' => 0,
|
||||
'GEOMETRYCOLLECTION' => array('geom_count' => 1),
|
||||
'0' => array(
|
||||
'gis_type' => 'LINESTRING',
|
||||
'LINESTRING' => array(
|
||||
'no_of_points' => 2,
|
||||
'0' => array(
|
||||
'x' => 5.02,
|
||||
'y' => 8.45
|
||||
),
|
||||
'1' => array(
|
||||
'x' => 6.14,
|
||||
'y' => 0.15
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for prepareRowAsPng
|
||||
*
|
||||
* @param string $spatial string to parse
|
||||
* @param string $label field label
|
||||
* @param string $line_color line color
|
||||
* @param array $scale_data scaling parameters
|
||||
* @param resource $image initial image
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForPrepareRowAsPng
|
||||
*/
|
||||
public function testPrepareRowAsPng(
|
||||
$spatial, $label, $line_color, $scale_data, $image
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPng(
|
||||
$spatial, $label, $line_color, $scale_data, $image
|
||||
);
|
||||
$this->assertEquals(120, imagesx($return));
|
||||
$this->assertEquals(150, imagesy($return));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testPrepareRowAsPng() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPng() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPng()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
|
||||
. '(20 30,35 32,30 20,20 30)))',
|
||||
'image',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
imagecreatetruecolor('120', '150')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for prepareRowAsPdf
|
||||
*
|
||||
* @param string $spatial string to parse
|
||||
* @param string $label field label
|
||||
* @param string $line_color line color
|
||||
* @param array $scale_data scaling parameters
|
||||
* @param string $pdf expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForPrepareRowAsPdf
|
||||
*/
|
||||
public function testPrepareRowAsPdf(
|
||||
$spatial, $label, $line_color, $scale_data, $pdf
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPdf(
|
||||
$spatial, $label, $line_color, $scale_data, $pdf
|
||||
);
|
||||
$this->assertInstanceOf('TCPDF', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testPrepareRowAsPdf() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPdf() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPdf()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
|
||||
. '(20 30,35 32,30 20,20 30)))',
|
||||
'pdf',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
new \TCPDF(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for prepareRowAsSvg
|
||||
*
|
||||
* @param string $spatial string to parse
|
||||
* @param string $label field label
|
||||
* @param string $line_color line color
|
||||
* @param array $scale_data scaling parameters
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForPrepareRowAsSvg
|
||||
*/
|
||||
public function testPrepareRowAsSvg(
|
||||
$spatial, $label, $line_color, $scale_data, $output
|
||||
) {
|
||||
$string = $this->object->prepareRowAsSvg(
|
||||
$spatial, $label, $line_color, $scale_data
|
||||
);
|
||||
$this->assertEquals(1, preg_match($output, $string));
|
||||
$this->assertRegExp(
|
||||
$output,
|
||||
$this->object->prepareRowAsSvg(
|
||||
$spatial, $label, $line_color, $scale_data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testPrepareRowAsSvg() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsSvg() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsSvg()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
|
||||
. '(20 30,35 32,30 20,20 30)))',
|
||||
'svg',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
'/^(<path d=" M 46, 268 L -4, 248 L 6, 208 L 66, 198 Z M 16,'
|
||||
. ' 228 L 46, 224 L 36, 248 Z " name="svg" id="svg)(\d+)'
|
||||
. '(" class="polygon vector" stroke="black" stroke-width="0.5"'
|
||||
. ' fill="#B02EE0" fill-rule="evenodd" fill-opacity="0.8"\/>)$/'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for prepareRowAsOl
|
||||
*
|
||||
* @param string $spatial string to parse
|
||||
* @param integer $srid SRID
|
||||
* @param string $label field label
|
||||
* @param string $line_color line color
|
||||
* @param array $scale_data scaling parameters
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForPrepareRowAsOl
|
||||
*/
|
||||
public function testPrepareRowAsOl(
|
||||
$spatial, $srid, $label, $line_color, $scale_data, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->prepareRowAsOl(
|
||||
$spatial, $srid, $label, $line_color, $scale_data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testPrepareRowAsOl() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsOl() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsOl()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
|
||||
. '(20 30,35 32,30 20,20 30)))',
|
||||
4326,
|
||||
'Ol',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'minX' => '0',
|
||||
'minY' => '0',
|
||||
'maxX' => '1',
|
||||
'maxY' => '1',
|
||||
),
|
||||
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
|
||||
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326'
|
||||
. '"), map.getProjectionObject())); bound.extend(new OpenLayer'
|
||||
. 's.LonLat(1, 1).transform(new OpenLayers.Projection("EPSG:43'
|
||||
. '26"), map.getProjectionObject()));vectorLayer.addFeatures(n'
|
||||
. 'ew OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygo'
|
||||
. 'n(new Array(new OpenLayers.Geometry.LinearRing(new Array((n'
|
||||
. 'ew OpenLayers.Geometry.Point(35,10)).transform(new OpenLaye'
|
||||
. 'rs.Projection("EPSG:4326"), map.getProjectionObject()), (ne'
|
||||
. 'w OpenLayers.Geometry.Point(10,20)).transform(new OpenLayer'
|
||||
. 's.Projection("EPSG:4326"), map.getProjectionObject()), (new'
|
||||
. ' OpenLayers.Geometry.Point(15,40)).transform(new OpenLayers.'
|
||||
. 'Projection("EPSG:4326"), map.getProjectionObject()), (new O'
|
||||
. 'penLayers.Geometry.Point(45,45)).transform(new OpenLayers.P'
|
||||
. 'rojection("EPSG:4326"), map.getProjectionObject()), (new Op'
|
||||
. 'enLayers.Geometry.Point(35,10)).transform(new OpenLayers.Pr'
|
||||
. 'ojection("EPSG:4326"), map.getProjectionObject()))), new Op'
|
||||
. 'enLayers.Geometry.LinearRing(new Array((new OpenLayers.Geom'
|
||||
. 'etry.Point(20,30)).transform(new OpenLayers.Projection("EPS'
|
||||
. 'G:4326"), map.getProjectionObject()), (new OpenLayers.Geome'
|
||||
. 'try.Point(35,32)).transform(new OpenLayers.Projection("EPSG'
|
||||
. ':4326"), map.getProjectionObject()), (new OpenLayers.Geomet'
|
||||
. 'ry.Point(30,20)).transform(new OpenLayers.Projection("EPSG:'
|
||||
. '4326"), map.getProjectionObject()), (new OpenLayers.Geometry'
|
||||
. '.Point(20,30)).transform(new OpenLayers.Projection("EPSG:43'
|
||||
. '26"), map.getProjectionObject()))))), null, {"strokeColor":'
|
||||
. '"#000000","strokeWidth":0.5,"fillColor":"#B02EE0","fillOpac'
|
||||
. 'ity":0.8,"label":"Ol","fontSize":10}));'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
366
#pma/test/classes/gis/GISLinestringTest.php
Normal file
366
#pma/test/classes/gis/GISLinestringTest.php
Normal file
@@ -0,0 +1,366 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISLinestring
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\gis\GISLinestring;
|
||||
|
||||
require_once 'GISGeomTest.php';
|
||||
require_once 'libraries/tcpdf/tcpdf.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\gis\GISLinestring class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISLinestringTest extends GISGeomTest
|
||||
{
|
||||
/**
|
||||
* @var GISLinestring
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = GISLinestring::singleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateWkt
|
||||
*
|
||||
* @return data for testGenerateWkt
|
||||
*/
|
||||
public function providerForTestGenerateWkt()
|
||||
{
|
||||
$temp1 = array(
|
||||
0 => array(
|
||||
'LINESTRING' => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array('x' => 5.02, 'y' => 8.45),
|
||||
1 => array('x' => 6.14, 'y' => 0.15)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$temp2 = $temp1;
|
||||
$temp2[0]['LINESTRING']['no_of_points'] = 3;
|
||||
$temp2[0]['LINESTRING'][2] = array('x' => 1.56);
|
||||
|
||||
$temp3 = $temp2;
|
||||
$temp3[0]['LINESTRING']['no_of_points'] = -1;
|
||||
|
||||
$temp4 = $temp3;
|
||||
$temp4[0]['LINESTRING']['no_of_points'] = 3;
|
||||
unset($temp4[0]['LINESTRING'][2]['x']);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$temp1,
|
||||
0,
|
||||
null,
|
||||
'LINESTRING(5.02 8.45,6.14 0.15)'
|
||||
),
|
||||
// if a coordinate is missing, default is empty string
|
||||
array(
|
||||
$temp2,
|
||||
0,
|
||||
null,
|
||||
'LINESTRING(5.02 8.45,6.14 0.15,1.56 )'
|
||||
),
|
||||
// if no_of_points is not valid, it is considered as 2
|
||||
array(
|
||||
$temp3,
|
||||
0,
|
||||
null,
|
||||
'LINESTRING(5.02 8.45,6.14 0.15)'
|
||||
),
|
||||
// missing coordinates are replaced with provided values (3rd parameter)
|
||||
array(
|
||||
$temp4,
|
||||
0,
|
||||
'0',
|
||||
'LINESTRING(5.02 8.45,6.14 0.15,0 0)'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateParams
|
||||
*
|
||||
* @return data for testGenerateParams
|
||||
*/
|
||||
public function providerForTestGenerateParams()
|
||||
{
|
||||
$temp = array(
|
||||
'LINESTRING' => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array('x' => '5.02', 'y' => '8.45'),
|
||||
1 => array('x' => '6.14', 'y' => '0.15')
|
||||
)
|
||||
);
|
||||
$temp1 = $temp;
|
||||
$temp1['gis_type'] = 'LINESTRING';
|
||||
|
||||
return array(
|
||||
array(
|
||||
"'LINESTRING(5.02 8.45,6.14 0.15)',124",
|
||||
null,
|
||||
array(
|
||||
'srid' => '124',
|
||||
0 => $temp
|
||||
)
|
||||
),
|
||||
array(
|
||||
'LINESTRING(5.02 8.45,6.14 0.15)',
|
||||
2,
|
||||
array(
|
||||
2 => $temp1
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testScaleRow
|
||||
*
|
||||
* @return data for testScaleRow
|
||||
*/
|
||||
public function providerForTestScaleRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
array(
|
||||
'minX' => 12,
|
||||
'maxX' => 69,
|
||||
'minY' => 23,
|
||||
'maxY' => 78
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPng() method
|
||||
*
|
||||
* @param string $spatial GIS LINESTRING object
|
||||
* @param string $label label for the GIS LINESTRING object
|
||||
* @param string $line_color color for the GIS LINESTRING object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $image image object
|
||||
*
|
||||
* @dataProvider providerForPrepareRowAsPng
|
||||
* @return void
|
||||
*/
|
||||
public function testPrepareRowAsPng($spatial, $label, $line_color,
|
||||
$scale_data, $image
|
||||
) {
|
||||
$this->object->prepareRowAsPng(
|
||||
$spatial, $label, $line_color, $scale_data, $image
|
||||
);
|
||||
/* TODO: this never fails */
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPng() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPng() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPng()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
'image',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
imagecreatetruecolor('120', '150')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPdf() method
|
||||
*
|
||||
* @param string $spatial GIS LINESTRING object
|
||||
* @param string $label label for the GIS LINESTRING object
|
||||
* @param string $line_color color for the GIS LINESTRING object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $pdf TCPDF instance
|
||||
*
|
||||
* @dataProvider providerForPrepareRowAsPdf
|
||||
* @return void
|
||||
*/
|
||||
public function testPrepareRowAsPdf($spatial, $label, $line_color,
|
||||
$scale_data, $pdf
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPdf(
|
||||
$spatial, $label, $line_color, $scale_data, $pdf
|
||||
);
|
||||
$this->assertInstanceOf('TCPDF', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPdf() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPdf() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPdf()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
'pdf',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
new TCPDF(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsSvg() method
|
||||
*
|
||||
* @param string $spatial GIS LINESTRING object
|
||||
* @param string $label label for the GIS LINESTRING object
|
||||
* @param string $line_color color for the GIS LINESTRING object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @dataProvider providerForPrepareRowAsSvg
|
||||
* @return void
|
||||
*/
|
||||
public function testPrepareRowAsSvg($spatial, $label, $line_color,
|
||||
$scale_data, $output
|
||||
) {
|
||||
$string = $this->object->prepareRowAsSvg(
|
||||
$spatial, $label, $line_color, $scale_data
|
||||
);
|
||||
$this->assertEquals(1, preg_match($output, $string));
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsSvg() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsSvg() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsSvg()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
'svg',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
'/^(<polyline points="0,218 72,138 114,242 26,198 4,182 46,132 " '
|
||||
. 'name="svg" id="svg)(\d+)(" class="linestring vector" fill="none" '
|
||||
. 'stroke="#B02EE0" stroke-width="2"\/>)$/'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsOl() method
|
||||
*
|
||||
* @param string $spatial GIS LINESTRING object
|
||||
* @param int $srid spatial reference ID
|
||||
* @param string $label label for the GIS LINESTRING object
|
||||
* @param string $line_color color for the GIS LINESTRING object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @dataProvider providerForPrepareRowAsOl
|
||||
* @return void
|
||||
*/
|
||||
public function testPrepareRowAsOl($spatial, $srid, $label,
|
||||
$line_color, $scale_data, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$this->object->prepareRowAsOl(
|
||||
$spatial, $srid, $label, $line_color, $scale_data
|
||||
),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsOl() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsOl() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsOl()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
4326,
|
||||
'Ol',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'minX' => '0',
|
||||
'minY' => '0',
|
||||
'maxX' => '1',
|
||||
'maxY' => '1',
|
||||
),
|
||||
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
|
||||
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
|
||||
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), map.get'
|
||||
. 'ProjectionObject()));vectorLayer.addFeatures(new OpenLayers.Feat'
|
||||
. 'ure.Vector(new OpenLayers.Geometry.LineString(new Array((new Open'
|
||||
. 'Layers.Geometry.Point(12,35)).transform(new OpenLayers.Projection'
|
||||
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.Geome'
|
||||
. 'try.Point(48,75)).transform(new OpenLayers.Projection("EPSG:4326"'
|
||||
. '), map.getProjectionObject()), (new OpenLayers.Geometry.Point(69'
|
||||
. ',23)).transform(new OpenLayers.Projection("EPSG:4326"), map.'
|
||||
. 'getProjectionObject()), (new OpenLayers.Geometry.Point(25,45)).'
|
||||
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.'
|
||||
. 'getProjectionObject()), (new OpenLayers.Geometry.Point(14,53)).'
|
||||
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.get'
|
||||
. 'ProjectionObject()), (new OpenLayers.Geometry.Point(35,78)).'
|
||||
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.'
|
||||
. 'getProjectionObject()))), null, {"strokeColor":"#B02EE0",'
|
||||
. '"strokeWidth":2,"label":"Ol","fontSize":10}));'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
430
#pma/test/classes/gis/GISMultilinestringTest.php
Normal file
430
#pma/test/classes/gis/GISMultilinestringTest.php
Normal file
@@ -0,0 +1,430 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISMultilinestring
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\gis\GISMultilinestring;
|
||||
|
||||
require_once 'GISGeomTest.php';
|
||||
require_once 'libraries/tcpdf/tcpdf.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\gis\GISMultilinestring class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISMultilinestringTest extends GISGeomTest
|
||||
{
|
||||
/**
|
||||
* @var GISMultilinestring
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = GISMultilinestring::singleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateWkt
|
||||
*
|
||||
* @return data for testGenerateWkt
|
||||
*/
|
||||
public function providerForTestGenerateWkt()
|
||||
{
|
||||
$temp = array(
|
||||
0 => array(
|
||||
'MULTILINESTRING' => array(
|
||||
'no_of_lines' => 2,
|
||||
0 => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array('x' => 5.02, 'y' => 8.45),
|
||||
1 => array('x' => 6.14, 'y' => 0.15)
|
||||
),
|
||||
1 => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array('x' => 1.23, 'y' => 4.25),
|
||||
1 => array('x' => 9.15, 'y' => 0.47)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$temp1 = $temp;
|
||||
unset($temp1[0]['MULTILINESTRING'][1][1]['y']);
|
||||
|
||||
$temp2 = $temp;
|
||||
$temp2[0]['MULTILINESTRING']['no_of_lines'] = 0;
|
||||
|
||||
$temp3 = $temp;
|
||||
$temp3[0]['MULTILINESTRING'][1]['no_of_points'] = 1;
|
||||
|
||||
return array(
|
||||
array(
|
||||
$temp,
|
||||
0,
|
||||
null,
|
||||
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))'
|
||||
),
|
||||
// values at undefined index
|
||||
array(
|
||||
$temp,
|
||||
1,
|
||||
null,
|
||||
'MULTILINESTRING(( , ))'
|
||||
),
|
||||
// if a coordinate is missing, default is empty string
|
||||
array(
|
||||
$temp1,
|
||||
0,
|
||||
null,
|
||||
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 ))'
|
||||
),
|
||||
// missing coordinates are replaced with provided values (3rd parameter)
|
||||
array(
|
||||
$temp1,
|
||||
0,
|
||||
'0',
|
||||
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0))'
|
||||
),
|
||||
// at least one line should be there
|
||||
array(
|
||||
$temp2,
|
||||
0,
|
||||
null,
|
||||
'MULTILINESTRING((5.02 8.45,6.14 0.15))'
|
||||
),
|
||||
// a line should have at least two points
|
||||
array(
|
||||
$temp3,
|
||||
0,
|
||||
'0',
|
||||
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getShape method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetShape()
|
||||
{
|
||||
$row_data = array(
|
||||
'numparts' => 2,
|
||||
'parts' => array(
|
||||
0 => array(
|
||||
'points' => array(
|
||||
0 => array('x' => 5.02, 'y' => 8.45),
|
||||
1 => array('x' => 6.14, 'y' => 0.15),
|
||||
),
|
||||
),
|
||||
1 => array(
|
||||
'points' => array(
|
||||
0 => array('x' => 1.23, 'y' => 4.25),
|
||||
1 => array('x' => 9.15, 'y' => 0.47),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->object->getShape($row_data),
|
||||
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateParams
|
||||
*
|
||||
* @return data for testGenerateParams
|
||||
*/
|
||||
public function providerForTestGenerateParams()
|
||||
{
|
||||
$temp = array(
|
||||
'MULTILINESTRING' => array(
|
||||
'no_of_lines' => 2,
|
||||
0 => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array('x' => 5.02, 'y' => 8.45),
|
||||
1 => array('x' => 6.14, 'y' => 0.15),
|
||||
),
|
||||
1 => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array('x' => 1.23, 'y' => 4.25),
|
||||
1 => array('x' => 9.15, 'y' => 0.47),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$temp1 = $temp;
|
||||
$temp1['gis_type'] = 'MULTILINESTRING';
|
||||
|
||||
return array(
|
||||
array(
|
||||
"'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))',124",
|
||||
null,
|
||||
array(
|
||||
'srid' => '124',
|
||||
0 => $temp
|
||||
)
|
||||
),
|
||||
array(
|
||||
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))',
|
||||
2,
|
||||
array(
|
||||
2 => $temp1
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testScaleRow
|
||||
*
|
||||
* @return data for testScaleRow
|
||||
*/
|
||||
public function providerForTestScaleRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
|
||||
array(
|
||||
'minX' => 17,
|
||||
'maxX' => 178,
|
||||
'minY' => 10,
|
||||
'maxY' => 75
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPng() method
|
||||
*
|
||||
* @param string $spatial GIS MULTILINESTRING object
|
||||
* @param string $label label for the GIS MULTILINESTRING object
|
||||
* @param string $line_color color for the GIS MULTILINESTRING object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $image image object
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPng
|
||||
*/
|
||||
public function testPrepareRowAsPng(
|
||||
$spatial, $label, $line_color, $scale_data, $image
|
||||
) {
|
||||
$this->object->prepareRowAsPng(
|
||||
$spatial, $label, $line_color, $scale_data, $image
|
||||
);
|
||||
/* TODO: this never fails */
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPng() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPng() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPng()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
|
||||
'image',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
imagecreatetruecolor('120', '150')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPdf() method
|
||||
*
|
||||
* @param string $spatial GIS MULTILINESTRING object
|
||||
* @param string $label label for the GIS MULTILINESTRING object
|
||||
* @param string $line_color color for the GIS MULTILINESTRING object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $pdf TCPDF instance
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPdf
|
||||
*/
|
||||
public function testPrepareRowAsPdf(
|
||||
$spatial, $label, $line_color, $scale_data, $pdf
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPdf(
|
||||
$spatial, $label, $line_color, $scale_data, $pdf
|
||||
);
|
||||
$this->assertInstanceOf('TCPDF', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPdf() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPdf() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPdf()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
|
||||
'pdf',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
new TCPDF(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsSvg() method
|
||||
*
|
||||
* @param string $spatial GIS MULTILINESTRING object
|
||||
* @param string $label label for the GIS MULTILINESTRING object
|
||||
* @param string $line_color color for the GIS MULTILINESTRING object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsSvg
|
||||
*/
|
||||
public function testPrepareRowAsSvg(
|
||||
$spatial, $label, $line_color, $scale_data, $output
|
||||
) {
|
||||
$string = $this->object->prepareRowAsSvg(
|
||||
$spatial, $label, $line_color, $scale_data
|
||||
);
|
||||
$this->assertEquals(1, preg_match($output, $string));
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsSvg() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsSvg() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsSvg()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
|
||||
'svg',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
'/^(<polyline points="48,260 70,242 100,138 " name="svg" '
|
||||
. 'class="linestring vector" fill="none" stroke="#B02EE0" '
|
||||
. 'stroke-width="2" id="svg)(\d+)("\/><polyline points="48,268 10,'
|
||||
. '242 332,182 " name="svg" class="linestring vector" fill="none" '
|
||||
. 'stroke="#B02EE0" stroke-width="2" id="svg)(\d+)("\/>)$/'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsOl() method
|
||||
*
|
||||
* @param string $spatial GIS MULTILINESTRING object
|
||||
* @param int $srid spatial reference ID
|
||||
* @param string $label label for the GIS MULTILINESTRING object
|
||||
* @param string $line_color color for the GIS MULTILINESTRING object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsOl
|
||||
*/
|
||||
public function testPrepareRowAsOl(
|
||||
$spatial, $srid, $label, $line_color, $scale_data, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->prepareRowAsOl(
|
||||
$spatial, $srid, $label, $line_color, $scale_data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsOl() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsOl() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsOl()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
|
||||
4326,
|
||||
'Ol',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'minX' => '0',
|
||||
'minY' => '0',
|
||||
'maxX' => '1',
|
||||
'maxY' => '1',
|
||||
),
|
||||
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
|
||||
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
|
||||
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), map.'
|
||||
. 'getProjectionObject()));vectorLayer.addFeatures(new OpenLayers.'
|
||||
. 'Feature.Vector(new OpenLayers.Geometry.MultiLineString(new Arr'
|
||||
. 'ay(new OpenLayers.Geometry.LineString(new Array((new OpenLayers.'
|
||||
. 'Geometry.Point(36,14)).transform(new OpenLayers.Projection("EPSG:'
|
||||
. '4326"), map.getProjectionObject()), (new OpenLayers.Geometry.Po'
|
||||
. 'int(47,23)).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject()), (new OpenLayers.Geometry.Point(62,75)'
|
||||
. ').transform(new OpenLayers.Projection("EPSG:4326"), map.getProjec'
|
||||
. 'tionObject()))), new OpenLayers.Geometry.LineString(new Array(('
|
||||
. 'new OpenLayers.Geometry.Point(36,10)).transform(new OpenLayers.'
|
||||
. 'Projection("EPSG:4326"), map.getProjectionObject()), (new Open'
|
||||
. 'Layers.Geometry.Point(17,23)).transform(new OpenLayers.Projection'
|
||||
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.Geo'
|
||||
. 'metry.Point(178,53)).transform(new OpenLayers.Projection("EPSG:'
|
||||
. '4326"), map.getProjectionObject()))))), null, {"strokeColor":"'
|
||||
. '#B02EE0","strokeWidth":2,"label":"Ol","fontSize":10}));'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
379
#pma/test/classes/gis/GISMultipointTest.php
Normal file
379
#pma/test/classes/gis/GISMultipointTest.php
Normal file
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISMultipoint
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\gis\GISMultipoint;
|
||||
|
||||
require_once 'GISGeomTest.php';
|
||||
require_once 'libraries/tcpdf/tcpdf.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\gis\GISMultipoint class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISMultipointTest extends GISGeomTest
|
||||
{
|
||||
/**
|
||||
* @var GISMultipoint
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = GISMultipoint::singleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateWkt
|
||||
*
|
||||
* @return data for testGenerateWkt
|
||||
*/
|
||||
public function providerForTestGenerateWkt()
|
||||
{
|
||||
$gis_data1 = array(
|
||||
0 => array(
|
||||
'MULTIPOINT' => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array(
|
||||
'x' => 5.02,
|
||||
'y' => 8.45
|
||||
),
|
||||
1 => array(
|
||||
'x' => 1.56,
|
||||
'y' => 4.36
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$gis_data2 = $gis_data1;
|
||||
$gis_data2[0]['MULTIPOINT']['no_of_points'] = -1;
|
||||
|
||||
return array(
|
||||
array(
|
||||
$gis_data1,
|
||||
0,
|
||||
null,
|
||||
'MULTIPOINT(5.02 8.45,1.56 4.36)'
|
||||
),
|
||||
array(
|
||||
$gis_data2,
|
||||
0,
|
||||
null,
|
||||
'MULTIPOINT(5.02 8.45)'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getShape method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetShape()
|
||||
{
|
||||
$gis_data = array(
|
||||
'numpoints' => 2,
|
||||
'points' => array(
|
||||
0 => array('x' => 5.02, 'y' => 8.45),
|
||||
1 => array('x' => 6.14, 'y' => 0.15)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->object->getShape($gis_data),
|
||||
'MULTIPOINT(5.02 8.45,6.14 0.15)'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateParams
|
||||
*
|
||||
* @return data for testGenerateParams
|
||||
*/
|
||||
public function providerForTestGenerateParams()
|
||||
{
|
||||
$temp1 = array(
|
||||
'MULTIPOINT' => array(
|
||||
'no_of_points' => 2,
|
||||
0 => array('x' => '5.02', 'y' => '8.45'),
|
||||
1 => array('x' => '6.14', 'y' => '0.15')
|
||||
)
|
||||
);
|
||||
$temp2 = $temp1;
|
||||
$temp2['gis_type'] = 'MULTIPOINT';
|
||||
|
||||
return array(
|
||||
array(
|
||||
"'MULTIPOINT(5.02 8.45,6.14 0.15)',124",
|
||||
null,
|
||||
array(
|
||||
'srid' => '124',
|
||||
0 => $temp1
|
||||
)
|
||||
),
|
||||
array(
|
||||
'MULTIPOINT(5.02 8.45,6.14 0.15)',
|
||||
2,
|
||||
array(
|
||||
2 => $temp2
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testScaleRow
|
||||
*
|
||||
* @return data for testScaleRow
|
||||
*/
|
||||
public function providerForTestScaleRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
array(
|
||||
'minX' => 12,
|
||||
'maxX' => 69,
|
||||
'minY' => 23,
|
||||
'maxY' => 78
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPng() method
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOINT object
|
||||
* @param string $label label for the GIS MULTIPOINT object
|
||||
* @param string $point_color color for the GIS MULTIPOINT object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $image image object
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPng
|
||||
*/
|
||||
public function testPrepareRowAsPng(
|
||||
$spatial, $label, $point_color, $scale_data, $image
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPng(
|
||||
$spatial, $label, $point_color, $scale_data, $image
|
||||
);
|
||||
$this->assertImage($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPng() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPng() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPng()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
'image',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
imagecreatetruecolor('120', '150'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPdf() method
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOINT object
|
||||
* @param string $label label for the GIS MULTIPOINT object
|
||||
* @param string $point_color color for the GIS MULTIPOINT object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $pdf TCPDF instance
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPdf
|
||||
*/
|
||||
public function testPrepareRowAsPdf(
|
||||
$spatial, $label, $point_color, $scale_data, $pdf
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPdf(
|
||||
$spatial, $label, $point_color, $scale_data, $pdf
|
||||
);
|
||||
$this->assertInstanceOf('TCPDF', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPdf() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPdf() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPdf()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
'pdf',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
new TCPDF(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsSvg() method
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOINT object
|
||||
* @param string $label label for the GIS MULTIPOINT object
|
||||
* @param string $point_color color for the GIS MULTIPOINT object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsSvg
|
||||
*/
|
||||
public function testPrepareRowAsSvg(
|
||||
$spatial, $label, $point_color, $scale_data, $output
|
||||
) {
|
||||
$string = $this->object->prepareRowAsSvg(
|
||||
$spatial, $label, $point_color, $scale_data
|
||||
);
|
||||
$this->assertEquals(1, preg_match($output, $string));
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsSvg() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsSvg() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsSvg()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
'svg',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
'/^(<circle cx="72" cy="138" r="3" name="svg" class="multipoint '
|
||||
. 'vector" fill="white" stroke="#B02EE0" stroke-width="2" id="svg)'
|
||||
. '(\d+)("\/><circle cx="114" cy="242" r="3" name="svg" class="mult'
|
||||
. 'ipoint vector" fill="white" stroke="#B02EE0" stroke-width="2" id'
|
||||
. '="svg)(\d+)("\/><circle cx="26" cy="198" r="3" name="svg" class='
|
||||
. '"multipoint vector" fill="white" stroke="#B02EE0" stroke-width='
|
||||
. '"2" id="svg)(\d+)("\/><circle cx="4" cy="182" r="3" name="svg" '
|
||||
. 'class="multipoint vector" fill="white" stroke="#B02EE0" stroke-'
|
||||
. 'width="2" id="svg)(\d+)("\/><circle cx="46" cy="132" r="3" name='
|
||||
. '"svg" class="multipoint vector" fill="white" stroke="#B02EE0" '
|
||||
. 'stroke-width="2" id="svg)(\d+)("\/>)$/'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsOl() method
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOINT object
|
||||
* @param int $srid spatial reference ID
|
||||
* @param string $label label for the GIS MULTIPOINT object
|
||||
* @param string $point_color color for the GIS MULTIPOINT object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsOl
|
||||
*/
|
||||
public function testPrepareRowAsOl(
|
||||
$spatial, $srid, $label, $point_color, $scale_data, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->prepareRowAsOl(
|
||||
$spatial, $srid, $label, $point_color, $scale_data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsOl() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsOl() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsOl()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
|
||||
4326,
|
||||
'Ol',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'minX' => '0',
|
||||
'minY' => '0',
|
||||
'maxX' => '1',
|
||||
'maxY' => '1',
|
||||
),
|
||||
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.Lon'
|
||||
. 'Lat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
|
||||
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), map.'
|
||||
. 'getProjectionObject()));vectorLayer.addFeatures(new OpenLayers.'
|
||||
. 'Feature.Vector(new OpenLayers.Geometry.MultiPoint(new Array(('
|
||||
. 'new OpenLayers.Geometry.Point(12,35)).transform(new OpenLayers.'
|
||||
. 'Projection("EPSG:4326"), map.getProjectionObject()), (new Open'
|
||||
. 'Layers.Geometry.Point(48,75)).transform(new OpenLayers.Projec'
|
||||
. 'tion("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.'
|
||||
. 'Geometry.Point(69,23)).transform(new OpenLayers.Projection("'
|
||||
. 'EPSG:4326"), map.getProjectionObject()), (new OpenLayers.Geometry'
|
||||
. '.Point(25,45)).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject()), (new OpenLayers.Geometry.Point(14,53)'
|
||||
. ').transform(new OpenLayers.Projection("EPSG:4326"), map.getProjec'
|
||||
. 'tionObject()), (new OpenLayers.Geometry.Point(35,78)).transform'
|
||||
. '(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject('
|
||||
. ')))), null, {"pointRadius":3,"fillColor":"#ffffff","strokeColor"'
|
||||
. ':"#B02EE0","strokeWidth":2,"label":"Ol","labelYOffset":-8,'
|
||||
. '"fontSize":10}));'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
487
#pma/test/classes/gis/GISMultipolygonTest.php
Normal file
487
#pma/test/classes/gis/GISMultipolygonTest.php
Normal file
@@ -0,0 +1,487 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISMultipolygon
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\gis\GISMultipolygon;
|
||||
|
||||
require_once 'GISGeomTest.php';
|
||||
require_once 'libraries/tcpdf/tcpdf.php';
|
||||
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\gis\GISMultipolygon class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISMultipolygonTest extends GISGeomTest
|
||||
{
|
||||
/**
|
||||
* @var GISMultipolygon
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = GISMultipolygon::singleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide some common data to data providers
|
||||
*
|
||||
* @return array common data for data providers
|
||||
*/
|
||||
private function _getData()
|
||||
{
|
||||
return array(
|
||||
'MULTIPOLYGON' => array(
|
||||
'no_of_polygons' => 2,
|
||||
0 => array(
|
||||
'no_of_lines' => 2,
|
||||
0 => array(
|
||||
'no_of_points' => 5,
|
||||
0 => array('x' => 35, 'y' => 10),
|
||||
1 => array('x' => 10, 'y' => 20),
|
||||
2 => array('x' => 15, 'y' => 40),
|
||||
3 => array('x' => 45, 'y' => 45),
|
||||
4 => array('x' => 35, 'y' => 10),
|
||||
),
|
||||
1 => array(
|
||||
'no_of_points' => 4,
|
||||
0 => array('x' => 20, 'y' => 30),
|
||||
1 => array('x' => 35, 'y' => 32),
|
||||
2 => array('x' => 30, 'y' => 20),
|
||||
3 => array('x' => 20, 'y' => 30),
|
||||
)
|
||||
),
|
||||
1 => array(
|
||||
'no_of_lines' => 1,
|
||||
0 => array(
|
||||
'no_of_points' => 4,
|
||||
0 => array('x' => 123, 'y' => 0),
|
||||
1 => array('x' => 23, 'y' => 30),
|
||||
2 => array('x' => 17, 'y' => 63),
|
||||
3 => array('x' => 123, 'y' => 0),
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateWkt
|
||||
*
|
||||
* @return data for testGenerateWkt
|
||||
*/
|
||||
public function providerForTestGenerateWkt()
|
||||
{
|
||||
$temp = array(
|
||||
0 => $this->_getData()
|
||||
);
|
||||
|
||||
$temp1 = $temp;
|
||||
$temp1[0]['MULTIPOLYGON']['no_of_polygons'] = 0;
|
||||
|
||||
$temp2 = $temp;
|
||||
$temp2[0]['MULTIPOLYGON'][1]['no_of_lines'] = 0;
|
||||
|
||||
$temp3 = $temp;
|
||||
$temp3[0]['MULTIPOLYGON'][1][0]['no_of_points'] = 3;
|
||||
|
||||
return array(
|
||||
array(
|
||||
$temp,
|
||||
0,
|
||||
null,
|
||||
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
|
||||
. ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))'
|
||||
),
|
||||
// at lease one polygon should be there
|
||||
array(
|
||||
$temp1,
|
||||
0,
|
||||
null,
|
||||
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
|
||||
. ',(20 30,35 32,30 20,20 30)))'
|
||||
),
|
||||
// a polygon should have at least one ring
|
||||
array(
|
||||
$temp2,
|
||||
0,
|
||||
null,
|
||||
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
|
||||
. ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))'
|
||||
),
|
||||
// a ring should have at least four points
|
||||
array(
|
||||
$temp3,
|
||||
0,
|
||||
'0',
|
||||
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
|
||||
. ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateParams
|
||||
*
|
||||
* @return data for testGenerateParams
|
||||
*/
|
||||
public function providerForTestGenerateParams()
|
||||
{
|
||||
$temp = $this->_getData();
|
||||
|
||||
$temp1 = $this->_getData();
|
||||
$temp1['gis_type'] = 'MULTIPOLYGON';
|
||||
|
||||
return array(
|
||||
array(
|
||||
"'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10),"
|
||||
. "(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))',124",
|
||||
null,
|
||||
array(
|
||||
'srid' => '124',
|
||||
0 => $temp
|
||||
)
|
||||
),
|
||||
array(
|
||||
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
|
||||
. ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))',
|
||||
2,
|
||||
array(
|
||||
2 => $temp1
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getShape method
|
||||
*
|
||||
* @param array $row_data array of GIS data
|
||||
* @param string $shape expected shape in WKT
|
||||
*
|
||||
* @dataProvider providerForTestGetShape
|
||||
* @return void
|
||||
*/
|
||||
public function testGetShape($row_data, $shape)
|
||||
{
|
||||
$this->assertEquals($this->object->getShape($row_data), $shape);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGetShape
|
||||
*
|
||||
* @return data for testGetShape
|
||||
*/
|
||||
public function providerForTestGetShape()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'parts' => array(
|
||||
0 => array(
|
||||
'points' => array(
|
||||
0 => array('x' => 10, 'y' => 10),
|
||||
1 => array('x' => 10, 'y' => 40),
|
||||
2 => array('x' => 50, 'y' => 40),
|
||||
3 => array('x' => 50, 'y' => 10),
|
||||
4 => array('x' => 10, 'y' => 10),
|
||||
),
|
||||
),
|
||||
1 => array(
|
||||
'points' => array(
|
||||
0 => array('x' => 60, 'y' => 40),
|
||||
1 => array('x' => 75, 'y' => 65),
|
||||
2 => array('x' => 90, 'y' => 40),
|
||||
3 => array('x' => 60, 'y' => 40),
|
||||
),
|
||||
),
|
||||
2 => array(
|
||||
'points' => array(
|
||||
0 => array('x' => 20, 'y' => 20),
|
||||
1 => array('x' => 40, 'y' => 20),
|
||||
2 => array('x' => 25, 'y' => 30),
|
||||
3 => array('x' => 20, 'y' => 20),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'MULTIPOLYGON(((10 10,10 40,50 40,50 10,10 10),(20 20,40 20,25 30'
|
||||
. ',20 20)),((60 40,75 65,90 40,60 40)))'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testScaleRow
|
||||
*
|
||||
* @return data for testScaleRow
|
||||
*/
|
||||
public function providerForTestScaleRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
|
||||
. '((105 0,56 20,78 73,105 0)))',
|
||||
array(
|
||||
'minX' => 16,
|
||||
'maxX' => 147,
|
||||
'minY' => 0,
|
||||
'maxY' => 83
|
||||
)
|
||||
),
|
||||
array(
|
||||
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20'
|
||||
. ',20 30)),((105 0,56 20,78 73,105 0)))',
|
||||
array(
|
||||
'minX' => 10,
|
||||
'maxX' => 105,
|
||||
'minY' => 0,
|
||||
'maxY' => 73
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPng() method
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOLYGON object
|
||||
* @param string $label label for the GIS MULTIPOLYGON object
|
||||
* @param string $fill_color color for the GIS MULTIPOLYGON object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $image image object
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPng
|
||||
*/
|
||||
public function testPrepareRowAsPng(
|
||||
$spatial, $label, $fill_color, $scale_data, $image
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPng(
|
||||
$spatial, $label, $fill_color, $scale_data, $image
|
||||
);
|
||||
$this->assertImage($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPng() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPng() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPng()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
|
||||
. '((105 0,56 20,78 73,105 0)))',
|
||||
'image',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
imagecreatetruecolor('120', '150'),
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPdf() method
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOLYGON object
|
||||
* @param string $label label for the GIS MULTIPOLYGON object
|
||||
* @param string $fill_color color for the GIS MULTIPOLYGON object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $pdf TCPDF instance
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPdf
|
||||
*/
|
||||
public function testPrepareRowAsPdf(
|
||||
$spatial, $label, $fill_color, $scale_data, $pdf
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPdf(
|
||||
$spatial, $label, $fill_color, $scale_data, $pdf
|
||||
);
|
||||
$this->assertInstanceOf('TCPDF', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPdf() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPdf() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPdf()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
|
||||
. '((105 0,56 20,78 73,105 0)))',
|
||||
'pdf',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
new TCPDF(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsSvg() method
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOLYGON object
|
||||
* @param string $label label for the GIS MULTIPOLYGON object
|
||||
* @param string $fill_color color for the GIS MULTIPOLYGON object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsSvg
|
||||
*/
|
||||
public function testPrepareRowAsSvg(
|
||||
$spatial, $label, $fill_color, $scale_data, $output
|
||||
) {
|
||||
$string = $this->object->prepareRowAsSvg(
|
||||
$spatial, $label, $fill_color, $scale_data
|
||||
);
|
||||
$this->assertEquals(1, preg_match($output, $string));
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsSvg() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsSvg() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsSvg()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
|
||||
. '((105 0,56 20,78 73,105 0)))',
|
||||
'svg',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
'/^(<path d=" M 248, 208 L 270, 122 L 8, 138 Z " name="svg" class="'
|
||||
. 'multipolygon vector" stroke="black" stroke-width="0.5" fill="'
|
||||
. '#B02EE0" fill-rule="evenodd" fill-opacity="0.8" id="svg)(\d+)'
|
||||
. '("\/><path d=" M 186, 288 L 88, 248 L 132, 142 Z " name="svg" '
|
||||
. 'class="multipolygon vector" stroke="black" stroke-width="0.5" '
|
||||
. 'fill="#B02EE0" fill-rule="evenodd" fill-opacity="0.8" id="svg)'
|
||||
. '(\d+)("\/>)$/'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsOl() method
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOLYGON object
|
||||
* @param int $srid spatial reference ID
|
||||
* @param string $label label for the GIS MULTIPOLYGON object
|
||||
* @param string $fill_color color for the GIS MULTIPOLYGON object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsOl
|
||||
*/
|
||||
public function testPrepareRowAsOl(
|
||||
$spatial, $srid, $label, $fill_color, $scale_data, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->prepareRowAsOl(
|
||||
$spatial, $srid, $label, $fill_color, $scale_data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsOl() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsOl() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsOl()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
|
||||
. '((105 0,56 20,78 73,105 0)))',
|
||||
4326,
|
||||
'Ol',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'minX' => '0',
|
||||
'minY' => '0',
|
||||
'maxX' => '1',
|
||||
'maxY' => '1',
|
||||
),
|
||||
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
|
||||
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
|
||||
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), map.ge'
|
||||
. 'tProjectionObject()));vectorLayer.addFeatures(new OpenLayers.'
|
||||
. 'Feature.Vector(new OpenLayers.Geometry.MultiPolygon(new Array'
|
||||
. '(new OpenLayers.Geometry.Polygon(new Array(new OpenLayers.Geo'
|
||||
. 'metry.LinearRing(new Array((new OpenLayers.Geometry.Point'
|
||||
. '(136,40)).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject()), (new OpenLayers.Geometry.Point(147,'
|
||||
. '83)).transform(new OpenLayers.Projection("EPSG:4326"), map.get'
|
||||
. 'ProjectionObject()), (new OpenLayers.Geometry.Point(16,75)).'
|
||||
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.getPro'
|
||||
. 'jectionObject()), (new OpenLayers.Geometry.Point(136,40)).trans'
|
||||
. 'form(new OpenLayers.Projection("EPSG:4326"), map.getProjection'
|
||||
. 'Object()))))), new OpenLayers.Geometry.Polygon(new Array(new '
|
||||
. 'OpenLayers.Geometry.LinearRing(new Array((new OpenLayers.Geometry'
|
||||
. '.Point(105,0)).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject()), (new OpenLayers.Geometry.Point(56,20)'
|
||||
. ').transform(new OpenLayers.Projection("EPSG:4326"), map.getProjec'
|
||||
. 'tionObject()), (new OpenLayers.Geometry.Point(78,73)).transform'
|
||||
. '(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject'
|
||||
. '()), (new OpenLayers.Geometry.Point(105,0)).transform(new Open'
|
||||
. 'Layers.Projection("EPSG:4326"), map.getProjectionObject()))))))'
|
||||
. '), null, {"strokeColor":"#000000","strokeWidth":0.5,"fillColor":'
|
||||
. '"#B02EE0","fillOpacity":0.8,"label":"Ol","fontSize":10}));'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
362
#pma/test/classes/gis/GISPointTest.php
Normal file
362
#pma/test/classes/gis/GISPointTest.php
Normal file
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISPoint
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\gis\GISPoint;
|
||||
|
||||
require_once 'GISGeomTest.php';
|
||||
require_once 'libraries/tcpdf/tcpdf.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\gis\GISPoint class.
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISPointTest extends GISGeomTest
|
||||
{
|
||||
/**
|
||||
* @var GISPoint
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = GISPoint::singleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateWkt
|
||||
*
|
||||
* @return data for testGenerateWkt
|
||||
*/
|
||||
public function providerForTestGenerateWkt()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))),
|
||||
0,
|
||||
null,
|
||||
'POINT(5.02 8.45)'
|
||||
),
|
||||
array(
|
||||
array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))),
|
||||
1,
|
||||
null,
|
||||
'POINT( )'
|
||||
),
|
||||
array(
|
||||
array(0 => array('POINT' => array('x' => 5.02))),
|
||||
0,
|
||||
null,
|
||||
'POINT(5.02 )'
|
||||
),
|
||||
array(
|
||||
array(0 => array('POINT' => array('y' => 8.45))),
|
||||
0,
|
||||
null,
|
||||
'POINT( 8.45)'
|
||||
),
|
||||
array(
|
||||
array(0 => array('POINT' => array())),
|
||||
0,
|
||||
null,
|
||||
'POINT( )'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getShape method
|
||||
*
|
||||
* @param array $row_data array of GIS data
|
||||
* @param string $shape expected shape in WKT
|
||||
*
|
||||
* @dataProvider providerForTestGetShape
|
||||
* @return void
|
||||
*/
|
||||
public function testGetShape($row_data, $shape)
|
||||
{
|
||||
$this->assertEquals($this->object->getShape($row_data), $shape);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGetShape
|
||||
*
|
||||
* @return data for testGetShape
|
||||
*/
|
||||
public function providerForTestGetShape()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('x' => 5.02, 'y' => 8.45),
|
||||
'POINT(5.02 8.45)'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateParams
|
||||
*
|
||||
* @return data for testGenerateParams
|
||||
*/
|
||||
public function providerForTestGenerateParams()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
"'POINT(5.02 8.45)',124",
|
||||
null,
|
||||
array(
|
||||
'srid' => '124',
|
||||
0 => array(
|
||||
'POINT' => array('x' => '5.02', 'y' => '8.45')
|
||||
),
|
||||
)
|
||||
),
|
||||
array(
|
||||
'POINT(5.02 8.45)',
|
||||
2,
|
||||
array(
|
||||
2 => array(
|
||||
'gis_type' => 'POINT',
|
||||
'POINT' => array('x' => '5.02', 'y' => '8.45')
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testScaleRow
|
||||
*
|
||||
* @return data for testScaleRow
|
||||
*/
|
||||
public function providerForTestScaleRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POINT(12 35)',
|
||||
array(
|
||||
'minX' => 12,
|
||||
'maxX' => 12,
|
||||
'minY' => 35,
|
||||
'maxY' => 35,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPng() method
|
||||
*
|
||||
* @param string $spatial GIS POINT object
|
||||
* @param string $label label for the GIS POINT object
|
||||
* @param string $point_color color for the GIS POINT object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $image image object
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPng
|
||||
*/
|
||||
public function testPrepareRowAsPng(
|
||||
$spatial, $label, $point_color, $scale_data, $image
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPng(
|
||||
$spatial, $label, $point_color, $scale_data, $image
|
||||
);
|
||||
$this->assertImage($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPng() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPng() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPng()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POINT(12 35)',
|
||||
'image',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
imagecreatetruecolor('120', '150')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPdf() method
|
||||
*
|
||||
* @param string $spatial GIS POINT object
|
||||
* @param string $label label for the GIS POINT object
|
||||
* @param string $point_color color for the GIS POINT object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $pdf TCPDF instance
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPdf
|
||||
*/
|
||||
public function testPrepareRowAsPdf(
|
||||
$spatial, $label, $point_color, $scale_data, $pdf
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPdf(
|
||||
$spatial, $label, $point_color, $scale_data, $pdf
|
||||
);
|
||||
$this->assertInstanceOf('TCPDF', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for prepareRowAsPdf() test case
|
||||
*
|
||||
* @return array test data for prepareRowAsPdf() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPdf()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POINT(12 35)',
|
||||
'pdf',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
new TCPDF(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsSvg() method
|
||||
*
|
||||
* @param string $spatial GIS POINT object
|
||||
* @param string $label label for the GIS POINT object
|
||||
* @param string $point_color color for the GIS POINT object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsSvg
|
||||
*/
|
||||
public function testPrepareRowAsSvg(
|
||||
$spatial, $label, $point_color, $scale_data, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->prepareRowAsSvg(
|
||||
$spatial, $label, $point_color, $scale_data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for prepareRowAsSvg() test case
|
||||
*
|
||||
* @return array test data for prepareRowAsSvg() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsSvg()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POINT(12 35)',
|
||||
'svg',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsOl() method
|
||||
*
|
||||
* @param string $spatial GIS POINT object
|
||||
* @param int $srid spatial reference ID
|
||||
* @param string $label label for the GIS POINT object
|
||||
* @param string $point_color color for the GIS POINT object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsOl
|
||||
*/
|
||||
public function testPrepareRowAsOl(
|
||||
$spatial, $srid, $label, $point_color, $scale_data, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->prepareRowAsOl(
|
||||
$spatial, $srid, $label, $point_color, $scale_data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsOl() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsOl() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsOl()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POINT(12 35)',
|
||||
4326,
|
||||
'Ol',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'minX' => '0',
|
||||
'minY' => '0',
|
||||
'maxX' => '1',
|
||||
'maxY' => '1',
|
||||
),
|
||||
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
|
||||
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
|
||||
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject()));vectorLayer.addFeatures(new Open'
|
||||
. 'Layers.Feature.Vector((new OpenLayers.Geometry.Point(12,35)).'
|
||||
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.get'
|
||||
. 'ProjectionObject()), null, {"pointRadius":3,"fillColor":"#ffffff"'
|
||||
. ',"strokeColor":"#B02EE0","strokeWidth":2,"label":"Ol","labelY'
|
||||
. 'Offset":-8,"fontSize":10}));'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
589
#pma/test/classes/gis/GISPolygonTest.php
Normal file
589
#pma/test/classes/gis/GISPolygonTest.php
Normal file
@@ -0,0 +1,589 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\gis\GISPolygon
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\gis\GISPolygon;
|
||||
|
||||
require_once 'GISGeomTest.php';
|
||||
require_once 'libraries/tcpdf/tcpdf.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\gis\GISPolygon class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class GISPolygonTest extends GISGeomTest
|
||||
{
|
||||
/**
|
||||
* @var GISPolygon
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = GISPolygon::singleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide some common data to data providers
|
||||
*
|
||||
* @return array common data for data providers
|
||||
*/
|
||||
private function _getData()
|
||||
{
|
||||
return array(
|
||||
'POLYGON' => array(
|
||||
'no_of_lines' => 2,
|
||||
0 => array(
|
||||
'no_of_points' => 5,
|
||||
0 => array('x' => 35, 'y' => 10),
|
||||
1 => array('x' => 10, 'y' => 20),
|
||||
2 => array('x' => 15, 'y' => 40),
|
||||
3 => array('x' => 45, 'y' => 45),
|
||||
4 => array('x' => 35, 'y' => 10),
|
||||
),
|
||||
1 => array(
|
||||
'no_of_points' => 4,
|
||||
0 => array('x' => 20, 'y' => 30),
|
||||
1 => array('x' => 35, 'y' => 32),
|
||||
2 => array('x' => 30, 'y' => 20),
|
||||
3 => array('x' => 20, 'y' => 30),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateWkt
|
||||
*
|
||||
* @return data for testGenerateWkt
|
||||
*/
|
||||
public function providerForTestGenerateWkt()
|
||||
{
|
||||
$temp = array(
|
||||
0 => $this->_getData()
|
||||
);
|
||||
|
||||
$temp1 = $temp;
|
||||
unset($temp1[0]['POLYGON'][1][3]['y']);
|
||||
|
||||
$temp2 = $temp;
|
||||
$temp2[0]['POLYGON']['no_of_lines'] = 0;
|
||||
|
||||
$temp3 = $temp;
|
||||
$temp3[0]['POLYGON'][1]['no_of_points'] = 3;
|
||||
|
||||
return array(
|
||||
array(
|
||||
$temp,
|
||||
0,
|
||||
null,
|
||||
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))'
|
||||
),
|
||||
// values at undefined index
|
||||
array(
|
||||
$temp,
|
||||
1,
|
||||
null,
|
||||
'POLYGON(( , , , ))'
|
||||
),
|
||||
// if a coordinate is missing, default is empty string
|
||||
array(
|
||||
$temp1,
|
||||
0,
|
||||
null,
|
||||
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 ))'
|
||||
),
|
||||
// missing coordinates are replaced with provided values (3rd parameter)
|
||||
array(
|
||||
$temp1,
|
||||
0,
|
||||
'0',
|
||||
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 0))'
|
||||
),
|
||||
// should have at least one ring
|
||||
array(
|
||||
$temp2,
|
||||
0,
|
||||
'0',
|
||||
'POLYGON((35 10,10 20,15 40,45 45,35 10))'
|
||||
),
|
||||
// a ring should have at least four points
|
||||
array(
|
||||
$temp3,
|
||||
0,
|
||||
'0',
|
||||
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGenerateParams
|
||||
*
|
||||
* @return data for testGenerateParams
|
||||
*/
|
||||
public function providerForTestGenerateParams()
|
||||
{
|
||||
$temp = $this->_getData();
|
||||
|
||||
$temp1 = $temp;
|
||||
$temp1['gis_type'] = 'POLYGON';
|
||||
|
||||
return array(
|
||||
array(
|
||||
"'POLYGON((35 10,10 20,15 40,45 45,35 10),"
|
||||
. "(20 30,35 32,30 20,20 30))',124",
|
||||
null,
|
||||
array(
|
||||
'srid' => '124',
|
||||
0 => $temp
|
||||
)
|
||||
),
|
||||
array(
|
||||
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))',
|
||||
2,
|
||||
array(
|
||||
2 => $temp1
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for Area
|
||||
*
|
||||
* @param array $ring array of points forming the ring
|
||||
* @param float $area area of the ring
|
||||
*
|
||||
* @dataProvider providerForTestArea
|
||||
* @return void
|
||||
*/
|
||||
public function testArea($ring, $area)
|
||||
{
|
||||
$this->assertEquals($this->object->area($ring), $area);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testArea
|
||||
*
|
||||
* @return data for testArea
|
||||
*/
|
||||
public function providerForTestArea()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
0 => array('x' => 35, 'y' => 10),
|
||||
1 => array('x' => 10, 'y' => 10),
|
||||
2 => array('x' => 15, 'y' => 40)
|
||||
),
|
||||
-375.00
|
||||
),
|
||||
// first point of the ring repeated as the last point
|
||||
array(
|
||||
array(
|
||||
0 => array('x' => 35, 'y' => 10),
|
||||
1 => array('x' => 10, 'y' => 10),
|
||||
2 => array('x' => 15, 'y' => 40),
|
||||
3 => array('x' => 35, 'y' => 10)
|
||||
),
|
||||
-375.00
|
||||
),
|
||||
// anticlockwise gives positive area
|
||||
array(
|
||||
array(
|
||||
0 => array('x' => 15, 'y' => 40),
|
||||
1 => array('x' => 10, 'y' => 10),
|
||||
2 => array('x' => 35, 'y' => 10)
|
||||
),
|
||||
375.00
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for isPointInsidePolygon
|
||||
*
|
||||
* @param array $point x, y coordinates of the point
|
||||
* @param array $polygon array of points forming the ring
|
||||
* @param bool $isInside output
|
||||
*
|
||||
* @dataProvider providerForTestIsPointInsidePolygon
|
||||
* @return void
|
||||
*/
|
||||
public function testIsPointInsidePolygon($point, $polygon, $isInside)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->isPointInsidePolygon($point, $polygon),
|
||||
$isInside
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testIsPointInsidePolygon
|
||||
*
|
||||
* @return data for testIsPointInsidePolygon
|
||||
*/
|
||||
public function providerForTestIsPointInsidePolygon()
|
||||
{
|
||||
$ring = array(
|
||||
0 => array('x' => 35, 'y' => 10),
|
||||
1 => array('x' => 10, 'y' => 10),
|
||||
2 => array('x' => 15, 'y' => 40),
|
||||
3 => array('x' => 35, 'y' => 10)
|
||||
);
|
||||
|
||||
return array(
|
||||
// point inside the ring
|
||||
array(
|
||||
array('x' => 20, 'y' => 15),
|
||||
$ring,
|
||||
true
|
||||
),
|
||||
// point on an edge of the ring
|
||||
array(
|
||||
array('x' => 20, 'y' => 10),
|
||||
$ring,
|
||||
false
|
||||
),
|
||||
// point on a vertex of the ring
|
||||
array(
|
||||
array('x' => 10, 'y' => 10),
|
||||
$ring,
|
||||
false
|
||||
),
|
||||
// point outside the ring
|
||||
array(
|
||||
array('x' => 5, 'y' => 10),
|
||||
$ring,
|
||||
false
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for getPointOnSurface
|
||||
*
|
||||
* @param array $ring array of points forming the ring
|
||||
*
|
||||
* @dataProvider providerForTestGetPointOnSurface
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPointOnSurface($ring)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->object->isPointInsidePolygon(
|
||||
$this->object->getPointOnSurface($ring),
|
||||
$ring
|
||||
),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testGetPointOnSurface
|
||||
*
|
||||
* @return data for testGetPointOnSurface
|
||||
*/
|
||||
public function providerForTestGetPointOnSurface()
|
||||
{
|
||||
$temp = $this->_getData();
|
||||
unset($temp['POLYGON'][0]['no_of_points']);
|
||||
unset($temp['POLYGON'][1]['no_of_points']);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$temp['POLYGON'][0]
|
||||
),
|
||||
array(
|
||||
$temp['POLYGON'][1]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testScaleRow
|
||||
*
|
||||
* @return data for testScaleRow
|
||||
*/
|
||||
public function providerForTestScaleRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POLYGON((123 0,23 30,17 63,123 0))',
|
||||
array(
|
||||
'minX' => 17,
|
||||
'maxX' => 123,
|
||||
'minY' => 0,
|
||||
'maxY' => 63,
|
||||
)
|
||||
),
|
||||
array(
|
||||
'POLYGON((35 10,10 20,15 40,45 45,35 10),'
|
||||
. '(20 30,35 32,30 20,20 30)))',
|
||||
array(
|
||||
'minX' => 10,
|
||||
'maxX' => 45,
|
||||
'minY' => 10,
|
||||
'maxY' => 45
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPng()
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label label for the GIS POLYGON object
|
||||
* @param string $fill_color color for the GIS POLYGON object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $image image object
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPng
|
||||
*/
|
||||
public function testPrepareRowAsPng(
|
||||
$spatial, $label, $fill_color, $scale_data, $image
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPng(
|
||||
$spatial, $label, $fill_color, $scale_data, $image
|
||||
);
|
||||
$this->assertImage($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPng() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPng() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPng()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POLYGON((123 0,23 30,17 63,123 0))',
|
||||
'image',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
imagecreatetruecolor('120', '150')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsPdf() method
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label label for the GIS POLYGON object
|
||||
* @param string $fill_color color for the GIS POLYGON object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param object $pdf TCPDF instance
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsPdf
|
||||
*/
|
||||
public function testPrepareRowAsPdf(
|
||||
$spatial, $label, $fill_color, $scale_data, $pdf
|
||||
) {
|
||||
$return = $this->object->prepareRowAsPdf(
|
||||
$spatial, $label, $fill_color, $scale_data, $pdf
|
||||
);
|
||||
$this->assertInstanceOf('TCPDF', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsPdf() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsPdf() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsPdf()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POLYGON((123 0,23 30,17 63,123 0))',
|
||||
'pdf',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
new TCPDF(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsSvg() method
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label label for the GIS POLYGON object
|
||||
* @param string $fill_color color for the GIS POLYGON object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsSvg
|
||||
*/
|
||||
public function testPrepareRowAsSvg(
|
||||
$spatial, $label, $fill_color, $scale_data, $output
|
||||
) {
|
||||
$string = $this->object->prepareRowAsSvg(
|
||||
$spatial, $label, $fill_color, $scale_data
|
||||
);
|
||||
$this->assertEquals(1, preg_match($output, $string));
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsSvg() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsSvg() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsSvg()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POLYGON((123 0,23 30,17 63,123 0))',
|
||||
'svg',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'x' => 12,
|
||||
'y' => 69,
|
||||
'scale' => 2,
|
||||
'height' => 150
|
||||
),
|
||||
'/^(<path d=" M 222, 288 L 22, 228 L 10, 162 Z " name="svg" '
|
||||
. 'id="svg)(\d+)(" class="polygon vector" stroke="black" '
|
||||
. 'stroke-width="0.5" fill="#B02EE0" fill-rule="evenodd" '
|
||||
. 'fill-opacity="0.8"\/>)$/'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for prepareRowAsOl() method
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param int $srid spatial reference ID
|
||||
* @param string $label label for the GIS POLYGON object
|
||||
* @param string $fill_color color for the GIS POLYGON object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $output expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForPrepareRowAsOl
|
||||
*/
|
||||
public function testPrepareRowAsOl(
|
||||
$spatial, $srid, $label, $fill_color, $scale_data, $output
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->object->prepareRowAsOl(
|
||||
$spatial, $srid, $label, $fill_color, $scale_data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testPrepareRowAsOl() test case
|
||||
*
|
||||
* @return array test data for testPrepareRowAsOl() test case
|
||||
*/
|
||||
public function providerForPrepareRowAsOl()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'POLYGON((123 0,23 30,17 63,123 0))',
|
||||
4326,
|
||||
'Ol',
|
||||
'#B02EE0',
|
||||
array(
|
||||
'minX' => '0',
|
||||
'minY' => '0',
|
||||
'maxX' => '1',
|
||||
'maxY' => '1',
|
||||
),
|
||||
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.Lon'
|
||||
. 'Lat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject())); bound.extend(new OpenLayers.'
|
||||
. 'LonLat(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), '
|
||||
. 'map.getProjectionObject()));vectorLayer.addFeatures(new Open'
|
||||
. 'Layers.Feature.Vector(new OpenLayers.Geometry.Polygon(new Array'
|
||||
. '(new OpenLayers.Geometry.LinearRing(new Array((new OpenLayers.'
|
||||
. 'Geometry.Point(123,0)).transform(new OpenLayers.Projection'
|
||||
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.'
|
||||
. 'Geometry.Point(23,30)).transform(new OpenLayers.Projection'
|
||||
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.'
|
||||
. 'Geometry.Point(17,63)).transform(new OpenLayers.Projection'
|
||||
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.'
|
||||
. 'Geometry.Point(123,0)).transform(new OpenLayers.Projection'
|
||||
. '("EPSG:4326"), map.getProjectionObject()))))), null, {"stroke'
|
||||
. 'Color":"#000000","strokeWidth":0.5,"fillColor":"#B02EE0",'
|
||||
. '"fillOpacity":0.8,"label":"Ol","fontSize":10}));'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test case for isOuterRing() method
|
||||
*
|
||||
* @param array $ring coordinates of the points in a ring
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForIsOuterRing
|
||||
*/
|
||||
public function testIsOuterRing($ring)
|
||||
{
|
||||
$this->assertTrue($this->object->isOuterRing($ring));
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testIsOuterRing() test case
|
||||
*
|
||||
* @return array test data for testIsOuterRing() test case
|
||||
*/
|
||||
public function providerForIsOuterRing()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
array('x' => 0, 'y' => 0),
|
||||
array('x' => 0, 'y' => 1),
|
||||
array('x' => 1, 'y' => 1),
|
||||
array('x' => 1, 'y' => 0)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
166
#pma/test/classes/navigation/NavigationTest.php
Normal file
166
#pma/test/classes/navigation/NavigationTest.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\Navigation class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\Navigation class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NavigationTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var PMA\libraries\navigation\Navigation
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new PMA\libraries\navigation\Navigation();
|
||||
$GLOBALS['cfgRelation']['db'] = 'pmadb';
|
||||
$GLOBALS['cfgRelation']['navigationhiding'] = 'navigationhiding';
|
||||
$GLOBALS['cfg']['Server']['user'] = 'user';
|
||||
$GLOBALS['cfg']['ActionLinksMode'] = 'both';
|
||||
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests hideNavigationItem() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testHideNavigationItem()
|
||||
{
|
||||
$expectedQuery = "INSERT INTO `pmadb`.`navigationhiding`"
|
||||
. "(`username`, `item_name`, `item_type`, `db_name`, `table_name`)"
|
||||
. " VALUES ('user','itemName','itemType','db','')";
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('tryQuery')
|
||||
->with($expectedQuery);
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$this->object->hideNavigationItem('itemName', 'itemType', 'db');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unhideNavigationItem() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testUnhideNavigationItem()
|
||||
{
|
||||
$expectedQuery = "DELETE FROM `pmadb`.`navigationhiding`"
|
||||
. " WHERE `username`='user' AND `item_name`='itemName'"
|
||||
. " AND `item_type`='itemType' AND `db_name`='db'";
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('tryQuery')
|
||||
->with($expectedQuery);
|
||||
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$this->object->unhideNavigationItem('itemName', 'itemType', 'db');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getItemUnhideDialog() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetItemUnhideDialog()
|
||||
{
|
||||
$expectedQuery = "SELECT `item_name`, `item_type`"
|
||||
. " FROM `pmadb`.`navigationhiding`"
|
||||
. " WHERE `username`='user' AND `db_name`='db' AND `table_name`=''";
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('tryQuery')
|
||||
->with($expectedQuery)
|
||||
->will($this->returnValue(true));
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchArray')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'item_name' => 'tableName',
|
||||
'item_type' => 'table'
|
||||
)
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchArray')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'item_name' => 'viewName',
|
||||
'item_type' => 'view'
|
||||
)
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fetchArray')
|
||||
->will($this->returnValue(false));
|
||||
$dbi->expects($this->once())
|
||||
->method('freeResult');
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$html = $this->object->getItemUnhideDialog('db');
|
||||
$this->assertContains(
|
||||
'<td>tableName</td>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<a href="navigation.php' . PMA_URL_getCommon()
|
||||
. '&unhideNavItem=true&itemType=table&itemName=tableName&dbName=db"'
|
||||
. ' class="unhideNavItem ajax">',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
104
#pma/test/classes/navigation/NavigationTreeTest.php
Normal file
104
#pma/test/classes/navigation/NavigationTreeTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\NavigationTree class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\navigation\NavigationTree;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\NavigationTree class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NavigationTreeTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var NavigationTree
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
$GLOBALS['cfg']['Server']['user'] = 'root';
|
||||
$GLOBALS['cfg']['Server']['pmadb'] = '';
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['ShowDatabasesNavigationAsTree'] = true;
|
||||
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$this->object = new PMA\libraries\navigation\NavigationTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Very basic rendering test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderState()
|
||||
{
|
||||
$result = $this->object->renderState();
|
||||
$this->assertContains('pma_quick_warp', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Very basic path rendering test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderPath()
|
||||
{
|
||||
$result = $this->object->renderPath();
|
||||
$this->assertContains('list_container', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Very basic select rendering test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderDbSelect()
|
||||
{
|
||||
$result = $this->object->renderDbSelect();
|
||||
$this->assertContains('pma_navigation_select_database', $result);
|
||||
}
|
||||
}
|
||||
51
#pma/test/classes/navigation/NodeColumnContainerTest.php
Normal file
51
#pma/test/classes/navigation/NodeColumnContainerTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeColumnContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeColumnContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeColumnContainerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\NodeFactory::__construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeColumnContainer');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'tbl_structure.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertEquals('columns', $parent->real_name);
|
||||
}
|
||||
}
|
||||
50
#pma/test/classes/navigation/NodeColumnTest.php
Normal file
50
#pma/test/classes/navigation/NodeColumnTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeColumn class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeColumn class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeColumnTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\NodeFactory::getInstance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeColumn');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'tbl_structure.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
}
|
||||
}
|
||||
91
#pma/test/classes/navigation/NodeDatabaseChildTest.php
Normal file
91
#pma/test/classes/navigation/NodeDatabaseChildTest.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\nodes\NodeDatabaseChild
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\navigation\nodes\NodeDatabaseChild;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeDatabaseChild class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeDatabaseChildTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var NodeDatabaseChild
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$GLOBALS['cfg']['DefaultTabDatabase'] = 'structure';
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['ServerDefault'] = 1;
|
||||
$_SESSION['relation'][1]['PMA_VERSION'] = PMA_VERSION;
|
||||
$_SESSION['relation'][1]['navwork'] = true;
|
||||
$this->object = $this->getMockForAbstractClass(
|
||||
'PMA\libraries\navigation\nodes\NodeDatabaseChild', array('child')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getHtmlForControlButtons() method
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetHtmlForControlButtons()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeDatabase', 'parent');
|
||||
$parent->addChild($this->object);
|
||||
$this->object->expects($this->once())
|
||||
->method('getItemType')
|
||||
->will($this->returnValue('itemType'));
|
||||
$html = $this->object->getHtmlForControlButtons();
|
||||
|
||||
$this->assertStringStartsWith(
|
||||
'<span class="navItemControls">',
|
||||
$html
|
||||
);
|
||||
$this->assertStringEndsWith(
|
||||
'</span>',
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
'<a href="navigation.php' . PMA_URL_getCommon()
|
||||
. '&hideNavItem=true&itemType=itemType&itemName=child'
|
||||
. '&dbName=parent" class="hideNavItem ajax">',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
137
#pma/test/classes/navigation/NodeDatabaseTest.php
Normal file
137
#pma/test/classes/navigation/NodeDatabaseTest.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeDatabase class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeDatabase class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeDatabaseTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['DefaultTabDatabase'] = 'structure';
|
||||
$GLOBALS['cfg']['MaxNavigationItems'] = 250;
|
||||
$GLOBALS['cfg']['Server'] = array();
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = true;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeDatabase');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_structure.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertContains('database', $parent->classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getPresence
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPresence()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeDatabase');
|
||||
$this->assertEquals(
|
||||
2,
|
||||
$parent->getPresence('tables')
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$parent->getPresence('views')
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$parent->getPresence('functions')
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$parent->getPresence('procedures')
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$parent->getPresence('events')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetData()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeDatabase');
|
||||
|
||||
$tables = $parent->getData('tables', 0);
|
||||
$this->assertContains(
|
||||
'test1',
|
||||
$tables
|
||||
);
|
||||
$this->assertContains(
|
||||
'test2',
|
||||
$tables
|
||||
);
|
||||
|
||||
$views = $parent->getData('views', 0);
|
||||
$this->assertEmpty($views);
|
||||
|
||||
$functions = $parent->getData('functions', 0);
|
||||
$this->assertContains(
|
||||
'testFunction',
|
||||
$functions
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count($functions)
|
||||
);
|
||||
|
||||
$this->assertEmpty($parent->getData('procedures', 0));
|
||||
$this->assertEmpty($parent->getData('events', 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setHiddenCount and getHiddenCount
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHiddenCount()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeDatabase');
|
||||
|
||||
$parent->setHiddenCount(3);
|
||||
$this->assertEquals(
|
||||
3,
|
||||
$parent->getHiddenCount()
|
||||
);
|
||||
}
|
||||
}
|
||||
51
#pma/test/classes/navigation/NodeEventContainerTest.php
Normal file
51
#pma/test/classes/navigation/NodeEventContainerTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeEventContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeEventContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeEventContainerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeEventContainer');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_events.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertEquals('events', $parent->real_name);
|
||||
}
|
||||
}
|
||||
50
#pma/test/classes/navigation/NodeEventTest.php
Normal file
50
#pma/test/classes/navigation/NodeEventTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeEvent class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeEvent class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeEventTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeEvent');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_events.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
}
|
||||
}
|
||||
103
#pma/test/classes/navigation/NodeFactoryTest.php
Normal file
103
#pma/test/classes/navigation/NodeFactoryTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for NodeFactory class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\navigation\nodes\Node;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for NodeFactory class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeFactoryTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\NodeFactory::getInstance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDefaultNode()
|
||||
{
|
||||
$node = NodeFactory::getInstance();
|
||||
$this->assertEquals('default', $node->name);
|
||||
$this->assertEquals(Node::OBJECT, $node->type);
|
||||
$this->assertEquals(false, $node->is_group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\NodeFactory::getInstance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDefaultContainer()
|
||||
{
|
||||
$node = NodeFactory::getInstance(
|
||||
'Node',
|
||||
'default',
|
||||
Node::CONTAINER
|
||||
);
|
||||
$this->assertEquals('default', $node->name);
|
||||
$this->assertEquals(Node::CONTAINER, $node->type);
|
||||
$this->assertEquals(false, $node->is_group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\NodeFactory::getInstance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupContainer()
|
||||
{
|
||||
$node = NodeFactory::getInstance(
|
||||
'Node',
|
||||
'default',
|
||||
Node::CONTAINER,
|
||||
true
|
||||
);
|
||||
$this->assertEquals('default', $node->name);
|
||||
$this->assertEquals(Node::CONTAINER, $node->type);
|
||||
$this->assertEquals(true, $node->is_group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\NodeFactory::getInstance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFileError()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error');
|
||||
NodeFactory::getInstance('NodeDoesNotExist');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\navigation\NodeFactory::getInstance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClassNameError()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error');
|
||||
NodeFactory::getInstance('Invalid');
|
||||
}
|
||||
}
|
||||
51
#pma/test/classes/navigation/NodeFunctionContainerTest.php
Normal file
51
#pma/test/classes/navigation/NodeFunctionContainerTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeFunctionContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeFunctionContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeFunctionContainerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeFunctionContainer');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_routines.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertEquals('functions', $parent->real_name);
|
||||
}
|
||||
}
|
||||
50
#pma/test/classes/navigation/NodeFunctionTest.php
Normal file
50
#pma/test/classes/navigation/NodeFunctionTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeFunction class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeFunction class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeFunctionTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeFunction');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_routines.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
}
|
||||
}
|
||||
51
#pma/test/classes/navigation/NodeIndexContainerTest.php
Normal file
51
#pma/test/classes/navigation/NodeIndexContainerTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeIndexContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeIndexContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeIndexContainerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeIndexContainer');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'tbl_structure.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertEquals('indexes', $parent->real_name);
|
||||
}
|
||||
}
|
||||
50
#pma/test/classes/navigation/NodeIndexTest.php
Normal file
50
#pma/test/classes/navigation/NodeIndexTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeIndex class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeIndex class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeIndexTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeIndex');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'tbl_indexes.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
}
|
||||
}
|
||||
51
#pma/test/classes/navigation/NodeProcedureContainerTest.php
Normal file
51
#pma/test/classes/navigation/NodeProcedureContainerTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeProcedureContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeProcedureContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeProcedureContainerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeProcedureContainer');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_routines.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertEquals('procedures', $parent->real_name);
|
||||
}
|
||||
}
|
||||
50
#pma/test/classes/navigation/NodeProcedureTest.php
Normal file
50
#pma/test/classes/navigation/NodeProcedureTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeProcedure class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeProcedure class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeProcedureTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeProcedure');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_routines.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
}
|
||||
}
|
||||
57
#pma/test/classes/navigation/NodeTableContainerTest.php
Normal file
57
#pma/test/classes/navigation/NodeTableContainerTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeTableContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeTableContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeTableContainerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
$GLOBALS['cfg']['NavigationTreeTableSeparator'] = '__';
|
||||
$GLOBALS['cfg']['NavigationTreeTableLevel'] = 1;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeTableContainer');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_structure.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertEquals('tables', $parent->real_name);
|
||||
$this->assertContains('tableContainer', $parent->classes);
|
||||
}
|
||||
}
|
||||
92
#pma/test/classes/navigation/NodeTableTest.php
Normal file
92
#pma/test/classes/navigation/NodeTableTest.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeTable class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeTable class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeTableTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = 'b_browse';
|
||||
$GLOBALS['cfg']['NavigationTreeDefaultTabTable2'] = '';
|
||||
$GLOBALS['cfg']['DefaultTabTable'] = 'browse';
|
||||
$GLOBALS['cfg']['MaxNavigationItems'] = 250;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
$GLOBALS['cfg']['NavigationTreeTableSeparator'] = '__';
|
||||
$GLOBALS['cfg']['NavigationTreeTableLevel'] = 1;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeTable');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'sql.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertContains('table', $parent->classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the node icon is properly set based on the icon target.
|
||||
*
|
||||
* @param string $target target of the icon
|
||||
* @param string $imageName name of the image that should be set
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider providerForTestIcon
|
||||
*/
|
||||
public function testIcon($target, $imageName)
|
||||
{
|
||||
$GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = $target;
|
||||
$node = NodeFactory::getInstance('NodeTable');
|
||||
$this->assertContains($imageName, $node->icon[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testIcon().
|
||||
*
|
||||
* @return array data for testIcon()
|
||||
*/
|
||||
public function providerForTestIcon()
|
||||
{
|
||||
return array(
|
||||
array('structure', 'b_props'),
|
||||
array('search', 'b_search'),
|
||||
array('insert', 'b_insrow'),
|
||||
array('sql', 'b_sql'),
|
||||
array('browse', 'b_browse'),
|
||||
);
|
||||
}
|
||||
}
|
||||
574
#pma/test/classes/navigation/NodeTest.php
Normal file
574
#pma/test/classes/navigation/NodeTest.php
Normal file
@@ -0,0 +1,574 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for Node class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\navigation\nodes\Node;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for Node class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp for AddNode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddNode()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('Node', 'parent');
|
||||
$child = NodeFactory::getInstance('Node', 'child');
|
||||
$parent->addChild($child);
|
||||
$this->assertEquals(
|
||||
$parent->getChild($child->name),
|
||||
$child
|
||||
);
|
||||
$this->assertEquals(
|
||||
$parent->getChild($child->real_name, true),
|
||||
$child
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp for getChild
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetChildError()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('Node', 'parent');
|
||||
$this->assertEquals(
|
||||
$parent->getChild("foo"),
|
||||
false
|
||||
);
|
||||
$this->assertEquals(
|
||||
$parent->getChild("foo", true),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp for getChild
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRemoveNode()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('Node', 'parent');
|
||||
$child = NodeFactory::getInstance('Node', 'child');
|
||||
$parent->addChild($child);
|
||||
$this->assertEquals(
|
||||
$parent->getChild($child->name),
|
||||
$child
|
||||
);
|
||||
$parent->removeChild($child->name);
|
||||
$this->assertEquals(
|
||||
$parent->getChild($child->name),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp for hasChildren
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNodeHasChildren()
|
||||
{
|
||||
$parent = NodeFactory::getInstance();
|
||||
$empty_container = NodeFactory::getInstance(
|
||||
'Node', 'empty', Node::CONTAINER
|
||||
);
|
||||
$child = NodeFactory::getInstance();
|
||||
// test with no children
|
||||
$this->assertEquals(
|
||||
$parent->hasChildren(true),
|
||||
false
|
||||
);
|
||||
$this->assertEquals(
|
||||
$parent->hasChildren(false),
|
||||
false
|
||||
);
|
||||
// test with an empty container
|
||||
$parent->addChild($empty_container);
|
||||
$this->assertEquals(
|
||||
$parent->hasChildren(true),
|
||||
true
|
||||
);
|
||||
$this->assertEquals(
|
||||
$parent->hasChildren(false),
|
||||
false
|
||||
);
|
||||
// test with a real child
|
||||
$parent->addChild($child);
|
||||
$this->assertEquals(
|
||||
$parent->hasChildren(true),
|
||||
true
|
||||
);
|
||||
$this->assertEquals(
|
||||
$parent->hasChildren(false),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp for numChildren
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNumChildren()
|
||||
{
|
||||
// start with root node only
|
||||
$parent = NodeFactory::getInstance();
|
||||
$this->assertEquals($parent->numChildren(), 0);
|
||||
// add a child
|
||||
$child = NodeFactory::getInstance();
|
||||
$parent->addChild($child);
|
||||
$this->assertEquals($parent->numChildren(), 1);
|
||||
// add a direct grandchild, this one doesn't count as
|
||||
// it's not enclosed in a CONTAINER
|
||||
$child->addChild(NodeFactory::getInstance());
|
||||
$this->assertEquals($parent->numChildren(), 1);
|
||||
// add a container, this one doesn't count wither
|
||||
$container = NodeFactory::getInstance(
|
||||
'Node', 'default', Node::CONTAINER
|
||||
);
|
||||
$parent->addChild($container);
|
||||
$this->assertEquals($parent->numChildren(), 1);
|
||||
// add a grandchild to container, this one counts
|
||||
$container->addChild(NodeFactory::getInstance());
|
||||
$this->assertEquals($parent->numChildren(), 2);
|
||||
// add another grandchild to container, this one counts
|
||||
$container->addChild(NodeFactory::getInstance());
|
||||
$this->assertEquals($parent->numChildren(), 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp for parents
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParents()
|
||||
{
|
||||
$parent = NodeFactory::getInstance();
|
||||
$this->assertEquals($parent->parents(), array()); // exclude self
|
||||
$this->assertEquals($parent->parents(true), array($parent)); // include self
|
||||
|
||||
$child = NodeFactory::getInstance();
|
||||
$parent->addChild($child);
|
||||
|
||||
$this->assertEquals($child->parents(), array($parent)); // exclude self
|
||||
$this->assertEquals(
|
||||
$child->parents(true),
|
||||
array($child, $parent)
|
||||
); // include self
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp for realParent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRealParent()
|
||||
{
|
||||
$parent = NodeFactory::getInstance();
|
||||
$this->assertEquals($parent->realParent(), false);
|
||||
|
||||
$child = NodeFactory::getInstance();
|
||||
$parent->addChild($child);
|
||||
$this->assertEquals($child->realParent(), $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether Node->hasSiblings() method returns false
|
||||
* when the node does not have any siblings.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testHasSiblingsWithNoSiblings()
|
||||
{
|
||||
$parent = NodeFactory::getInstance();
|
||||
$child = NodeFactory::getInstance();
|
||||
$parent->addChild($child);
|
||||
$this->assertEquals(false, $child->hasSiblings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether Node->hasSiblings() method returns true
|
||||
* when it actually has siblings.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testHasSiblingsWithSiblings()
|
||||
{
|
||||
$parent = NodeFactory::getInstance();
|
||||
$firstChild = NodeFactory::getInstance();
|
||||
$parent->addChild($firstChild);
|
||||
$secondChild = NodeFactory::getInstance();
|
||||
$parent->addChild($secondChild);
|
||||
// Normal case; two Node:NODE type siblings
|
||||
$this->assertEquals(true, $firstChild->hasSiblings());
|
||||
|
||||
$parent = NodeFactory::getInstance();
|
||||
$firstChild = NodeFactory::getInstance();
|
||||
$parent->addChild($firstChild);
|
||||
$secondChild = NodeFactory::getInstance(
|
||||
'Node', 'default', Node::CONTAINER
|
||||
);
|
||||
$parent->addChild($secondChild);
|
||||
// Empty Node::CONTAINER type node should not be considered in hasSiblings()
|
||||
$this->assertEquals(false, $firstChild->hasSiblings());
|
||||
|
||||
$grandChild = NodeFactory::getInstance();
|
||||
$secondChild->addChild($grandChild);
|
||||
// Node::CONTAINER type nodes with children are counted for hasSiblings()
|
||||
$this->assertEquals(true, $firstChild->hasSiblings());
|
||||
}
|
||||
|
||||
/**
|
||||
* It is expected that Node->hasSiblings() method always return true
|
||||
* for Nodes that are 3 levels deep (columns and indexes).
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testHasSiblingsForNodesAtLevelThree()
|
||||
{
|
||||
$parent = NodeFactory::getInstance();
|
||||
$child = NodeFactory::getInstance();
|
||||
$parent->addChild($child);
|
||||
$grandChild = NodeFactory::getInstance();
|
||||
$child->addChild($grandChild);
|
||||
$greatGrandChild = NodeFactory::getInstance();
|
||||
$grandChild->addChild($greatGrandChild);
|
||||
|
||||
// Should return false for node that are two levels deeps
|
||||
$this->assertEquals(false, $grandChild->hasSiblings());
|
||||
// Should return true for node that are three levels deeps
|
||||
$this->assertEquals(true, $greatGrandChild->hasSiblings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests private method _getWhereClause()
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetWhereClause()
|
||||
{
|
||||
$method = new ReflectionMethod(
|
||||
'PMA\libraries\navigation\nodes\Node', '_getWhereClause'
|
||||
);
|
||||
$method->setAccessible(true);
|
||||
|
||||
// Vanilla case
|
||||
$node = NodeFactory::getInstance();
|
||||
$this->assertEquals(
|
||||
"WHERE TRUE ", $method->invoke($node, 'SCHEMA_NAME')
|
||||
);
|
||||
|
||||
// When a schema names is passed as search clause
|
||||
$this->assertEquals(
|
||||
"WHERE TRUE AND `SCHEMA_NAME` LIKE '%schemaName%' ",
|
||||
$method->invoke($node, 'SCHEMA_NAME', 'schemaName')
|
||||
);
|
||||
|
||||
if (! isset($GLOBALS['cfg']['Server'])) {
|
||||
$GLOBALS['cfg']['Server'] = array();
|
||||
}
|
||||
|
||||
// When hide_db regular expression is present
|
||||
$GLOBALS['cfg']['Server']['hide_db'] = 'regexpHideDb';
|
||||
$this->assertEquals(
|
||||
"WHERE TRUE AND `SCHEMA_NAME` NOT REGEXP 'regexpHideDb' ",
|
||||
$method->invoke($node, 'SCHEMA_NAME')
|
||||
);
|
||||
unset($GLOBALS['cfg']['Server']['hide_db']);
|
||||
|
||||
// When only_db directive is present and it's a single db
|
||||
$GLOBALS['cfg']['Server']['only_db'] = 'stringOnlyDb';
|
||||
$this->assertEquals(
|
||||
"WHERE TRUE AND ( `SCHEMA_NAME` LIKE 'stringOnlyDb' ) ",
|
||||
$method->invoke($node, 'SCHEMA_NAME')
|
||||
);
|
||||
unset($GLOBALS['cfg']['Server']['only_db']);
|
||||
|
||||
// When only_db directive is present and it's an array of dbs
|
||||
$GLOBALS['cfg']['Server']['only_db'] = array('onlyDbOne', 'onlyDbTwo');
|
||||
$this->assertEquals(
|
||||
"WHERE TRUE AND ( `SCHEMA_NAME` LIKE 'onlyDbOne' "
|
||||
. "OR `SCHEMA_NAME` LIKE 'onlyDbTwo' ) ",
|
||||
$method->invoke($node, 'SCHEMA_NAME')
|
||||
);
|
||||
unset($GLOBALS['cfg']['Server']['only_db']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getData() method when DisableIS is false and navigation tree
|
||||
* grouping enabled.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDataWithEnabledISAndGroupingEnabled()
|
||||
{
|
||||
$pos = 10;
|
||||
$limit = 20;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['FirstLevelNavigationItems'] = $limit;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
|
||||
$expectedSql = "SELECT `SCHEMA_NAME` ";
|
||||
$expectedSql .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA`, ";
|
||||
$expectedSql .= "(";
|
||||
$expectedSql .= "SELECT DB_first_level ";
|
||||
$expectedSql .= "FROM ( ";
|
||||
$expectedSql .= "SELECT DISTINCT SUBSTRING_INDEX(SCHEMA_NAME, ";
|
||||
$expectedSql .= "'_', 1) ";
|
||||
$expectedSql .= "DB_first_level ";
|
||||
$expectedSql .= "FROM INFORMATION_SCHEMA.SCHEMATA ";
|
||||
$expectedSql .= "WHERE TRUE ";
|
||||
$expectedSql .= ") t ";
|
||||
$expectedSql .= "ORDER BY DB_first_level ASC ";
|
||||
$expectedSql .= "LIMIT $pos, $limit";
|
||||
$expectedSql .= ") t2 ";
|
||||
$expectedSql .= "WHERE TRUE AND 1 = LOCATE(CONCAT(DB_first_level, '_'), ";
|
||||
$expectedSql .= "CONCAT(SCHEMA_NAME, '_')) ";
|
||||
$expectedSql .= "ORDER BY SCHEMA_NAME ASC";
|
||||
|
||||
// It would have been better to mock _getWhereClause method
|
||||
// but strangely, mocking private methods is not supported in PHPUnit
|
||||
$node = NodeFactory::getInstance();
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('fetchResult')
|
||||
->with($expectedSql);
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getData('', $pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getData() method when DisableIS is false and navigation tree
|
||||
* grouping disabled.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDataWithEnabledISAndGroupingDisabled()
|
||||
{
|
||||
$pos = 10;
|
||||
$limit = 20;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = false;
|
||||
$GLOBALS['cfg']['FirstLevelNavigationItems'] = $limit;
|
||||
|
||||
$expectedSql = "SELECT `SCHEMA_NAME` ";
|
||||
$expectedSql .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
|
||||
$expectedSql .= "WHERE TRUE ";
|
||||
$expectedSql .= "ORDER BY `SCHEMA_NAME` ";
|
||||
$expectedSql .= "LIMIT $pos, $limit";
|
||||
|
||||
// It would have been better to mock _getWhereClause method
|
||||
// but strangely, mocking private methods is not supported in PHPUnit
|
||||
$node = NodeFactory::getInstance();
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('fetchResult')
|
||||
->with($expectedSql);
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getData('', $pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getData() method when DisableIS is true and navigation tree
|
||||
* grouping enabled.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetDataWithDisabledISAndGroupingEnabled()
|
||||
{
|
||||
$pos = 0;
|
||||
$limit = 10;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = true;
|
||||
$GLOBALS['dbs_to_test'] = false;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['FirstLevelNavigationItems'] = $limit;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
|
||||
$node = NodeFactory::getInstance();
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('tryQuery')
|
||||
->with("SHOW DATABASES WHERE TRUE AND `Database` LIKE '%db%' ")
|
||||
->will($this->returnValue(true));
|
||||
$dbi->expects($this->exactly(3))
|
||||
->method('fetchArray')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(
|
||||
'0' => 'db'
|
||||
),
|
||||
array(
|
||||
'0' => 'aa_db'
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('fetchResult')
|
||||
->with(
|
||||
"SHOW DATABASES WHERE TRUE AND `Database` LIKE '%db%' AND ("
|
||||
. " LOCATE('db_', CONCAT(`Database`, '_')) = 1"
|
||||
. " OR LOCATE('aa_', CONCAT(`Database`, '_')) = 1 )"
|
||||
);
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getData('', $pos, 'db');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getPresence method when DisableIS is false and navigation tree
|
||||
* grouping enabled.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetPresenceWithEnabledISAndGroupingEnabled()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
|
||||
$query = "SELECT COUNT(*) ";
|
||||
$query .= "FROM ( ";
|
||||
$query .= "SELECT DISTINCT SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) ";
|
||||
$query .= "DB_first_level ";
|
||||
$query .= "FROM INFORMATION_SCHEMA.SCHEMATA ";
|
||||
$query .= "WHERE TRUE ";
|
||||
$query .= ") t ";
|
||||
|
||||
// It would have been better to mock _getWhereClause method
|
||||
// but strangely, mocking private methods is not supported in PHPUnit
|
||||
$node = NodeFactory::getInstance();
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('fetchValue')
|
||||
->with($query);
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getPresence();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getPresence method when DisableIS is false and navigation tree
|
||||
* grouping disabled.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetPresenceWithEnabledISAndGroupingDisabled()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = false;
|
||||
|
||||
$query = "SELECT COUNT(*) ";
|
||||
$query .= "FROM INFORMATION_SCHEMA.SCHEMATA ";
|
||||
$query .= "WHERE TRUE ";
|
||||
|
||||
$node = NodeFactory::getInstance();
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('fetchValue')
|
||||
->with($query);
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getPresence();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getPresence method when DisableIS is true
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testGetPresenceWithDisabledIS()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = true;
|
||||
$GLOBALS['dbs_to_test'] = false;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
|
||||
$node = NodeFactory::getInstance();
|
||||
|
||||
// test with no search clause
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('tryQuery')
|
||||
->with("SHOW DATABASES WHERE TRUE ");
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getPresence();
|
||||
|
||||
// test with a search clause
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->once())
|
||||
->method('tryQuery')
|
||||
->with("SHOW DATABASES WHERE TRUE AND `Database` LIKE '%dbname%' ");
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getPresence('', 'dbname');
|
||||
}
|
||||
}
|
||||
52
#pma/test/classes/navigation/NodeTriggerContainerTest.php
Normal file
52
#pma/test/classes/navigation/NodeTriggerContainerTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeTrigger class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeTrigger class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeTriggerContainerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeTriggerContainer');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_triggers.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertEquals('triggers', $parent->real_name);
|
||||
}
|
||||
}
|
||||
51
#pma/test/classes/navigation/NodeTriggerTest.php
Normal file
51
#pma/test/classes/navigation/NodeTriggerTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeTrigger class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeTrigger class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeTriggerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeTrigger');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_triggers.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
}
|
||||
}
|
||||
57
#pma/test/classes/navigation/NodeViewContainerTest.php
Normal file
57
#pma/test/classes/navigation/NodeViewContainerTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeViewContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeViewContainer class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeViewContainerTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
$GLOBALS['cfg']['NavigationTreeTableSeparator'] = '__';
|
||||
$GLOBALS['cfg']['NavigationTreeTableLevel'] = 1;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeViewContainer');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'db_structure.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertEquals('views', $parent->real_name);
|
||||
$this->assertContains('viewContainer', $parent->classes);
|
||||
}
|
||||
}
|
||||
53
#pma/test/classes/navigation/NodeViewTest.php
Normal file
53
#pma/test/classes/navigation/NodeViewTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeView class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\navigation\NodeFactory;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
require_once 'libraries/navigation/NodeFactory.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\navigation\nodes\NodeView class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class NodeViewTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$parent = NodeFactory::getInstance('NodeView');
|
||||
$this->assertArrayHasKey(
|
||||
'text',
|
||||
$parent->links
|
||||
);
|
||||
$this->assertContains(
|
||||
'sql.php',
|
||||
$parent->links['text']
|
||||
);
|
||||
$this->assertContains('b_props', $parent->icon);
|
||||
$this->assertContains('view', $parent->classes);
|
||||
}
|
||||
}
|
||||
150
#pma/test/classes/plugin/auth/AuthenticationConfigTest.php
Normal file
150
#pma/test/classes/plugin/auth/AuthenticationConfigTest.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\auth\AuthenticationConfig class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\plugins\auth\AuthenticationConfig;
|
||||
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\auth\AuthenticationConfig class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class AuthenticationConfigTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['token_provided'] = true;
|
||||
$GLOBALS['token_mismatch'] = false;
|
||||
$this->object = new AuthenticationConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuth()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->auth()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::authCheck
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthCheck()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->authCheck()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::authSetUser
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthSetUser()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->authSetUser()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::authFails
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthFails()
|
||||
{
|
||||
$removeConstant = false;
|
||||
$GLOBALS['error_handler'] = new PMA\libraries\ErrorHandler;
|
||||
$GLOBALS['cfg']['Servers'] = array(1);
|
||||
$GLOBALS['allowDeny_forbidden'] = false;
|
||||
$GLOBALS['collation_connection'] = 'utf-8';
|
||||
if (!defined('PMA_USR_BROWSER_AGENT')) {
|
||||
define('PMA_USR_BROWSER_AGENT', 'chrome');
|
||||
|
||||
$removeConstant = true;
|
||||
|
||||
if (! PMA_HAS_RUNKIT) {
|
||||
$this->markTestSkipped('Cannot remove constant');
|
||||
}
|
||||
}
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$result = $this->object->authFails();
|
||||
$html = ob_get_clean();
|
||||
|
||||
$this->assertTrue(
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'You probably did not create a configuration file. You might want ' .
|
||||
'to use the <a href="setup/">setup script</a> to create one.',
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<strong>MySQL said: </strong><a href="./url.php?url=https%3A%2F%2F' .
|
||||
'dev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Ferror-messages-server.html"' .
|
||||
' target="mysql_doc">' .
|
||||
'<img src="themes/dot.gif" title="Documentation" alt="Documentation" ' .
|
||||
'class="icon ic_b_help" /></a>',
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'Cannot connect: invalid settings.',
|
||||
$html
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<a href="index.php?server=0&lang=en'
|
||||
. '&collation_connection=utf-8&token=token" '
|
||||
. 'class="button disableAjax">Retry to connect</a>',
|
||||
$html
|
||||
);
|
||||
if ($removeConstant) {
|
||||
runkit_constant_remove('PMA_USR_BROWSER_AGENT');
|
||||
}
|
||||
}
|
||||
}
|
||||
1182
#pma/test/classes/plugin/auth/AuthenticationCookieTest.php
Normal file
1182
#pma/test/classes/plugin/auth/AuthenticationCookieTest.php
Normal file
File diff suppressed because it is too large
Load Diff
463
#pma/test/classes/plugin/auth/AuthenticationHttpTest.php
Normal file
463
#pma/test/classes/plugin/auth/AuthenticationHttpTest.php
Normal file
@@ -0,0 +1,463 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\auth\AuthenticationHttp class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\plugins\auth\AuthenticationHttp;
|
||||
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\auth\AuthenticationHttp class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class AuthenticationHttpTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var AuthenticationHttp
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config;
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['lang'] = "en";
|
||||
$GLOBALS['text_dir'] = "ltr";
|
||||
$GLOBALS['token_provided'] = true;
|
||||
$GLOBALS['token_mismatch'] = false;
|
||||
$this->object = new AuthenticationHttp();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
public function doMockResponse($set_minimal, $body_id, $set_title)
|
||||
{
|
||||
$restoreInstance = PMA\libraries\Response::getInstance();
|
||||
|
||||
// mock footer
|
||||
$mockFooter = $this->getMockBuilder('PMA\libraries\Footer')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('setMinimal'))
|
||||
->getMock();
|
||||
|
||||
$mockFooter->expects($this->exactly($set_minimal))
|
||||
->method('setMinimal')
|
||||
->with();
|
||||
|
||||
// mock header
|
||||
|
||||
$mockHeader = $this->getMockBuilder('PMA\libraries\Header')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(
|
||||
array('setBodyId', 'setTitle', 'disableMenuAndConsole', 'addHTML')
|
||||
)
|
||||
->getMock();
|
||||
|
||||
$mockHeader->expects($this->exactly($body_id))
|
||||
->method('setBodyId')
|
||||
->with('loginform');
|
||||
|
||||
$mockHeader->expects($this->exactly($set_title))
|
||||
->method('setTitle')
|
||||
->with('Access denied!');
|
||||
|
||||
$mockHeader->expects($this->exactly($set_title))
|
||||
->method('disableMenuAndConsole')
|
||||
->with();
|
||||
|
||||
// set mocked headers and footers
|
||||
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getHeader', 'getFooter', 'addHTML', 'header', 'headersSent'))
|
||||
->getMock();
|
||||
|
||||
$mockResponse->expects($this->exactly($set_title))
|
||||
->method('getFooter')
|
||||
->with()
|
||||
->will($this->returnValue($mockFooter));
|
||||
|
||||
$mockResponse->expects($this->exactly($set_title))
|
||||
->method('getHeader')
|
||||
->with()
|
||||
->will($this->returnValue($mockHeader));
|
||||
|
||||
$mockResponse->expects($this->any())
|
||||
->method('headersSent')
|
||||
->with()
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$mockResponse->expects($this->exactly($set_title * 6))
|
||||
->method('addHTML')
|
||||
->with();
|
||||
|
||||
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
|
||||
$attrInstance->setAccessible(true);
|
||||
$attrInstance->setValue($mockResponse);
|
||||
|
||||
$headers = array_slice(func_get_args(), 3);
|
||||
|
||||
$header_method = $mockResponse->expects($this->exactly(count($headers)))
|
||||
->method('header');
|
||||
|
||||
call_user_func_array(array($header_method, 'withConsecutive'), $headers);
|
||||
|
||||
try {
|
||||
if (!empty($_REQUEST['old_usr'])) {
|
||||
$this->object->logOut();
|
||||
} else {
|
||||
$this->assertFalse(
|
||||
$this->object->auth()
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
$attrInstance->setValue($restoreInstance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationHttp::auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthLogoutUrl()
|
||||
{
|
||||
|
||||
$_REQUEST['old_usr'] = '1';
|
||||
$GLOBALS['cfg']['Server']['LogoutURL'] = 'https://example.com/logout';
|
||||
|
||||
$this->doMockResponse(
|
||||
0, 0, 0,
|
||||
array('Location: https://example.com/logout')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthVerbose()
|
||||
{
|
||||
$_REQUEST['old_usr'] = '';
|
||||
$GLOBALS['cfg']['Server']['verbose'] = 'verboseMessagê';
|
||||
|
||||
$this->doMockResponse(
|
||||
1, 1, 1,
|
||||
array('WWW-Authenticate: Basic realm="phpMyAdmin verboseMessag"'),
|
||||
array('HTTP/1.0 401 Unauthorized'),
|
||||
array('status: 401 Unauthorized')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthHost()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['verbose'] = '';
|
||||
$GLOBALS['cfg']['Server']['host'] = 'hòst';
|
||||
|
||||
$this->doMockResponse(
|
||||
1, 1, 1,
|
||||
array('WWW-Authenticate: Basic realm="phpMyAdmin hst"'),
|
||||
array('HTTP/1.0 401 Unauthorized'),
|
||||
array('status: 401 Unauthorized')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthRealm()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['host'] = '';
|
||||
$GLOBALS['cfg']['Server']['auth_http_realm'] = 'rêäealmmessage';
|
||||
|
||||
$this->doMockResponse(
|
||||
1, 1, 1,
|
||||
array('WWW-Authenticate: Basic realm="realmmessage"'),
|
||||
array('HTTP/1.0 401 Unauthorized'),
|
||||
array('status: 401 Unauthorized')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationHttp::authCheck
|
||||
*
|
||||
* @param string $user test username
|
||||
* @param string $pass test password
|
||||
* @param string $userIndex index to test username against
|
||||
* @param string $passIndex index to test username against
|
||||
* @param string $expectedReturn expected return value from test
|
||||
* @param string $expectedUser expected username to be set
|
||||
* @param string $expectedPass expected password to be set
|
||||
* @param string $old_usr value for $_REQUEST['old_usr']
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider authCheckProvider
|
||||
*/
|
||||
public function testAuthCheck($user, $pass, $userIndex, $passIndex,
|
||||
$expectedReturn, $expectedUser, $expectedPass, $old_usr = ''
|
||||
) {
|
||||
$GLOBALS['PHP_AUTH_USER'] = '';
|
||||
$GLOBALS['PHP_AUTH_PW'] = '';
|
||||
|
||||
$_SERVER[$userIndex] = $user;
|
||||
$_SERVER[$passIndex] = $pass;
|
||||
|
||||
$_REQUEST['old_usr'] = $old_usr;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedReturn,
|
||||
$this->object->authCheck()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedUser,
|
||||
$GLOBALS['PHP_AUTH_USER']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedPass,
|
||||
$GLOBALS['PHP_AUTH_PW']
|
||||
);
|
||||
|
||||
$_SERVER[$userIndex] = null;
|
||||
$_SERVER[$passIndex] = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testAuthCheck
|
||||
*
|
||||
* @return array Test data
|
||||
*/
|
||||
public function authCheckProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Basic ' . base64_encode('foo:bar'),
|
||||
'pswd',
|
||||
'PHP_AUTH_USER',
|
||||
'PHP_AUTH_PW',
|
||||
false,
|
||||
'',
|
||||
'bar',
|
||||
'foo'
|
||||
),
|
||||
array(
|
||||
'Basic ' . base64_encode('foobar'),
|
||||
'pswd',
|
||||
'REMOTE_USER',
|
||||
'REMOTE_PASSWORD',
|
||||
true,
|
||||
'Basic Zm9vYmFy',
|
||||
'pswd'
|
||||
),
|
||||
array(
|
||||
'Basic ' . base64_encode('foobar:'),
|
||||
'pswd',
|
||||
'AUTH_USER',
|
||||
'AUTH_PASSWORD',
|
||||
true,
|
||||
'foobar',
|
||||
false
|
||||
),
|
||||
array(
|
||||
'Basic ' . base64_encode(':foobar'),
|
||||
'pswd',
|
||||
'HTTP_AUTHORIZATION',
|
||||
'AUTH_PASSWORD',
|
||||
true,
|
||||
'Basic OmZvb2Jhcg==',
|
||||
'pswd'
|
||||
),
|
||||
array(
|
||||
'BasicTest',
|
||||
'pswd',
|
||||
'Authorization',
|
||||
'AUTH_PASSWORD',
|
||||
true,
|
||||
'BasicTest',
|
||||
'pswd'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationHttp::authSetUser
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthSetUser()
|
||||
{
|
||||
// case 1
|
||||
|
||||
$GLOBALS['PHP_AUTH_USER'] = 'testUser';
|
||||
$GLOBALS['PHP_AUTH_PW'] = 'testPass';
|
||||
$GLOBALS['server'] = 2;
|
||||
$GLOBALS['cfg']['Server']['user'] = 'testUser';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->authSetUser()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'testUser',
|
||||
$GLOBALS['cfg']['Server']['user']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'testPass',
|
||||
$GLOBALS['cfg']['Server']['password']
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
isset($GLOBALS['PHP_AUTH_PW'])
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
isset($_SERVER['PHP_AUTH_PW'])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
2,
|
||||
$GLOBALS['server']
|
||||
);
|
||||
|
||||
// case 2
|
||||
$GLOBALS['PHP_AUTH_USER'] = 'testUser';
|
||||
$GLOBALS['PHP_AUTH_PW'] = 'testPass';
|
||||
$GLOBALS['cfg']['Servers'][1] = array(
|
||||
'host' => 'a',
|
||||
'user' => 'testUser',
|
||||
'foo' => 'bar'
|
||||
);
|
||||
|
||||
$GLOBALS['cfg']['Server']= array(
|
||||
'host' => 'a',
|
||||
'user' => 'user2'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->authSetUser()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'user' => 'testUser',
|
||||
'password' => 'testPass',
|
||||
'host' => 'a',
|
||||
'foo' => 'bar'
|
||||
),
|
||||
$GLOBALS['cfg']['Server']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$GLOBALS['server']
|
||||
);
|
||||
|
||||
// case 3
|
||||
$GLOBALS['server'] = 3;
|
||||
$GLOBALS['PHP_AUTH_USER'] = 'testUser';
|
||||
$GLOBALS['PHP_AUTH_PW'] = 'testPass';
|
||||
$GLOBALS['cfg']['Servers'][1] = array(
|
||||
'host' => 'a',
|
||||
'user' => 'testUsers',
|
||||
'foo' => 'bar'
|
||||
);
|
||||
|
||||
$GLOBALS['cfg']['Server']= array(
|
||||
'host' => 'a',
|
||||
'user' => 'user2'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->authSetUser()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'user' => 'testUser',
|
||||
'password' => 'testPass',
|
||||
'host' => 'a'
|
||||
),
|
||||
$GLOBALS['cfg']['Server']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
3,
|
||||
$GLOBALS['server']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationHttp::authSetFails
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testAuthFails()
|
||||
{
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->at(0))
|
||||
->method('getError')
|
||||
->will($this->returnValue('error 123'));
|
||||
|
||||
$dbi->expects($this->at(1))
|
||||
->method('getError')
|
||||
->will($this->returnValue('error 321'));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('getError')
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$GLOBALS['errno'] = 31;
|
||||
|
||||
ob_start();
|
||||
$this->object->authFails();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'<p>error 123</p>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationHttp')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('authForm'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->exactly(2))
|
||||
->method('authForm');
|
||||
// case 2
|
||||
$GLOBALS['cfg']['Server']['host'] = 'host';
|
||||
$GLOBALS['errno'] = 1045;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->authFails()
|
||||
);
|
||||
|
||||
// case 3
|
||||
$GLOBALS['errno'] = 1043;
|
||||
$this->assertTrue(
|
||||
$this->object->authFails()
|
||||
);
|
||||
}
|
||||
}
|
||||
480
#pma/test/classes/plugin/auth/AuthenticationSignonTest.php
Normal file
480
#pma/test/classes/plugin/auth/AuthenticationSignonTest.php
Normal file
@@ -0,0 +1,480 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\auth\AuthenticationSignon class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
use PMA\libraries\plugins\auth\AuthenticationSignon;
|
||||
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\auth\AuthenticationSignon class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class AuthenticationSignonTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['PMA_Config'] = new PMA\libraries\Config;
|
||||
$GLOBALS['PMA_Config']->enableBc();
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new AuthenticationSignon();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuth()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonURL'] = '';
|
||||
|
||||
ob_start();
|
||||
$this->object->auth();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'You must set SignonURL!',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthLogoutURL()
|
||||
{
|
||||
$restoreInstance = PMA\libraries\Response::getInstance();
|
||||
|
||||
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('isAjax', 'headersSent', 'header'))
|
||||
->getMock();
|
||||
|
||||
$mockResponse->expects($this->any())
|
||||
->method('headersSent')
|
||||
->with()
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$mockResponse->expects($this->once())
|
||||
->method('header')
|
||||
->with('Location: https://example.com/logoutURL');
|
||||
|
||||
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
|
||||
$attrInstance->setAccessible(true);
|
||||
$attrInstance->setValue($mockResponse);
|
||||
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
|
||||
$GLOBALS['cfg']['Server']['LogoutURL'] = 'https://example.com/logoutURL';
|
||||
|
||||
$this->object->logOut();
|
||||
|
||||
$attrInstance->setValue($restoreInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthLogout()
|
||||
{
|
||||
$restoreInstance = PMA\libraries\Response::getInstance();
|
||||
|
||||
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('isAjax', 'headersSent', 'header'))
|
||||
->getMock();
|
||||
|
||||
$mockResponse->expects($this->any())
|
||||
->method('headersSent')
|
||||
->with()
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$mockResponse->expects($this->once())
|
||||
->method('header')
|
||||
->with('Location: https://example.com/SignonURL');
|
||||
|
||||
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
|
||||
$attrInstance->setAccessible(true);
|
||||
$attrInstance->setValue($mockResponse);
|
||||
$GLOBALS['header'] = array();
|
||||
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
|
||||
$GLOBALS['cfg']['Server']['LogoutURL'] = '';
|
||||
|
||||
$this->object->logOut();
|
||||
|
||||
$attrInstance->setValue($restoreInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthCheckEmpty()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
|
||||
$_SESSION['LAST_SIGNON_URL'] = 'https://example.com/SignonDiffURL';
|
||||
|
||||
$this->assertFalse(
|
||||
$this->object->authCheck()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthCheckSession()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
|
||||
$_SESSION['LAST_SIGNON_URL'] = 'https://example.com/SignonURL';
|
||||
$GLOBALS['cfg']['Server']['SignonScript'] = './examples/signon-script.php';
|
||||
$GLOBALS['cfg']['Server']['SignonSession'] = 'session123';
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
$GLOBALS['cfg']['Server']['port'] = '80';
|
||||
$GLOBALS['cfg']['Server']['user'] = 'user';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->authCheck()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'user',
|
||||
$GLOBALS['PHP_AUTH_USER']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'password',
|
||||
$GLOBALS['PHP_AUTH_PW']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'https://example.com/SignonURL',
|
||||
$_SESSION['LAST_SIGNON_URL']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthCheckToken()
|
||||
{
|
||||
$restoreInstance = PMA\libraries\Response::getInstance();
|
||||
|
||||
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('isAjax', 'headersSent', 'header'))
|
||||
->getMock();
|
||||
|
||||
$mockResponse->expects($this->any())
|
||||
->method('headersSent')
|
||||
->with()
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$mockResponse->expects($this->once())
|
||||
->method('header')
|
||||
->with('Location: https://example.com/SignonURL');
|
||||
|
||||
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
|
||||
$attrInstance->setAccessible(true);
|
||||
$attrInstance->setValue($mockResponse);
|
||||
|
||||
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
|
||||
$GLOBALS['cfg']['Server']['SignonSession'] = 'session123';
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
$GLOBALS['cfg']['Server']['port'] = '80';
|
||||
$GLOBALS['cfg']['Server']['user'] = 'user';
|
||||
$GLOBALS['cfg']['Server']['SignonScript'] = '';
|
||||
$_COOKIE['session123'] = true;
|
||||
$_SESSION['PMA_single_signon_user'] = 'user123';
|
||||
$_SESSION['PMA_single_signon_password'] = 'pass123';
|
||||
$_SESSION['PMA_single_signon_host'] = 'local';
|
||||
$_SESSION['PMA_single_signon_port'] = '12';
|
||||
$_SESSION['PMA_single_signon_cfgupdate'] = array('foo' => 'bar');
|
||||
$_SESSION['PMA_single_signon_token'] = 'pmaToken';
|
||||
$sessionName = session_name();
|
||||
$sessionID = session_id();
|
||||
|
||||
$this->object->logOut();
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'SignonURL' => 'https://example.com/SignonURL',
|
||||
'SignonScript' => '',
|
||||
'SignonSession' => 'session123',
|
||||
'host' => 'localhost',
|
||||
'port' => '80',
|
||||
'user' => 'user',
|
||||
),
|
||||
$GLOBALS['cfg']['Server']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$sessionName,
|
||||
session_name()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$sessionID,
|
||||
session_id()
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
isset($_SESSION['LAST_SIGNON_URL'])
|
||||
);
|
||||
$attrInstance->setValue($restoreInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthCheckKeep()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
|
||||
$GLOBALS['cfg']['Server']['SignonSession'] = 'session123';
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
$GLOBALS['cfg']['Server']['port'] = '80';
|
||||
$GLOBALS['cfg']['Server']['user'] = 'user';
|
||||
$GLOBALS['cfg']['Server']['SignonScript'] = '';
|
||||
$_COOKIE['session123'] = true;
|
||||
$_REQUEST['old_usr'] = '';
|
||||
$_SESSION['PMA_single_signon_user'] = 'user123';
|
||||
$_SESSION['PMA_single_signon_password'] = 'pass123';
|
||||
$_SESSION['PMA_single_signon_host'] = 'local';
|
||||
$_SESSION['PMA_single_signon_port'] = '12';
|
||||
$_SESSION['PMA_single_signon_cfgupdate'] = array('foo' => 'bar');
|
||||
$_SESSION['PMA_single_signon_token'] = 'pmaToken';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->authCheck()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'user123',
|
||||
$GLOBALS['PHP_AUTH_USER']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'pass123',
|
||||
$GLOBALS['PHP_AUTH_PW']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authSetUser
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthSetUser()
|
||||
{
|
||||
$GLOBALS['PHP_AUTH_USER'] = 'testUser123';
|
||||
$GLOBALS['PHP_AUTH_PW'] = 'testPass123';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->authSetUser()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'testUser123',
|
||||
$GLOBALS['cfg']['Server']['user']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'testPass123',
|
||||
$GLOBALS['cfg']['Server']['password']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthFailsForbidden()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
|
||||
$_COOKIE['newSession'] = '42';
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('auth'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->exactly(1))
|
||||
->method('auth');
|
||||
|
||||
$GLOBALS['login_without_password_is_forbidden'] = true;
|
||||
|
||||
$this->object->authFails();
|
||||
|
||||
$this->assertEquals(
|
||||
'Login without a password is forbidden by configuration '
|
||||
. '(see AllowNoPassword)',
|
||||
$_SESSION['PMA_single_signon_error_message']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthFailsDeny()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
|
||||
$_COOKIE['newSession'] = '42';
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('auth'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->exactly(1))
|
||||
->method('auth');
|
||||
|
||||
$GLOBALS['login_without_password_is_forbidden'] = null;
|
||||
$GLOBALS['allowDeny_forbidden'] = true;
|
||||
|
||||
$this->object->authFails();
|
||||
|
||||
$this->assertEquals(
|
||||
'Access denied!',
|
||||
$_SESSION['PMA_single_signon_error_message']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthFailsTimeout()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
|
||||
$_COOKIE['newSession'] = '42';
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('auth'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->exactly(1))
|
||||
->method('auth');
|
||||
|
||||
$GLOBALS['allowDeny_forbidden'] = null;
|
||||
$GLOBALS['no_activity'] = true;
|
||||
$GLOBALS['cfg']['LoginCookieValidity'] = '1440';
|
||||
|
||||
$this->object->authFails();
|
||||
|
||||
$this->assertEquals(
|
||||
'No activity within 1440 seconds; please log in again.',
|
||||
$_SESSION['PMA_single_signon_error_message']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthFailsMySQLError()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
|
||||
$_COOKIE['newSession'] = '42';
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('auth'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->exactly(1))
|
||||
->method('auth');
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->at(0))
|
||||
->method('getError')
|
||||
->will($this->returnValue('error<123>'));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$GLOBALS['no_activity'] = null;
|
||||
|
||||
$this->object->authFails();
|
||||
|
||||
$this->assertEquals(
|
||||
'error<123>',
|
||||
$_SESSION['PMA_single_signon_error_message']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthFailsConnect()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
|
||||
$_COOKIE['newSession'] = '42';
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('auth'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->exactly(1))
|
||||
->method('auth');
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->at(0))
|
||||
->method('getError')
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object->authFails();
|
||||
|
||||
$this->assertEquals(
|
||||
'Cannot log in to the MySQL server',
|
||||
$_SESSION['PMA_single_signon_error_message']
|
||||
);
|
||||
}
|
||||
}
|
||||
482
#pma/test/classes/plugin/export/ExportCodegenTest.php
Normal file
482
#pma/test/classes/plugin/export/ExportCodegenTest.php
Normal file
@@ -0,0 +1,482 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportCodegen class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportCodegen;
|
||||
|
||||
require_once 'libraries/export.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'export.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportCodegen class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportCodegenTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new ExportCodegen(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::initSpecificVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInitSpecificVariables()
|
||||
{
|
||||
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportCodegen', 'initSpecificVariables');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrCgFormats = new ReflectionProperty('PMA\libraries\plugins\export\ExportCodegen', '_cgFormats');
|
||||
$attrCgFormats->setAccessible(true);
|
||||
|
||||
$attrCgHandlers = new ReflectionProperty('PMA\libraries\plugins\export\ExportCodegen', '_cgHandlers');
|
||||
$attrCgHandlers->setAccessible(true);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
"NHibernate C# DO",
|
||||
"NHibernate XML"
|
||||
),
|
||||
$attrCgFormats->getValue($this->object)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
"_handleNHibernateCSBody",
|
||||
"_handleNHibernateXMLBody"
|
||||
),
|
||||
$attrCgHandlers->getValue($this->object)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportCodegen', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportCodegen', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'CodeGen',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'cs',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/cs',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Options',
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
$options = $properties->getOptions();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Format Specific Options',
|
||||
$options->getName()
|
||||
);
|
||||
|
||||
$generalOptionsArray = $options->getProperties();
|
||||
$generalOptions = $generalOptionsArray[0];
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'general_opts',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$hidden = $generalProperties[0];
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\HiddenPropertyItem',
|
||||
$hidden
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_or_data',
|
||||
$hidden->getName()
|
||||
);
|
||||
|
||||
$select = $generalProperties[1];
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\SelectPropertyItem',
|
||||
$select
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'format',
|
||||
$select->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Format:',
|
||||
$select->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
"NHibernate C# DO",
|
||||
"NHibernate XML"
|
||||
),
|
||||
$select->getValues()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$GLOBALS['codegen_format'] = 1;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->object->exportData(
|
||||
'testDB', 'testTable', "\n", 'example.com', 'test'
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'<?xml version="1.0" encoding="utf-8" ?>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<class name="TestTable" table="TestTable">',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'</class>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'</hibernate-mapping>',
|
||||
$result
|
||||
);
|
||||
|
||||
$GLOBALS['codegen_format'] = 4;
|
||||
|
||||
$this->object->exportData(
|
||||
'testDB', 'testTable', "\n", 'example.com', 'test'
|
||||
);
|
||||
|
||||
$this->expectOutputString(
|
||||
'4 is not supported.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::cgMakeIdentifier
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCgMakeIdentifier()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'_Ⅲfoo',
|
||||
ExportCodegen::cgMakeIdentifier('Ⅲ{}96`{}foo', true)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'TestⅢ',
|
||||
ExportCodegen::cgMakeIdentifier('`98testⅢ{}96`{}', true)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'testⅢ',
|
||||
ExportCodegen::cgMakeIdentifier('`98testⅢ{}96`{}', false)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::_handleNHibernateCSBody
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHandleNHibernateCSBody()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('DESC `db`.`table`')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->at(1))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array('a', 'b', 'c', false, 'e', 'f')));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportCodegen', '_handleNHibernateCSBody');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke($this->object, 'db', 'table', "\n");
|
||||
|
||||
$this->assertEquals(
|
||||
"using System;\n" .
|
||||
"using System.Collections;\n" .
|
||||
"using System.Collections.Generic;\n" .
|
||||
"using System.Text;\n" .
|
||||
"namespace Db\n" .
|
||||
"{\n" .
|
||||
" #region Table\n" .
|
||||
" public class Table\n" .
|
||||
" {\n" .
|
||||
" #region Member Variables\n" .
|
||||
" protected unknown _a;\n" .
|
||||
" #endregion\n" .
|
||||
" #region Constructors\n" .
|
||||
" public Table() { }\n" .
|
||||
" public Table(unknown a)\n" .
|
||||
" {\n" .
|
||||
" this._a=a;\n" .
|
||||
" }\n" .
|
||||
" #endregion\n" .
|
||||
" #region Public Properties\n" .
|
||||
" public virtual unknown A\n" .
|
||||
" {\n" .
|
||||
" get {return _a;}\n" .
|
||||
" set {_a=value;}\n" .
|
||||
" }\n" .
|
||||
" #endregion\n" .
|
||||
" }\n" .
|
||||
" #endregion\n" .
|
||||
"}",
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCodegen::_handleNHibernateXMLBody
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHandleNHibernateXMLBody()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('DESC `db`.`table`')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->at(1))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array('a', 'b', 'c', false, 'e', 'f')));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array('g', 'h', 'i', 'PRI', 'j', 'k')));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportCodegen', '_handleNHibernateXMLBody');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke($this->object, 'db', 'table', "\n");
|
||||
|
||||
$this->assertEquals(
|
||||
'<?xml version="1.0" encoding="utf-8" ?>' . "\n" .
|
||||
'<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Db" ' .
|
||||
'assembly="Db">' . "\n" .
|
||||
' <class name="Table" table="Table">' . "\n" .
|
||||
' <property name="A" type="Unknown">' . "\n" .
|
||||
' <column name="a" sql-type="b" not-null="false" />' . "\n" .
|
||||
' </property>' . "\n" .
|
||||
' <id name="G" type="Unknown" unsaved-value="0">' . "\n" .
|
||||
' <column name="g" sql-type="h" not-null="false" ' .
|
||||
'unique="true" index="PRIMARY"/>' . "\n" .
|
||||
' <generator class="native" />' . "\n" .
|
||||
' </id>' . "\n" .
|
||||
' </class>' . "\n" .
|
||||
'</hibernate-mapping>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for
|
||||
* - PMA\libraries\plugins\export\ExportCodegen::_getCgFormats
|
||||
* - PMA\libraries\plugins\export\ExportCodegen::_setCgFormats
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetCgFormats()
|
||||
{
|
||||
$reflection = new ReflectionClass('PMA\libraries\plugins\export\ExportCodegen');
|
||||
|
||||
$getter = $reflection->getMethod('_getCgFormats');
|
||||
$setter = $reflection->getMethod('_setCgFormats');
|
||||
|
||||
$getter->setAccessible(true);
|
||||
$setter->setAccessible(true);
|
||||
|
||||
$setter->invoke($this->object, array(1, 2));
|
||||
|
||||
$this->assertEquals(
|
||||
array(1, 2),
|
||||
$getter->invoke($this->object)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for
|
||||
* - PMA\libraries\plugins\export\ExportCodegen::_getCgHandlers
|
||||
* - PMA\libraries\plugins\export\ExportCodegen::_setCgHandlers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetCgHandlers()
|
||||
{
|
||||
$reflection = new ReflectionClass('PMA\libraries\plugins\export\ExportCodegen');
|
||||
|
||||
$getter = $reflection->getMethod('_getCgHandlers');
|
||||
$setter = $reflection->getMethod('_setCgHandlers');
|
||||
|
||||
$getter->setAccessible(true);
|
||||
$setter->setAccessible(true);
|
||||
|
||||
$setter->invoke($this->object, array(1, 2));
|
||||
|
||||
$this->assertEquals(
|
||||
array(1, 2),
|
||||
$getter->invoke($this->object)
|
||||
);
|
||||
}
|
||||
}
|
||||
750
#pma/test/classes/plugin/export/ExportCsvTest.php
Normal file
750
#pma/test/classes/plugin/export/ExportCsvTest.php
Normal file
@@ -0,0 +1,750 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportCsv class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportCsv;
|
||||
|
||||
require_once 'libraries/export.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'export.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportCsv class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportCsvTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new ExportCsv();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCsv::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportCsv', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportCsv', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'CSV',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'csv',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/comma-separated-values',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Options',
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
$options = $properties->getOptions();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Format Specific Options',
|
||||
$options->getName()
|
||||
);
|
||||
|
||||
$generalOptionsArray = $options->getProperties();
|
||||
$generalOptions = $generalOptionsArray[0];
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'general_opts',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'separator',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Columns separated with:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'enclosed',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Columns enclosed with:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'escaped',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Columns escaped with:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'terminated',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Lines terminated with:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'null',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Replace NULL with:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'removeCRLF',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Remove carriage return/line feed characters within columns',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'columns',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Put columns names in the first row',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\HiddenPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_or_data',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCsv::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
// case 1
|
||||
|
||||
$GLOBALS['what'] = 'excel';
|
||||
$GLOBALS['excel_edition'] = 'win';
|
||||
$GLOBALS['excel_columns'] = true;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"\015\012",
|
||||
$GLOBALS['csv_terminated']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
";",
|
||||
$GLOBALS['csv_separator']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'"',
|
||||
$GLOBALS['csv_enclosed']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'"',
|
||||
$GLOBALS['csv_escaped']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'yes',
|
||||
$GLOBALS['csv_columns']
|
||||
);
|
||||
|
||||
// case 2
|
||||
|
||||
$GLOBALS['excel_edition'] = 'mac_excel2003';
|
||||
unset($GLOBALS['excel_columns']);
|
||||
$GLOBALS['csv_columns'] = 'no';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"\015\012",
|
||||
$GLOBALS['csv_terminated']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
";",
|
||||
$GLOBALS['csv_separator']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'"',
|
||||
$GLOBALS['csv_enclosed']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'"',
|
||||
$GLOBALS['csv_escaped']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'no',
|
||||
$GLOBALS['csv_columns']
|
||||
);
|
||||
|
||||
// case 3
|
||||
|
||||
$GLOBALS['excel_edition'] = 'mac_excel2008';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"\015\012",
|
||||
$GLOBALS['csv_terminated']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
",",
|
||||
$GLOBALS['csv_separator']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'"',
|
||||
$GLOBALS['csv_enclosed']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'"',
|
||||
$GLOBALS['csv_escaped']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'no',
|
||||
$GLOBALS['csv_columns']
|
||||
);
|
||||
|
||||
// case 4
|
||||
|
||||
$GLOBALS['excel_edition'] = 'testBlank';
|
||||
$GLOBALS['csv_separator'] = '#';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'#',
|
||||
$GLOBALS['csv_separator']
|
||||
);
|
||||
|
||||
// case 5
|
||||
|
||||
$GLOBALS['what'] = 'notExcel';
|
||||
$GLOBALS['crlf'] = "\n";
|
||||
$GLOBALS['csv_terminated'] = '';
|
||||
$GLOBALS['csv_separator'] = 'a\\t';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$GLOBALS['csv_terminated'],
|
||||
"\n"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$GLOBALS['csv_separator'],
|
||||
"a\011"
|
||||
);
|
||||
// case 6
|
||||
|
||||
$GLOBALS['csv_terminated'] = 'AUTO';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$GLOBALS['csv_terminated'],
|
||||
"\n"
|
||||
);
|
||||
|
||||
// case 7
|
||||
|
||||
$GLOBALS['csv_terminated'] = 'a\\rb\\nc\\t';
|
||||
$GLOBALS['csv_separator'] = 'a\\t';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$GLOBALS['csv_terminated'],
|
||||
"a\015b\012c\011"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$GLOBALS['csv_separator'],
|
||||
"a\011"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCsv::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCsv::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCsv::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCsv::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportCsv::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
// case 1
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['csv_columns'] = 'yes';
|
||||
$GLOBALS['csv_terminated'] = ';';
|
||||
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = true;
|
||||
$GLOBALS['file_handle'] = null;
|
||||
|
||||
ob_start();
|
||||
$this->assertFalse(
|
||||
$this->object->exportData(
|
||||
'testDB', 'testTable', "\n", 'example.com', 'test'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
// case 2
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('test', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('fieldName')
|
||||
->with(true, 0)
|
||||
->will($this->returnValue("foo'\\bar"));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array(null, 'b', 'c', false, 'e', 'f')));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['what'] = 'UT';
|
||||
$GLOBALS['UT_null'] = 'customNull';
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'testDB', 'testTable', "\n", 'example.com', 'test'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"foo'ba;customNull;",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 3
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('test', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('fieldName')
|
||||
->with(true, 0)
|
||||
->will($this->returnValue("foo\"\\bar"));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array(1 => 'a')));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['csv_enclosed'] = '"';
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'testDB', 'testTable', "\n", 'example.com', 'test'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"\"foo\"bar;customNull;",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 4
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('test', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('fieldName')
|
||||
->with(true, 0)
|
||||
->will($this->returnValue("foo\"\\bar"));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array("test\015\012\n")));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['csv_enclosed'] = '"';
|
||||
$GLOBALS['what'] = 'excel';
|
||||
$GLOBALS['excel_removeCRLF'] = true;
|
||||
$GLOBALS['csv_escaped'] = '"';
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'testDB', 'testTable', "\n", 'example.com', 'test'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"\"foo\"\"bar;\"test\";",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 5
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('test', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('fieldName')
|
||||
->with(true, 0)
|
||||
->will($this->returnValue("foo\"\\bar"));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array("test\015\n")));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['csv_enclosed'] = '"';
|
||||
unset($GLOBALS['excel_removeCRLF']);
|
||||
$GLOBALS['csv_escaped'] = ';';
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'testDB', 'testTable', "\n", 'example.com', 'test'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"\"foo;\"bar;\"test\n\";",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 6
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('test', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(2));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fieldName')
|
||||
->will($this->returnValue("foo\"\\bar"));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array("test\015\n", "test\n")));
|
||||
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['csv_enclosed'] = '"';
|
||||
$GLOBALS['csv_escaped'] = ';';
|
||||
$GLOBALS['csv_escaped'] = '#';
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'testDB', 'testTable', "\n", 'example.com', 'test'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"\"foo#\"bar\"\"foo#\"bar;\"test\n" .
|
||||
"\"\"test\n" .
|
||||
"\";",
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
||||
203
#pma/test/classes/plugin/export/ExportExcelTest.php
Normal file
203
#pma/test/classes/plugin/export/ExportExcelTest.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportExcel class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportExcel;
|
||||
|
||||
require_once 'libraries/export.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'export.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportExcel class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportExcelTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new ExportExcel();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportExcel::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportExcel', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportExcel', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'CSV for MS Excel',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'csv',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/comma-separated-values',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Options',
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
$options = $properties->getOptions();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Format Specific Options',
|
||||
$options->getName()
|
||||
);
|
||||
|
||||
$generalOptionsArray = $options->getProperties();
|
||||
$generalOptions = $generalOptionsArray[0];
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'general_opts',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'null',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Replace NULL with:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'removeCRLF',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Remove carriage return/line feed characters within columns',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'columns',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Put columns names in the first row',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\SelectPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'edition',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'win' => 'Windows',
|
||||
'mac_excel2003' => 'Excel 2003 / Macintosh',
|
||||
'mac_excel2008' => 'Excel 2008 / Macintosh'
|
||||
),
|
||||
$property->getValues()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"Excel edition:",
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\HiddenPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_or_data',
|
||||
$property->getName()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user