Initial commit
This commit is contained in:
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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
912
#pma/test/classes/plugin/export/ExportHtmlwordTest.php
Normal file
912
#pma/test/classes/plugin/export/ExportHtmlwordTest.php
Normal file
@ -0,0 +1,912 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportHtmlword class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportHtmlword;
|
||||
|
||||
require_once 'libraries/export.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/transformations.lib.php';
|
||||
require_once 'export.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportHtmlword class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportHtmlwordTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$this->object = new ExportHtmlword();
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportHtmlword', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportHtmlword', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Microsoft Word 2000',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'doc',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'application/vnd.ms-word',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Options',
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$properties->getForceFile()
|
||||
);
|
||||
|
||||
$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(
|
||||
'dump_what',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Dump table',
|
||||
$generalOptions->getText()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\RadioPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_or_data',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
),
|
||||
$property->getValues()
|
||||
);
|
||||
|
||||
$generalOptions = $generalOptionsArray[1];
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'dump_what',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Data dump options',
|
||||
$generalOptions->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure',
|
||||
$generalOptions->getForce()
|
||||
);
|
||||
|
||||
$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(
|
||||
'columns',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Put columns names in the first row',
|
||||
$property->getText()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
ob_start();
|
||||
$this->object->exportHeader();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$expected
|
||||
= '<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:x="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
|
||||
. ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset='
|
||||
. 'utf-8' . '" />
|
||||
</head>
|
||||
<body>';
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$result
|
||||
);
|
||||
|
||||
// case 2
|
||||
|
||||
$GLOBALS['charset'] = 'ISO-8859-1';
|
||||
ob_start();
|
||||
$this->object->exportHeader();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$expected
|
||||
= '<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:x="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
|
||||
. ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset='
|
||||
. 'ISO-8859-1' . '" />
|
||||
</head>
|
||||
<body>';
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'</body></html>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('d"b')
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'<h1>Database d"b</h1>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
// case 1
|
||||
|
||||
$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(5));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fieldName')
|
||||
->will($this->returnValue("foo\\bar"));
|
||||
|
||||
$dbi->expects($this->at(7))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array(null, '0', 'test', false)));
|
||||
|
||||
$dbi->expects($this->at(8))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['htmlword_columns'] = true;
|
||||
$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 = htmlspecialchars_decode(ob_get_clean());
|
||||
|
||||
$this->assertEquals(
|
||||
'<h2>Dumping data for table testTable</h2>' .
|
||||
'<table class="width100" cellspacing="1"><tr class="print-category">' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'</tr><tr class="print-category"><td class="print">' .
|
||||
'customNull</td><td class="print">0</td><td class="print">test</td>' .
|
||||
'<td class="print"></td><td class="print">customNull</td></tr></table>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::getTableDefStandIn
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTableDefStandIn()
|
||||
{
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportHtmlword')
|
||||
->setMethods(array('formatOneColumnDefinition'))
|
||||
->getMock();
|
||||
|
||||
// case 1
|
||||
|
||||
$keys = array(
|
||||
array(
|
||||
'Non_unique' => 0,
|
||||
'Column_name' => 'name1'
|
||||
),
|
||||
array(
|
||||
'Non_unique' => 1,
|
||||
'Column_name' => 'name2'
|
||||
)
|
||||
);
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('database', 'view')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumns')
|
||||
->with('database', 'view')
|
||||
->will($this->returnValue(array(array('Field' => 'column'))));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object->expects($this->once())
|
||||
->method('formatOneColumnDefinition')
|
||||
->with(array('Field' => 'column'), array('name1'), 'column')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$this->assertEquals(
|
||||
'<table class="width100" cellspacing="1">' .
|
||||
'<tr class="print-category"><th class="print">Column</th>' .
|
||||
'<td class="print"><strong>Type</strong></td>' .
|
||||
'<td class="print"><strong>Null</strong></td>' .
|
||||
'<td class="print"><strong>Default</strong></td></tr>' .
|
||||
'1</tr></table>',
|
||||
$this->object->getTableDefStandIn('database', 'view', "\n")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::getTableDef
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTableDef()
|
||||
{
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportHtmlword')
|
||||
->setMethods(array('formatOneColumnDefinition'))
|
||||
->getMock();
|
||||
|
||||
$keys = array(
|
||||
array(
|
||||
'Non_unique' => 0,
|
||||
'Column_name' => 'name1'
|
||||
),
|
||||
array(
|
||||
'Non_unique' => 1,
|
||||
'Column_name' => 'name2'
|
||||
)
|
||||
);
|
||||
|
||||
// case 1
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('fetchResult')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(),
|
||||
array(
|
||||
'fieldname' => array(
|
||||
'values' => 'test-',
|
||||
'transformation' => 'testfoo',
|
||||
'mimetype' => 'test<'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$columns = array(
|
||||
'Field' => 'fieldname'
|
||||
);
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumns')
|
||||
->with('database', '')
|
||||
->will($this->returnValue(array($columns)));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('query')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('numRows')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'comment' => array('fieldname' => 'testComment')
|
||||
)
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object->expects($this->exactly(3))
|
||||
->method('formatOneColumnDefinition')
|
||||
->with($columns, array('name1'))
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$GLOBALS['controllink'] = null;
|
||||
$_SESSION['relation'][0] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'relwork' => true,
|
||||
'commwork' => true,
|
||||
'mimework' => true,
|
||||
'db' => 'database',
|
||||
'relation' => 'rel',
|
||||
'column_info' => 'col'
|
||||
);
|
||||
|
||||
$result = $this->object->getTableDef(
|
||||
'database',
|
||||
'',
|
||||
true,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<table class="width100" cellspacing="1">' .
|
||||
'<tr class="print-category"><th class="print">Column</th>' .
|
||||
'<td class="print"><strong>Type</strong></td>' .
|
||||
'<td class="print"><strong>Null</strong></td>' .
|
||||
'<td class="print"><strong>Default</strong></td>' .
|
||||
'<td class="print"><strong>Comments</strong></td>' .
|
||||
'<td class="print"><strong>MIME</strong></td></tr>' .
|
||||
'1<td class="print"></td><td class="print">Test<</td></tr></table>',
|
||||
$result
|
||||
);
|
||||
|
||||
// case 2
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('fetchResult')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(
|
||||
'fieldname' => array(
|
||||
'foreign_table' => 'ftable',
|
||||
'foreign_field' => 'ffield'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'field' => array(
|
||||
'values' => 'test-',
|
||||
'transformation' => 'testfoo',
|
||||
'mimetype' => 'test<'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$columns = array(
|
||||
'Field' => 'fieldname'
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumns')
|
||||
->with('database', '')
|
||||
->will($this->returnValue(array($columns)));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('query')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('numRows')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'comment' => array('field' => 'testComment')
|
||||
)
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$_SESSION['relation'][0] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'relwork' => true,
|
||||
'commwork' => true,
|
||||
'mimework' => true,
|
||||
'db' => 'database',
|
||||
'relation' => 'rel',
|
||||
'column_info' => 'col'
|
||||
);
|
||||
|
||||
$result = $this->object->getTableDef(
|
||||
'database',
|
||||
'',
|
||||
true,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<td class="print">ftable (ffield)</td>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<td class="print"></td><td class="print"></td>',
|
||||
$result
|
||||
);
|
||||
|
||||
// case 3
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$columns = array(
|
||||
'Field' => 'fieldname'
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumns')
|
||||
->with('database', '')
|
||||
->will($this->returnValue(array($columns)));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('query')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('numRows')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'comment' => array('field' => 'testComment')
|
||||
)
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$_SESSION['relation'][0] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'relwork' => false,
|
||||
'commwork' => false,
|
||||
'mimework' => false,
|
||||
'db' => 'database',
|
||||
'relation' => 'rel',
|
||||
'column_info' => 'col'
|
||||
);
|
||||
|
||||
$result = $this->object->getTableDef(
|
||||
'database',
|
||||
'',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<table class="width100" cellspacing="1">' .
|
||||
'<tr class="print-category"><th class="print">Column</th>' .
|
||||
'<td class="print"><strong>Type</strong></td>' .
|
||||
'<td class="print"><strong>Null</strong></td>' .
|
||||
'<td class="print"><strong>Default</strong></td></tr>1</tr></table>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::getTriggers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTriggers()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$triggers = array(
|
||||
array(
|
||||
'name' => 'tna"me',
|
||||
'action_timing' => 'ac>t',
|
||||
'event_manipulation' => 'manip&',
|
||||
'definition' => 'def'
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTriggers')
|
||||
->with('database', 'table')
|
||||
->will($this->returnValue($triggers));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportHtmlword', 'getTriggers');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke($this->object, 'database', 'table');
|
||||
|
||||
$this->assertContains(
|
||||
'<td class="print">tna"me</td>' .
|
||||
'<td class="print">ac>t</td>' .
|
||||
'<td class="print">manip&</td>' .
|
||||
'<td class="print">def</td>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportStructure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportStructure()
|
||||
{
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTriggers')
|
||||
->with('db', 'tbl')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportHtmlword')
|
||||
->setMethods(array('getTableDef', 'getTriggers', 'getTableDefStandIn'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->at(0))
|
||||
->method('getTableDef')
|
||||
->with('db', 'tbl', false, false, false, false)
|
||||
->will($this->returnValue('dumpText1'));
|
||||
|
||||
$this->object->expects($this->once())
|
||||
->method('getTriggers')
|
||||
->with('db', 'tbl')
|
||||
->will($this->returnValue('dumpText2'));
|
||||
|
||||
$this->object->expects($this->at(2))
|
||||
->method('getTableDef')
|
||||
->with('db', 'tbl', false, false, false, true, array())
|
||||
->will($this->returnValue('dumpText3'));
|
||||
|
||||
$this->object->expects($this->once())
|
||||
->method('getTableDefStandIn')
|
||||
->with('db', 'tbl', "\n")
|
||||
->will($this->returnValue('dumpText4'));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 'tbl', "\n", "example.com", "create_table", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'<h2>Table structure for table tbl</h2>dumpText1',
|
||||
$result
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 'tbl', "\n", "example.com", "triggers", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'<h2>Triggers tbl</h2>dumpText2',
|
||||
$result
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 'tbl', "\n", "example.com", "create_view", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'<h2>Structure for view tbl</h2>dumpText3',
|
||||
$result
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 'tbl', "\n", "example.com", "stand_in", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'<h2>Stand-in structure for view tbl</h2>dumpText4',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportHtmlword::formatOneColumnDefinition
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFormatOneColumnDefinition()
|
||||
{
|
||||
$method = new ReflectionMethod(
|
||||
'PMA\libraries\plugins\export\ExportHtmlword', 'formatOneColumnDefinition'
|
||||
);
|
||||
$method->setAccessible(true);
|
||||
|
||||
$cols = array(
|
||||
'Null' => 'Yes',
|
||||
'Field' => 'field',
|
||||
'Key' => 'PRI',
|
||||
'Type' => 'set(abc)enum123'
|
||||
);
|
||||
|
||||
$unique_keys = array(
|
||||
'field'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<tr class="print-category"><td class="print"><em>' .
|
||||
'<strong>field</strong></em></td><td class="print">set(abc)</td>' .
|
||||
'<td class="print">Yes</td><td class="print">NULL</td>',
|
||||
$method->invoke($this->object, $cols, $unique_keys)
|
||||
);
|
||||
|
||||
$cols = array(
|
||||
'Null' => 'NO',
|
||||
'Field' => 'fields',
|
||||
'Key' => 'COMP',
|
||||
'Type' => '',
|
||||
'Default' => 'def'
|
||||
);
|
||||
|
||||
$unique_keys = array(
|
||||
'field'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<tr class="print-category"><td class="print">fields</td>' .
|
||||
'<td class="print">&nbsp;</td><td class="print">No</td>' .
|
||||
'<td class="print">def</td>',
|
||||
$method->invoke($this->object, $cols, $unique_keys)
|
||||
);
|
||||
}
|
||||
}
|
254
#pma/test/classes/plugin/export/ExportJsonTest.php
Normal file
254
#pma/test/classes/plugin/export/ExportJsonTest.php
Normal file
@ -0,0 +1,254 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportJson class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportJson;
|
||||
|
||||
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\ExportJson class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportJsonTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$this->object = new ExportJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportJson::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportJson', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportJson', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'JSON',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'json',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/plain',
|
||||
$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\HiddenPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_or_data',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportJson::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
$GLOBALS['crlf'] = "\n";
|
||||
|
||||
$this->expectOutputString(
|
||||
'/**' . "\n"
|
||||
. ' Export to JSON plugin for PHPMyAdmin' . "\n"
|
||||
. ' @version ' . PMA_VERSION . "\n"
|
||||
. ' */' . "\n" . "\n"
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportJson::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportJson::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$GLOBALS['crlf'] = "\n";
|
||||
|
||||
$this->expectOutputString(
|
||||
"// Database 'testDB'\n"
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportJson::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportJson::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportJson::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(null)
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fieldName')
|
||||
->with(null, 0)
|
||||
->will($this->returnValue('f1'));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchRow')
|
||||
->with(null)
|
||||
->will($this->returnValue(array('foo')));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(null)
|
||||
->will($this->returnValue(array('bar')));
|
||||
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fetchRow')
|
||||
->with(null)
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->expectOutputString(
|
||||
"\n// db.tbl\n\n" .
|
||||
"[{\"f1\":\"foo\"}, {\"f1\":\"bar\"}]\n"
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportData('db', 'tbl', "\n", "example.com", "SELECT")
|
||||
);
|
||||
}
|
||||
}
|
993
#pma/test/classes/plugin/export/ExportLatexTest.php
Normal file
993
#pma/test/classes/plugin/export/ExportLatexTest.php
Normal file
@ -0,0 +1,993 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportLatex class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportLatex;
|
||||
|
||||
require_once 'libraries/export.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/transformations.lib.php';
|
||||
require_once 'export.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportLatex class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportLatexTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$GLOBALS['plugin_param'] = array();
|
||||
$GLOBALS['plugin_param']['export_type'] = 'table';
|
||||
$GLOBALS['plugin_param']['single_table'] = false;
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$this->object = new ExportLatex();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$GLOBALS['plugin_param']['export_type'] = '';
|
||||
$GLOBALS['plugin_param']['single_table'] = false;
|
||||
$GLOBALS['cfgRelation']['mimework'] = true;
|
||||
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportLatex', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportLatex', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'LaTeX',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'tex',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'application/x-tex',
|
||||
$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 = array_shift($generalOptionsArray);
|
||||
|
||||
$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\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'caption',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Include table caption',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'dump_what',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Dump table',
|
||||
$generalOptions->getText()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\RadioPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_or_data',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
),
|
||||
$property->getValues()
|
||||
);
|
||||
|
||||
// hide structure
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Object creation options',
|
||||
$generalOptions->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'data',
|
||||
$generalOptions->getForce()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_caption',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Table caption:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'faq6-27',
|
||||
$property->getDoc()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_continued_caption',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Table caption (continued):',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'faq6-27',
|
||||
$property->getDoc()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_label',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Label key:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'faq6-27',
|
||||
$property->getDoc()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'relation',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Display foreign key relationships',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'comments',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Display comments',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'mime',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Display MIME types',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
// data options
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'data',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Data dump options',
|
||||
$generalOptions->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure',
|
||||
$generalOptions->getForce()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$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\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'data_caption',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Table caption:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'faq6-27',
|
||||
$property->getDoc()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'data_continued_caption',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Table caption (continued):',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'faq6-27',
|
||||
$property->getDoc()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'data_label',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Label key:',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'faq6-27',
|
||||
$property->getDoc()
|
||||
);
|
||||
|
||||
$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()
|
||||
);
|
||||
|
||||
// case 2
|
||||
$GLOBALS['plugin_param']['export_type'] = 'table';
|
||||
$GLOBALS['plugin_param']['single_table'] = false;
|
||||
|
||||
$method->invoke($this->object, null);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$generalOptionsArray = $options->getProperties();
|
||||
|
||||
$this->assertCount(
|
||||
4,
|
||||
$generalOptionsArray
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
if (!defined("PMA_MYSQL_STR_VERSION")) {
|
||||
define("PMA_MYSQL_STR_VERSION", "5.0.0");
|
||||
}
|
||||
|
||||
$GLOBALS['crlf'] = "\n";
|
||||
$GLOBALS['cfg']['Server']['port'] = 80;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
"\n% Host: localhost:80",
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$GLOBALS['crlf'] = "\n";
|
||||
|
||||
$this->expectOutputString(
|
||||
"% \n% Database: 'testDB'\n% \n"
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$GLOBALS['latex_caption'] = true;
|
||||
$GLOBALS['latex_data_caption'] = 'latex data caption';
|
||||
$GLOBALS['latex_data_continued_caption'] = 'continued caption';
|
||||
$GLOBALS['latex_columns'] = true;
|
||||
$GLOBALS['latex_data_label'] = 'datalabel';
|
||||
$GLOBALS['latex_null'] = 'null';
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
$GLOBALS['cfg']['Server']['verbose'] = 'verb';
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(null)
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fieldName')
|
||||
->with(null, 0)
|
||||
->will($this->returnValue('f1'));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchAssoc')
|
||||
->with(null)
|
||||
->will($this->returnValue(array('f1' => 'foo$%')));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchAssoc')
|
||||
->with(null)
|
||||
->will($this->returnValue(array('f1' => null)));
|
||||
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fetchAssoc')
|
||||
->with(null)
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData('db', 'tbl', "\n", "example.com", "SELECT")
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"\n" . '%' . "\n" .
|
||||
'% Data: tbl' . "\n" .
|
||||
'%' . "\n" .
|
||||
' \\begin{longtable}{|l|} ' . "\n" .
|
||||
' \\hline \\endhead \\hline \\endfoot \\hline ' . "\n" .
|
||||
' \\caption{latex data caption} \\label{datalabel} ' .
|
||||
'\\\\\\hline \\multicolumn{1}{|c|}{\\textbf{f1}} ' .
|
||||
'\\\\ \\hline \hline \\endfirsthead ' . "\n" .
|
||||
'\caption{continued caption} \\\\ \hline \multicolumn{1}' .
|
||||
'{|c|}{\textbf{f1}} \\\\ \hline \hline \endhead \endfoot' . "\n" .
|
||||
'foo\$\% \\\\ \hline ' . "\n" .
|
||||
'null \\\\ \hline ' . "\n" .
|
||||
' \end{longtable}' . "\n",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 2
|
||||
unset($GLOBALS['latex_columns']);
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(null)
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fieldName')
|
||||
->with(null, 0)
|
||||
->will($this->returnValue('f1'));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fetchAssoc')
|
||||
->with(null)
|
||||
->will($this->returnValue(array('f1' => 'foo$%')));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchAssoc')
|
||||
->with(null)
|
||||
->will($this->returnValue(array('f1' => null)));
|
||||
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fetchAssoc')
|
||||
->with(null)
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData('db', 'tbl', "\n", "example.com", "SELECT")
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'{datalabel} \\\\\\\\ \hlinefoo',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::exportStructure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportStructure()
|
||||
{
|
||||
// $this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportHtmlword')
|
||||
// ->setMethods(array('formatOneColumnDefinition'))
|
||||
// ->getMock();
|
||||
|
||||
$keys = array(
|
||||
array(
|
||||
'Non_unique' => 0,
|
||||
'Column_name' => 'name1'
|
||||
),
|
||||
array(
|
||||
'Non_unique' => 1,
|
||||
'Column_name' => 'name2'
|
||||
)
|
||||
);
|
||||
|
||||
// case 1
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('fetchResult')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(),
|
||||
array(
|
||||
'name1' => array(
|
||||
'values' => 'test-',
|
||||
'transformation' => 'testfoo',
|
||||
'mimetype' => 'testmimetype_'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$columns = array(
|
||||
array(
|
||||
'Null' => 'Yes',
|
||||
'Field' => 'name1',
|
||||
'Key' => 'PRI',
|
||||
'Type' => 'set(abc)enum123'
|
||||
),
|
||||
array(
|
||||
'Null' => 'NO',
|
||||
'Field' => 'fields',
|
||||
'Key' => 'COMP',
|
||||
'Type' => '',
|
||||
'Default' => 'def'
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumns')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($columns));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('query')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('numRows')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'comment' => array('name1' => 'testComment')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
if (isset($GLOBALS['latex_caption'])) {
|
||||
unset($GLOBALS['latex_caption']);
|
||||
}
|
||||
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$_SESSION['relation'][0] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'relwork' => true,
|
||||
'commwork' => true,
|
||||
'mimework' => true,
|
||||
'db' => 'database',
|
||||
'relation' => 'rel',
|
||||
'column_info' => 'col'
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'database',
|
||||
'',
|
||||
"\n",
|
||||
"example.com",
|
||||
'test',
|
||||
'test',
|
||||
true,
|
||||
true,
|
||||
true
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
//echo $result; die;
|
||||
$this->assertEquals(
|
||||
"\n" . '%' . "\n" .
|
||||
'% Structure: ' . "\n" .
|
||||
'%' . "\n" .
|
||||
' \\begin{longtable}{|l|c|c|c|l|l|} ' . "\n" .
|
||||
' \\hline \\multicolumn{1}{|c|}{\\textbf{Column}} & ' .
|
||||
'\\multicolumn{1}{|c|}{\\textbf{Type}} & \\multicolumn{1}{|c|}' .
|
||||
'{\\textbf{Null}} & \\multicolumn{1}{|c|}{\\textbf{Default}} &' .
|
||||
' \\multicolumn{1}{|c|}{\\textbf{Comments}} & \\multicolumn{1}' .
|
||||
'{|c|}{\\textbf{MIME}} \\\\ \\hline \\hline' . "\n" .
|
||||
'\\endfirsthead' . "\n" . ' \\hline \\multicolumn{1}{|c|}' .
|
||||
'{\\textbf{Column}} & \\multicolumn{1}' . '{|c|}{\\textbf{Type}}' .
|
||||
' & \\multicolumn{1}{|c|}{\\textbf{Null}} & \\multicolumn' .
|
||||
'{1}{|c|}{\\textbf{Default}} & \\multicolumn{1}{|c|}{\\textbf' .
|
||||
'{Comments}} & \\multicolumn{1}{|c|}{\\textbf{MIME}} \\\\ ' .
|
||||
'\\hline \\hline \\endhead \\endfoot ' . "\n" . '\\textbf{\\textit' .
|
||||
'{name1}} & set(abc) & Yes & NULL & ' .
|
||||
'& Testmimetype/ \\\\ \\hline ' . "\n" .
|
||||
'fields & & No & def & & \\\\ \\hline ' . "\n" .
|
||||
' \\end{longtable}' . "\n",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 2
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('fetchResult')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(
|
||||
'name1' => array(
|
||||
'foreign_table' => 'ftable',
|
||||
'foreign_field' => 'ffield'
|
||||
),
|
||||
'foreign_keys_data' => array()
|
||||
),
|
||||
array(
|
||||
'field' => array(
|
||||
'values' => 'test-',
|
||||
'transformation' => 'testfoo',
|
||||
'mimetype' => 'test<'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumns')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($columns));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('query')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('numRows')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'comment' => array('field' => 'testComment')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$_SESSION['relation'][0] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'relwork' => true,
|
||||
'commwork' => true,
|
||||
'mimework' => true,
|
||||
'db' => 'database',
|
||||
'relation' => 'rel',
|
||||
'column_info' => 'col'
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'database',
|
||||
'',
|
||||
"\n",
|
||||
"example.com",
|
||||
'test',
|
||||
'test',
|
||||
true,
|
||||
true,
|
||||
true
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'\\textbf{\\textit{name1}} & set(abc) & Yes & NULL & ' .
|
||||
'ftable (ffield) & & \\\\ \\hline',
|
||||
$result
|
||||
);
|
||||
|
||||
// case 3
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumns')
|
||||
->with('database', '')
|
||||
->will($this->returnValue($columns));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('query')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('numRows')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fetchAssoc')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
'comment' => array('field' => 'testComment')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$GLOBALS['latex_caption'] = true;
|
||||
$GLOBALS['latex_structure_caption'] = 'latexstructure';
|
||||
$GLOBALS['latex_structure_label'] = 'latexlabel';
|
||||
$GLOBALS['latex_structure_continued_caption'] = 'latexcontinued';
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
$GLOBALS['cfg']['Server']['verbose'] = 'verb';
|
||||
|
||||
$_SESSION['relation'][0] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'relwork' => false,
|
||||
'commwork' => false,
|
||||
'mimework' => false,
|
||||
'db' => 'database',
|
||||
'relation' => 'rel',
|
||||
'column_info' => 'col'
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'database',
|
||||
'',
|
||||
"\n",
|
||||
"example.com",
|
||||
'test',
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'\\caption{latexstructure} \\label{latexlabel}',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'caption{latexcontinued}',
|
||||
$result
|
||||
);
|
||||
|
||||
// case 4
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'database',
|
||||
'',
|
||||
"\n",
|
||||
"example.com",
|
||||
'triggers',
|
||||
'test'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportLatex::texEscape
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTexEscape()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'\\$\\%\\{foo\\&bar\\}\\#\\_\\^',
|
||||
ExportLatex::texEscape('$%{foo&bar}#_^')
|
||||
);
|
||||
}
|
||||
}
|
420
#pma/test/classes/plugin/export/ExportMediawikiTest.php
Normal file
420
#pma/test/classes/plugin/export/ExportMediawikiTest.php
Normal file
@ -0,0 +1,420 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportMediawiki class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportMediawiki;
|
||||
|
||||
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\ExportMediawiki class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportMediawikiTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$this->object = new ExportMediawiki();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportMediawiki::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportMediawiki', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportMediawiki', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'MediaWiki Table',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'mediawiki',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/plain',
|
||||
$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()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Dump table',
|
||||
$generalOptions->getText()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertySubgroup',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'dump_table',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Dump table',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$sgHeader = $property->getSubGroupHeader();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\RadioPropertyItem',
|
||||
$sgHeader
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_or_data',
|
||||
$sgHeader->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
),
|
||||
$sgHeader->getValues()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'caption',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Export table names',
|
||||
$property->getText()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'headers',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Export table headers',
|
||||
$property->getText()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ExportMediaWiki::exportStructure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportStructure()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$columns = array(
|
||||
array(
|
||||
'Null' => 'Yes',
|
||||
'Field' => 'name1',
|
||||
'Key' => 'PRI',
|
||||
'Type' => 'set(abc)enum123',
|
||||
'Default' => '',
|
||||
'Extra' => ''
|
||||
),
|
||||
array(
|
||||
'Null' => 'NO',
|
||||
'Field' => 'fields',
|
||||
'Key' => 'COMP',
|
||||
'Type' => '',
|
||||
'Default' => 'def',
|
||||
'Extra' => 'ext'
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->at(0))
|
||||
->method('getColumns')
|
||||
->with('db', 'table')
|
||||
->will($this->returnValue($columns));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$GLOBALS['mediawiki_caption'] = true;
|
||||
$GLOBALS['mediawiki_headers'] = true;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 'table', "\n", "example.com", "create_table", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"\n<!--\n" .
|
||||
"Table structure for `table`\n" .
|
||||
"-->\n" .
|
||||
"\n" .
|
||||
"{| class=\"wikitable\" style=\"text-align:center;\"\n" .
|
||||
"|+'''table'''\n" .
|
||||
"|- style=\"background:#ffdead;\"\n" .
|
||||
"! style=\"background:#ffffff\" | \n" .
|
||||
" | name1\n" .
|
||||
" | fields\n" .
|
||||
"|-\n" .
|
||||
"! Type\n" .
|
||||
" | set(abc)enum123\n" .
|
||||
" | \n" .
|
||||
"|-\n" .
|
||||
"! Null\n" .
|
||||
" | Yes\n" .
|
||||
" | NO\n" .
|
||||
"|-\n" .
|
||||
"! Default\n" .
|
||||
" | \n" .
|
||||
" | def\n" .
|
||||
"|-\n" .
|
||||
"! Extra\n" .
|
||||
" | \n" .
|
||||
" | ext\n" .
|
||||
"|}\n\n",
|
||||
$result
|
||||
);
|
||||
|
||||
/**
|
||||
* This case produces an error, should it be tested?
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 'table', "\n", "example.com", "defaultTest", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
*/
|
||||
}
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumnNames')
|
||||
->with('db', 'table')
|
||||
->will($this->returnValue(array('name1', 'fields')));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', 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->at(3))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array('r1', 'r2')));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array('r3', '')));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$GLOBALS['mediawiki_caption'] = true;
|
||||
$GLOBALS['mediawiki_headers'] = true;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'table', "\n", "example.com", "SELECT"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"\n<!--\n" .
|
||||
"Table data for `table`\n" .
|
||||
"-->\n" .
|
||||
"\n" .
|
||||
"{| class=\"wikitable sortable\" style=\"text-align:" .
|
||||
"center;\"\n" .
|
||||
"|+'''table'''\n" .
|
||||
"|-\n" .
|
||||
" ! name1\n" .
|
||||
" ! fields\n" .
|
||||
"|-\n" .
|
||||
" | r1\n" .
|
||||
" | r2\n" .
|
||||
"|-\n" .
|
||||
" | r3\n" .
|
||||
" | \n" .
|
||||
"|}\n\n",
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
508
#pma/test/classes/plugin/export/ExportOdsTest.php
Normal file
508
#pma/test/classes/plugin/export/ExportOdsTest.php
Normal file
@ -0,0 +1,508 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportOds class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportOds;
|
||||
|
||||
//ExportOds required because of initialisation inside
|
||||
require_once 'libraries/plugins/export/ExportOds.php';
|
||||
require_once 'libraries/export.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'export.php';
|
||||
require_once 'libraries/opendocument.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportOds class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportOdsTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$this->object = new ExportOds();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportOds::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportOds', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportOds', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'OpenDocument Spreadsheet',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'ods',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'application/vnd.oasis.opendocument.spreadsheet',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Options',
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$properties->getForceFile()
|
||||
);
|
||||
|
||||
$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(
|
||||
'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\ExportOds::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
isset($GLOBALS['ods_buffer'])
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportOds::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$GLOBALS['ods_buffer'] = 'header';
|
||||
|
||||
$this->expectOutputRegex('/^504b.*636f6e74656e742e786d6c/');
|
||||
$this->setOutputCallback('bin2hex');
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'header',
|
||||
$GLOBALS['ods_buffer']
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'</office:spreadsheet>',
|
||||
$GLOBALS['ods_buffer']
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'</office:body>',
|
||||
$GLOBALS['ods_buffer']
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'</office:document-content>',
|
||||
$GLOBALS['ods_buffer']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportOds::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportOds::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportOds::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportOds::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$flags = array();
|
||||
$a = new StdClass;
|
||||
$flags[] = $a;
|
||||
|
||||
$a = new StdClass;
|
||||
$a->blob = true;
|
||||
$flags[] = $a;
|
||||
|
||||
$a = new StdClass;
|
||||
$a->blob = false;
|
||||
$a->type = 'date';
|
||||
$flags[] = $a;
|
||||
|
||||
$a = new StdClass;
|
||||
$a->blob = false;
|
||||
$a->type = 'time';
|
||||
$flags[] = $a;
|
||||
|
||||
$a = new StdClass;
|
||||
$a->blob = false;
|
||||
$a->type = 'datetime';
|
||||
$flags[] = $a;
|
||||
|
||||
$a = new StdClass;
|
||||
$a->numeric = true;
|
||||
$a->type = 'none';
|
||||
$a->blob = false;
|
||||
$flags[] = $a;
|
||||
|
||||
$a = new StdClass;
|
||||
$a->numeric = true;
|
||||
$a->type = 'real';
|
||||
$a->blob = true;
|
||||
$flags[] = $a;
|
||||
|
||||
$a = new StdClass;
|
||||
$a->type = "dummy";
|
||||
$a->blob = false;
|
||||
$a->numeric = false;
|
||||
$flags[] = $a;
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getFieldsMeta')
|
||||
->with(true)
|
||||
->will($this->returnValue($flags));
|
||||
|
||||
$dbi->expects($this->exactly(8))
|
||||
->method('fieldFlags')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
'BINARYTEST',
|
||||
'binary',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
''
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(8));
|
||||
|
||||
$dbi->expects($this->at(11))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
null, '01-01-2000', '01-01-2000', '01-01-2000 10:00:00',
|
||||
"01-01-2014 10:02:00", "t>s", "a&b", "<"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$GLOBALS['mediawiki_caption'] = true;
|
||||
$GLOBALS['mediawiki_headers'] = true;
|
||||
$GLOBALS['what'] = 'foo';
|
||||
$GLOBALS['foo_null'] = "&";
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'table', "\n", "example.com", "SELECT"
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<table:table table:name="table"><table:table-row><table:table-cell ' .
|
||||
'office:value-type="string"><text:p>&</text:p></table:table-cell>' .
|
||||
'<table:table-cell office:value-type="string"><text:p></text:p>' .
|
||||
'</table:table-cell><table:table-cell office:value-type="date" office:' .
|
||||
'date-value="2000-01-01" table:style-name="DateCell"><text:p>01-01' .
|
||||
'-2000</text:p></table:table-cell><table:table-cell office:value-type=' .
|
||||
'"time" office:time-value="PT10H00M00S" table:style-name="TimeCell">' .
|
||||
'<text:p>01-01-2000 10:00:00</text:p></table:table-cell><table:table-' .
|
||||
'cell office:value-type="date" office:date-value="2014-01-01T10:02:00"' .
|
||||
' table:style-name="DateTimeCell"><text:p>01-01-2014 10:02:00' .
|
||||
'</text:p></table:table-cell><table:table-cell office:value-type=' .
|
||||
'"float" office:value="t>s" ><text:p>t>s</text:p>' .
|
||||
'</table:table-cell><table:table-cell office:value-type="float" ' .
|
||||
'office:value="a&b" ><text:p>a&b</text:p></table:table-cell>' .
|
||||
'<table:table-cell office:value-type="string"><text:p><</text:p>' .
|
||||
'</table:table-cell></table:table-row></table:table>',
|
||||
$GLOBALS['ods_buffer']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportOds::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDataWithFieldNames()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$flags = array();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getFieldsMeta')
|
||||
->with(true)
|
||||
->will($this->returnValue($flags));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('fieldFlags')
|
||||
->will($this->returnValue('BINARYTEST'));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', 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->at(5))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fna\"me'));
|
||||
|
||||
$dbi->expects($this->at(6))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fnam/<e2'));
|
||||
|
||||
$dbi->expects($this->at(7))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will(
|
||||
$this->returnValue(
|
||||
null
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$GLOBALS['mediawiki_caption'] = true;
|
||||
$GLOBALS['mediawiki_headers'] = true;
|
||||
$GLOBALS['what'] = 'foo';
|
||||
$GLOBALS['foo_null'] = "&";
|
||||
$GLOBALS['foo_columns'] = true;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'table', "\n", "example.com", "SELECT"
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<table:table table:name="table"><table:table-row><table:table-cell ' .
|
||||
'office:value-type="string"><text:p>fna"me</text:p></table:table' .
|
||||
'-cell><table:table-cell office:value-type="string"><text:p>' .
|
||||
'fnam/<e2</text:p></table:table-cell></table:table-row>' .
|
||||
'</table:table>',
|
||||
$GLOBALS['ods_buffer']
|
||||
);
|
||||
|
||||
// with no row count
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$flags = array();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getFieldsMeta')
|
||||
->with(true)
|
||||
->will($this->returnValue($flags));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(0));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will(
|
||||
$this->returnValue(
|
||||
null
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$GLOBALS['mediawiki_caption'] = true;
|
||||
$GLOBALS['mediawiki_headers'] = true;
|
||||
$GLOBALS['what'] = 'foo';
|
||||
$GLOBALS['foo_null'] = "&";
|
||||
$GLOBALS['ods_buffer'] = '';
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'table', "\n", "example.com", "SELECT"
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<table:table table:name="table"><table:table-row></table:table-row>' .
|
||||
'</table:table>',
|
||||
$GLOBALS['ods_buffer']
|
||||
);
|
||||
}
|
||||
}
|
1082
#pma/test/classes/plugin/export/ExportOdtTest.php
Normal file
1082
#pma/test/classes/plugin/export/ExportOdtTest.php
Normal file
File diff suppressed because it is too large
Load Diff
343
#pma/test/classes/plugin/export/ExportPdfTest.php
Normal file
343
#pma/test/classes/plugin/export/ExportPdfTest.php
Normal file
@ -0,0 +1,343 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportPdf class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportPdf;
|
||||
use PMA\libraries\plugins\export\PMA_ExportPdf;
|
||||
|
||||
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\ExportPdf class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportPdfTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$this->object = new ExportPdf();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPdf::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportPdf', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'PDF',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'pdf',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'application/pdf',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Options',
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$properties->getForceFile()
|
||||
);
|
||||
|
||||
$options = $properties->getOptions();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Format Specific Options',
|
||||
$options->getName()
|
||||
);
|
||||
|
||||
$generalOptionsArray = $options->getProperties();
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$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(
|
||||
'report_title',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'dump_what',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Dump table',
|
||||
$generalOptions->getText()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\RadioPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure_or_data',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
),
|
||||
$property->getValues()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPdf::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
$pdf = $this->getMockBuilder('PMA\libraries\plugins\export\PMA_ExportPdf')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$pdf->expects($this->once())
|
||||
->method('Open');
|
||||
|
||||
$pdf->expects($this->once())
|
||||
->method('setAttributes');
|
||||
|
||||
$pdf->expects($this->once())
|
||||
->method('setTopMargin');
|
||||
|
||||
$attrPdf = new ReflectionProperty('PMA\libraries\plugins\export\ExportPdf', '_pdf');
|
||||
$attrPdf->setAccessible(true);
|
||||
$attrPdf->setValue($this->object, $pdf);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPdf::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$pdf = $this->getMockBuilder('PMA\libraries\plugins\export\PMA_ExportPdf')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$pdf->expects($this->once())
|
||||
->method('getPDFData');
|
||||
|
||||
$attrPdf = new ReflectionProperty('PMA\libraries\plugins\export\ExportPdf', '_pdf');
|
||||
$attrPdf->setAccessible(true);
|
||||
$attrPdf->setValue($this->object, $pdf);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPdf::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPdf::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPdf::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPdf::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$pdf = $this->getMockBuilder('PMA\libraries\plugins\export\PMA_ExportPdf')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$pdf->expects($this->once())
|
||||
->method('setAttributes')
|
||||
->with(
|
||||
array(
|
||||
'currentDb' => 'db', 'currentTable' => 'table',
|
||||
'dbAlias' => 'db', 'tableAlias' => 'table',
|
||||
'aliases' => array()
|
||||
)
|
||||
);
|
||||
|
||||
$pdf->expects($this->once())
|
||||
->method('mysqlReport')
|
||||
->with('SELECT');
|
||||
|
||||
$attrPdf = new ReflectionProperty('PMA\libraries\plugins\export\ExportPdf', '_pdf');
|
||||
$attrPdf->setAccessible(true);
|
||||
$attrPdf->setValue($this->object, $pdf);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'table', "\n", "phpmyadmin.net/err", 'SELECT'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for
|
||||
* - PMA\libraries\plugins\export\ExportPdf::_setPdf
|
||||
* - PMA\libraries\plugins\export\ExportPdf::_getPdf
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetPdf()
|
||||
{
|
||||
$setter = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', '_setPdf');
|
||||
$setter->setAccessible(true);
|
||||
$setter->invoke($this->object, new PMA_ExportPdf);
|
||||
|
||||
$getter = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', '_getPdf');
|
||||
$getter->setAccessible(true);
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\plugins\export\PMA_ExportPdf',
|
||||
$getter->invoke($this->object)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for
|
||||
* - PMA\libraries\plugins\export\ExportPdf::_setPdfReportTitle
|
||||
* - PMA\libraries\plugins\export\ExportPdf::_getPdfReportTitle
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetPdfTitle()
|
||||
{
|
||||
$setter = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', '_setPdfReportTitle');
|
||||
$setter->setAccessible(true);
|
||||
$setter->invoke($this->object, "title");
|
||||
|
||||
$getter = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', '_getPdfReportTitle');
|
||||
$getter->setAccessible(true);
|
||||
$this->assertEquals(
|
||||
'title',
|
||||
$getter->invoke($this->object)
|
||||
);
|
||||
}
|
||||
}
|
298
#pma/test/classes/plugin/export/ExportPhparrayTest.php
Normal file
298
#pma/test/classes/plugin/export/ExportPhparrayTest.php
Normal file
@ -0,0 +1,298 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportPhparray class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportPhparray;
|
||||
|
||||
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\ExportPhparray class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportPhparrayTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$this->object = new ExportPhparray();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPhparray::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportPhparray', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportPhparray', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'PHP array',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'php',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/plain',
|
||||
$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\HiddenPropertyItem',
|
||||
$property
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPhparray::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
$GLOBALS['crlf'] = ' ';
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'<?php ',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPhparray::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPhparray::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$GLOBALS['crlf'] = "\n";
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader("db")
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
"/**\n * Database `db`\n */",
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPhparray::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPhparray::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportPhparray::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', 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->at(2))
|
||||
->method('fieldName')
|
||||
->with(true, 0)
|
||||
->will($this->returnValue('c1'));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fieldName')
|
||||
->with(true, 1)
|
||||
->will($this->returnValue(''));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array(1, 'a')));
|
||||
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'table', "\n", 'phpmyadmin.net/err', 'SELECT'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
"\n" . '/* `db`.`table` */' . "\n" .
|
||||
'$table = array(' . "\n" .
|
||||
' array(\'c1\' => 1,\'\' => \'a\')' . "\n" .
|
||||
');' . "\n",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 2: test invalid variable name fix
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(0));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', '0`932table', "\n", 'phpmyadmin.net/err', 'SELECT'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'$_0_932table',
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
2010
#pma/test/classes/plugin/export/ExportSqlTest.php
Normal file
2010
#pma/test/classes/plugin/export/ExportSqlTest.php
Normal file
File diff suppressed because it is too large
Load Diff
645
#pma/test/classes/plugin/export/ExportTexytextTest.php
Normal file
645
#pma/test/classes/plugin/export/ExportTexytextTest.php
Normal file
@ -0,0 +1,645 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportTexytext class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportTexytext;
|
||||
|
||||
require_once 'libraries/export.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/transformations.lib.php';
|
||||
require_once 'export.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportTexytext class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportTexytextTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = false;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$GLOBALS['plugin_param'] = array();
|
||||
$GLOBALS['plugin_param']['export_type'] = 'table';
|
||||
$GLOBALS['plugin_param']['single_table'] = false;
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$this->object = new ExportTexytext();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportTexytext', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportTexytext', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Texy! text',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'txt',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/plain',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$options = $properties->getOptions();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Format Specific Options',
|
||||
$options->getName()
|
||||
);
|
||||
|
||||
$generalOptionsArray = $options->getProperties();
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'general_opts',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"Dump table",
|
||||
$generalOptions->getText()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\RadioPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'data',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'columns',
|
||||
$property->getName()
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\TextPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'null',
|
||||
$property->getName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$this->expectOutputString(
|
||||
"===Database testDb\n\n"
|
||||
);
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('testDb')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('testDB')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(3));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fName1'));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fNa"me2'));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fName3'));
|
||||
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array(null, '0', 'test')));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$GLOBALS['what'] = 'foo';
|
||||
$GLOBALS['foo_columns'] = "&";
|
||||
$GLOBALS['foo_null'] = ">";
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'ta<ble', "\n", "example.com", "SELECT"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
"|fName1|fNa&quot;me2|fName3",
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
"|&gt;|0|test",
|
||||
$result
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::getTableDefStandIn
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTableDefStandIn()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getColumns')
|
||||
->with('db', 'view')
|
||||
->will($this->returnValue(array(1, 2)));
|
||||
|
||||
$keys = array(
|
||||
array(
|
||||
'Non_unique' => 0,
|
||||
'Column_name' => 'cname'
|
||||
),
|
||||
array(
|
||||
'Non_unique' => 1,
|
||||
'Column_name' => 'cname2'
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('db', 'view')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('selectDb')
|
||||
->with('db');
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportTexytext')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('formatOneColumnDefinition'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->at(0))
|
||||
->method('formatOneColumnDefinition')
|
||||
->with(1, array('cname'))
|
||||
->will($this->returnValue('c1'));
|
||||
|
||||
$this->object->expects($this->at(1))
|
||||
->method('formatOneColumnDefinition')
|
||||
->with(2, array('cname'))
|
||||
->will($this->returnValue('c2'));
|
||||
|
||||
$result = $this->object->getTableDefStandIn('db', 'view', '#');
|
||||
|
||||
$this->assertContains(
|
||||
"c1\nc2",
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::getTableDef
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTableDef()
|
||||
{
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportTexytext')
|
||||
->setMethods(array('formatOneColumnDefinition'))
|
||||
->getMock();
|
||||
$GLOBALS['controllink'] = null;
|
||||
|
||||
// case 1
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$keys = array(
|
||||
array(
|
||||
'Non_unique' => 0,
|
||||
'Column_name' => 'cname'
|
||||
),
|
||||
array(
|
||||
'Non_unique' => 1,
|
||||
'Column_name' => 'cname2'
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTableIndexes')
|
||||
->with('db', 'table')
|
||||
->will($this->returnValue($keys));
|
||||
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('fetchResult')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(
|
||||
'fname' => array(
|
||||
'foreign_table' => '<ftable',
|
||||
'foreign_field' => 'ffield>'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'fname' => array(
|
||||
'values' => 'test-',
|
||||
'transformation' => 'testfoo',
|
||||
'mimetype' => 'test<'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('fetchValue')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
'SELECT a FROM b'
|
||||
)
|
||||
);
|
||||
|
||||
$columns = array(
|
||||
'Field' => 'fname',
|
||||
'Comment' => 'comm'
|
||||
);
|
||||
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('getColumns')
|
||||
->with('db', 'table')
|
||||
->will($this->returnValue(array($columns)));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object->expects($this->exactly(1))
|
||||
->method('formatOneColumnDefinition')
|
||||
->with(array('Field' => 'fname', 'Comment' => 'comm'), array('cname'))
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$_SESSION['relation'][0] = array(
|
||||
'PMA_VERSION' => PMA_VERSION,
|
||||
'relwork' => true,
|
||||
'commwork' => true,
|
||||
'mimework' => true,
|
||||
'db' => 'db',
|
||||
'relation' => 'rel',
|
||||
'column_info' => 'col'
|
||||
);
|
||||
|
||||
$result = $this->object->getTableDef(
|
||||
'db',
|
||||
'table',
|
||||
"\n",
|
||||
"example.com",
|
||||
true,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'1|<ftable (ffield>)|comm|Test<',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::getTriggers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTriggers()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$triggers = array(
|
||||
array(
|
||||
'name' => 'tna"me',
|
||||
'action_timing' => 'ac>t',
|
||||
'event_manipulation' => 'manip&',
|
||||
'definition' => 'def'
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTriggers')
|
||||
->with('database', 'ta<ble')
|
||||
->will($this->returnValue($triggers));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$result = $this->object->getTriggers('database', 'ta<ble');
|
||||
|
||||
$this->assertContains(
|
||||
'|tna"me|ac>t|manip&|def',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'|Name|Time|Event|Definition',
|
||||
$result
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::exportStructure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportStructure()
|
||||
{
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTriggers')
|
||||
->with('db', 't&bl')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportTexytext')
|
||||
->setMethods(array('getTableDef', 'getTriggers', 'getTableDefStandIn'))
|
||||
->getMock();
|
||||
|
||||
$this->object->expects($this->at(0))
|
||||
->method('getTableDef')
|
||||
->with('db', 't&bl', "\n", "example.com", false, false, false, false)
|
||||
->will($this->returnValue('dumpText1'));
|
||||
|
||||
$this->object->expects($this->once())
|
||||
->method('getTriggers')
|
||||
->with('db', 't&bl')
|
||||
->will($this->returnValue('dumpText2'));
|
||||
|
||||
$this->object->expects($this->at(2))
|
||||
->method('getTableDef')
|
||||
->with(
|
||||
'db', 't&bl', "\n", "example.com",
|
||||
false, false, false, false, true, true
|
||||
)
|
||||
->will($this->returnValue('dumpText3'));
|
||||
|
||||
$this->object->expects($this->once())
|
||||
->method('getTableDefStandIn')
|
||||
->with('db', 't&bl', "\n")
|
||||
->will($this->returnValue('dumpText4'));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
// case 1
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 't&bl', "\n", "example.com", "create_table", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'== Table structure for table t&bl' . "\n\ndumpText1",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 2
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 't&bl', "\n", "example.com", "triggers", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'== Triggers t&bl' . "\n\ndumpText2",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 3
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 't&bl', "\n", "example.com", "create_view", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'== Structure for view t&bl' . "\n\ndumpText3",
|
||||
$result
|
||||
);
|
||||
|
||||
// case 4
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'db', 't&bl', "\n", "example.com", "stand_in", "test"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'== Stand-in structure for view t&bl' . "\n\ndumpText4",
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportTexytext::formatOneColumnDefinition
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFormatOneColumnDefinition()
|
||||
{
|
||||
$cols = array(
|
||||
'Null' => 'Yes',
|
||||
'Field' => 'field',
|
||||
'Key' => 'PRI',
|
||||
'Type' => 'set(abc)enum123'
|
||||
);
|
||||
|
||||
$unique_keys = array(
|
||||
'field'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'|//**field**//|set(abc)|Yes|NULL',
|
||||
$this->object->formatOneColumnDefinition($cols, $unique_keys)
|
||||
);
|
||||
|
||||
$cols = array(
|
||||
'Null' => 'NO',
|
||||
'Field' => 'fields',
|
||||
'Key' => 'COMP',
|
||||
'Type' => '',
|
||||
'Default' => 'def'
|
||||
);
|
||||
|
||||
$unique_keys = array(
|
||||
'field'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'|fields|&nbsp;|No|def',
|
||||
$this->object->formatOneColumnDefinition($cols, $unique_keys)
|
||||
);
|
||||
}
|
||||
}
|
564
#pma/test/classes/plugin/export/ExportXmlTest.php
Normal file
564
#pma/test/classes/plugin/export/ExportXmlTest.php
Normal file
@ -0,0 +1,564 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportXml class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportXml;
|
||||
use PMA\libraries\Table;
|
||||
|
||||
$GLOBALS['db'] = 'db';
|
||||
|
||||
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\ExportXml class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportXmlTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = false;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$GLOBALS['plugin_param'] = array();
|
||||
$GLOBALS['plugin_param']['export_type'] = 'table';
|
||||
$GLOBALS['plugin_param']['single_table'] = false;
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$this->object = new ExportXml();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportXml::setProperties
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportXml', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportXml', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'XML',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'xml',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/xml',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$options = $properties->getOptions();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Format Specific Options',
|
||||
$options->getName()
|
||||
);
|
||||
|
||||
$generalOptionsArray = $options->getProperties();
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$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\HiddenPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'structure',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
|
||||
$generalOptions
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'data',
|
||||
$generalOptions->getName()
|
||||
);
|
||||
|
||||
$generalProperties = $generalOptions->getProperties();
|
||||
|
||||
$property = array_shift($generalProperties);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\items\BoolPropertyItem',
|
||||
$property
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportXml::exportHeader
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
if (!defined("PMA_MYSQL_STR_VERSION")) {
|
||||
define("PMA_MYSQL_STR_VERSION", "5.0.0");
|
||||
}
|
||||
|
||||
$GLOBALS['xml_export_functions'] = 1;
|
||||
$GLOBALS['xml_export_contents'] = 1;
|
||||
$GLOBALS['output_charset_conversion'] = 1;
|
||||
$GLOBALS['charset'] = 'iso-8859-1';
|
||||
$GLOBALS['cfg']['Server']['port'] = 80;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['xml_export_tables'] = 1;
|
||||
$GLOBALS['xml_export_triggers'] = 1;
|
||||
$GLOBALS['xml_export_procedures'] = 1;
|
||||
$GLOBALS['xml_export_functions'] = 1;
|
||||
$GLOBALS['crlf'] = "\n";
|
||||
$GLOBALS['db'] = 'd<"b';
|
||||
|
||||
$result = array(
|
||||
0 => array(
|
||||
'DEFAULT_COLLATION_NAME' => 'utf8_general_ci',
|
||||
'DEFAULT_CHARACTER_SET_NAME' => 'utf-8',
|
||||
|
||||
),
|
||||
'table' => array(null, '"tbl"')
|
||||
);
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->exactly(3))
|
||||
->method('fetchResult')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$result,
|
||||
$result,
|
||||
false
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTriggers')
|
||||
->with('d<"b', 'table')
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
array(
|
||||
'create' => 'crt',
|
||||
'name' => 'trname'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('getProceduresOrFunctions')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
array(
|
||||
'fn'
|
||||
),
|
||||
array(
|
||||
'pr'
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('getDefinition')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
'fndef',
|
||||
'prdef'
|
||||
);
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTable')
|
||||
->will($this->returnValue(new Table('table', 'd<"b', $dbi)));
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['tables'] = array();
|
||||
$GLOBALS['table'] = 'table';
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'<pma_xml_export version="1.0" xmlns:pma="' .
|
||||
'https://www.phpmyadmin.net/some_doc_url/">',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'<pma:structure_schemas>' . "\n" .
|
||||
' <pma:database name="d&lt;&quot;b" collat' .
|
||||
'ion="utf8_general_ci" charset="utf-8">' . "\n" .
|
||||
' <pma:table name="table">' . "\n" .
|
||||
' &quot;tbl&quot;;' . "\n" .
|
||||
' </pma:table>' . "\n" .
|
||||
' <pma:trigger name="trname">' . "\n" .
|
||||
' ' . "\n" .
|
||||
' </pma:trigger>' . "\n" .
|
||||
' <pma:function name="fn">' . "\n" .
|
||||
' fndef' . "\n" .
|
||||
' </pma:function>' . "\n" .
|
||||
' <pma:procedure name="pr">' . "\n" .
|
||||
' prdef' . "\n" .
|
||||
' </pma:procedure>' . "\n" .
|
||||
' </pma:database>' . "\n" .
|
||||
' </pma:structure_schemas>',
|
||||
$result
|
||||
);
|
||||
|
||||
// case 2 with isView as true and false
|
||||
|
||||
unset($GLOBALS['xml_export_contents']);
|
||||
unset($GLOBALS['xml_export_views']);
|
||||
unset($GLOBALS['xml_export_tables']);
|
||||
unset($GLOBALS['xml_export_functions']);
|
||||
unset($GLOBALS['xml_export_procedures']);
|
||||
$GLOBALS['output_charset_conversion'] = 0;
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$result_1 = array(
|
||||
array(
|
||||
'DEFAULT_COLLATION_NAME' => 'utf8_general_ci',
|
||||
'DEFAULT_CHARACTER_SET_NAME' => 'utf-8',
|
||||
|
||||
)
|
||||
);
|
||||
$result_2 = array(
|
||||
't1' => array(null, '"tbl"')
|
||||
);
|
||||
|
||||
$result_3 = array(
|
||||
't2' => array(null, '"tbl"')
|
||||
);
|
||||
|
||||
|
||||
$dbi->expects($this->exactly(5))
|
||||
->method('fetchResult')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$result_1,
|
||||
$result_2,
|
||||
true,
|
||||
$result_3,
|
||||
false
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('getTable')
|
||||
->will($this->returnValue(new Table('table', 'd<"b', $dbi)));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$GLOBALS['tables'] = array('t1', 't2');
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
//echo $result; die;
|
||||
$this->assertContains(
|
||||
'<pma:structure_schemas>' . "\n" .
|
||||
' <pma:database name="d&lt;&quot;b" collat' .
|
||||
'ion="utf8_general_ci" charset="utf-8">' . "\n" .
|
||||
' </pma:database>' . "\n" .
|
||||
' </pma:structure_schemas>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportXml::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->expectOutputString(
|
||||
'</pma_xml_export>'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportXml::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$GLOBALS['xml_export_contents'] = true;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('&db')
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'<database name="&amp;db">',
|
||||
$result
|
||||
);
|
||||
|
||||
$GLOBALS['xml_export_contents'] = false;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('&db')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportXml::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$GLOBALS['xml_export_contents'] = true;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('&db')
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
'</database>',
|
||||
$result
|
||||
);
|
||||
|
||||
$GLOBALS['xml_export_contents'] = false;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('&db')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportXml::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportXml::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$GLOBALS['xml_export_contents'] = true;
|
||||
$GLOBALS['asfile'] = true;
|
||||
$GLOBALS['output_charset_conversion'] = false;
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$_table = $this->getMockBuilder('PMA\libraries\Table')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$_table->expects($this->once())
|
||||
->method('isMerge')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('getTable')
|
||||
->will($this->returnValue($_table));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('getTable')
|
||||
->will($this->returnValue($_table));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(3));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fName1'));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fNa"me2'));
|
||||
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fNa\\me3'));
|
||||
|
||||
$dbi->expects($this->at(6))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will($this->returnValue(array(null, '<a>')));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'ta<ble', "\n", "example.com", "SELECT"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
"<!-- Table ta<ble -->",
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
"<table name=\"ta<ble\">",
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
"<column name=\"fName1\">NULL</column>",
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
"<column name=\"fNa"me2\"><a>" .
|
||||
"</column>",
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
"<column name=\"fName3\">NULL</column>",
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
"</table>",
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
268
#pma/test/classes/plugin/export/ExportYamlTest.php
Normal file
268
#pma/test/classes/plugin/export/ExportYamlTest.php
Normal file
@ -0,0 +1,268 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportYaml class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\ExportYaml;
|
||||
|
||||
require_once 'libraries/export.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'export.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\ExportYaml class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group medium
|
||||
*/
|
||||
class ExportYamlTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
$GLOBALS['buffer_needed'] = false;
|
||||
$GLOBALS['asfile'] = false;
|
||||
$GLOBALS['save_on_server'] = false;
|
||||
$GLOBALS['crlf'] = "\n";
|
||||
$GLOBALS['cfgRelation']['relation'] = true;
|
||||
$this->object = new ExportYaml();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportYaml::setProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProperties()
|
||||
{
|
||||
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportYaml', 'setProperties');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->object, null);
|
||||
|
||||
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportYaml', 'properties');
|
||||
$attrProperties->setAccessible(true);
|
||||
$properties = $attrProperties->getValue($this->object);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\plugins\ExportPluginProperties',
|
||||
$properties
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'YAML',
|
||||
$properties->getText()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'yml',
|
||||
$properties->getExtension()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'text/yaml',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
|
||||
$options = $properties->getOptions();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Format Specific Options',
|
||||
$options->getName()
|
||||
);
|
||||
|
||||
$generalOptionsArray = $options->getProperties();
|
||||
|
||||
$generalOptions = array_shift($generalOptionsArray);
|
||||
|
||||
$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\HiddenPropertyItem',
|
||||
$property
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportYaml::exportHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportHeader()
|
||||
{
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertContains(
|
||||
"%YAML 1.1\n---\n",
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportYaml::exportFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFooter()
|
||||
{
|
||||
$this->expectOutputString(
|
||||
"...\n"
|
||||
);
|
||||
$this->assertTrue(
|
||||
$this->object->exportFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportYaml::exportDBHeader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBHeader()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBHeader('&db')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportYaml::exportDBFooter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBFooter()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBFooter('&db')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportYaml::exportDBCreate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportDBCreate()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->object->exportDBCreate('testDB', 'database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\ExportYaml::exportData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExportData()
|
||||
{
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
->method('numFields')
|
||||
->with(true)
|
||||
->will($this->returnValue(4));
|
||||
|
||||
$dbi->expects($this->at(2))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fName1'));
|
||||
|
||||
$dbi->expects($this->at(3))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fNa"me2'));
|
||||
|
||||
$dbi->expects($this->at(4))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fNa\\me3'));
|
||||
|
||||
$dbi->expects($this->at(5))
|
||||
->method('fieldName')
|
||||
->will($this->returnValue('fName4'));
|
||||
|
||||
$dbi->expects($this->at(6))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(null, '123', "\"c\\a\nb\r")
|
||||
)
|
||||
);
|
||||
|
||||
$dbi->expects($this->at(7))
|
||||
->method('fetchRow')
|
||||
->with(true)
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(null)
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db', 'ta<ble', "\n", "example.com", "SELECT"
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'# db.ta<ble' . "\n" .
|
||||
'-' . "\n" .
|
||||
' fNa"me2: 123' . "\n" .
|
||||
' fName3: "\"c\\\\a\nb\r"' . "\n" .
|
||||
'-' . "\n",
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
343
#pma/test/classes/plugin/export/TablePropertyTest.php
Normal file
343
#pma/test/classes/plugin/export/TablePropertyTest.php
Normal file
@ -0,0 +1,343 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\TableProperty class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PMA\libraries\plugins\export\TableProperty;
|
||||
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* tests for PMA\libraries\plugins\export\TableProperty class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class TablePropertyTest extends PMATestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Configures global environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['server'] = 0;
|
||||
$row = array(' name ', 'int ', true, ' PRI', '0', 'mysql');
|
||||
$this->object = new TableProperty($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::__construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'name',
|
||||
$this->object->name
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'int',
|
||||
$this->object->type
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->nullable
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'PRI',
|
||||
$this->object->key
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'0',
|
||||
$this->object->defaultValue
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'mysql',
|
||||
$this->object->ext
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::getPureType
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPureType()
|
||||
{
|
||||
$this->object->type = "int(10)";
|
||||
|
||||
$this->assertEquals(
|
||||
"int",
|
||||
$this->object->getPureType()
|
||||
);
|
||||
|
||||
$this->object->type = "char";
|
||||
|
||||
$this->assertEquals(
|
||||
"char",
|
||||
$this->object->getPureType()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::isNotNull
|
||||
*
|
||||
* @param string $nullable nullable value
|
||||
* @param string $expected expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider isNotNullProvider
|
||||
*/
|
||||
public function testIsNotNull($nullable, $expected)
|
||||
{
|
||||
$this->object->nullable = $nullable;
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->object->isNotNull()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testIsNotNull
|
||||
*
|
||||
* @return array Test Data
|
||||
*/
|
||||
public function isNotNullProvider()
|
||||
{
|
||||
return array(
|
||||
array("NO", "true"),
|
||||
array("", "false"),
|
||||
array("no", "false")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::isUnique
|
||||
*
|
||||
* @param string $key key value
|
||||
* @param string $expected expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider isUniqueProvider
|
||||
*/
|
||||
public function testIsUnique($key, $expected)
|
||||
{
|
||||
$this->object->key = $key;
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->object->isUnique()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testIsUnique
|
||||
*
|
||||
* @return array Test Data
|
||||
*/
|
||||
public function isUniqueProvider()
|
||||
{
|
||||
return array(
|
||||
array("PRI", "true"),
|
||||
array("UNI", "true"),
|
||||
array("", "false"),
|
||||
array("pri", "false"),
|
||||
array("uni", "false"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::getDotNetPrimitiveType
|
||||
*
|
||||
* @param string $type type value
|
||||
* @param string $expected expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider getDotNetPrimitiveTypeProvider
|
||||
*/
|
||||
public function testGetDotNetPrimitiveType($type, $expected)
|
||||
{
|
||||
$this->object->type = $type;
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->object->getDotNetPrimitiveType()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetDotNetPrimitiveType
|
||||
*
|
||||
* @return array Test Data
|
||||
*/
|
||||
public function getDotNetPrimitiveTypeProvider()
|
||||
{
|
||||
return array(
|
||||
array("int", "int"),
|
||||
array("long", "long"),
|
||||
array("char", "string"),
|
||||
array("varchar", "string"),
|
||||
array("text", "string"),
|
||||
array("longtext", "string"),
|
||||
array("tinyint", "bool"),
|
||||
array("datetime", "DateTime"),
|
||||
array("", "unknown"),
|
||||
array("dummy", "unknown"),
|
||||
array("INT", "unknown")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::getDotNetObjectType
|
||||
*
|
||||
* @param string $type type value
|
||||
* @param string $expected expected output
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider getDotNetObjectTypeProvider
|
||||
*/
|
||||
public function testGetDotNetObjectType($type, $expected)
|
||||
{
|
||||
$this->object->type = $type;
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->object->getDotNetObjectType()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetDotNetObjectType
|
||||
*
|
||||
* @return array Test Data
|
||||
*/
|
||||
public function getDotNetObjectTypeProvider()
|
||||
{
|
||||
return array(
|
||||
array("int", "Int32"),
|
||||
array("long", "Long"),
|
||||
array("char", "String"),
|
||||
array("varchar", "String"),
|
||||
array("text", "String"),
|
||||
array("longtext", "String"),
|
||||
array("tinyint", "Boolean"),
|
||||
array("datetime", "DateTime"),
|
||||
array("", "Unknown"),
|
||||
array("dummy", "Unknown"),
|
||||
array("INT", "Unknown")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::getIndexName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetIndexName()
|
||||
{
|
||||
$this->object->name = "ä'7<ab>";
|
||||
$this->object->key = "PRI";
|
||||
|
||||
$this->assertEquals(
|
||||
"index=\"ä'7<ab>\"",
|
||||
$this->object->getIndexName()
|
||||
);
|
||||
|
||||
$this->object->key = "";
|
||||
|
||||
$this->assertEquals(
|
||||
"",
|
||||
$this->object->getIndexName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::isPK
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsPK()
|
||||
{
|
||||
$this->object->key = "PRI";
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->isPK()
|
||||
);
|
||||
|
||||
$this->object->key = "";
|
||||
|
||||
$this->assertFalse(
|
||||
$this->object->isPK()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::formatCs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFormatCs()
|
||||
{
|
||||
$this->object->name = 'Name#name#123';
|
||||
|
||||
$this->assertEquals(
|
||||
'text123Namename',
|
||||
$this->object->formatCs("text123#name#")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::formatXml
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFormatXml()
|
||||
{
|
||||
$this->object->name = '"a\'';
|
||||
|
||||
$this->assertEquals(
|
||||
'"a\'index=""a\'"',
|
||||
$this->object->formatXml("#name##indexName#")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA\libraries\plugins\export\TableProperty::format
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFormat()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'NameintInt32intfalsetrue',
|
||||
$this->object->format(
|
||||
"#ucfirstName##dotNetPrimitiveType##dotNetObjectType##type#" .
|
||||
"#notNull##unique#"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
202
#pma/test/classes/plugin/import/ImportCsvTest.php
Normal file
202
#pma/test/classes/plugin/import/ImportCsvTest.php
Normal file
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportCsv class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportCsv;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportCsv class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportCsvTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var ImportCsv
|
||||
* @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['plugin_param'] = "csv";
|
||||
$this->object = new ImportCsv();
|
||||
|
||||
unset($GLOBALS['db']);
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/db_test.csv';
|
||||
$GLOBALS['import_text'] = 'ImportCsv_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'Xml';
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
|
||||
//separator for csv
|
||||
$GLOBALS['csv_terminated'] = "\015";
|
||||
$GLOBALS['csv_enclosed'] = '"';
|
||||
$GLOBALS['csv_escaped'] = '"';
|
||||
$GLOBALS['csv_new_line'] = 'auto';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('CSV'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'csv',
|
||||
$properties->getExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
'CREATE DATABASE IF NOT EXISTS `CSV_DB` DEFAULT CHARACTER',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `CSV_DB`.`TBL_NAME`',
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties for Table param
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetPropertiesForTable()
|
||||
{
|
||||
$GLOBALS['plugin_param'] = 'table';
|
||||
$this->object = new ImportCsv();
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('CSV'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'csv',
|
||||
$properties->getExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport for _getAnalyze = false, should be OK as well
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImportNotAnalysis()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
'CREATE DATABASE IF NOT EXISTS `CSV_DB` DEFAULT CHARACTER',
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `CSV_DB`.`TBL_NAME`',
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
}
|
266
#pma/test/classes/plugin/import/ImportLdiTest.php
Normal file
266
#pma/test/classes/plugin/import/ImportLdiTest.php
Normal file
@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportLdi class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportLdi;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['plugin_param'] = "table";
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportLdi class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportLdiTest 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()
|
||||
{
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/db_test_ldi.csv';
|
||||
$GLOBALS['import_text'] = 'ImportLdi_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'csv';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
|
||||
//setting for Ldi
|
||||
$GLOBALS['cfg']['Import']['ldi_replace'] = false;
|
||||
$GLOBALS['cfg']['Import']['ldi_ignore'] = false;
|
||||
$GLOBALS['cfg']['Import']['ldi_terminated'] = ';';
|
||||
$GLOBALS['cfg']['Import']['ldi_enclosed'] = '"';
|
||||
$GLOBALS['cfg']['Import']['ldi_escaped'] = '\\';
|
||||
$GLOBALS['cfg']['Import']['ldi_new_line'] = 'auto';
|
||||
$GLOBALS['cfg']['Import']['ldi_columns'] = '';
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = false;
|
||||
$GLOBALS['table'] = "phpmyadmintest";
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->any())->method('tryQuery')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->any())->method('numRows')
|
||||
->will($this->returnValue(10));
|
||||
|
||||
$fetchRowResult = array("ON");
|
||||
$dbi->expects($this->any())->method('fetchRow')
|
||||
->will($this->returnValue($fetchRowResult));
|
||||
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object = new ImportLdi();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('CSV using LOAD DATA'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'ldi',
|
||||
$properties->getExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties for ldi_local_option = auto
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetPropertiesAutoLdi()
|
||||
{
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = 'auto';
|
||||
$this->object = new ImportLdi();
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option']
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('CSV using LOAD DATA'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'ldi',
|
||||
$properties->getExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
"LOAD DATA INFILE 'test/test_data/db_test_ldi.csv' INTO TABLE "
|
||||
. "`phpmyadmintest`",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport : invalid import file
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImportInvalidFile()
|
||||
{
|
||||
global $import_file;
|
||||
$import_file = 'none';
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
// We handle only some kind of data!
|
||||
$this->assertContains(
|
||||
__('This plugin does not support compressed imports!'),
|
||||
$GLOBALS['message']->__toString()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['error']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport with LDI setting
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImportLDISetting()
|
||||
{
|
||||
global $ldi_local_option, $ldi_replace, $ldi_ignore, $ldi_terminated,
|
||||
$ldi_enclosed, $ldi_new_line, $skip_queries;
|
||||
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
$ldi_local_option = true;
|
||||
$ldi_replace = true;
|
||||
$ldi_ignore = true;
|
||||
$ldi_terminated = ',';
|
||||
$ldi_enclosed = ')';
|
||||
$ldi_new_line = 'newline_mark';
|
||||
$skip_queries = true;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
//replace
|
||||
$this->assertContains(
|
||||
"LOAD DATA LOCAL INFILE 'test/test_data/db_test_ldi.csv' REPLACE INTO "
|
||||
. "TABLE `phpmyadmintest`",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//FIELDS TERMINATED
|
||||
$this->assertContains(
|
||||
"FIELDS TERMINATED BY ','",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//LINES TERMINATED
|
||||
$this->assertContains(
|
||||
"LINES TERMINATED BY 'newline_mark'",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//IGNORE
|
||||
$this->assertContains(
|
||||
"IGNORE 1 LINES",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
}
|
167
#pma/test/classes/plugin/import/ImportMediawikiTest.php
Normal file
167
#pma/test/classes/plugin/import/ImportMediawikiTest.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportMediawiki class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportMediawiki;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportMediawiki class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportMediawikiTest 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['plugin_param'] = 'database';
|
||||
$this->object = new ImportMediawiki();
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/phpmyadmin.mediawiki';
|
||||
$GLOBALS['import_text'] = 'ImportMediawiki_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'Mediawiki';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('MediaWiki Table'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'txt',
|
||||
$properties->getExtension()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'text/plain',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$properties->getOptions()
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('Options'),
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
// If import successfully, PMA will show all databases and
|
||||
// tables imported as following HTML Page
|
||||
/*
|
||||
The following structures have either been created or altered. Here you
|
||||
can:
|
||||
View a structure's contents by clicking on its name
|
||||
Change any of its settings by clicking the corresponding "Options" link
|
||||
Edit structure by following the "Structure" link
|
||||
|
||||
mediawiki_DB (Options)
|
||||
pma_bookmarktest (Structure) (Options)
|
||||
*/
|
||||
|
||||
//asset that all databases and tables are imported
|
||||
$this->assertContains(
|
||||
'The following structures have either been created or altered.',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to database: `mediawiki_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `mediawiki_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to table: `pma_bookmarktest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `pma_bookmarktest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
|
||||
}
|
||||
}
|
179
#pma/test/classes/plugin/import/ImportOdsTest.php
Normal file
179
#pma/test/classes/plugin/import/ImportOdsTest.php
Normal file
@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportOds class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportOds;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/plugins/import/ImportOds.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportOds class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportOdsTest 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['plugin_param'] = "csv";
|
||||
$this->object = new ImportOds();
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/db_test.ods';
|
||||
|
||||
/**
|
||||
* Load interface for zip extension.
|
||||
*/
|
||||
include_once 'libraries/zip_extension.lib.php';
|
||||
$result = PMA_getZipContents($GLOBALS['import_file']);
|
||||
$GLOBALS['import_text'] = $result["data"];
|
||||
$GLOBALS['compression'] = 'application/zip';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'ods';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
|
||||
//variable for Ods
|
||||
$_REQUEST['ods_recognize_percentages'] = true;
|
||||
$_REQUEST['ods_recognize_currency'] = true;
|
||||
$_REQUEST['ods_empty_rows'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('OpenDocument Spreadsheet'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'ods',
|
||||
$properties->getExtension()
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('Options'),
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice, $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
$this->assertContains(
|
||||
'CREATE DATABASE IF NOT EXISTS `ODS_DB` DEFAULT CHARACTER SET '
|
||||
. 'utf8 COLLATE utf8_general_ci',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `ODS_DB`.`pma_bookmark`',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
"INSERT INTO `ODS_DB`.`pma_bookmark` (`A`, `B`, `C`, `D`) VALUES "
|
||||
. "(1, 'dbbase', NULL, 'ddd');",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//asset that all databases and tables are imported
|
||||
$this->assertContains(
|
||||
'The following structures have either been created or altered.',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to database: `ODS_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `ODS_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to table: `pma_bookmark`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `pma_bookmark`',
|
||||
$import_notice
|
||||
);
|
||||
|
||||
//asset that the import process is finished
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
}
|
227
#pma/test/classes/plugin/import/ImportShpTest.php
Normal file
227
#pma/test/classes/plugin/import/ImportShpTest.php
Normal file
@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportShp class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportShp;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportShp class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportShpTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var ImportShp
|
||||
* @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()
|
||||
{
|
||||
//setting
|
||||
$GLOBALS['plugin_param'] = 'table';
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object = new ImportShp();
|
||||
|
||||
$GLOBALS['compression'] = 'application/zip';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'ods';
|
||||
unset($GLOBALS['db'], $GLOBALS['table']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes import of given file
|
||||
*
|
||||
* @param string $filename Name of test file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function runImport($filename)
|
||||
{
|
||||
$GLOBALS['import_file'] = $filename;
|
||||
$GLOBALS['import_handle'] = @fopen($filename, 'r');
|
||||
|
||||
$this->object->doImport();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('ESRI Shape File'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'shp',
|
||||
$properties->getExtension()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$properties->getOptions()
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('Options'),
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport with complex data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testImportOsm()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice, $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->runImport('test/test_data/dresden_osm.shp.zip');
|
||||
|
||||
$this->assertMessages($import_notice);
|
||||
$this->assertContains(
|
||||
"(GeomFromText('MULTIPOLYGON((("
|
||||
. "13.737122 51.0542065,"
|
||||
. "13.7373039 51.0541298,"
|
||||
. "13.7372661 51.0540944,"
|
||||
. "13.7370842 51.0541711,"
|
||||
. "13.737122 51.0542065)))'))",
|
||||
$sql_query
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice, $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->runImport('test/test_data/timezone.shp.zip');
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
'CREATE DATABASE IF NOT EXISTS `SHP_DB` DEFAULT CHARACTER '
|
||||
. 'SET utf8 COLLATE utf8_general_ci',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `SHP_DB`.`TBL_NAME` '
|
||||
. '(`SPATIAL` geometry) DEFAULT CHARACTER '
|
||||
. 'SET utf8 COLLATE utf8_general_ci;',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
"INSERT INTO `SHP_DB`.`TBL_NAME` (`SPATIAL`) VALUES",
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
"GeomFromText('POINT(1294523.1759236",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//asset that all databases and tables are imported
|
||||
$this->assertMessages($import_notice);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates import messages
|
||||
*
|
||||
* @param string $import_notice Messages to check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function assertMessages($import_notice)
|
||||
{
|
||||
$this->assertContains(
|
||||
'The following structures have either been created or altered.',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to database: `SHP_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `SHP_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to table: `TBL_NAME`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `TBL_NAME`',
|
||||
$import_notice
|
||||
);
|
||||
|
||||
//asset that the import process is finished
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
}
|
116
#pma/test/classes/plugin/import/ImportSqlTest.php
Normal file
116
#pma/test/classes/plugin/import/ImportSqlTest.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportSql class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportSql;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportSql class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportSqlTest 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 ImportSql();
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/pma_bookmark.sql';
|
||||
$GLOBALS['import_text'] = 'ImportSql_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'Xml';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `pma_bookmark`',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'INSERT INTO `pma_bookmark` (`id`, `dbase`, `user`, `label`, `query`) '
|
||||
. 'VALUES',
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
|
||||
}
|
||||
}
|
168
#pma/test/classes/plugin/import/ImportXmlTest.php
Normal file
168
#pma/test/classes/plugin/import/ImportXmlTest.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportXml class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportXml;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportXml class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportXmlTest 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 ImportXml();
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/phpmyadmin_importXML_'
|
||||
. 'For_Testing.xml';
|
||||
$GLOBALS['import_text'] = 'ImportXml_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'Xml';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('XML'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'xml',
|
||||
$properties->getExtension()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'text/xml',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$properties->getOptions()
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('Options'),
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
// If import successfully, PMA will show all databases and tables
|
||||
// imported as following HTML Page
|
||||
/*
|
||||
The following structures have either been created or altered. Here you
|
||||
can:
|
||||
View a structure's contents by clicking on its name
|
||||
Change any of its settings by clicking the corresponding "Options" link
|
||||
Edit structure by following the "Structure" link
|
||||
|
||||
phpmyadmintest (Options)
|
||||
pma_bookmarktest (Structure) (Options)
|
||||
*/
|
||||
|
||||
//asset that all databases and tables are imported
|
||||
$this->assertContains(
|
||||
'The following structures have either been created or altered.',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to database: `phpmyadmintest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `phpmyadmintest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to table: `pma_bookmarktest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `pma_bookmarktest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user