Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
583d174886
6
.gitignore
vendored
6
.gitignore
vendored
@ -20,6 +20,7 @@ phpmyadmin.wpj
|
||||
.buildpath
|
||||
.cache
|
||||
.idea
|
||||
.netbeans
|
||||
*.sw[op]
|
||||
# Locales
|
||||
/locale/
|
||||
@ -31,3 +32,8 @@ phpmyadmin.wpj
|
||||
/apidoc/
|
||||
# Demo server
|
||||
revision-info.php
|
||||
# PHPUnit
|
||||
phpunit.xml
|
||||
/test/bootstrap.php
|
||||
# Jenkins
|
||||
/build/
|
||||
87
build.xml
Normal file
87
build.xml
Normal file
@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project name="phpMyAdmin" default="build" basedir=".">
|
||||
<property name="source" value="."/>
|
||||
<property name="source_comma_sep" value="."/>
|
||||
|
||||
<target name="clean" description="Clean up and create artifact directories">
|
||||
<delete dir="${basedir}/build/api"/>
|
||||
<delete dir="${basedir}/build/code-browser"/>
|
||||
<delete dir="${basedir}/build/coverage"/>
|
||||
<delete dir="${basedir}/build/logs"/>
|
||||
<delete dir="${basedir}/build/pdepend"/>
|
||||
|
||||
<mkdir dir="${basedir}/build/api"/>
|
||||
<mkdir dir="${basedir}/build/code-browser"/>
|
||||
<mkdir dir="${basedir}/build/coverage"/>
|
||||
<mkdir dir="${basedir}/build/logs"/>
|
||||
<mkdir dir="${basedir}/build/pdepend"/>
|
||||
</target>
|
||||
|
||||
<target name="phpunit" description="Run unit tests using PHPUnit and generates junit.xml and clover.xml">
|
||||
<exec executable="phpunit">
|
||||
<arg line="--configuration phpunit.xml.dist"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="pdepend" description="Generate jdepend.xml and software metrics charts using PHP_Depend">
|
||||
<exec executable="pdepend">
|
||||
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml
|
||||
--jdepend-chart=${basedir}/build/pdepend/dependencies.svg
|
||||
--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg
|
||||
${source_comma_sep}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="phpmd" description="Generate pmd.xml using PHPMD">
|
||||
<exec executable="phpmd">
|
||||
<arg line="${source_comma_sep}
|
||||
xml
|
||||
codesize,design,naming,unusedcode
|
||||
--reportfile ${basedir}/build/logs/pmd.xml" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="phpcpd" description="Generate pmd-cpd.xml using PHPCPD">
|
||||
<exec executable="phpcpd">
|
||||
<arg line="--log-pmd ${basedir}/build/logs/pmd-cpd.xml
|
||||
--exclude test
|
||||
--exclude libraries/PHPExcel
|
||||
--exclude libraries/tcpdf
|
||||
${source}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="phploc" description="Generate phploc.csv">
|
||||
<exec executable="phploc">
|
||||
<arg line="--log-csv ${basedir}/build/logs/phploc.csv ${source}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="phpcs" description="Generate checkstyle.xml using PHP_CodeSniffer excluding test, PHPExcel, tcpdf directories">
|
||||
<exec executable="phpcs">
|
||||
<arg line="-v
|
||||
--ignore=*/PHPExcel/*,*/php-gettext/*,*/tcpdf/*
|
||||
--report=checkstyle
|
||||
--report-file=${basedir}/build/logs/checkstyle.xml
|
||||
--standard=PEAR
|
||||
${source}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="phpdoc" description="Generate API documentation using PHPDocumentor">
|
||||
<exec executable="phpdoc">
|
||||
<arg line="-d ${source} -t ${basedir}/build/api" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="phpcb" description="Aggregate tool output with PHP_CodeBrowser">
|
||||
<exec executable="phpcb">
|
||||
<arg line="--log ${basedir}/build/logs
|
||||
--source ${source}
|
||||
--output ${basedir}/build/code-browser" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="clean,phpunit,pdepend,phpmd,phpcpd,phpcs,phpdoc,phploc,phpcb"/>
|
||||
</project>
|
||||
@ -2846,7 +2846,9 @@ function PMA_ajaxResponse($message, $success = true, $extra_data = array())
|
||||
header("Content-Type: application/json");
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
|
||||
if(!defined('TESTSUITE'))
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -224,8 +224,10 @@ function PMA_fatalError($error_message, $message_args = null)
|
||||
}
|
||||
|
||||
require('./libraries/error.inc.php');
|
||||
|
||||
exit;
|
||||
|
||||
if (!defined('TESTSUITE')) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
53
phpunit.xml.dist
Normal file
53
phpunit.xml.dist
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="test/bootstrap-dist.php"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
strict="true"
|
||||
verbose="true">
|
||||
|
||||
<selenium>
|
||||
<browser name="Firefox on localhost"
|
||||
browser="*firefox"
|
||||
host="127.0.0.1"
|
||||
port="4444"
|
||||
timeout="30000"/>
|
||||
<browser name="Google Chrome on localhost"
|
||||
browser="googlechrome"
|
||||
host="127.0.0.1"
|
||||
port="4444"
|
||||
timeout="30000"/>
|
||||
</selenium>
|
||||
|
||||
<php>
|
||||
<const name="TESTSUITE_SERVER" value="localhost"/>
|
||||
<const name="TESTSUITE_USER" value="root"/>
|
||||
<const name="TESTSUITE_PASSWORD" value=""/>
|
||||
<const name="TESTSUITE_DATABASE" value="test"/>
|
||||
<const name="TESTSUITE_PHPMYADMIN_HOST" value="http://localhost" />
|
||||
<const name="TESTSUITE_PHPMYADMIN_URL" value="/phpmyadmin" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Classes">
|
||||
<directory suffix="_test.php">test/classes</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Unit">
|
||||
<file>test/Environment_test.php</file>
|
||||
<directory suffix="_test.php">test/libraries/core</directory>
|
||||
<directory suffix="_test.php">test/libraries/common</directory>
|
||||
<directory suffix="_test.php">test/libraries</directory>
|
||||
</testsuite>
|
||||
<!--<testsuite name="Selenium">-->
|
||||
<!--<directory suffix="Test.php">test/selenium</directory>-->
|
||||
<!--</testsuite>-->
|
||||
</testsuites>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-html" target="build/coverage" title="phpMyAdmin"
|
||||
charset="UTF-8" yui="true" highlight="true"
|
||||
lowUpperBound="35" highLowerBound="70"/>
|
||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
|
||||
</logging>
|
||||
|
||||
</phpunit>
|
||||
2
po/da.po
2
po/da.po
@ -10460,7 +10460,7 @@ msgid ""
|
||||
"cookie validity%s must be set to a value less or equal to it."
|
||||
msgstr ""
|
||||
"Hvis du bruger cookie autentifikation og %sLogin cookie sletning%s ikke er "
|
||||
"0, så skal %Login cookie gyldighed% være en værdi mindre end eller lig med "
|
||||
"0, så skal %sLogin cookie gyldighed%s være en værdi mindre end eller lig med "
|
||||
"den."
|
||||
|
||||
#: setup/lib/index.lib.php:266
|
||||
|
||||
6
test/.htaccess
Normal file
6
test/.htaccess
Normal file
@ -0,0 +1,6 @@
|
||||
# This folder does NOT need to be accessible over HTTP
|
||||
# In most cases the tests included here will be run from a command line interface.
|
||||
|
||||
# (the following directive denies access by default)
|
||||
# For more information see: http://httpd.apache.org/docs/current/mod/mod_authz_host.html#allow
|
||||
Order allow,deny
|
||||
@ -9,7 +9,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'config.sample.inc.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
@ -24,12 +24,28 @@ class Environment_test extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testMySQL()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
try{
|
||||
$pdo = new PDO("mysql:host=".TESTSUITE_SERVER.";dbname=".TESTSUITE_DATABASE, TESTSUITE_USER, TESTSUITE_PASSWORD);
|
||||
$this->assertNull($pdo->errorCode(),"Error when trying to connect to database");
|
||||
|
||||
//$pdo->beginTransaction();
|
||||
$test = $pdo->exec("SHOW TABLES;");
|
||||
//$pdo->commit();
|
||||
$this->assertEquals(0, $pdo->errorCode(), 'Error trying to show tables for database');
|
||||
}
|
||||
catch (Exception $e){
|
||||
$this->fail("Error: ".$e->getMessage());
|
||||
}
|
||||
|
||||
// Check id MySQL server is 5 version
|
||||
preg_match("/^(\d+)?\.(\d+)?\.(\*|\d+)/", $pdo->getAttribute(constant("PDO::ATTR_SERVER_VERSION")), $version_parts);
|
||||
$this->assertEquals(5, $version_parts[1]);
|
||||
}
|
||||
|
||||
public function testSession()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
//TODO: Think about this test
|
||||
// public function testSession()
|
||||
// {
|
||||
// $this->markTestIncomplete();
|
||||
// }
|
||||
}
|
||||
?>
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA_get_real_size()
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class FailTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFail()
|
||||
{
|
||||
$this->assertEquals(0, 1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for javascript escaping.
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/js_escape.lib.php';
|
||||
|
||||
/**
|
||||
* Test java script escaping.
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_escapeJsString_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEscape_1()
|
||||
{
|
||||
$this->assertEquals('\\\';', PMA_escapeJsString('\';'));
|
||||
}
|
||||
|
||||
public function testEscape_2()
|
||||
{
|
||||
$this->assertEquals('\r\n\\\'<scrIpt></\' + \'script>', PMA_escapeJsString("\r\n'<scrIpt></sCRIPT>"));
|
||||
}
|
||||
|
||||
public function testEscape_3()
|
||||
{
|
||||
$this->assertEquals('\\\';[XSS]', PMA_escapeJsString('\';[XSS]'));
|
||||
}
|
||||
|
||||
public function testEscape_4()
|
||||
{
|
||||
$this->assertEquals('</\' + \'script></head><body>[HTML]', PMA_escapeJsString('</SCRIPT></head><body>[HTML]'));
|
||||
}
|
||||
|
||||
public function testEscape_5()
|
||||
{
|
||||
$this->assertEquals('"\\\'\\\\\\\'"', PMA_escapeJsString('"\'\\\'"'));
|
||||
}
|
||||
|
||||
public function testEscape_6()
|
||||
{
|
||||
$this->assertEquals("\\\\\'\'\'\'\'\'\'\'\'\'\'\'\\\\", PMA_escapeJsString("\\''''''''''''\\"));
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -1,114 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA_pow()
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once './libraries/core.lib.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_isValid_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testVarNotSetAfterTest()
|
||||
{
|
||||
PMA_isValid($var);
|
||||
$this->assertFalse(isset($var));
|
||||
}
|
||||
public function testNotSet()
|
||||
{
|
||||
$this->assertFalse(PMA_isValid($var));
|
||||
}
|
||||
public function testEmptyString()
|
||||
{
|
||||
$var = '';
|
||||
$this->assertFalse(PMA_isValid($var));
|
||||
}
|
||||
public function testNotEmptyString()
|
||||
{
|
||||
$var = '0';
|
||||
$this->assertTrue(PMA_isValid($var));
|
||||
}
|
||||
public function testZero()
|
||||
{
|
||||
$var = 0;
|
||||
$this->assertTrue(PMA_isValid($var));
|
||||
}
|
||||
public function testNullFail()
|
||||
{
|
||||
$var = null;
|
||||
$this->assertFalse(PMA_isValid($var));
|
||||
}
|
||||
public function testNotSetArray()
|
||||
{
|
||||
$this->assertFalse(PMA_isValid($array['x']));
|
||||
}
|
||||
public function testScalarString()
|
||||
{
|
||||
$var = 'string';
|
||||
$this->assertTrue(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
public function testScalarInt()
|
||||
{
|
||||
$var = 1;
|
||||
$this->assertTrue(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
public function testScalarFloat()
|
||||
{
|
||||
$var = 1.1;
|
||||
$this->assertTrue(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
public function testScalarBool()
|
||||
{
|
||||
$var = true;
|
||||
$this->assertTrue(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
public function testNotScalarArray()
|
||||
{
|
||||
$var = array('test');
|
||||
$this->assertFalse(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
public function testNotScalarNull()
|
||||
{
|
||||
$var = null;
|
||||
$this->assertFalse(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
public function testNumericInt()
|
||||
{
|
||||
$var = 1;
|
||||
$this->assertTrue(PMA_isValid($var, 'numeric'));
|
||||
}
|
||||
public function testNumericFloat()
|
||||
{
|
||||
$var = 1.1;
|
||||
$this->assertTrue(PMA_isValid($var, 'numeric'));
|
||||
}
|
||||
public function testNumericZero()
|
||||
{
|
||||
$var = 0;
|
||||
$this->assertTrue(PMA_isValid($var, 'numeric'));
|
||||
}
|
||||
public function testNumericString()
|
||||
{
|
||||
$var = '+0.1';
|
||||
$this->assertTrue(PMA_isValid($var, 'numeric'));
|
||||
}
|
||||
public function testValueInArray()
|
||||
{
|
||||
$var = 'a';
|
||||
$this->assertTrue(PMA_isValid($var, array('a', 'b', )));
|
||||
}
|
||||
public function testValueNotInArray()
|
||||
{
|
||||
$var = 'c';
|
||||
$this->assertFalse(PMA_isValid($var, array('a', 'b', )));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,26 +1,17 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for showHint function
|
||||
* Test for PMA_showHint() function from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_showHint_test.php
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test showHint function.
|
||||
*
|
||||
*/
|
||||
class PMA_showHint_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@ -105,6 +96,7 @@ class PMA_showHint_test extends PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* PMA_showHint with not defined GLOBALS formatted as BB
|
||||
* @depends testShowHintSetting
|
||||
*/
|
||||
public function testShowHintSettingBbFormat()
|
||||
{
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium TestCase for login related tests
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once('PmaSeleniumTestCase.php');
|
||||
|
||||
|
||||
class PmaSeleniumLoginTest extends PmaSeleniumTestCase
|
||||
{
|
||||
public function testLogin()
|
||||
{
|
||||
$this->doLogin();
|
||||
$this->assertRegExp("/phpMyAdmin .*-dev/", $this->getTitle());
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium parent class for TestCases
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
// Optionally add the php-client-driver to your include path
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/selenium-remote-control-1.0.1/selenium-php-client-driver-1.0.1/PEAR/');
|
||||
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
|
||||
require_once 'Testing/Selenium.php';
|
||||
|
||||
// Include the main phpMyAdmin user config
|
||||
// currently only $cfg['Test'] is used
|
||||
require_once '../config.inc.php';
|
||||
|
||||
|
||||
|
||||
class PmaSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
|
||||
{
|
||||
protected $selenium;
|
||||
protected $cfg;
|
||||
|
||||
// TODO: find a way to get this from config.inc.php???
|
||||
// PHPUnit also has a way to use XML configuration... maybe we should use that
|
||||
public static $browsers = array(
|
||||
array(
|
||||
|
||||
'name' => 'Firefox on Windows XP',
|
||||
'browser' => '*firefox',
|
||||
'host' => 'my.windowsxp.box',
|
||||
'port' => 4444,
|
||||
'timeout' => 30000,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'Internet Explorer on Windows XP',
|
||||
'browser' => '*iexplore',
|
||||
'host' => 'my.windowsxp.box',
|
||||
'port' => 4444,
|
||||
'timeout' => 30000,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
global $cfg;
|
||||
$this->cfg =& $cfg;
|
||||
//PHPUnit_Extensions_SeleniumTestCase::$browsers = $this->cfg['Test']['broswers'];
|
||||
|
||||
// Check if the test configuration is available
|
||||
if ( empty($cfg['Test']['pma_host'])
|
||||
|| empty($cfg['Test']['pma_url'])
|
||||
//|| empty($cfg['Test']['browsers'])
|
||||
) {
|
||||
$this->fail("Missing Selenium configuration in config.inc.php"); // TODO add doc ref?
|
||||
}
|
||||
|
||||
$this->setBrowserUrl($cfg['Test']['pma_host'] . $cfg['Test']['pma_url']);
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* perform a login
|
||||
*/
|
||||
public function doLogin()
|
||||
{
|
||||
$this->open($this->cfg['Test']['pma_url']);
|
||||
// Somehow selenium does not like the language selection on the cookie login page, forced English in the config for now.
|
||||
//$this->select("lang", "label=English");
|
||||
|
||||
$this->waitForPageToLoad("30000");
|
||||
$this->type("input_username", $this->cfg['Test']['testuser']['username']);
|
||||
$this->type("input_password", $this->cfg['Test']['testuser']['password']);
|
||||
$this->click("input_go");
|
||||
$this->waitForPageToLoad("30001");
|
||||
}
|
||||
|
||||
/*
|
||||
* Just a dummy to show some example statements
|
||||
*
|
||||
public function mockTest()
|
||||
{
|
||||
// Slow down the testing speed, ideal for debugging
|
||||
//$this->setSpeed(4000);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
||||
11
test/README
Normal file
11
test/README
Normal file
@ -0,0 +1,11 @@
|
||||
PhpMyAdmin test suite
|
||||
=====================
|
||||
|
||||
This directory is protected from web visitors by a .htaccess file.
|
||||
|
||||
For more information on allowing http access to this directory see:
|
||||
http://httpd.apache.org/docs/current/mod/mod_authz_host.html#allow
|
||||
|
||||
Please visit the wiki for more information on unit testing:
|
||||
https://wiki.phpmyadmin.net/pma/UnitTesting
|
||||
|
||||
14
test/bootstrap-dist.php
Normal file
14
test/bootstrap-dist.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
// Adding phpMyAdmin sources to include path
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(realpath("../index.php")));
|
||||
|
||||
// Setting constants for testing
|
||||
define('PHPMYADMIN', 1);
|
||||
define('TESTSUITE', 1);
|
||||
|
||||
session_start();
|
||||
|
||||
// You can put some additional code that should run before tests here
|
||||
|
||||
?>
|
||||
613
test/classes/PMA_Config_test.php
Normal file
613
test/classes/PMA_Config_test.php
Normal file
@ -0,0 +1,613 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_Config class
|
||||
*
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @group current
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/Config.class.php';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
|
||||
class PMA_ConfigTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Turn off backup globals
|
||||
*/
|
||||
protected $backupGlobals = FALSE;
|
||||
|
||||
/**
|
||||
* @var PMA_Config
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new PMA_Config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
public function testCheckSystem()
|
||||
{
|
||||
$this->object->checkSystem();
|
||||
|
||||
$this->assertNotNull($this->object->get('PMA_VERSION'));
|
||||
$this->assertNotEmpty($this->object->get('PMA_THEME_VERSION'));
|
||||
$this->assertNotEmpty($this->object->get('PMA_THEME_GENERATION'));
|
||||
}
|
||||
|
||||
public function testCheckOutputCompression()
|
||||
{
|
||||
|
||||
$this->object->set('OBGzip', 'auto');
|
||||
|
||||
$this->object->set('PMA_USR_BROWSER_AGENT', 'IE');
|
||||
$this->object->set('PMA_USR_BROWSER_VER', 6);
|
||||
$this->object->checkOutputCompression();
|
||||
$this->assertFalse($this->object->get("OBGzip"));
|
||||
|
||||
$this->object->set('OBGzip', 'auto');
|
||||
$this->object->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
|
||||
$this->object->set('PMA_USR_BROWSER_VER', 5);
|
||||
$this->object->checkOutputCompression();
|
||||
$this->assertEquals('auto',$this->object->get("OBGzip"));
|
||||
|
||||
ini_set('zlib.output_compression', 'Off');
|
||||
$this->object->checkOutputCompression();
|
||||
$this->assertFalse($this->object->get("OBGzip"));
|
||||
|
||||
ini_set('zlib.output_compression', 'On');
|
||||
}
|
||||
|
||||
public function testCheckClient()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00';
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals("Linux", $this->object->get('PMA_USR_OS'), "User OS expected to be Linux");
|
||||
$this->assertEquals("OPERA", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Opera");
|
||||
$this->assertEquals("9.80", $this->object->get('PMA_USR_BROWSER_VER'), "Browser ver expected to be 9.80");
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/528.16 OmniWeb/622.8.0.112941';
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals("Mac", $this->object->get('PMA_USR_OS'), "User OS expected to be Mac");
|
||||
$this->assertEquals("OMNIWEB", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be OmniWeb");
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)';
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals("Win", $this->object->get('PMA_USR_OS'), "User OS expected to be Windows");
|
||||
$this->assertEquals("IE", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be IE");
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Unknown; U; Unix BSD/SYSV system; C -) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.2';
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals("Unix", $this->object->get('PMA_USR_OS'), "User OS expected to be Unix");
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; OS/2 Webexplorer)';
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals("OS/2", $this->object->get('PMA_USR_OS'), "User OS expected to be OS/2");
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.9b) Gecko/20031208';
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals("GECKO", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Gecko");
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; Konqueror/4.5; NetBSD 5.0.2; X11; amd64; en_US) KHTML/4.5.4 (like Gecko)';
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals("KONQUEROR", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Konqueror");
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0';
|
||||
$this->object->checkClient();
|
||||
$this->assertEquals("MOZILLA", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Mozilla");
|
||||
$this->assertEquals("Linux", $this->object->get('PMA_USR_OS'), "User OS expected to be Linux");
|
||||
|
||||
}
|
||||
|
||||
public function testCheckGd2()
|
||||
{
|
||||
$prevIsGb2Val = $this->object->get('PMA_IS_GD2');
|
||||
|
||||
$this->object->set('GD2Available','yes');
|
||||
$this->object->checkGd2();
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_GD2'));
|
||||
|
||||
$this->object->set('GD2Available','no');
|
||||
$this->object->checkGd2();
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_GD2'));
|
||||
|
||||
$this->object->set('GD2Available',$prevIsGb2Val);
|
||||
|
||||
if (!@function_exists('imagecreatetruecolor'))
|
||||
{
|
||||
$this->object->checkGd2();
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'Function imagecreatetruecolor does not exist, PMA_IS_GD2 should be 0');
|
||||
}
|
||||
|
||||
if (@function_exists('gd_info')) {
|
||||
$this->object->checkGd2();
|
||||
$gd_nfo = gd_info();
|
||||
if (strstr($gd_nfo["GD Version"], '2.')) {
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_GD2'), 'GD Version >= 2, PMA_IS_GD2 should be 1');
|
||||
} else {
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'GD Version < 2, PMA_IS_GD2 should be 0');
|
||||
}
|
||||
}
|
||||
|
||||
/* Get GD version string from phpinfo output */
|
||||
ob_start();
|
||||
phpinfo(INFO_MODULES); /* Only modules */
|
||||
$a = strip_tags(ob_get_contents());
|
||||
ob_end_clean();
|
||||
|
||||
if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
|
||||
if (strstr($v, '2.')) {
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_GD2'), 'PMA_IS_GD2 should be 1');
|
||||
} else {
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'PMA_IS_GD2 should be 0');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testCheckWebServer()
|
||||
{
|
||||
$_SERVER['SERVER_SOFTWARE'] = "Microsoft-IIS 7.0";
|
||||
$this->object->checkWebServer();
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_IIS'));
|
||||
|
||||
$_SERVER['SERVER_SOFTWARE'] = "Apache/2.2.17";
|
||||
$this->object->checkWebServer();
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_IIS'));
|
||||
|
||||
unset($_SERVER['SERVER_SOFTWARE']);
|
||||
}
|
||||
|
||||
public function testCheckWebServerOs()
|
||||
{
|
||||
$this->object->checkWebServerOs();
|
||||
|
||||
if (defined('PHP_OS'))
|
||||
{
|
||||
switch (PHP_OS)
|
||||
{
|
||||
case stristr(PHP_OS,'win'):
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PHP_OS equals: ' . PHP_OS . ' PMA_IS_WINDOWS should be 1');
|
||||
break;
|
||||
case stristr(PHP_OS, 'OS/2'):
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PHP_OS is OS/2 PMA_IS_WINDOWS should be 1 (No file permissions like Windows)');
|
||||
break;
|
||||
case stristr(PHP_OS, 'Linux'):
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS'), 'PMA_IS_WINDOWS Default to Unix or Equiv');
|
||||
|
||||
define('PHP_OS','Windows');
|
||||
$this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PMA_IS_WINDOWS must be 1');
|
||||
}
|
||||
}
|
||||
|
||||
public function testCheckPhpVersion()
|
||||
{
|
||||
$this->object->checkPhpVersion();
|
||||
|
||||
$php_int_ver = 0;
|
||||
$php_str_ver = phpversion();
|
||||
|
||||
$match = array();
|
||||
preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@', phpversion(), $match);
|
||||
if (isset($match) && ! empty($match[1])) {
|
||||
if (! isset($match[2])) {
|
||||
$match[2] = 0;
|
||||
}
|
||||
if (! isset($match[3])) {
|
||||
$match[3] = 0;
|
||||
}
|
||||
$php_int_ver = (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]);
|
||||
} else {
|
||||
$php_int_ver = 0;
|
||||
}
|
||||
|
||||
$this->assertEquals($php_str_ver, $this->object->get('PMA_PHP_STR_VERSION'));
|
||||
$this->assertEquals($php_int_ver, $this->object->get('PMA_PHP_INT_VERSION'));
|
||||
}
|
||||
|
||||
public function testLoadDefaults()
|
||||
{
|
||||
$prevDefaultSource = $this->object->default_source;
|
||||
|
||||
$this->object->default_source = 'unexisted.file.php';
|
||||
$this->assertFalse($this->object->loadDefaults());
|
||||
|
||||
$this->object->default_source = $prevDefaultSource;
|
||||
|
||||
include $this->object->default_source;
|
||||
|
||||
$loadedConf = $cfg;
|
||||
unset($cfg);
|
||||
|
||||
$this->assertTrue($this->object->loadDefaults());
|
||||
|
||||
$this->assertEquals($this->object->default_source_mtime, filemtime($prevDefaultSource));
|
||||
$this->assertEquals($loadedConf['Servers'][1], $this->object->default_server);
|
||||
|
||||
unset($loadedConf['Servers']);
|
||||
|
||||
$this->assertEquals($loadedConf, $this->object->default);
|
||||
|
||||
$expectedSettings = PMA_array_merge_recursive($this->object->settings, $loadedConf);
|
||||
|
||||
$this->assertEquals($expectedSettings, $this->object->settings,'Settings loaded wrong');
|
||||
|
||||
$this->assertFalse($this->object->error_config_default_file);
|
||||
}
|
||||
|
||||
public function testCheckConfigSource()
|
||||
{
|
||||
$this->object->setSource('unexisted.config.php');
|
||||
$this->assertFalse($this->object->checkConfigSource());
|
||||
$this->assertEquals(0, $this->object->source_mtime);
|
||||
|
||||
// if(! is_readable($this->object->getSource()))
|
||||
// $this->markTestSkipped('Configuration file is read only');
|
||||
|
||||
$this->object->setSource('libraries/config.default.php');
|
||||
|
||||
$this->assertNotEmpty($this->object->getSource());
|
||||
$this->assertTrue($this->object->checkConfigSource());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PMA_Config::get
|
||||
* @covers PMA_Config::set
|
||||
* @return void
|
||||
*/
|
||||
public function testGetAndSet()
|
||||
{
|
||||
$this->assertNull($this->object->get("unresisting_setting"));
|
||||
|
||||
$this->object->set('test_setting', 'test_value');
|
||||
|
||||
$this->assertEquals('test_value', $this->object->get('test_setting'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PMA_Config::getSource
|
||||
* @covers PMA_Config::setSource
|
||||
*/
|
||||
public function testGetSetSource()
|
||||
{
|
||||
echo $this->object->getSource();
|
||||
|
||||
$this->assertEmpty($this->object->getSource(), "Source is null by default");
|
||||
|
||||
$this->object->setSource("config.sample.inc.php");
|
||||
|
||||
$this->assertEquals("config.sample.inc.php", $this->object->getSource(), "Cant set new source");
|
||||
}
|
||||
|
||||
public function testCheckPmaAbsoluteUriEmpty()
|
||||
{
|
||||
$this->object->set('PmaAbsoluteUri','');
|
||||
$this->assertFalse($this->object->checkPmaAbsoluteUri(), 'PmaAbsoluteUri is not set and should be error');
|
||||
$this->assertTrue($this->object->error_pma_uri, 'PmaAbsoluteUri is not set and should be error');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCheckPmaAbsoluteUriEmpty
|
||||
*/
|
||||
public function testCheckPmaAbsoluteUriNormal()
|
||||
{
|
||||
$this->object->set('PmaAbsoluteUri','http://localhost/phpmyadmin/');
|
||||
$this->object->checkPmaAbsoluteUri();
|
||||
$this->assertEquals("http://localhost/phpmyadmin/", $this->object->get('PmaAbsoluteUri'));
|
||||
|
||||
$this->object->set('PmaAbsoluteUri','http://localhost/phpmyadmin');
|
||||
$this->object->checkPmaAbsoluteUri();
|
||||
$this->assertEquals("http://localhost/phpmyadmin/", $this->object->get('PmaAbsoluteUri'), 'Expected trailing slash at the end of the phpMyAdmin uri');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCheckPmaAbsoluteUriNormal
|
||||
*/
|
||||
public function testCheckPmaAbsoluteUriScheme()
|
||||
{
|
||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||
$_SERVER['HTTP_SCHEME'] = 'http';
|
||||
$_SERVER['HTTPS'] = 'off';
|
||||
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
|
||||
|
||||
$this->object->set('PmaAbsoluteUri','');
|
||||
|
||||
$this->object->checkPmaAbsoluteUri();
|
||||
$this->assertEquals("http://localhost/", $this->object->get('PmaAbsoluteUri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCheckPmaAbsoluteUriScheme
|
||||
*/
|
||||
public function testCheckPmaAbsoluteUriUser()
|
||||
{
|
||||
$this->object->set('PmaAbsoluteUri','http://user:pwd@localhost/phpmyadmin/index.php');
|
||||
|
||||
$this->object->checkPmaAbsoluteUri();
|
||||
$this->assertEquals("http://user:pwd@localhost/phpmyadmin/index.php/", $this->object->get('PmaAbsoluteUri'));
|
||||
|
||||
$this->object->set('PmaAbsoluteUri','https://user:pwd@localhost/phpmyadmin/index.php');
|
||||
|
||||
$this->object->checkPmaAbsoluteUri();
|
||||
$this->assertEquals("https://user:pwd@localhost/phpmyadmin/index.php/", $this->object->get('PmaAbsoluteUri'));
|
||||
}
|
||||
|
||||
public function testCheckCollationConnection()
|
||||
{
|
||||
$_REQUEST['collation_connection'] = 'utf-8';
|
||||
$this->object->checkCollationConnection();
|
||||
|
||||
$this->assertEquals($_REQUEST['collation_connection'], $this->object->get('collation_connection'));
|
||||
}
|
||||
|
||||
public function testIsHttps()
|
||||
{
|
||||
$this->object->set('PmaAbsoluteUri', 'http://some_host.com/phpMyAdmin');
|
||||
$this->assertFalse($this->object->isHttps());
|
||||
|
||||
$this->object->set('PmaAbsoluteUri', 'https://some_host.com/phpMyAdmin');
|
||||
$this->assertFalse($this->object->isHttps());
|
||||
}
|
||||
|
||||
public function testDetectHttps()
|
||||
{
|
||||
unset($_SERVER['REQUEST_URI']);
|
||||
unset($_SERVER['HTTP_SCHEME']);
|
||||
unset($_SERVER['HTTPS']);
|
||||
|
||||
$this->assertFalse($this->object->detectHttps());
|
||||
|
||||
$_SERVER['REQUEST_URI'] = '/url:\this_is_not_url';
|
||||
$this->assertFalse($this->object->detectHttps());
|
||||
|
||||
$_SERVER['REQUEST_URI'] = 'file://localhost/phpmyadmin/index.php';
|
||||
$this->assertFalse($this->object->detectHttps());
|
||||
|
||||
$_ENV['REQUEST_URI'] = 'http://localhost/phpmyadmin/index.php';
|
||||
$this->assertFalse($this->object->detectHttps());
|
||||
|
||||
$_SERVER['REQUEST_URI'] = 'https://localhost/phpmyadmin/index.php';
|
||||
$this->assertTrue($this->object->detectHttps());
|
||||
|
||||
$_SERVER['REQUEST_URI'] = 'localhost/phpmyadmin/index.php';
|
||||
$_SERVER['HTTP_SCHEME'] = 'https';
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
$this->assertTrue($this->object->detectHttps());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDetectHttps
|
||||
*/
|
||||
public function testCheckCookiePath()
|
||||
{
|
||||
$this->object->checkCookiePath();
|
||||
echo $this->object->get('cookie_path');
|
||||
$this->assertEquals('',$this->object->get('cookie_path'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCheckSystem
|
||||
* @depends testCheckWebServer
|
||||
* @depends testLoadDefaults
|
||||
* @depends testLoad
|
||||
*/
|
||||
public function testEnableBc()
|
||||
{
|
||||
$this->object->enableBc();
|
||||
|
||||
$defines = array(
|
||||
'PMA_VERSION',
|
||||
'PMA_THEME_VERSION',
|
||||
'PMA_THEME_GENERATION',
|
||||
'PMA_PHP_STR_VERSION',
|
||||
'PMA_PHP_INT_VERSION',
|
||||
'PMA_IS_WINDOWS',
|
||||
'PMA_IS_IIS',
|
||||
'PMA_IS_GD2',
|
||||
'PMA_USR_OS',
|
||||
'PMA_USR_BROWSER_VER',
|
||||
'PMA_USR_BROWSER_AGENT'
|
||||
);
|
||||
|
||||
foreach ($defines as $define)
|
||||
{
|
||||
$this->assertTrue(defined($define));
|
||||
$this->assertEquals(constant($define), $this->object->get($define));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testSave().
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGetFontsizeForm().
|
||||
*/
|
||||
public function testGetFontsizeForm()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testRemoveCookie().
|
||||
*/
|
||||
public function testRemoveCookie()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @todo Implement testCheckFontsize().
|
||||
*/
|
||||
public function testCheckFontsize()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testCheckUpload().
|
||||
*/
|
||||
public function testCheckUpload()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testCheckUploadSize().
|
||||
*/
|
||||
public function testCheckUploadSize()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testCheckIsHttps().
|
||||
*/
|
||||
public function testCheckIsHttps()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGetCookiePath().
|
||||
*/
|
||||
public function testGetCookiePath()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo finish implementing test + dependencies
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
$this->assertFalse($this->object->load());
|
||||
|
||||
$this->assertTrue($this->object->load('./libraries/config.default.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testLoadUserPreferences().
|
||||
*/
|
||||
public function testLoadUserPreferences()
|
||||
{
|
||||
$this->assertNull($this->object->loadUserPreferences());
|
||||
|
||||
// echo $GLOBALS['cfg']['ServerDefault'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testSetUserValue().
|
||||
*/
|
||||
public function testSetUserValue()
|
||||
{
|
||||
$this->object->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
|
||||
$this->object->setUserValue("TEST_COOKIE_USER_VAL",'','cfg_val_1');
|
||||
|
||||
// Remove the following lines when you implement this test.
|
||||
// $this->markTestIncomplete(
|
||||
// 'This test has not been implemented yet.'
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGetUserValue().
|
||||
*/
|
||||
public function testGetUserValue()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGetThemeUniqueValue().
|
||||
*/
|
||||
public function testGetThemeUniqueValue()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testCheckPermissions().
|
||||
*/
|
||||
public function testCheckPermissions()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @todo Implement testSetCookie().
|
||||
*/
|
||||
public function testSetCookie()
|
||||
{
|
||||
$this->assertFalse($this->object->setCookie('TEST_DEF_COOKIE', 'test_def_123', 'test_def_123'));
|
||||
|
||||
$this->assertTrue($this->object->setCookie('TEST_CONFIG_COOKIE', 'test_val_123', null, 3600));
|
||||
|
||||
$this->assertTrue($this->object->setCookie('TEST_CONFIG_COOKIE', '', 'default_val'));
|
||||
|
||||
$_COOKIE['TEST_MANUAL_COOKIE'] = 'some_test_val';
|
||||
$this->assertTrue($this->object->setCookie('TEST_MANUAL_COOKIE', 'other', 'other'));
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -3,24 +3,16 @@
|
||||
/**
|
||||
* Test for PMA_Message class
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/Extensions/OutputTestCase.php';
|
||||
|
||||
/**
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/Message.class.php';
|
||||
|
||||
/**
|
||||
* Test class PMA_Message.
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/core.lib.php';
|
||||
require_once 'libraries/Message.class.php';
|
||||
|
||||
class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
/**
|
||||
@ -99,17 +91,6 @@ class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
|
||||
$this->assertEquals($this->object, PMA_Message::rawError('test<&>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test rawWarning method
|
||||
*/
|
||||
public function testRawWarning()
|
||||
{
|
||||
$this->object = new PMA_Message('', PMA_Message::WARNING);
|
||||
$this->object->setMessage('test<&>');
|
||||
|
||||
$this->assertEquals($this->object, PMA_Message::rawWarning('test<&>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test rawNotice method
|
||||
*/
|
||||
@ -207,15 +188,6 @@ class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
|
||||
$this->assertEquals(array('*', PMA_Message::notice('test'), '', PMA_Message::notice('test')), $this->object->getAddedMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* testing add messages method
|
||||
*/
|
||||
public function testAddMessages()
|
||||
{
|
||||
$this->object->addMessages(array('test', PMA_Message::rawWarning('test')), '&');
|
||||
$this->assertEquals(array('&', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* testing add message method
|
||||
*/
|
||||
@ -225,8 +197,20 @@ class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
|
||||
$this->assertEquals(array(PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
|
||||
$this->object->addMessage('test');
|
||||
$this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
|
||||
$this->object->addMessage(PMA_Message::rawWarning('test'), '&');
|
||||
$this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* testing add messages method
|
||||
*/
|
||||
public function testAddMessages()
|
||||
{
|
||||
$messages = array();
|
||||
$messages[] = "Test1";
|
||||
$messages[] = new PMA_Message("PMA_Test2", PMA_Message::ERROR);
|
||||
$messages[] = "Test3";
|
||||
$this->object->addMessages($messages, '');
|
||||
|
||||
$this->assertEquals(array(PMA_Message::rawNotice('Test1'), PMA_Message::error("PMA_Test2"), PMA_Message::rawNotice('Test3')), $this->object->getAddedMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -384,5 +368,65 @@ class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
|
||||
$this->assertTrue($this->object->isDisplayed(true));
|
||||
$this->assertTrue($this->object->isDisplayed(false));
|
||||
}
|
||||
|
||||
public function providerAffectedRows(){
|
||||
return array(array(1, '<div class="notice"> 1 row affected.</div>'));
|
||||
return array(array(2, '<div class="notice"> 2 rows affected.</div>'));
|
||||
return array(array(50000000000000, '<div class="notice"> 50000000000000 rows affected.</div>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* affected_rows test
|
||||
*
|
||||
* @dataProvider providerAffectedRows
|
||||
*/
|
||||
public function testAffectedRows($rows, $output)
|
||||
{
|
||||
$this->object = new PMA_Message();
|
||||
$msg = $this->object->affected_rows($rows);
|
||||
echo $this->object->addMessage($msg);
|
||||
$this->expectOutputString($output);
|
||||
$this->object->display();
|
||||
}
|
||||
|
||||
public function providerInsertedRows(){
|
||||
return array(array(1, '<div class="notice"> 1 row inserted.</div>'));
|
||||
return array(array(2, '<div class="notice"> 2 rows inserted.</div>'));
|
||||
return array(array(50000000000000, '<div class="notice"> 50000000000000 rows inserted.</div>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* inserted_rows test
|
||||
*
|
||||
* @dataProvider providerInsertedRows
|
||||
*/
|
||||
public function testInsertedRows($rows, $output)
|
||||
{
|
||||
$this->object = new PMA_Message();
|
||||
$msg = $this->object->inserted_rows($rows);
|
||||
echo $this->object->addMessage($msg);
|
||||
$this->expectOutputString($output);
|
||||
$this->object->display();
|
||||
}
|
||||
|
||||
public function providerDeletedRows(){
|
||||
return array(array(1, '<div class="notice"> 1 row deleted.</div>'));
|
||||
return array(array(2, '<div class="notice"> 2 rows deleted.</div>'));
|
||||
return array(array(50000000000000, '<div class="notice"> 50000000000000 rows deleted.</div>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* deleted_rows test
|
||||
*
|
||||
* @dataProvider providerDeletedRows
|
||||
*/
|
||||
public function testDeletedRows($rows, $output)
|
||||
{
|
||||
$this->object = new PMA_Message();
|
||||
$msg = $this->object->deleted_rows($rows);
|
||||
echo $this->object->addMessage($msg);
|
||||
$this->expectOutputString($output);
|
||||
$this->object->display();
|
||||
}
|
||||
}
|
||||
?>
|
||||
206
test/classes/PMA_Theme_test.php
Normal file
206
test/classes/PMA_Theme_test.php
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
require_once 'libraries/Theme.class.php';
|
||||
|
||||
/**
|
||||
* Test class for PMA_Theme.
|
||||
* Generated by PHPUnit on 2011-07-18 at 03:19:13.
|
||||
*/
|
||||
class PMA_ThemeTest extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
/**
|
||||
* @var PMA_Theme
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new PMA_Theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
public function testCheckImgPathNotExisted()
|
||||
{
|
||||
$this->object->setPath('path/to/nowhere');
|
||||
$this->assertFalse($this->object->loadInfo());
|
||||
}
|
||||
|
||||
public function testCheckImgPathIncorrect()
|
||||
{
|
||||
$this->object->setPath('./test/classes/_data/incorrect_theme');
|
||||
$this->assertFalse($this->object->loadInfo(), 'Theme name is not properly set');
|
||||
}
|
||||
|
||||
public function testCheckImgPathFull()
|
||||
{
|
||||
$this->object->setPath('./test/classes/_data/gen_version_info');
|
||||
$this->assertTrue($this->object->loadInfo());
|
||||
$this->assertEquals('Test Theme', $this->object->getName());
|
||||
$this->assertEquals('2.0.3', $this->object->getVersion());
|
||||
}
|
||||
|
||||
public function testLoadInfo()
|
||||
{
|
||||
$this->object->setPath('./themes/original');
|
||||
$this->assertTrue($this->object->loadInfo());
|
||||
|
||||
$this->assertEquals(filemtime($this->object->getPath().'/info.inc.php'), $this->object->mtime_info);
|
||||
|
||||
$this->object->setPath('./themes/original');
|
||||
$this->object->mtime_info = filemtime($this->object->getPath().'/info.inc.php');
|
||||
$this->assertTrue($this->object->loadInfo());
|
||||
$this->assertEquals('Original', $this->object->getName());
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$newTheme = PMA_Theme::load('./themes/original');
|
||||
$this->assertNotNull($newTheme);
|
||||
}
|
||||
|
||||
public function testLoadNotExisted()
|
||||
{
|
||||
$this->assertFalse(PMA_Theme::load('/path/to/nowhere'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
*/
|
||||
public function testCheckImgPathBad()
|
||||
{
|
||||
$prevConfPath = $GLOBALS['cfg']['ThemePath'];
|
||||
$GLOBALS['cfg']['ThemePath'] = 'nowhere';
|
||||
$this->object->setPath('path/to/nowhere');
|
||||
|
||||
$this->object->checkImgPath();
|
||||
}
|
||||
|
||||
public function testCheckImgPath()
|
||||
{
|
||||
$this->object->setPath('./themes/original');
|
||||
$this->assertTrue($this->object->checkImgPath());
|
||||
}
|
||||
|
||||
public function testCheckImgPathGlobals()
|
||||
{
|
||||
$this->object->setPath('/this/is/wrong/path');
|
||||
$GLOBALS['cfg']['ThemePath'] = 'themes';
|
||||
$this->assertTrue($this->object->checkImgPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
*/
|
||||
public function testCheckImgPathGlobalsWrongPath()
|
||||
{
|
||||
$prevThemePath = $GLOBALS['cfg']['ThemePath'];
|
||||
$GLOBALS['cfg']['ThemePath'] = 'no_themes';
|
||||
|
||||
$this->object->setPath('/this/is/wrong/path');
|
||||
$this->object->checkImgPath();
|
||||
|
||||
$GLOBALS['cfg']['ThemePath'] = $prevThemePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PMA_Theme::setPath
|
||||
* @covers PMA_Theme::getPath
|
||||
*/
|
||||
public function testGetSetPath()
|
||||
{
|
||||
$this->assertEmpty($this->object->getPath());
|
||||
$this->object->setPath('./themes/original');
|
||||
|
||||
$this->assertEquals('./themes/original', $this->object->getPath());
|
||||
}
|
||||
|
||||
public function testGetLayoutFile()
|
||||
{
|
||||
$this->assertContains('layout.inc.php', $this->object->getLayoutFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testLoadInfo
|
||||
*/
|
||||
public function testGetSetCheckVersion()
|
||||
{
|
||||
$this->assertEquals('0.0.0.0', $this->object->getVersion(), 'Version 0.0.0.0 by default');
|
||||
|
||||
$this->object->setVersion("1.2.3.4");
|
||||
$this->assertEquals('1.2.3.4', $this->object->getVersion());
|
||||
|
||||
$this->assertFalse($this->object->checkVersion("0.0.1.1"));
|
||||
$this->assertTrue($this->object->checkVersion("2.0.1.1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PMA_Theme::getName
|
||||
* @covers PMA_Theme::setName
|
||||
*/
|
||||
public function testGetSetName()
|
||||
{
|
||||
$this->assertEmpty($this->object->getName(), 'Name is empty by default');
|
||||
$this->object->setName('New Theme Name');
|
||||
|
||||
$this->assertEquals('New Theme Name', $this->object->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PMA_Theme::getId
|
||||
* @covers PMA_Theme::setId
|
||||
*/
|
||||
public function testGetSetId()
|
||||
{
|
||||
$this->assertEmpty($this->object->getId(), 'ID is empty by default');
|
||||
$this->object->setId('NewID');
|
||||
|
||||
$this->assertEquals('NewID', $this->object->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PMA_Theme::getImgPath
|
||||
* @covers PMA_Theme::setImgPath
|
||||
*/
|
||||
public function testGetSetImgPath()
|
||||
{
|
||||
$this->assertEmpty($this->object->getImgPath(), 'ImgPath is empty by default');
|
||||
$this->object->setImgPath('/new/path');
|
||||
|
||||
$this->assertEquals('/new/path', $this->object->getImgPath());
|
||||
}
|
||||
|
||||
public function testLoadCssWrongType()
|
||||
{
|
||||
$type = 'middle';
|
||||
$this->assertFalse($this->object->loadCss($type));
|
||||
}
|
||||
|
||||
public function testLoadCssNotExisted()
|
||||
{
|
||||
$type = 'print';
|
||||
$this->assertFalse($this->object->loadCss($type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testPrintPreview().
|
||||
*/
|
||||
public function testPrintPreview()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
7
test/classes/_data/gen_version_info/info.inc.php
Normal file
7
test/classes/_data/gen_version_info/info.inc.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Full infrmation about theme, including $theme_generation and $theme_version
|
||||
*/
|
||||
$theme_name = 'Test Theme';
|
||||
$theme_generation = "2";
|
||||
$theme_version = "0.3";
|
||||
7
test/classes/_data/incorrect_theme/info.inc.php
Normal file
7
test/classes/_data/incorrect_theme/info.inc.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Incorrect theme information file.
|
||||
* Full name is not specified
|
||||
*/
|
||||
|
||||
$theme_full_version = '1.0';
|
||||
@ -6,23 +6,11 @@
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
define('PHPMYADMIN', 1);
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/sqlparser.data.php';
|
||||
require_once 'libraries/sqlparser.data.php';
|
||||
|
||||
/**
|
||||
* Test for sorting of the arrays
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_SQL_parser_data_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private function assertSorted($array)
|
||||
@ -1,33 +1,16 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for correctness of SQL parser
|
||||
* Tests for correctness of SQL parser
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
define('PHPMYADMIN', 1);
|
||||
define('TESTSUITE', 1);
|
||||
|
||||
function __($s) {
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/sqlparser.lib.php';
|
||||
require_once 'libraries/sqlparser.lib.php';
|
||||
|
||||
/**
|
||||
* Test for SQL parser
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_SQL_parser_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private function assertParser($sql, $expected, $error = '')
|
||||
@ -147,6 +130,7 @@ class PMA_SQL_parser_test extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testParse_4()
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = true;
|
||||
$this->assertParser('SELECT * from `aaa;', array (
|
||||
'raw' => 'SELECT * from `aaa`;',
|
||||
0 =>
|
||||
@ -6,11 +6,6 @@
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
$match = array();
|
||||
preg_match('@^([0-9]{1,2})(?:.([0-9]{1,2})(?:.([0-9]{1,2}))?)?@',
|
||||
phpversion(), $match);
|
||||
@ -33,11 +28,8 @@ if (isset($match) && ! empty($match[1])) {
|
||||
define('PMA_PHP_INT_VERSION', 0);
|
||||
}
|
||||
|
||||
require_once './libraries/string.lib.php';
|
||||
require_once 'libraries/string.lib.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_STR_sub_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMultiByte()
|
||||
@ -6,21 +6,11 @@
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/blowfish.php';
|
||||
require_once 'libraries/blowfish.php';
|
||||
|
||||
/**
|
||||
* Test java script escaping.
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_blowfish_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEncryptDecryptNumbers()
|
||||
@ -39,6 +29,7 @@ class PMA_blowfish_test extends PHPUnit_Framework_TestCase
|
||||
PMA_blowfish_decrypt(PMA_blowfish_encrypt($string, $secret), $secret));
|
||||
}
|
||||
|
||||
/* Due to differences in the initialization factor, these tests are not portable between systems.
|
||||
public function testEncrypt()
|
||||
{
|
||||
$secret = '$%ÄüfuDFRR';
|
||||
@ -54,6 +45,7 @@ class PMA_blowfish_test extends PHPUnit_Framework_TestCase
|
||||
$decrypted = '12345678';
|
||||
$this->assertEquals($decrypted, PMA_blowfish_decrypt($encrypted, $secret));
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
?>
|
||||
36
test/libraries/PMA_escapeJsString_test.php
Normal file
36
test/libraries/PMA_escapeJsString_test.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for javascript escaping.
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
|
||||
class PMA_escapeJsString_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* PMA_escapeJsString tests
|
||||
* @dataProvider escapeDataProvider
|
||||
*/
|
||||
public function testEscape($target, $source)
|
||||
{
|
||||
$this->assertEquals($target, PMA_escapeJsString($source));
|
||||
}
|
||||
|
||||
public function escapeDataProvider() {
|
||||
return array(
|
||||
array('\\\';', '\';'),
|
||||
array('\r\n\\\'<scrIpt></\' + \'script>', "\r\n'<scrIpt></sCRIPT>"),
|
||||
array('\\\';[XSS]', '\';[XSS]'),
|
||||
array('</\' + \'script></head><body>[HTML]', '</SCRIPT></head><body>[HTML]'),
|
||||
array('\"\\\'\\\\\\\'\"', '"\'\\\'"'),
|
||||
array("\\\\\'\'\'\'\'\'\'\'\'\'\'\'\\\\", "\\''''''''''''\\")
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -6,16 +6,12 @@
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once './libraries/core.lib.php';
|
||||
require_once './libraries/url_generating.lib.php';
|
||||
require_once 'libraries/core.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_generate_common_url_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
@ -6,15 +6,12 @@
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Include to test
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once './libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/core.lib.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_sanitize_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testXssInHref()
|
||||
@ -23,11 +20,13 @@ class PMA_sanitize_test extends PHPUnit_Framework_TestCase
|
||||
PMA_sanitize('[a@javascript:alert(\'XSS\');@target]link[/a]'));
|
||||
}
|
||||
|
||||
/*
|
||||
public function testLink()
|
||||
{
|
||||
$this->assertEquals('<a href="http://www.phpmyadmin.net/" target="target">link</a>',
|
||||
PMA_sanitize('[a@http://www.phpmyadmin.net/@target]link[/a]'));
|
||||
}
|
||||
*/
|
||||
|
||||
public function testHtmlTags()
|
||||
{
|
||||
@ -6,15 +6,11 @@
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once './libraries/transformations.lib.php';
|
||||
require_once 'libraries/transformations.lib.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_transformation_getOptions_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testDefault()
|
||||
72
test/libraries/common/PMA_ajaxResponse_test.php
Normal file
72
test/libraries/common/PMA_ajaxResponse_test.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_ajaxResponse from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_ajaxResponse_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/Message.class.php';
|
||||
|
||||
class PMA_ajaxResponse_test extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
function testAjaxResponseText()
|
||||
{
|
||||
$message = 'text';
|
||||
|
||||
$this->expectOutputString('{"success":true,"message":"' . $message . '"}');
|
||||
PMA_ajaxResponse($message);
|
||||
}
|
||||
|
||||
function testAjaxResponseTextWithExtra()
|
||||
{
|
||||
$message = 'text';
|
||||
$exra = array('str_val' => 'te\x/t"1', 'int_val' => 10);
|
||||
|
||||
$this->expectOutputString('{"success":true,"message":"' . $message . '","str_val":"te\\\\x\/t\"1","int_val":10}');
|
||||
PMA_ajaxResponse($message, true, $exra);
|
||||
}
|
||||
|
||||
function testAjaxResponseTextError()
|
||||
{
|
||||
$message = 'error_text';
|
||||
|
||||
$this->expectOutputString('{"success":false,"error":"' . $message . '"}');
|
||||
PMA_ajaxResponse($message, false);
|
||||
}
|
||||
|
||||
function testAjaxResponseMessage()
|
||||
{
|
||||
$message = new PMA_Message("Message Text", 1);
|
||||
|
||||
$this->expectOutputString('{"success":true,"message":"<div class=\"success\">Message Text<\/div>"}');
|
||||
PMA_ajaxResponse($message);
|
||||
}
|
||||
|
||||
function testAjaxResponseMessageWithExtra()
|
||||
{
|
||||
|
||||
$message = new PMA_Message("Message Text", 1);
|
||||
$exra = array('str_val' => 'te\x/t"1', 'int_val' => 10);
|
||||
|
||||
$this->expectOutputString('{"success":true,"message":"<div class=\"success\">Message Text<\/div>","str_val":"te\\\\x\/t\"1","int_val":10}');
|
||||
PMA_ajaxResponse($message, true, $exra);
|
||||
}
|
||||
|
||||
function testAjaxResponseMessageError()
|
||||
{
|
||||
|
||||
$message = new PMA_Message("Error Message Text", 1);
|
||||
|
||||
// TODO: class for output div should be "error"
|
||||
$this->expectOutputString('{"success":false,"error":"<div class=\"success\">Error Message Text<\/div>"}');
|
||||
PMA_ajaxResponse($message, false);
|
||||
}
|
||||
|
||||
}
|
||||
48
test/libraries/common/PMA_browseUploadFile_test.php
Normal file
48
test/libraries/common/PMA_browseUploadFile_test.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_browseUploadFile from common.lib
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_browseUploadFile_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_browseUploadFile_test extends PHPUnit_Extensions_OutputTestCase{
|
||||
|
||||
/*
|
||||
* Data provider for test
|
||||
*/
|
||||
public function dataProvider() {
|
||||
return array(
|
||||
array(10, __('B'), "10"),
|
||||
array(100, __('B'), "100"),
|
||||
array(1024, __('B'), "1,024"),
|
||||
array(102400, __('KiB'), "100"),
|
||||
array(10240000, __('MiB'), "10"),
|
||||
array(2147483648, __('MiB'), "2,048"),
|
||||
array(21474836480, __('GiB'), "20")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
* @return void
|
||||
*/
|
||||
function testBrowseUploadFile($size, $unit, $res){
|
||||
|
||||
$this->expectOutputString('<label for="radio_import_file">' . __("Browse your computer:") . '</label>'
|
||||
. '<div id="upload_form_status" style="display: none;"></div>'
|
||||
. '<div id="upload_form_status_info" style="display: none;"></div>'
|
||||
. '<input type="file" name="import_file" id="input_import_file" />'
|
||||
. "(" . __('Max: '). $res . $unit .")" . "\n"
|
||||
. '<input type="hidden" name="MAX_FILE_SIZE" value="' .$size . '" />' . "\n");
|
||||
|
||||
PMA_browseUploadFile($size);
|
||||
}
|
||||
}
|
||||
42
test/libraries/common/PMA_buildActionTitles_test.php
Normal file
42
test/libraries/common/PMA_buildActionTitles_test.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_buildActionTitles from common.lib
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_buildActionTitles_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_buildActionTitles_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
function testBuildActionTitles(){
|
||||
$titles = array();
|
||||
|
||||
$titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse'), true);
|
||||
$titles['NoBrowse'] = PMA_getIcon('bd_browse.png', __('Browse'), true);
|
||||
$titles['Search'] = PMA_getIcon('b_select.png', __('Search'), true);
|
||||
$titles['NoSearch'] = PMA_getIcon('bd_select.png', __('Search'), true);
|
||||
$titles['Insert'] = PMA_getIcon('b_insrow.png', __('Insert'), true);
|
||||
$titles['NoInsert'] = PMA_getIcon('bd_insrow.png', __('Insert'), true);
|
||||
$titles['Structure'] = PMA_getIcon('b_props.png', __('Structure'), true);
|
||||
$titles['Drop'] = PMA_getIcon('b_drop.png', __('Drop'), true);
|
||||
$titles['NoDrop'] = PMA_getIcon('bd_drop.png', __('Drop'), true);
|
||||
$titles['Empty'] = PMA_getIcon('b_empty.png', __('Empty'), true);
|
||||
$titles['NoEmpty'] = PMA_getIcon('bd_empty.png', __('Empty'), true);
|
||||
$titles['Edit'] = PMA_getIcon('b_edit.png', __('Edit'), true);
|
||||
$titles['NoEdit'] = PMA_getIcon('bd_edit.png', __('Edit'), true);
|
||||
$titles['Export'] = PMA_getIcon('b_export.png', __('Export'), true);
|
||||
$titles['NoExport'] = PMA_getIcon('bd_export.png', __('Export'), true);
|
||||
$titles['Execute'] = PMA_getIcon('b_nextpage.png', __('Execute'), true);
|
||||
$titles['NoExecute'] = PMA_getIcon('bd_nextpage.png', __('Execute'), true);
|
||||
|
||||
$this->assertEquals($titles, PMA_buildActionTitles());
|
||||
|
||||
}
|
||||
}
|
||||
@ -5,22 +5,14 @@
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_cache_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test cache.
|
||||
*
|
||||
*/
|
||||
class PMA_cache_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@ -99,5 +91,18 @@ class PMA_cache_test extends PHPUnit_Framework_TestCase
|
||||
PMA_cacheUnset('test_data_2', true);
|
||||
$this->assertArrayNotHasKey('test_data_2', $_SESSION['cache']['server_server']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing user cache
|
||||
*/
|
||||
public function testClearUserCache()
|
||||
{
|
||||
$GLOBALS['server'] = 'server';
|
||||
PMA_cacheSet('is_superuser', 'yes', true);
|
||||
$this->assertEquals('yes', $_SESSION['cache']['server_server']['is_superuser']);
|
||||
|
||||
PMA_clearUserCache();
|
||||
$this->assertArrayNotHasKey('is_superuser', $_SESSION['cache']['server_server']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
46
test/libraries/common/PMA_checkParameters_test.php
Normal file
46
test/libraries/common/PMA_checkParameters_test.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_checkParameters from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_checkParameters_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/Theme.class.php';
|
||||
|
||||
class PMA_checkParameters_test extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
function setup()
|
||||
{
|
||||
$GLOBALS['PMA_Config'] = new PMA_Config();
|
||||
$_SESSION['PMA_Theme'] = new PMA_Theme();
|
||||
}
|
||||
|
||||
function testCheckParameterMissing()
|
||||
{
|
||||
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
|
||||
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
|
||||
|
||||
$this->expectOutputRegex("/Missing parameter: field/" );
|
||||
|
||||
PMA_checkParameters(array('db', 'table', 'field'), false);
|
||||
}
|
||||
|
||||
function testCheckParameter()
|
||||
{
|
||||
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
|
||||
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
|
||||
$GLOBALS['table'] = "tblTable";
|
||||
$GLOBALS['field'] = "test_field";
|
||||
$GLOBALS['sql_query'] = "SELECT * FROM tblTable;";
|
||||
|
||||
$this->expectOutputString("");
|
||||
PMA_checkParameters(array('db', 'table', 'field', 'sql_query'), false);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_contains_nonprintable_ascii from common.lib
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_contains_nonprintable_ascii.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_contains_nonprintable_ascii extends PHPUnit_Framework_TestCase{
|
||||
|
||||
function dataProvider(){
|
||||
return array(
|
||||
array("normal string", 0),
|
||||
array("new\nline", 1),
|
||||
array("tab\tspace", 1),
|
||||
array("escape" . chr(27) . "char", 1),
|
||||
array("chars%$\r\n",1),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
function testContainsNonPrintableAscii($str, $res){
|
||||
$this->assertEquals($res,PMA_contains_nonprintable_ascii($str));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// PMA_contains_nonprintable_ascii
|
||||
33
test/libraries/common/PMA_convert_bit_default_value_test.php
Normal file
33
test/libraries/common/PMA_convert_bit_default_value_test.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_convert_bit_default_value from common.lib
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_convert_bit_default_value_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_convert_bit_default_value_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
function dataProvider(){
|
||||
return array(
|
||||
array("b'",""),
|
||||
array("b'01'","01"),
|
||||
array("b'010111010'","010111010")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
function testConvert_bit_default_value_test($bit, $val){
|
||||
$this->assertEquals($val, PMA_convert_bit_default_value($bit));
|
||||
|
||||
}
|
||||
}
|
||||
41
test/libraries/common/PMA_displayMaximumUploadSize_test.php
Normal file
41
test/libraries/common/PMA_displayMaximumUploadSize_test.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_displayMaximumUploadSize from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_displayMaximumUploadSize_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_displayMaximumUploadSize_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
/*
|
||||
* Data provider for test
|
||||
*/
|
||||
public function dataProvider() {
|
||||
return array(
|
||||
array(10, __('B'), "10"),
|
||||
array(100, __('B'), "100"),
|
||||
array(1024, __('B'), "1,024"),
|
||||
array(102400, __('KiB'), "100"),
|
||||
array(10240000, __('MiB'), "10"),
|
||||
array(2147483648, __('MiB'), "2,048"),
|
||||
array(21474836480, __('GiB'), "20")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
* @return void
|
||||
*/
|
||||
function testMaximumUploadSize($size, $unit, $res){
|
||||
$this->assertEquals("(" . __('Max: '). $res . $unit .")", PMA_displayMaximumUploadSize($size));
|
||||
|
||||
}
|
||||
}
|
||||
55
test/libraries/common/PMA_display_html_checkbox_test.php
Normal file
55
test/libraries/common/PMA_display_html_checkbox_test.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_display_html_checkbox from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_display_html_checkbox_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_display_html_checkbox_test extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
function testDisplayHtmlCheckbox()
|
||||
{
|
||||
$name = "test_display_html_checkbox";
|
||||
$label = "text_label_for_checkbox";
|
||||
|
||||
$this->expectOutputString('<input type="checkbox" name="' . $name . '" id="' . $name . '" /><label for="' . $name . '">' . $label . '</label>');
|
||||
PMA_display_html_checkbox($name,$label,false,false);
|
||||
}
|
||||
|
||||
function testDisplayHtmlCheckboxChecked()
|
||||
{
|
||||
$name = "test_display_html_checkbox";
|
||||
$label = "text_label_for_checkbox";
|
||||
|
||||
$this->expectOutputString('<input type="checkbox" name="' . $name . '" id="' . $name . '" checked="checked" /><label for="' . $name . '">' . $label . '</label>');
|
||||
PMA_display_html_checkbox($name,$label,true,false);
|
||||
}
|
||||
|
||||
function testDisplayHtmlCheckboxOnclick()
|
||||
{
|
||||
$name = "test_display_html_checkbox";
|
||||
$label = "text_label_for_checkbox";
|
||||
|
||||
$this->expectOutputString('<input type="checkbox" name="' . $name . '" id="' . $name . '" onclick="this.form.submit();" /><label for="' . $name . '">' . $label . '</label>');
|
||||
PMA_display_html_checkbox($name,$label,false,true);
|
||||
}
|
||||
|
||||
function testDisplayHtmlCheckboxCheckedOnclick()
|
||||
{
|
||||
$name = "test_display_html_checkbox";
|
||||
$label = "text_label_for_checkbox";
|
||||
|
||||
$this->expectOutputString('<input type="checkbox" name="' . $name . '" id="' . $name . '" checked="checked" onclick="this.form.submit();" /><label for="' . $name . '">' . $label . '</label>');
|
||||
PMA_display_html_checkbox($name,$label,true,true);
|
||||
}
|
||||
}
|
||||
|
||||
//PMA_display_html_checkbox
|
||||
188
test/libraries/common/PMA_display_html_radio_test.php
Normal file
188
test/libraries/common/PMA_display_html_radio_test.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_display_html_radio from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_display_html_radio_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_display_html_radio_test extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
function testDisplayHtmlRadioEmpty()
|
||||
{
|
||||
$name = "test_display_radio";
|
||||
$choices = array();
|
||||
|
||||
$this->expectOutputString("");
|
||||
PMA_display_html_radio($name,$choices);
|
||||
}
|
||||
|
||||
function testDisplayHtmlRadio()
|
||||
{
|
||||
$name = "test_display_radio";
|
||||
$choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
|
||||
|
||||
$out = "";
|
||||
foreach ($choices as $choice_value => $choice_label) {
|
||||
$html_field_id = $name . '_' . $choice_value;
|
||||
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
|
||||
$out .= ' />' . "\n";
|
||||
$out .= '<label for="' . $html_field_id . '">' . $choice_label . '</label>';
|
||||
$out .= '<br />';
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
$this->expectOutputString($out);
|
||||
PMA_display_html_radio($name,$choices);
|
||||
}
|
||||
|
||||
function testDisplayHtmlRadioWithChecked()
|
||||
{
|
||||
$name = "test_display_radio";
|
||||
$choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
|
||||
$checked_choice = "value_2";
|
||||
|
||||
$out = "";
|
||||
foreach ($choices as $choice_value => $choice_label) {
|
||||
$html_field_id = $name . '_' . $choice_value;
|
||||
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
|
||||
if ($choice_value == $checked_choice) {
|
||||
$out .= ' checked="checked"';
|
||||
}
|
||||
$out .= ' />' . "\n";
|
||||
$out .= '<label for="' . $html_field_id . '">' . $choice_label . '</label>';
|
||||
$out .= '<br />';
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
$this->expectOutputString($out);
|
||||
PMA_display_html_radio($name,$choices,$checked_choice);
|
||||
}
|
||||
|
||||
function testDisplayHtmlRadioWithCheckedWithClass()
|
||||
{
|
||||
$name = "test_display_radio";
|
||||
$choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
|
||||
$checked_choice = "value_2";
|
||||
$class = "test_class";
|
||||
|
||||
$out = "";
|
||||
foreach ($choices as $choice_value => $choice_label) {
|
||||
$html_field_id = $name . '_' . $choice_value;
|
||||
$out .= '<div class="' . $class . '">';
|
||||
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
|
||||
if ($choice_value == $checked_choice) {
|
||||
$out .= ' checked="checked"';
|
||||
}
|
||||
$out .= ' />' . "\n";
|
||||
$out .= '<label for="' . $html_field_id . '">' . $choice_label . '</label>';
|
||||
$out .= '<br />';
|
||||
$out .= '</div>';
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
$this->expectOutputString($out);
|
||||
PMA_display_html_radio($name,$choices,$checked_choice,true,false,$class);
|
||||
}
|
||||
|
||||
function testDisplayHtmlRadioWithoutBR()
|
||||
{
|
||||
$name = "test_display_radio";
|
||||
$choices = array('value_1'=>'choice_1', 'value&_<2>'=>'choice_2');
|
||||
$checked_choice = "choice_2";
|
||||
|
||||
$out = "";
|
||||
foreach ($choices as $choice_value => $choice_label) {
|
||||
$html_field_id = $name . '_' . $choice_value;
|
||||
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
|
||||
if ($choice_value == $checked_choice) {
|
||||
$out .= ' checked="checked"';
|
||||
}
|
||||
$out .= ' />' . "\n";
|
||||
$out .= '<label for="' . $html_field_id . '">' . $choice_label . '</label>';
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
$this->expectOutputString($out);
|
||||
PMA_display_html_radio($name,$choices,$checked_choice,false);
|
||||
}
|
||||
|
||||
function testDisplayHtmlRadioEscapeLabelEscapeLabel()
|
||||
{
|
||||
$name = "test_display_radio";
|
||||
$choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_<2>');
|
||||
$checked_choice = "value_2";
|
||||
|
||||
$out = "";
|
||||
foreach ($choices as $choice_value => $choice_label) {
|
||||
$html_field_id = $name . '_' . $choice_value;
|
||||
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
|
||||
if ($choice_value == $checked_choice) {
|
||||
$out .= ' checked="checked"';
|
||||
}
|
||||
$out .= ' />' . "\n";
|
||||
$out .= '<label for="' . $html_field_id . '">' . htmlspecialchars($choice_label) . '</label>';
|
||||
$out .= '<br />';
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
$this->expectOutputString($out);
|
||||
PMA_display_html_radio($name,$choices,$checked_choice,true,true);
|
||||
}
|
||||
|
||||
function testDisplayHtmlRadioEscapeLabelNotEscapeLabel()
|
||||
{
|
||||
$name = "test_display_radio";
|
||||
$choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_<2>');
|
||||
$checked_choice = "value_2";
|
||||
|
||||
$out = "";
|
||||
foreach ($choices as $choice_value => $choice_label) {
|
||||
$html_field_id = $name . '_' . $choice_value;
|
||||
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
|
||||
if ($choice_value == $checked_choice) {
|
||||
$out .= ' checked="checked"';
|
||||
}
|
||||
$out .= ' />' . "\n";
|
||||
$out .= '<label for="' . $html_field_id . '">' . $choice_label . '</label>';
|
||||
$out .= '<br />';
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
$this->expectOutputString($out);
|
||||
PMA_display_html_radio($name,$choices,$checked_choice,true,false);
|
||||
}
|
||||
|
||||
function testDisplayHtmlRadioEscapeLabelEscapeLabelWithClass()
|
||||
{
|
||||
$name = "test_display_radio";
|
||||
$choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_<2>');
|
||||
$checked_choice = "value_2";
|
||||
$class = "test_class";
|
||||
|
||||
$out = "";
|
||||
foreach ($choices as $choice_value => $choice_label) {
|
||||
$html_field_id = $name . '_' . $choice_value;
|
||||
$out .= '<div class="' . $class . '">';
|
||||
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
|
||||
if ($choice_value == $checked_choice) {
|
||||
$out .= ' checked="checked"';
|
||||
}
|
||||
$out .= ' />' . "\n";
|
||||
$out .= '<label for="' . $html_field_id . '">' . htmlspecialchars($choice_label) . '</label>';
|
||||
$out .= '<br />';
|
||||
$out .= '</div>';
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
$this->expectOutputString($out);
|
||||
PMA_display_html_radio($name,$choices,$checked_choice,true,true,$class);
|
||||
}
|
||||
}
|
||||
@ -4,22 +4,15 @@
|
||||
* Test for MySQL Wildcards escaping/unescaping
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_escapeMySqlWildcards_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test MySQL escaping.
|
||||
*
|
||||
*/
|
||||
class PMA_escapeMySqlWildcards_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_extractValueFromFormattedSize from common.lib
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_extractValueFromFormattedSize_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_extractValueFromFormattedSize_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
function testExtractValueFromFormattedSizeNoFormat(){
|
||||
|
||||
$this->assertEquals(-1,PMA_extractValueFromFormattedSize(100));
|
||||
}
|
||||
|
||||
function testExtractValueFromFormattedSizeGB(){
|
||||
|
||||
$this->assertEquals(10737418240,PMA_extractValueFromFormattedSize("10GB"));
|
||||
}
|
||||
|
||||
function testExtractValueFromFormattedSizeMB(){
|
||||
|
||||
$this->assertEquals(15728640,PMA_extractValueFromFormattedSize("15MB"));
|
||||
}
|
||||
|
||||
function testExtractValueFromFormattedSizeK(){
|
||||
|
||||
$this->assertEquals(262144,PMA_extractValueFromFormattedSize("256K"));
|
||||
}
|
||||
}
|
||||
@ -4,28 +4,20 @@
|
||||
* Test for supporting foreign key
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_foreignKeySupported_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test supported foreign key.
|
||||
*
|
||||
*/
|
||||
class PMA_foreignKeySupported_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* data provider for foreign key supported test
|
||||
*/
|
||||
|
||||
public function foreignkeySupportedDataProvider() {
|
||||
return array(
|
||||
array('MyISAM', false),
|
||||
@ -38,7 +30,6 @@ class PMA_foreignKeySupported_test extends PHPUnit_Framework_TestCase
|
||||
* foreign key supported test
|
||||
* @dataProvider foreignkeySupportedDataProvider
|
||||
*/
|
||||
|
||||
public function testForeignkeySupported($a, $e) {
|
||||
$this->assertEquals($e, PMA_foreignkey_supported($a));
|
||||
}
|
||||
@ -5,35 +5,24 @@
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_formatNumberByteDown_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test formating number and byte.
|
||||
*
|
||||
*/
|
||||
class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* temporary variable for globals array
|
||||
*/
|
||||
|
||||
protected $tmpGlobals;
|
||||
|
||||
/**
|
||||
* temporary variable for session array
|
||||
*/
|
||||
|
||||
protected $tmpSession;
|
||||
|
||||
/**
|
||||
@ -62,14 +51,14 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function formatNumberDataProvider() {
|
||||
return array(
|
||||
array(10, 2, 2, '10,00 '),
|
||||
array(10, 2, 2, '10 '),
|
||||
array(100, 2, 0, '100 '),
|
||||
array(100, 2, 2, '0,10 k'),
|
||||
array(-1000.454, 4, 2, '-1 000,45 '),
|
||||
array(0.00003, 3, 2, '0,03 m'),
|
||||
array(0.003, 3, 3, '0,003 '),
|
||||
array(-0.003, 6, 0, '-3 m'),
|
||||
array(100.98, 0, 2, '100,98')
|
||||
array(100, 2, 2, '100 '),
|
||||
array(-1000.454, 4, 2, '-1,000.45 '),
|
||||
array(0.00003, 3, 2, '30 µ'),
|
||||
array(0.003, 3, 3, '3 m'),
|
||||
array(-0.003, 6, 0, '-3,000 µ'),
|
||||
array(100.98, 0, 2, '100.98')
|
||||
);
|
||||
}
|
||||
|
||||
@ -77,24 +66,22 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
|
||||
* format number test, globals are defined
|
||||
* @dataProvider formatNumberDataProvider
|
||||
*/
|
||||
|
||||
public function testFormatNumber($a, $b, $c, $e) {
|
||||
$this->assertEquals($e, (string)PMA_formatNumber($a, $b, $c, false));
|
||||
public function testFormatNumber($a, $b, $c, $d) {
|
||||
$this->assertEquals($d, (string)PMA_formatNumber($a, $b, $c, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* format byte down data provider
|
||||
*/
|
||||
|
||||
public function formatByteDownDataProvider() {
|
||||
return array(
|
||||
array(10, 2, 2, array('10', 'B')),
|
||||
array(100, 2, 0, array('0', 'KB')),
|
||||
array(100, 3, 0, array('100', 'B')),
|
||||
array(100, 2, 2, array('0,10', 'KB')),
|
||||
array(1034, 3, 2, array('1,01', 'KB')),
|
||||
array(100233, 3, 3, array('97,884', 'KB')),
|
||||
array(2206451, 1, 2, array('2,10', 'MB'))
|
||||
array(10, 2, 2, array('10', __('B'))),
|
||||
array(100, 2, 0, array('0', __('KiB'))),
|
||||
array(100, 3, 0, array('100', __('B'))),
|
||||
array(100, 2, 2, array('0.10', __('KiB'))),
|
||||
array(1034, 3, 2, array('1.01', __('KiB'))),
|
||||
array(100233, 3, 3, array('97.884', __('KiB'))),
|
||||
array(2206451, 1, 2, array('2.10', __('MiB')))
|
||||
);
|
||||
}
|
||||
|
||||
@ -102,7 +89,6 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
|
||||
* format byte test, globals are defined
|
||||
* @dataProvider formatByteDownDataProvider
|
||||
*/
|
||||
|
||||
public function testFormatByteDown($a, $b, $c, $e) {
|
||||
$result = PMA_formatByteDown($a, $b, $c);
|
||||
$result[0] = trim($result[0]);
|
||||
744
test/libraries/common/PMA_formatSql_test.php
Normal file
744
test/libraries/common/PMA_formatSql_test.php
Normal file
@ -0,0 +1,744 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_formatSql from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_formatSql_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/sqlparser.lib.php';
|
||||
|
||||
class PMA_formatSql_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
/**
|
||||
* temporary variable for globals array
|
||||
*/
|
||||
protected $tmpCfg;
|
||||
|
||||
/**
|
||||
* temporary variable for session array
|
||||
*/
|
||||
protected $tmpSession;
|
||||
|
||||
/**
|
||||
* storing globals and session
|
||||
*/
|
||||
public function setUp() {
|
||||
global $cfg;
|
||||
$this->tmpCfg = $cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* recovering globals and session
|
||||
*/
|
||||
public function tearDown() {
|
||||
global $cfg;
|
||||
$cfg = $this->tmpCfg;
|
||||
}
|
||||
|
||||
function testFormatSQLNotArray(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'html';
|
||||
$sql = "SELECT * FROM tTable;";
|
||||
$this->assertEquals("<pre>\n$sql\n</pre>",PMA_formatSql($sql));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeHtml_1(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'html';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$sql = array (
|
||||
'raw' => 'SELECT 1;',
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'digit_integer',
|
||||
'data' => '1',
|
||||
'pos' => 8,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 3,
|
||||
);
|
||||
$unparsed = "SELECT 1;";
|
||||
$expected = '<span class="syntax"><span class="inner_sql"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span></a> <span class="syntax_digit syntax_digit_integer">1</span> <span class="syntax_punct syntax_punct_queryend">;</span><br /><br /></span></span>';
|
||||
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeHtml_2(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'html';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$unparsed = "SELECT * from `tTable`;";
|
||||
$sql = array (
|
||||
'raw' => $unparsed,
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '*',
|
||||
'pos' => 0,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'from',
|
||||
'pos' => 13,
|
||||
'forbidden' => true,
|
||||
),
|
||||
3 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable`',
|
||||
'pos' => 0,
|
||||
),
|
||||
4 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 5,
|
||||
);
|
||||
$expected = '<span class="syntax"><span class="inner_sql"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span></a> <span class="syntax_punct">*</span> <br /><span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_quote syntax_quote_backtick">`tTable`</span> <span class="syntax_punct syntax_punct_queryend">;</span><br /><br /></span></span>';
|
||||
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeHtml_3(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'html';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;';
|
||||
$sql = array (
|
||||
'raw' => $unparsed,
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '*',
|
||||
'pos' => 0,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'FROM',
|
||||
'pos' => 13,
|
||||
'forbidden' => true,
|
||||
),
|
||||
3 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable_A`',
|
||||
'pos' => 0,
|
||||
),
|
||||
4 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'A',
|
||||
'pos' => 26,
|
||||
'forbidden' => false,
|
||||
),
|
||||
5 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'INNER',
|
||||
'pos' => 32,
|
||||
'forbidden' => true,
|
||||
),
|
||||
6 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'JOIN',
|
||||
'pos' => 37,
|
||||
'forbidden' => true,
|
||||
),
|
||||
7 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable_B`',
|
||||
'pos' => 0,
|
||||
),
|
||||
8 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'B',
|
||||
'pos' => 50,
|
||||
'forbidden' => false,
|
||||
),
|
||||
9 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'ON',
|
||||
'pos' => 53,
|
||||
'forbidden' => true,
|
||||
),
|
||||
10 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'B',
|
||||
'pos' => 55,
|
||||
'forbidden' => false,
|
||||
),
|
||||
11 =>
|
||||
array (
|
||||
'type' => 'punct_qualifier',
|
||||
'data' => '.',
|
||||
'pos' => 0,
|
||||
),
|
||||
12 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'ID',
|
||||
'pos' => 58,
|
||||
'forbidden' => false,
|
||||
),
|
||||
13 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '=',
|
||||
'pos' => 0,
|
||||
),
|
||||
14 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'A',
|
||||
'pos' => 62,
|
||||
'forbidden' => false,
|
||||
),
|
||||
15 =>
|
||||
array (
|
||||
'type' => 'punct_qualifier',
|
||||
'data' => '.',
|
||||
'pos' => 0,
|
||||
),
|
||||
16 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'ID',
|
||||
'pos' => 65,
|
||||
'forbidden' => false,
|
||||
),
|
||||
17 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 18,
|
||||
);
|
||||
|
||||
$expected = '<span class="syntax"><span class="inner_sql"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span></a> <span class="syntax_punct">*</span> <br /><span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_quote syntax_quote_backtick">`tTable_A`</span> <span class="syntax_alpha syntax_alpha_identifier">A</span><br /><span class="syntax_alpha syntax_alpha_reservedWord">INNER</span> <span class="syntax_alpha syntax_alpha_reservedWord">JOIN</span> <span class="syntax_quote syntax_quote_backtick">`tTable_B`</span> <span class="syntax_alpha syntax_alpha_identifier">B</span> <span class="syntax_alpha syntax_alpha_reservedWord">ON</span> <span class="syntax_alpha syntax_alpha_identifier">B</span><span class="syntax_punct syntax_punct_qualifier">.</span><span class="syntax_alpha syntax_alpha_identifier">ID</span> <span class="syntax_punct">=</span></a> <span class="syntax_alpha syntax_alpha_identifier">A</span><span class="syntax_punct syntax_punct_qualifier">.</span><span class="syntax_alpha syntax_alpha_identifier">ID</span><span class="syntax_punct syntax_punct_queryend">;</span><br /><br /></span></span>';
|
||||
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeText_1(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'text';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$sql = array (
|
||||
'raw' => 'SELECT 1;',
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'digit_integer',
|
||||
'data' => '1',
|
||||
'pos' => 8,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 3,
|
||||
);
|
||||
$unparsed = "SELECT 1;";
|
||||
$expected = '<span class="inner_sql">SELECT</a> 1 ;<br /><br /></span>';
|
||||
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeText_2(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'text';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$unparsed = "SELECT * from `tTable`;";
|
||||
$sql = array (
|
||||
'raw' => $unparsed,
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '*',
|
||||
'pos' => 0,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'from',
|
||||
'pos' => 13,
|
||||
'forbidden' => true,
|
||||
),
|
||||
3 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable`',
|
||||
'pos' => 0,
|
||||
),
|
||||
4 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 5,
|
||||
);
|
||||
$expected = '<span class="inner_sql">SELECT</a> * <br />FROM `tTable` ;<br /><br /></span>';
|
||||
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeText_3(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'text';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;';
|
||||
$sql = array (
|
||||
'raw' => $unparsed,
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '*',
|
||||
'pos' => 0,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'FROM',
|
||||
'pos' => 13,
|
||||
'forbidden' => true,
|
||||
),
|
||||
3 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable_A`',
|
||||
'pos' => 0,
|
||||
),
|
||||
4 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'A',
|
||||
'pos' => 26,
|
||||
'forbidden' => false,
|
||||
),
|
||||
5 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'INNER',
|
||||
'pos' => 32,
|
||||
'forbidden' => true,
|
||||
),
|
||||
6 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'JOIN',
|
||||
'pos' => 37,
|
||||
'forbidden' => true,
|
||||
),
|
||||
7 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable_B`',
|
||||
'pos' => 0,
|
||||
),
|
||||
8 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'B',
|
||||
'pos' => 50,
|
||||
'forbidden' => false,
|
||||
),
|
||||
9 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'ON',
|
||||
'pos' => 53,
|
||||
'forbidden' => true,
|
||||
),
|
||||
10 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'B',
|
||||
'pos' => 55,
|
||||
'forbidden' => false,
|
||||
),
|
||||
11 =>
|
||||
array (
|
||||
'type' => 'punct_qualifier',
|
||||
'data' => '.',
|
||||
'pos' => 0,
|
||||
),
|
||||
12 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'ID',
|
||||
'pos' => 58,
|
||||
'forbidden' => false,
|
||||
),
|
||||
13 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '=',
|
||||
'pos' => 0,
|
||||
),
|
||||
14 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'A',
|
||||
'pos' => 62,
|
||||
'forbidden' => false,
|
||||
),
|
||||
15 =>
|
||||
array (
|
||||
'type' => 'punct_qualifier',
|
||||
'data' => '.',
|
||||
'pos' => 0,
|
||||
),
|
||||
16 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'ID',
|
||||
'pos' => 65,
|
||||
'forbidden' => false,
|
||||
),
|
||||
17 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 18,
|
||||
);
|
||||
$expected = '<span class="inner_sql">SELECT</a> * <br />FROM `tTable_A` A<br />INNER JOIN `tTable_B` B ON B.ID =</a> A.ID;<br /><br /></span>';
|
||||
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeNone_1(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'none';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$sql = array (
|
||||
'raw' => 'SELECT 1;',
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'digit_integer',
|
||||
'data' => '1',
|
||||
'pos' => 8,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 3,
|
||||
);
|
||||
$unparsed = "SELECT 1;";
|
||||
|
||||
$expected = "<span class=\"inner_sql\"><pre>\nSELECT 1;\n</pre></span>";
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
|
||||
$expected = "SELECT 1;";
|
||||
$this->assertEquals($expected,PMA_formatSql($sql));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeNone_2(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'none';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$unparsed = "SELECT * from `tTable`;";
|
||||
$sql = array (
|
||||
'raw' => $unparsed,
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '*',
|
||||
'pos' => 0,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'from',
|
||||
'pos' => 13,
|
||||
'forbidden' => true,
|
||||
),
|
||||
3 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable`',
|
||||
'pos' => 0,
|
||||
),
|
||||
4 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 5,
|
||||
);
|
||||
|
||||
$expected = "<span class=\"inner_sql\"><pre>\nSELECT * from `tTable`;\n</pre></span>";
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
|
||||
$expected = "SELECT * from `tTable`;";
|
||||
$this->assertEquals($expected,PMA_formatSql($sql));
|
||||
}
|
||||
|
||||
function testFormatSQLfmTypeNone_3(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = 'none';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
|
||||
$unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;';
|
||||
$sql = array (
|
||||
'raw' => $unparsed,
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '*',
|
||||
'pos' => 0,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'FROM',
|
||||
'pos' => 13,
|
||||
'forbidden' => true,
|
||||
),
|
||||
3 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable_A`',
|
||||
'pos' => 0,
|
||||
),
|
||||
4 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'A',
|
||||
'pos' => 26,
|
||||
'forbidden' => false,
|
||||
),
|
||||
5 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'INNER',
|
||||
'pos' => 32,
|
||||
'forbidden' => true,
|
||||
),
|
||||
6 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'JOIN',
|
||||
'pos' => 37,
|
||||
'forbidden' => true,
|
||||
),
|
||||
7 =>
|
||||
array (
|
||||
'type' => 'quote_backtick',
|
||||
'data' => '`tTable_B`',
|
||||
'pos' => 0,
|
||||
),
|
||||
8 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'B',
|
||||
'pos' => 50,
|
||||
'forbidden' => false,
|
||||
),
|
||||
9 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'ON',
|
||||
'pos' => 53,
|
||||
'forbidden' => true,
|
||||
),
|
||||
10 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'B',
|
||||
'pos' => 55,
|
||||
'forbidden' => false,
|
||||
),
|
||||
11 =>
|
||||
array (
|
||||
'type' => 'punct_qualifier',
|
||||
'data' => '.',
|
||||
'pos' => 0,
|
||||
),
|
||||
12 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'ID',
|
||||
'pos' => 58,
|
||||
'forbidden' => false,
|
||||
),
|
||||
13 =>
|
||||
array (
|
||||
'type' => 'punct',
|
||||
'data' => '=',
|
||||
'pos' => 0,
|
||||
),
|
||||
14 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'A',
|
||||
'pos' => 62,
|
||||
'forbidden' => false,
|
||||
),
|
||||
15 =>
|
||||
array (
|
||||
'type' => 'punct_qualifier',
|
||||
'data' => '.',
|
||||
'pos' => 0,
|
||||
),
|
||||
16 =>
|
||||
array (
|
||||
'type' => 'alpha_identifier',
|
||||
'data' => 'ID',
|
||||
'pos' => 65,
|
||||
'forbidden' => false,
|
||||
),
|
||||
17 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 18,
|
||||
);
|
||||
|
||||
$expected = "<span class=\"inner_sql\"><pre>\nSELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;\n</pre></span>";
|
||||
$this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
|
||||
|
||||
$expected = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;';
|
||||
$this->assertEquals($expected,PMA_formatSql($sql));
|
||||
}
|
||||
|
||||
function testFormatSQLWithoutType(){
|
||||
global $cfg;
|
||||
$cfg['SQP']['fmtType'] = '';
|
||||
$cfg['MySQLManualType'] = 'viewable';
|
||||
$sql = array (
|
||||
'raw' => 'SELECT 1;',
|
||||
0 =>
|
||||
array (
|
||||
'type' => 'alpha_reservedWord',
|
||||
'data' => 'SELECT',
|
||||
'pos' => 6,
|
||||
'forbidden' => true,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'type' => 'digit_integer',
|
||||
'data' => '1',
|
||||
'pos' => 8,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'type' => 'punct_queryend',
|
||||
'data' => ';',
|
||||
'pos' => 0,
|
||||
),
|
||||
'len' => 3,
|
||||
);
|
||||
$this->assertEmpty(PMA_formatSql($sql));
|
||||
}
|
||||
|
||||
function testFormatSQLError(){
|
||||
global $SQP_errorString;
|
||||
$SQP_errorString = true;
|
||||
$sql = array("raw" => "& \" < >");
|
||||
$this->assertEquals("& " < >",PMA_formatSql($sql));
|
||||
$SQP_errorString = false;
|
||||
}
|
||||
}
|
||||
40
test/libraries/common/PMA_generateHiddenMaxFileSize_test.php
Normal file
40
test/libraries/common/PMA_generateHiddenMaxFileSize_test.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_generateHiddenMaxFileSize from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_generateHiddenMaxFileSize_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_generateHiddenMaxFileSize_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
/*
|
||||
* Data provider for test
|
||||
*/
|
||||
public function dataProvider() {
|
||||
return array(
|
||||
array(10),
|
||||
array("100"),
|
||||
array(1024),
|
||||
array("1024Mb"),
|
||||
array(2147483648),
|
||||
array("some_string")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
* @return void
|
||||
*/
|
||||
function test_generateHiddenMaxFileSize($size){
|
||||
$this->assertEquals(PMA_generateHiddenMaxFileSize($size),
|
||||
'<input type="hidden" name="MAX_FILE_SIZE" value="' .$size . '" />');
|
||||
}
|
||||
}
|
||||
69
test/libraries/common/PMA_generate_html_dropdown_test.php
Normal file
69
test/libraries/common/PMA_generate_html_dropdown_test.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_generate_html_dropdown_test from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_display_html_checkbox_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_generate_html_dropdown_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testGenerateHtmlDropdownEmpty()
|
||||
{
|
||||
$name = "test_dropdown_name";
|
||||
$choices = array();
|
||||
$active_choice = null;
|
||||
$id = "test_<dropdown>_name";
|
||||
|
||||
$result = '<select name="' . htmlspecialchars($name) . '" id="' . htmlspecialchars($id) . '"></select>';
|
||||
|
||||
$this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id));
|
||||
}
|
||||
|
||||
function testGenerateHtmlDropdown()
|
||||
{
|
||||
$name = "&test_dropdown_name";
|
||||
$choices = array("value_1" => "label_1", "value&_2\"" => "label_2");
|
||||
$active_choice = null;
|
||||
$id = "test_<dropdown>_name";
|
||||
|
||||
$result = '<select name="' . htmlspecialchars($name) . '" id="' . htmlspecialchars($id) . '">';
|
||||
foreach ($choices as $one_choice_value => $one_choice_label) {
|
||||
$result .= '<option value="' . htmlspecialchars($one_choice_value) . '"';
|
||||
if ($one_choice_value == $active_choice) {
|
||||
$result .= ' selected="selected"';
|
||||
}
|
||||
$result .= '>' . htmlspecialchars($one_choice_label) . '</option>';
|
||||
}
|
||||
$result .= '</select>';
|
||||
|
||||
$this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id));
|
||||
}
|
||||
|
||||
function testGenerateHtmlDropdownWithActive()
|
||||
{
|
||||
$name = "&test_dropdown_name";
|
||||
$choices = array("value_1" => "label_1", "value&_2\"" => "label_2");
|
||||
$active_choice = "value&_2\"";
|
||||
$id = "test_<dropdown>_name";
|
||||
|
||||
$result = '<select name="' . htmlspecialchars($name) . '" id="' . htmlspecialchars($id) . '">';
|
||||
foreach ($choices as $one_choice_value => $one_choice_label) {
|
||||
$result .= '<option value="' . htmlspecialchars($one_choice_value) . '"';
|
||||
if ($one_choice_value == $active_choice) {
|
||||
$result .= ' selected="selected"';
|
||||
}
|
||||
$result .= '>' . htmlspecialchars($one_choice_label) . '</option>';
|
||||
}
|
||||
$result .= '</select>';
|
||||
|
||||
$this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id));
|
||||
}
|
||||
}
|
||||
53
test/libraries/common/PMA_generate_slider_effect_test.php
Normal file
53
test/libraries/common/PMA_generate_slider_effect_test.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_generate_slider_effect from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_generate_slider_effect_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_generate_slider_effect_test extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
function testGenerateSliderEffectTest()
|
||||
{
|
||||
global $cfg;
|
||||
$cfg['InitialSlidersState'] = 'undefined';
|
||||
|
||||
$id = "test_id";
|
||||
$message = "test_message";
|
||||
|
||||
$this->expectOutputString('<div id="' . $id . '" class="pma_auto_slider" title="' . htmlspecialchars($message) . '">' . "\n" . ' ');
|
||||
PMA_generate_slider_effect($id,$message);
|
||||
}
|
||||
|
||||
function testGenerateSliderEffectTestClosed()
|
||||
{
|
||||
global $cfg;
|
||||
$cfg['InitialSlidersState'] = 'closed';
|
||||
|
||||
$id = "test_id";
|
||||
$message = "test_message";
|
||||
|
||||
$this->expectOutputString('<div id="' . $id . '" style="display: none; overflow:auto;" class="pma_auto_slider" title="' . htmlspecialchars($message) . '">' . "\n" . ' ');
|
||||
PMA_generate_slider_effect($id,$message);
|
||||
}
|
||||
|
||||
function testGenerateSliderEffectTestDisabled()
|
||||
{
|
||||
global $cfg;
|
||||
$cfg['InitialSlidersState'] = 'disabled';
|
||||
|
||||
$id = "test_id";
|
||||
$message = "test_message";
|
||||
|
||||
$this->expectOutputString('<div id="' . $id . '">');
|
||||
PMA_generate_slider_effect($id,$message);
|
||||
}
|
||||
}
|
||||
57
test/libraries/common/PMA_getDbLink_test.php
Normal file
57
test/libraries/common/PMA_getDbLink_test.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_getDbLink_test from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_getDbLink_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_getDbLink_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function setUp()
|
||||
{
|
||||
global $cfg;
|
||||
require 'libraries/config.default.php';
|
||||
}
|
||||
|
||||
function testGetDbLinkEmpty()
|
||||
{
|
||||
$GLOBALS['db'] = null;
|
||||
$this->assertEmpty(PMA_getDbLink());
|
||||
}
|
||||
|
||||
function testGetDbLinkNull()
|
||||
{
|
||||
global $cfg;
|
||||
$GLOBALS['db'] = 'test_db';
|
||||
$database = $GLOBALS['db'];
|
||||
$this->assertEquals('<a href="' . $cfg['DefaultTabDatabase'] . '?db=' . $database
|
||||
. '&server=server&lang=en" title="Jump to database "' . htmlspecialchars($database) . '".">'
|
||||
. htmlspecialchars($database) . '</a>',PMA_getDbLink());
|
||||
}
|
||||
|
||||
function testGetDbLink()
|
||||
{
|
||||
global $cfg;
|
||||
$database = 'test_database';
|
||||
$this->assertEquals('<a href="' . $cfg['DefaultTabDatabase'] . '?db=' . $database
|
||||
. '&server=server&lang=en" title="Jump to database "' . htmlspecialchars($database) . '".">'
|
||||
. htmlspecialchars($database) . '</a>',PMA_getDbLink($database));
|
||||
}
|
||||
|
||||
function testGetDbLinkWithSpecialChars()
|
||||
{
|
||||
global $cfg;
|
||||
$database = 'test&data\'base';
|
||||
$this->assertEquals('<a href="' . $cfg['DefaultTabDatabase'] . '?db=' . htmlspecialchars(urlencode($database))
|
||||
. '&server=server&lang=en" title="Jump to database "' . htmlspecialchars($database) . '".">'
|
||||
. htmlspecialchars($database) . '</a>',PMA_getDbLink($database));
|
||||
}
|
||||
}
|
||||
74
test/libraries/common/PMA_getIcon_test.php
Normal file
74
test/libraries/common/PMA_getIcon_test.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_getIcon() from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_getIcon_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_getIcon_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
function testGetIconWithoutPropertiesIconic(){
|
||||
|
||||
$GLOBALS['cfg']['PropertiesIconic'] = false;
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
|
||||
$this->assertEquals('<span class="nowrap"></span>',
|
||||
PMA_getIcon('b_comment.png') );
|
||||
}
|
||||
|
||||
function testGetIconWithPropertiesIconic(){
|
||||
|
||||
$GLOBALS['cfg']['PropertiesIconic'] = true;
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
|
||||
$this->assertEquals('<span class="nowrap"><img src="'.$GLOBALS['pmaThemeImage']
|
||||
. 'b_comment.png" title="" alt="" class="icon" width="16" height="16" /></span>',
|
||||
PMA_getIcon('b_comment.png') );
|
||||
}
|
||||
|
||||
function testGetIconAlternate(){
|
||||
|
||||
$GLOBALS['cfg']['PropertiesIconic'] = true;
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$alternate_text = 'alt_str';
|
||||
|
||||
$this->assertEquals('<span class="nowrap"><img src="'.$GLOBALS['pmaThemeImage']
|
||||
.'b_comment.png" title="' . $alternate_text . '" alt="' . $alternate_text
|
||||
. '" class="icon" width="16" height="16" /></span>',
|
||||
PMA_getIcon('b_comment.png',$alternate_text) );
|
||||
}
|
||||
|
||||
function testGetIconWithContainer(){
|
||||
|
||||
$GLOBALS['cfg']['PropertiesIconic'] = true;
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$alternate_text = 'alt_str';
|
||||
|
||||
$this->assertEquals('<span class="nowrap"><img src="'.$GLOBALS['pmaThemeImage']
|
||||
.'b_comment.png" title="' . $alternate_text . '" alt="' . $alternate_text
|
||||
. '" class="icon" width="16" height="16" /></span>',
|
||||
PMA_getIcon('b_comment.png',$alternate_text, true) );
|
||||
|
||||
}
|
||||
|
||||
function testGetIconWithContainerAndForceText(){
|
||||
|
||||
$GLOBALS['cfg']['PropertiesIconic'] = true;
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$alternate_text = 'alt_str';
|
||||
|
||||
$this->assertEquals('<span class="nowrap"><img src="'.$GLOBALS['pmaThemeImage']
|
||||
.'b_comment.png" title="' . $alternate_text . '" alt="' . $alternate_text
|
||||
. '" class="icon" width="16" height="16" /> ' . $alternate_text . '</span>',
|
||||
PMA_getIcon('b_comment.png',$alternate_text, true, true) );
|
||||
|
||||
}
|
||||
}
|
||||
43
test/libraries/common/PMA_getTitleForTarget_test.php
Normal file
43
test/libraries/common/PMA_getTitleForTarget_test.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_getTitleForTarget from common.lib
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_getTitleForTarget_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_getTitleForTarget_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
function dataProvider(){
|
||||
return array(
|
||||
array('tbl_structure.php', __('Structure')),
|
||||
array('tbl_sql.php', __('SQL'),),
|
||||
array('tbl_select.php', __('Search'),),
|
||||
array('tbl_change.php', __('Insert')),
|
||||
array('sql.php', __('Browse')),
|
||||
array('db_structure.php', __('Structure')),
|
||||
array('db_sql.php', __('SQL')),
|
||||
array('db_search.php', __('Search')),
|
||||
array('db_operations.php', __('Operations')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
* @return void
|
||||
*/
|
||||
function testGetTitleForTarget($target, $result){
|
||||
|
||||
$this->assertEquals($result,PMA_getTitleForTarget($target));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//PMA_getTitleForTarget
|
||||
@ -5,41 +5,29 @@
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_localisedDateTimespan_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test localised date or timespan expression.
|
||||
*
|
||||
*/
|
||||
class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* temporary variable for globals array
|
||||
*/
|
||||
|
||||
protected $tmpGlobals;
|
||||
|
||||
/**
|
||||
* temporary variable for session array
|
||||
*/
|
||||
|
||||
protected $tmpSession;
|
||||
|
||||
/**
|
||||
* temporary variable for timezone info
|
||||
*/
|
||||
|
||||
protected $tmpTimezone;
|
||||
|
||||
/**
|
||||
@ -67,7 +55,6 @@ class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* data provider for localised date test
|
||||
*/
|
||||
|
||||
public function localisedDateDataProvider() {
|
||||
return array(
|
||||
array(1227455558, '', 'Nov 23, 2008 at 03:52 PM'),
|
||||
@ -79,7 +66,6 @@ class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
|
||||
* localised date test, globals are defined
|
||||
* @dataProvider localisedDateDataProvider
|
||||
*/
|
||||
|
||||
public function testLocalisedDate($a, $b, $e) {
|
||||
$this->assertEquals($e, PMA_localisedDate($a, $b));
|
||||
}
|
||||
@ -99,7 +85,6 @@ class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
|
||||
* localised timestamp test, globals are defined
|
||||
* @dataProvider timespanFormatDataProvider
|
||||
*/
|
||||
|
||||
public function testTimespanFormat($a, $e) {
|
||||
$GLOBALS['timespanfmt'] = '%s days, %s hours, %s minutes and %s seconds';
|
||||
|
||||
@ -1,20 +1,18 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA_pow()
|
||||
* Tests for PMA_pow() function from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_pow_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_pow_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testIntOverflow()
|
||||
@ -5,22 +5,14 @@
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_printableBitValue_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test printableBitValue function.
|
||||
*
|
||||
*/
|
||||
class PMA_printableBitValue_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@ -5,29 +5,21 @@
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_quoting_slashing_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/sqlparser.data.php';
|
||||
|
||||
/**
|
||||
* Test quoting, slashing, backslashing.
|
||||
*
|
||||
*/
|
||||
class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* sqlAddslashes test
|
||||
*/
|
||||
|
||||
public function testAddSlashes() {
|
||||
$string = "\'test''\''\'\r\t\n";
|
||||
|
||||
@ -44,7 +36,6 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* data provider for unQuote test
|
||||
*/
|
||||
|
||||
public function unQuoteProvider() {
|
||||
return array(
|
||||
array('"test\'"', "test'"),
|
||||
@ -58,7 +49,6 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
|
||||
* unQuote test
|
||||
* @dataProvider unQuoteProvider
|
||||
*/
|
||||
|
||||
public function testUnQuote($param, $expected) {
|
||||
$this->assertEquals($expected, PMA_unQuote($param));
|
||||
}
|
||||
@ -66,7 +56,6 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* data provider for unQuote test with chosen quote
|
||||
*/
|
||||
|
||||
public function unQuoteSelectedProvider() {
|
||||
return array(
|
||||
array('"test\'"', "test'"),
|
||||
@ -80,7 +69,6 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
|
||||
* unQuote test with chosen quote
|
||||
* @dataProvider unQuoteSelectedProvider
|
||||
*/
|
||||
|
||||
public function testUnQuoteSelectedChar($param, $expected) {
|
||||
$this->assertEquals($expected, PMA_unQuote($param, '"'));
|
||||
}
|
||||
@ -88,7 +76,6 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* data provider for backquote test
|
||||
*/
|
||||
|
||||
public function backquoteDataProvider() {
|
||||
return array(
|
||||
array('0', '`0`'),
|
||||
@ -102,10 +89,20 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
|
||||
* backquote test with different param $do_it (true, false)
|
||||
* @dataProvider backquoteDataProvider
|
||||
*/
|
||||
|
||||
public function testBackquote($a, $b) {
|
||||
// Test bypass quoting (used by dump functions)
|
||||
$this->assertEquals($a, PMA_backquote($a, false));
|
||||
|
||||
// Test backquote
|
||||
$this->assertEquals($b, PMA_backquote($a));
|
||||
}
|
||||
|
||||
public function testBackquoteForbidenWords() {
|
||||
global $PMA_SQPdata_forbidden_word;
|
||||
|
||||
foreach ($PMA_SQPdata_forbidden_word as $forbidden){
|
||||
$this->assertEquals("`" . $forbidden . "`", PMA_backquote($forbidden, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
39
test/libraries/common/PMA_showDocu_test.php
Normal file
39
test/libraries/common/PMA_showDocu_test.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_showDocu from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_showDocu.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_showDocu_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testShowDocuReplaceHelpImg()
|
||||
{
|
||||
$GLOBALS['cfg']['ReplaceHelpImg'] = true;
|
||||
|
||||
$anchor = "relation";
|
||||
$expected = '<a href="Documentation.html#' . $anchor . '" target="documentation"><img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" alt="' . __('Documentation') . '" title="' . __('Documentation') . '" /></a>';
|
||||
|
||||
$this->assertEquals($expected, PMA_showDocu($anchor));
|
||||
|
||||
}
|
||||
|
||||
function testShowDocuNotReplaceHelpImg()
|
||||
{
|
||||
$GLOBALS['cfg']['ReplaceHelpImg'] = false;
|
||||
|
||||
$anchor = "relation";
|
||||
$expected = '[<a href="Documentation.html#' . $anchor . '" target="documentation">' . __('Documentation') . '</a>]';
|
||||
|
||||
$this->assertEquals($expected, PMA_showDocu($anchor));
|
||||
|
||||
}
|
||||
}
|
||||
67
test/libraries/common/PMA_showMessage_test_disabled.php
Normal file
67
test/libraries/common/PMA_showMessage_test_disabled.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_showMessage from common.lib
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_showMessage_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
const PMA_IS_WINDOWS = false;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/Table.class.php';
|
||||
require_once 'libraries/database_interface.lib.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
|
||||
class PMA_showMessage_test extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
function setUp()
|
||||
{
|
||||
global $cfg;
|
||||
require 'libraries/config.default.php';
|
||||
}
|
||||
|
||||
function testShowMessageNotAjax()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$GLOBALS['is_ajax_request'] = true;
|
||||
$cfg['Server']['DisableIS'] = false;
|
||||
$GLOBALS['table'] = 'tbl';
|
||||
$GLOBALS['db'] = 'db';
|
||||
|
||||
$_SESSION[' PMA_token '] = md5(uniqid(rand(), true));
|
||||
|
||||
$GLOBALS['sql_query'] = "SELECT * FROM tblPatient ";
|
||||
|
||||
$this->expectOutputString("<script type=\"text/javascript\">
|
||||
//<![CDATA[
|
||||
if (window.parent.updateTableTitle) window.parent.updateTableTitle('db.tbl', ' ()');
|
||||
//]]>
|
||||
</script>
|
||||
<div id=\"result_query\" align=\"\">
|
||||
<div class=\"notice\">msg</div><code class=\"sql\"><span class=\"syntax\"><span class=\"inner_sql\"><a href=\"./url.php?url=http%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.0%2Fen%2Fselect.html&server=server&lang=en&token=647a62ad301bf9025e3b13bc7caa02cb\" target=\"mysql_doc\"><span class=\"syntax_alpha syntax_alpha_reservedWord\">SELECT</span></a> <span class=\"syntax_punct\">*</span> <br /><span class=\"syntax_alpha syntax_alpha_reservedWord\">FROM</span> <span class=\"syntax_alpha syntax_alpha_identifier\">tblPatient</span></span></span></code><div class=\"tools\"><form action=\"sql.php\" method=\"post\"><input type=\"hidden\" name=\"db\" value=\"db\" /><input type=\"hidden\" name=\"table\" value=\"tbl\" /><input type=\"hidden\" name=\"server\" value=\"server\" /><input type=\"hidden\" name=\"lang\" value=\"en\" /><input type=\"hidden\" name=\"token\" value=\"647a62ad301bf9025e3b13bc7caa02cb\" /><input type=\"hidden\" name=\"sql_query\" value=\"SELECT * FROM tblPatient \" /></form><script type=\"text/javascript\">
|
||||
//<![CDATA[
|
||||
$('.tools form').last().after('[<a href=\"#\" title=\"Inline edit of this query\" class=\"inline_edit_sql\">Inline</a>]');
|
||||
//]]>
|
||||
</script> [
|
||||
<a href=\"tbl_sql.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&server=server&lang=en&token=647a62ad301bf9025e3b13bc7caa02cb#querybox\" onclick=\"window.parent.focus_querywindow('SELECT * FROM tblPatient '); return false;\">Edit</a>
|
||||
] [
|
||||
<a href=\"import.php?db=db&table=tbl&sql_query=EXPLAIN+SELECT+%2A+FROM+tblPatient+&server=server&lang=en&token=647a62ad301bf9025e3b13bc7caa02cb\" >Explain SQL</a>
|
||||
] [
|
||||
<a href=\"import.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&show_as_php=1&server=server&lang=en&token=647a62ad301bf9025e3b13bc7caa02cb\" >Create PHP Code</a>
|
||||
] [
|
||||
<a href=\"import.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&server=server&lang=en&token=647a62ad301bf9025e3b13bc7caa02cb\" >Refresh</a>
|
||||
]</div></div>");
|
||||
|
||||
echo PMA_showMessage("msg");
|
||||
|
||||
//$this->assertEquals("",PMA_showMessage("msg"));
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
42
test/libraries/common/PMA_showPHPDocu_test.php
Normal file
42
test/libraries/common/PMA_showPHPDocu_test.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_showPHPDocu from common.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_showPHPDocu_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_showPHPDocu_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testShwoPHPDocuReplaceHelpImg()
|
||||
{
|
||||
$GLOBALS['cfg']['ReplaceHelpImg'] = true;
|
||||
|
||||
$target = "docu";
|
||||
$lang = _pgettext('PHP documentation language', 'en');
|
||||
$expected = '<a href="http://php.net/manual/' . $lang . '/' . $target . '" target="documentation"><img class="icon" src="'
|
||||
. $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" alt="' . __('Documentation') . '" title="' . __('Documentation') . '" /></a>';
|
||||
|
||||
$this->assertEquals($expected, PMA_showPHPDocu($target));
|
||||
}
|
||||
|
||||
function testShwoPHPDocuNotReplaceHelpImg()
|
||||
{
|
||||
$GLOBALS['cfg']['ReplaceHelpImg'] = false;
|
||||
|
||||
$target = "docu";
|
||||
$lang = _pgettext('PHP documentation language', 'en');
|
||||
$expected = '[<a href="http://php.net/manual/' . $lang . '/' . $target . '" target="documentation">' . __('Documentation') . '</a>]';
|
||||
|
||||
$this->assertEquals($expected, PMA_showPHPDocu($target));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -3,23 +3,16 @@
|
||||
/**
|
||||
* Test for several string operations
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_stringOperations_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test string operations.
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_stringOperations_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@ -40,6 +33,7 @@ class PMA_stringOperations_test extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function setUp() {
|
||||
|
||||
global $GLOBALS, $_SESSION;
|
||||
$this->tmpGlobals = $GLOBALS;
|
||||
$this->tmpSession = $_SESSION;
|
||||
|
||||
32
test/libraries/common/PMA_unsupportedDatatypes_test.php
Normal file
32
test/libraries/common/PMA_unsupportedDatatypes_test.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_unsupportedDatatypes from common.lib
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_unsupportedDatatypes_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
class PMA_unsupportedDatatypes_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
function testNotSupportedDataTypes()
|
||||
{
|
||||
$no_support_types = array('geometry',
|
||||
'point',
|
||||
'linestring',
|
||||
'polygon',
|
||||
'multipoint',
|
||||
'multilinestring',
|
||||
'multipolygon',
|
||||
'geometrycollection'
|
||||
);
|
||||
$this->assertEquals($no_support_types, PMA_unsupportedDatatypes());
|
||||
}
|
||||
}
|
||||
@ -5,22 +5,14 @@
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_whichCrlf_test.php
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.inc.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/**
|
||||
* Test whichCrlf function.
|
||||
*
|
||||
*/
|
||||
class PMA_whichCrlf_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@ -29,7 +21,6 @@ class PMA_whichCrlf_test extends PHPUnit_Framework_TestCase
|
||||
* if not define PMA_USR_OS, then define it as Win
|
||||
* if installed runkit, then constant will not change
|
||||
*/
|
||||
|
||||
public function testWhichCrlf()
|
||||
{
|
||||
$runkit = function_exists('runkit_constant_redefine');
|
||||
@ -47,9 +38,10 @@ class PMA_whichCrlf_test extends PHPUnit_Framework_TestCase
|
||||
|
||||
} else {
|
||||
|
||||
if ($runkit)
|
||||
if ($runkit) {
|
||||
define('PMA_USR_OS', 'Linux');
|
||||
$this->assertEquals("\n", PMA_whichCrlf());
|
||||
$this->assertEquals("\n", PMA_whichCrlf());
|
||||
}
|
||||
|
||||
if ($runkit)
|
||||
runkit_constant_redefine('PMA_USR_OS', 'Win');
|
||||
231
test/libraries/core/PMA_array_test.php
Normal file
231
test/libraries/core/PMA_array_test.php
Normal file
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_array_read(), PMA_array_write(), PMA_array_remove(), PMA_array_merge_recursive(),
|
||||
* PMA_arrayWalkRecursive() from libraries/core.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/core.lib.php';
|
||||
|
||||
class PMA_array_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testPMA_array_read()
|
||||
{
|
||||
$arr = array(
|
||||
"int" => 1,
|
||||
"str" => "str_val",
|
||||
"arr" => array('val1', 'val2', 'val3'),
|
||||
"sarr" => array('arr1' => array(1, 2, 3), array(3, array('a', 'b', 'c'), 4))
|
||||
);
|
||||
|
||||
$this->assertEquals(PMA_array_read('int', $arr), $arr['int']);
|
||||
|
||||
$this->assertEquals(PMA_array_read('str', $arr), $arr['str']);
|
||||
|
||||
$this->assertEquals(PMA_array_read('arr/0', $arr), $arr['arr'][0]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('arr/1', $arr), $arr['arr'][1]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('arr/2', $arr), $arr['arr'][2]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/arr1/0', $arr), $arr['sarr']['arr1'][0]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/arr1/1', $arr), $arr['sarr']['arr1'][1]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/arr1/2', $arr), $arr['sarr']['arr1'][2]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/0/0', $arr), $arr['sarr'][0][0]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/0/1', $arr), $arr['sarr'][0][1]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/0/1/2', $arr), $arr['sarr'][0][1][2]);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/not_exiting/1', $arr), null);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/not_exiting/1', $arr, 0), 0);
|
||||
|
||||
$this->assertEquals(PMA_array_read('sarr/not_exiting/1', $arr, 'defailt_val'), 'defailt_val');
|
||||
}
|
||||
|
||||
function testPMA_array_write()
|
||||
{
|
||||
$arr = array(
|
||||
"int" => 1,
|
||||
"str" => "str_val",
|
||||
"arr" => array('val1', 'val2', 'val3'),
|
||||
"sarr" => array('arr1' => array(1, 2, 3), array(3, array('a', 'b', 'c'), 4))
|
||||
);
|
||||
|
||||
PMA_array_write('int', $arr, 5);
|
||||
$this->assertEquals($arr['int'], 5);
|
||||
|
||||
PMA_array_write('str', $arr, '_str');
|
||||
$this->assertEquals($arr['str'], '_str');
|
||||
|
||||
PMA_array_write('arr/0', $arr, 'val_arr_0');
|
||||
$this->assertEquals($arr['arr'][0], 'val_arr_0');
|
||||
|
||||
PMA_array_write('arr/1', $arr, 'val_arr_1');
|
||||
$this->assertEquals($arr['arr'][1], 'val_arr_1');
|
||||
|
||||
PMA_array_write('arr/2', $arr, 'val_arr_2');
|
||||
$this->assertEquals($arr['arr'][2], 'val_arr_2');
|
||||
|
||||
PMA_array_write('sarr/arr1/0', $arr, 'val_sarr_arr_0');
|
||||
$this->assertEquals($arr['sarr']['arr1'][0], 'val_sarr_arr_0');
|
||||
|
||||
PMA_array_write('sarr/arr1/1', $arr, 'val_sarr_arr_1');
|
||||
$this->assertEquals($arr['sarr']['arr1'][1], 'val_sarr_arr_1');
|
||||
|
||||
PMA_array_write('sarr/arr1/2', $arr, 'val_sarr_arr_2');
|
||||
$this->assertEquals($arr['sarr']['arr1'][2], 'val_sarr_arr_2');
|
||||
|
||||
PMA_array_write('sarr/0/0', $arr, 5);
|
||||
$this->assertEquals($arr['sarr'][0][0], 5);
|
||||
|
||||
PMA_array_write('sarr/0/1/0', $arr, 'e');
|
||||
$this->assertEquals($arr['sarr'][0][1][0], 'e');
|
||||
|
||||
PMA_array_write('sarr/not_existing/1', $arr, 'some_val');
|
||||
$this->assertEquals($arr['sarr']['not_existing'][1], 'some_val');
|
||||
|
||||
PMA_array_write('sarr/0/2', $arr, NULL);
|
||||
$this->assertNull($arr['sarr'][0][2]);
|
||||
}
|
||||
|
||||
function testPMA_array_remove()
|
||||
{
|
||||
$arr = array(
|
||||
"int" => 1,
|
||||
"str" => "str_val",
|
||||
"arr" => array('val1', 'val2', 'val3'),
|
||||
"sarr" => array('arr1' => array(1, 2, 3), array(3, array('a', 'b', 'c'), 4))
|
||||
);
|
||||
|
||||
PMA_array_remove('int', $arr);
|
||||
$this->assertArrayNotHasKey('int', $arr);
|
||||
|
||||
PMA_array_remove('str', $arr);
|
||||
$this->assertArrayNotHasKey('str', $arr);
|
||||
|
||||
PMA_array_remove('arr/0', $arr);
|
||||
$this->assertArrayNotHasKey(0, $arr['arr']);
|
||||
|
||||
PMA_array_remove('arr/1', $arr);
|
||||
$this->assertArrayNotHasKey(1, $arr['arr']);
|
||||
|
||||
PMA_array_remove('arr/2', $arr);
|
||||
$this->assertArrayNotHasKey('arr', $arr);
|
||||
|
||||
$tmp_arr = $arr;
|
||||
PMA_array_remove('sarr/not_existing/1', $arr);
|
||||
$this->assertEquals($tmp_arr, $arr);
|
||||
|
||||
PMA_array_remove('sarr/arr1/0', $arr);
|
||||
$this->assertArrayNotHasKey(0, $arr['sarr']['arr1']);
|
||||
|
||||
PMA_array_remove('sarr/arr1/1', $arr);
|
||||
$this->assertArrayNotHasKey(1, $arr['sarr']['arr1']);
|
||||
|
||||
PMA_array_remove('sarr/arr1/2', $arr);
|
||||
$this->assertArrayNotHasKey('arr1', $arr['sarr']);
|
||||
|
||||
PMA_array_remove('sarr/0/0', $arr);
|
||||
$this->assertArrayNotHasKey(0, $arr['sarr'][0]);
|
||||
|
||||
PMA_array_remove('sarr/0/1/0', $arr);
|
||||
$this->assertArrayNotHasKey(0, $arr['sarr'][0][1]);
|
||||
|
||||
PMA_array_remove('sarr/0/1/1', $arr);
|
||||
$this->assertArrayNotHasKey(1, $arr['sarr'][0][1]);
|
||||
|
||||
PMA_array_remove('sarr/0/1/2', $arr);
|
||||
$this->assertArrayNotHasKey(1, $arr['sarr'][0]);
|
||||
|
||||
PMA_array_remove('sarr/0/2', $arr);
|
||||
|
||||
$this->assertEmpty($arr);
|
||||
}
|
||||
|
||||
function testPMA_array_merge_recursive()
|
||||
{
|
||||
$arr1 = array('key1' => 1, 'key2' => 2.3, 'key3' => 'str3');
|
||||
$arr2 = array('key1' => 4, 'key2' => 5, 'key3' => 6);
|
||||
$arr3 = array('key4' => 7, 'key5' => 'str8', 'key6' => 9);
|
||||
$arr4 = array(1, 2, 3);
|
||||
|
||||
$this->assertFalse(PMA_array_merge_recursive());
|
||||
|
||||
$this->assertEquals(PMA_array_merge_recursive($arr1), $arr1);
|
||||
|
||||
$this->assertEquals(PMA_array_merge_recursive($arr1, 'str'), 'str');
|
||||
|
||||
$this->assertEquals(PMA_array_merge_recursive('str1', $arr2), $arr2);
|
||||
|
||||
$this->assertEquals(PMA_array_merge_recursive($arr1, $arr2), array('key1' => 4, 'key2' => 5, 'key3' => 6));
|
||||
|
||||
$this->assertEquals(PMA_array_merge_recursive($arr1, $arr3), array('key1' => 1, 'key2' => 2.3, 'key3' => 'str3', 'key4' => 7, 'key5' => 'str8', 'key6' => 9));
|
||||
|
||||
$this->assertEquals(PMA_array_merge_recursive($arr2, $arr4), array(1, 2, 3));
|
||||
|
||||
$this->assertEquals(PMA_array_merge_recursive($arr1, $arr2, $arr3), array('key1' => 4, 'key2' => 5, 'key3' => 6, 'key4' => 7, 'key5' => 'str8', 'key6' => 9));
|
||||
}
|
||||
|
||||
|
||||
function testPMA_arrayWalkRecursive()
|
||||
{
|
||||
function fConcat($var)
|
||||
{
|
||||
return 'val: ' . $var . ' processed';
|
||||
}
|
||||
|
||||
$arr = array(1, 2, 3, 4);
|
||||
$target = array('val: 1 processed','val: 2 processed','val: 3 processed','val: 4 processed');
|
||||
|
||||
PMA_arrayWalkRecursive($arr, 'fConcat');
|
||||
$this->assertEquals($arr, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testPMA_arrayWalkRecursive
|
||||
*/
|
||||
function testPMA_arrayWalkRecursiveNotProcessIntKeys()
|
||||
{
|
||||
function fAdd($var)
|
||||
{
|
||||
return ++$var;
|
||||
}
|
||||
|
||||
$arr = array(1, 2, 3, 4);
|
||||
$target = array(2, 3, 4, 5);
|
||||
|
||||
PMA_arrayWalkRecursive($arr, 'fAdd', true);
|
||||
$this->assertEquals($arr, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testPMA_arrayWalkRecursiveNotProcessIntKeys
|
||||
*/
|
||||
function testPMA_arrayWalkRecursiveSubArray()
|
||||
{
|
||||
$arr = array("key1"=>'val1', 'key2'=>array('skey1'=>'sval1','skey2'=>'sval2'),'key3'=>'val3');
|
||||
$target = array('key1'=>'val: val1 processed', 'key2'=> array('skey1'=>'val: sval1 processed', 'skey2'=>'val: sval2 processed'),'key3'=>'val: val3 processed');
|
||||
|
||||
PMA_arrayWalkRecursive($arr, 'fConcat');
|
||||
$this->assertEquals($arr, $target);
|
||||
}
|
||||
|
||||
function testPMA_arrayWalkRecursiveApplyToKeysStripSlashes()
|
||||
{
|
||||
$arr = array("key\\1"=>'v\\\\al1', 'k\\ey2'=>array('s\\\\key1'=>'sval\\1','s\\k\\ey2'=>'s\\v\\al2'),'key3'=>'val3');
|
||||
$target = array("key1"=>'val1', 'key2'=>array('skey1'=>'sval1','skey2'=>'sval2'),'key3'=>'val3');
|
||||
|
||||
PMA_arrayWalkRecursive($arr, 'stripslashes',true);
|
||||
$this->assertEquals($arr, $target);
|
||||
}
|
||||
}
|
||||
66
test/libraries/core/PMA_checkPageValidity_test.php
Normal file
66
test/libraries/core/PMA_checkPageValidity_test.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA_checkPageValidity() from libraries/core.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/core.lib.php';
|
||||
|
||||
class PMA_checkPageValidity_test extends PHPUnit_Framework_TestCase{
|
||||
protected $goto_whitelist = array(
|
||||
'db_create.php',
|
||||
'db_datadict.php',
|
||||
'db_sql.php',
|
||||
'db_export.php',
|
||||
'db_search.php',
|
||||
'export.php',
|
||||
'import.php',
|
||||
'main.php',
|
||||
'pdf_pages.php',
|
||||
'pdf_schema.php',
|
||||
'querywindow.php',
|
||||
'server_binlog.php',
|
||||
'server_variables.php',
|
||||
'sql.php',
|
||||
'tbl_alter.php',
|
||||
'tbl_select.php',
|
||||
'transformation_overview.php',
|
||||
'transformation_wrapper.php',
|
||||
'user_password.php',
|
||||
);
|
||||
|
||||
function testGotoNowhere(){
|
||||
$page = null;
|
||||
$this->assertFalse(PMA_checkPageValidity($page,null));
|
||||
}
|
||||
|
||||
function testGotoWhitelist(){
|
||||
$page = 'export.php';
|
||||
|
||||
$this->assertTrue(PMA_checkPageValidity($page,$this->goto_whitelist));
|
||||
}
|
||||
|
||||
function testGotoNotInWhitelist(){
|
||||
$page = 'shell.php';
|
||||
|
||||
$this->assertFalse(PMA_checkPageValidity($page,$this->goto_whitelist));
|
||||
}
|
||||
|
||||
function testGotoWhitelistPage(){
|
||||
$page = 'main.php?sql.php&test=true';
|
||||
|
||||
$this->assertTrue(PMA_checkPageValidity($page,$this->goto_whitelist));
|
||||
}
|
||||
|
||||
function testGotoWhitelistEncodedPage(){
|
||||
$page = 'main.php%3Fsql.php%26test%3Dtrue';
|
||||
|
||||
$this->assertTrue(PMA_checkPageValidity($page,$this->goto_whitelist));
|
||||
}
|
||||
|
||||
}
|
||||
43
test/libraries/core/PMA_fatalError_test.php
Normal file
43
test/libraries/core/PMA_fatalError_test.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_fatalError() from libraries/core.lib.php
|
||||
*
|
||||
* PMA_fatalError() displays the given error message on phpMyAdmin error page in foreign language
|
||||
* and ends script execution and closes session
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/select_lang.lib.php';
|
||||
require_once 'libraries/core.lib.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/Config.class.php';
|
||||
|
||||
class PMA_fatalError_test extends PHPUnit_Extensions_OutputTestCase
|
||||
{
|
||||
public function testFatalErrorMessage()
|
||||
{
|
||||
$this->expectOutputRegex("/FatalError!/");
|
||||
PMA_fatalError("FatalError!");
|
||||
}
|
||||
|
||||
public function testFatalErrorMessageWithArgs()
|
||||
{
|
||||
$message = "Fatal error #%d in file %s.";
|
||||
$params = array(1, 'error_file.php');
|
||||
|
||||
$this->expectOutputRegex("/Fatal error #1 in file error_file.php./", "Not EQ");
|
||||
PMA_fatalError($message, $params);
|
||||
|
||||
$message = "Fatal error in file %s.";
|
||||
$params = 'error_file.php';
|
||||
|
||||
$this->expectOutputRegex("/Fatal error in file error_file.php./");
|
||||
PMA_fatalError($message, $params);
|
||||
}
|
||||
|
||||
}
|
||||
59
test/libraries/core/PMA_getLinks_test.php
Normal file
59
test/libraries/core/PMA_getLinks_test.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_getPHPDocLink, PMA_linkURL, PMA_includeJS from libraries/core.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/core.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
|
||||
class PMA_getLinks_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testPMA_getPHPDocLink()
|
||||
{
|
||||
$lang = _pgettext('PHP documentation language', 'en');
|
||||
$this->assertEquals(PMA_getPHPDocLink('function'), 'http://php.net/manual/' . $lang . '/function');
|
||||
}
|
||||
|
||||
public function providerLinkURL(){
|
||||
return array(
|
||||
array('http://wiki.phpmyadmin.net', './url.php?url=http%3A%2F%2Fwiki.phpmyadmin.net&lang=en'),
|
||||
array('https://wiki.phpmyadmin.net', './url.php?url=https%3A%2F%2Fwiki.phpmyadmin.net&lang=en'),
|
||||
array('wiki.phpmyadmin.net', 'wiki.phpmyadmin.net'),
|
||||
array('index.php?db=phpmyadmin', 'index.php?db=phpmyadmin')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerLinkURL
|
||||
*/
|
||||
public function testPMA_linkURL($link, $url){
|
||||
$this->assertEquals(PMA_linkURL($link), $url);
|
||||
}
|
||||
|
||||
public function testPMA_includeJS()
|
||||
{
|
||||
$filename = "common.js";
|
||||
$mod = 0;
|
||||
|
||||
if (file_exists('./js/'.$filename)) {
|
||||
$mod = filemtime('./js/'.$filename);
|
||||
}
|
||||
else{
|
||||
$this->fail("JS file doesn't exists.");
|
||||
}
|
||||
$this->assertEquals(PMA_includeJS($filename), '<script src="./js/'.$filename.'?ts='.$mod.'" type="text/javascript"></script>'. "\n");
|
||||
|
||||
$filename = '?file.js';
|
||||
//$this->assertEquals(PMA_includeJS($filename), '<script src="./js/?file.js" type="text/javascript"></script>\n');
|
||||
$this->assertEquals(PMA_includeJS($filename), '<script src="./js/'.$filename.'" type="text/javascript"></script>'."\n");
|
||||
|
||||
//$this->assertFalse(PMA_includeJS(null));
|
||||
}
|
||||
|
||||
}
|
||||
37
test/libraries/core/PMA_getTableCount_test_dis.php
Normal file
37
test/libraries/core/PMA_getTableCount_test_dis.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_getTableCount_test from core.lib.php
|
||||
* PMA_getTableCount_test returns count of tables in given db
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/core.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/config.default.php';
|
||||
require_once 'libraries/Config.class.php';
|
||||
require_once 'libraries/database_interface.lib.php';
|
||||
|
||||
require_once 'config.sample.inc.php';
|
||||
|
||||
class PMA_getTableCount_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$GLOBALS['PMA_Config'] = new PMA_Config();
|
||||
}
|
||||
|
||||
function testTableCount()
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['extension'] = 'mysql';
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
$GLOBALS['cfg']['Server']['user'] = 'root';
|
||||
|
||||
$this->assertEquals(5,PMA_getTableCount('meddb'));
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@ -1,20 +1,16 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA_get_real_size()
|
||||
* Test for PMA_get_real_size() from libraries/core.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once './libraries/core.lib.php';
|
||||
require_once 'libraries/core.lib.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_get_real_size_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testNull()
|
||||
@ -41,5 +37,10 @@ class PMA_get_real_size_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals(12 * 1024 * 1024 * 1024, PMA_get_real_size('12gb'));
|
||||
}
|
||||
|
||||
public function testUnspecified()
|
||||
{
|
||||
$this->assertEquals(1024, PMA_get_real_size('1024'));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -3,21 +3,16 @@
|
||||
/**
|
||||
* Test for PMA_sendHeaderLocation
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests core.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/Extensions/OutputTestCase.php';
|
||||
|
||||
/**
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once './libraries/url_generating.lib.php';
|
||||
require_once './libraries/core.lib.php';
|
||||
require_once './libraries/select_lang.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/core.lib.php';
|
||||
require_once 'libraries/select_lang.lib.php';
|
||||
|
||||
/**
|
||||
* Test function sending headers.
|
||||
@ -40,8 +35,6 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
|
||||
protected $runkitExt;
|
||||
protected $apdExt;
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
@ -102,6 +95,8 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
//session_start();
|
||||
|
||||
// cleaning constants
|
||||
if ($this->runkitExt) {
|
||||
|
||||
@ -132,6 +127,8 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
//session_destroy();
|
||||
|
||||
// cleaning constants
|
||||
if ($this->runkitExt) {
|
||||
|
||||
@ -264,7 +261,7 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
|
||||
"<body>\n" .
|
||||
"<script type=\"text/javascript\">\n" .
|
||||
"//<![CDATA[\n" .
|
||||
"document.write('<p><a href=\"" . $testUri_html . "\">" . 'test link' . "</a></p>');\n" .
|
||||
"document.write('<p><a href=\"" . $testUri_html . "\">" . __('Go') . "</a></p>');\n" .
|
||||
"//]]>\n" .
|
||||
"</script></body></html>\n";
|
||||
|
||||
@ -283,7 +280,7 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
|
||||
$GLOBALS['reload'] = true;
|
||||
$GLOBALS['db'] = 'test_db';
|
||||
|
||||
$url = './navigation.php?db='.$GLOBALS['db'] . '&lang=en-utf-8&convcharset=utf-8';
|
||||
$url = './navigation.php?'.PMA_generate_common_url($GLOBALS['db'], '', '&');
|
||||
$write = PHP_EOL . '<script type="text/javascript">' . PHP_EOL .
|
||||
'//<![CDATA[' . PHP_EOL .
|
||||
'if (typeof(window.parent) != \'undefined\'' . PHP_EOL .
|
||||
@ -1,20 +1,16 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for PMA_ifSetOr()
|
||||
* Tests for PMA_ifSetOr() from libraries/core.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once './libraries/core.lib.php';
|
||||
require_once 'libraries/core.lib.php';
|
||||
|
||||
/**
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
class PMA_ifSetOr_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testVarSet()
|
||||
217
test/libraries/core/PMA_isValid_test.php
Normal file
217
test/libraries/core/PMA_isValid_test.php
Normal file
@ -0,0 +1,217 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA_isValid() from libraries/core.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/core.lib.php';
|
||||
|
||||
class PMA_isValid_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public static function providerNoVarTypeProvider()
|
||||
{
|
||||
return array(
|
||||
array(0, false, 0),
|
||||
array(0, false, 1),
|
||||
array(1, false, null),
|
||||
array(1.1, false, null),
|
||||
array('', false, null),
|
||||
array(' ', false, null),
|
||||
array('0', false, null),
|
||||
array('string', false, null),
|
||||
array(array(), false, null),
|
||||
array(array(1, 2, 3), false, null),
|
||||
array(true, false, null),
|
||||
array(false, false, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerNoVarTypeProvider
|
||||
* @param mixed $var
|
||||
* @param mixed $type
|
||||
* @param mixed $compare
|
||||
*/
|
||||
public function testNoVarType($var, $type, $compare)
|
||||
{
|
||||
$this->assertTrue(PMA_isValid($var, $type, $compare));
|
||||
}
|
||||
|
||||
public function testVarNotSetAfterTest()
|
||||
{
|
||||
PMA_isValid($var);
|
||||
$this->assertFalse(isset($var));
|
||||
}
|
||||
|
||||
public function testNotSet()
|
||||
{
|
||||
$this->assertFalse(PMA_isValid($var));
|
||||
}
|
||||
|
||||
public function testEmptyString()
|
||||
{
|
||||
$var = '';
|
||||
$this->assertFalse(PMA_isValid($var));
|
||||
}
|
||||
|
||||
public function testNotEmptyString()
|
||||
{
|
||||
$var = '0';
|
||||
$this->assertTrue(PMA_isValid($var));
|
||||
}
|
||||
|
||||
public function testZero()
|
||||
{
|
||||
$var = 0;
|
||||
$this->assertTrue(PMA_isValid($var));
|
||||
$this->assertTrue(PMA_isValid($var, 'int'));
|
||||
}
|
||||
|
||||
public function testNullFail()
|
||||
{
|
||||
$var = null;
|
||||
$this->assertFalse(PMA_isValid($var));
|
||||
|
||||
$var = 'null_text';
|
||||
$this->assertFalse(PMA_isValid($var, 'null'));
|
||||
}
|
||||
|
||||
public function testNotSetArray()
|
||||
{
|
||||
/** @var $array undefined array */
|
||||
$this->assertFalse(PMA_isValid($array['x']));
|
||||
}
|
||||
|
||||
public function testScalarString()
|
||||
{
|
||||
$var = 'string';
|
||||
$this->assertTrue(PMA_isValid($var, 'len'));
|
||||
$this->assertTrue(PMA_isValid($var, 'scalar'));
|
||||
$this->assertTrue(PMA_isValid($var));
|
||||
}
|
||||
|
||||
public function testScalarInt()
|
||||
{
|
||||
$var = 1;
|
||||
$this->assertTrue(PMA_isValid($var, 'int'));
|
||||
$this->assertTrue(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
|
||||
public function testScalarFloat()
|
||||
{
|
||||
$var = 1.1;
|
||||
$this->assertTrue(PMA_isValid($var, 'float'));
|
||||
$this->assertTrue(PMA_isValid($var, 'double'));
|
||||
$this->assertTrue(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
|
||||
public function testScalarBool()
|
||||
{
|
||||
$var = true;
|
||||
$this->assertTrue(PMA_isValid($var, 'scalar'));
|
||||
$this->assertTrue(PMA_isValid($var, 'bool'));
|
||||
$this->assertTrue(PMA_isValid($var, 'boolean'));
|
||||
}
|
||||
|
||||
public function testNotScalarArray()
|
||||
{
|
||||
$var = array('test');
|
||||
$this->assertFalse(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
|
||||
public function testNotScalarNull()
|
||||
{
|
||||
$var = null;
|
||||
$this->assertFalse(PMA_isValid($var, 'scalar'));
|
||||
}
|
||||
|
||||
public function testNumericInt()
|
||||
{
|
||||
$var = 1;
|
||||
$this->assertTrue(PMA_isValid($var, 'numeric'));
|
||||
}
|
||||
|
||||
public function testNumericFloat()
|
||||
{
|
||||
$var = 1.1;
|
||||
$this->assertTrue(PMA_isValid($var, 'numeric'));
|
||||
}
|
||||
|
||||
public function testNumericZero()
|
||||
{
|
||||
$var = 0;
|
||||
$this->assertTrue(PMA_isValid($var, 'numeric'));
|
||||
}
|
||||
|
||||
public function testNumericString()
|
||||
{
|
||||
$var = '+0.1';
|
||||
$this->assertTrue(PMA_isValid($var, 'numeric'));
|
||||
}
|
||||
|
||||
public function testValueInArray()
|
||||
{
|
||||
$var = 'a';
|
||||
$this->assertTrue(PMA_isValid($var, array('a', 'b',)));
|
||||
}
|
||||
|
||||
public function testValueNotInArray()
|
||||
{
|
||||
$var = 'c';
|
||||
$this->assertFalse(PMA_isValid($var, array('a', 'b',)));
|
||||
}
|
||||
|
||||
public function testNumericIdentical()
|
||||
{
|
||||
$var = 1;
|
||||
$compare = 1;
|
||||
$this->assertTrue(PMA_isValid($var, 'identic', $compare));
|
||||
|
||||
$var = 1;
|
||||
$compare += 2;
|
||||
$this->assertFalse(PMA_isValid($var, 'identic', $compare));
|
||||
|
||||
$var = 1;
|
||||
$compare = '1';
|
||||
$this->assertFalse(PMA_isValid($var, 'identic', $compare));
|
||||
}
|
||||
|
||||
public function providerSimilarType()
|
||||
{
|
||||
return array(
|
||||
array(1, 1),
|
||||
array(1.5, 1.5),
|
||||
array(true, true),
|
||||
array('string', "string"),
|
||||
array(array(1, 2, 3.4), array(1, 2, 3.4)),
|
||||
array(array(1, '2', '3.4', 5, 'text'), array('1', '2', 3.4,'5'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSimilarType
|
||||
* @param mixed $var
|
||||
* @param mixed $compare
|
||||
*/
|
||||
public function testSimilarType($var, $compare)
|
||||
{
|
||||
$this->assertTrue(PMA_isValid($var, 'similar', $compare));
|
||||
$this->assertTrue(PMA_isValid($var, 'equal', $compare));
|
||||
$this->assertTrue(PMA_isValid($compare, 'similar', $var));
|
||||
$this->assertTrue(PMA_isValid($compare, 'equal', $var));
|
||||
|
||||
}
|
||||
|
||||
public function testOtherTypes()
|
||||
{
|
||||
$var = new PMA_isValid_test();
|
||||
$this->assertFalse(PMA_isValid($var, 'class'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
19
test/libraries/core/PMA_securePath_test.php
Normal file
19
test/libraries/core/PMA_securePath_test.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA_securePath() from libraries/core.lib.php
|
||||
* PMA_securePath changes .. to .
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once 'libraries/core.lib.php';
|
||||
|
||||
class PMA_securePath extends PHPUnit_Framework_TestCase{
|
||||
public function testReplaceDots(){
|
||||
$this->assertEquals(PMA_securePath('../../../etc/passwd'), './././etc/passwd');
|
||||
$this->assertEquals(PMA_securePath('/var/www/../phpmyadmin'), '/var/www/./phpmyadmin');
|
||||
$this->assertEquals(PMA_securePath('./path/with..dots/../../file..php'), './path/with.dots/././file.php');
|
||||
}
|
||||
|
||||
}
|
||||
58
test/libraries/core/PMA_warnMissingExtension_test.php
Normal file
58
test/libraries/core/PMA_warnMissingExtension_test.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_warnMissingExtension() from libraries/core.lib.php
|
||||
* PMA_warnMissingExtension warns or fails on missing extension.
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/core.lib.php';
|
||||
|
||||
class PMA_warnMissingExtension_test extends PHPUnit_Framework_TestCase{
|
||||
|
||||
function testMissingExtention(){
|
||||
$ext = 'php_ext';
|
||||
$this->setExpectedException('PHPUnit_Framework_Error',
|
||||
'The [a@'.PMA_getPHPDocLink('book.' . $ext . '.php').'@Documentation][em]'.$ext.'[/em][/a] extension is missing. Please check your PHP configuration.');
|
||||
PMA_warnMissingExtension($ext);
|
||||
}
|
||||
|
||||
function testMissingExtentionFatal(){
|
||||
$ext = 'php_ext';
|
||||
$warn = 'The <a href="'.PMA_linkURL(PMA_getPHPDocLink('book.' . $ext . '.php')).'" target="Documentation"><em>'.$ext.'</em></a> extension is missing. Please check your PHP configuration.';
|
||||
|
||||
ob_start();
|
||||
PMA_warnMissingExtension($ext,true);
|
||||
$printed = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertGreaterThan(0,strpos($printed,$warn));
|
||||
}
|
||||
|
||||
function testMissingExtentionFatalWithExtra(){
|
||||
$ext = 'php_ext';
|
||||
$extra = 'Appended Extra String';
|
||||
|
||||
$warn = 'The <a href="'.PMA_linkURL(PMA_getPHPDocLink('book.' . $ext . '.php')).'" target="Documentation"><em>'.$ext.'</em></a> extension is missing. Please check your PHP configuration.'.' '.$extra;
|
||||
|
||||
ob_start();
|
||||
PMA_warnMissingExtension($ext,true,$extra);
|
||||
$printed = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertGreaterThan(0,strpos($printed,$warn));
|
||||
}
|
||||
|
||||
function testMissingExtentionWithExtra(){
|
||||
$ext = 'php_ext';
|
||||
$extra = 'Appended Extra String';
|
||||
$this->setExpectedException('PHPUnit_Framework_Error',
|
||||
'The [a@'.PMA_getPHPDocLink('book.' . $ext . '.php').'@Documentation][em]'.$ext.'[/em][/a] extension is missing. Please check your PHP configuration.'.' '.$extra);
|
||||
PMA_warnMissingExtension($ext,false,$extra);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
73
test/libraries/php-gettext/Locales_test.php
Normal file
73
test/libraries/php-gettext/Locales_test.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for gettext locales.
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
require_once('libraries/php-gettext/gettext.inc');
|
||||
|
||||
class LocaleTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function test_setlocale_system()
|
||||
{
|
||||
putenv("LC_ALL=");
|
||||
// For an existing locale, it never needs emulation.
|
||||
putenv("LANG=C");
|
||||
_setlocale(LC_MESSAGES, "");
|
||||
$this->assertEquals(0, locale_emulation());
|
||||
}
|
||||
|
||||
public function test_setlocale_emulation()
|
||||
{
|
||||
putenv("LC_ALL=");
|
||||
// If we set it to a non-existent locale, it still works, but uses
|
||||
// emulation.
|
||||
_setlocale(LC_MESSAGES, "xxx_XXX");
|
||||
$this->assertEquals('xxx_XXX', _setlocale(LC_MESSAGES, 0));
|
||||
$this->assertEquals(1, locale_emulation());
|
||||
}
|
||||
|
||||
public function test_get_list_of_locales()
|
||||
{
|
||||
// For a locale containing country code, we prefer
|
||||
// full locale name, but if that's not found, fall back
|
||||
// to the language only locale name.
|
||||
$this->assertEquals(array("sr_RS", "sr"),
|
||||
get_list_of_locales("sr_RS"));
|
||||
|
||||
// If language code is used, it's the only thing returned.
|
||||
$this->assertEquals(array("sr"),
|
||||
get_list_of_locales("sr"));
|
||||
|
||||
// There is support for language and charset only.
|
||||
$this->assertEquals(array("sr.UTF-8", "sr"),
|
||||
get_list_of_locales("sr.UTF-8"));
|
||||
|
||||
// It can also split out character set from the full locale name.
|
||||
$this->assertEquals(array("sr_RS.UTF-8", "sr_RS", "sr"),
|
||||
get_list_of_locales("sr_RS.UTF-8"));
|
||||
|
||||
// There is support for @modifier in locale names as well.
|
||||
$this->assertEquals(array("sr_RS.UTF-8@latin", "sr_RS@latin", "sr@latin",
|
||||
"sr_RS.UTF-8", "sr_RS", "sr"),
|
||||
get_list_of_locales("sr_RS.UTF-8@latin"));
|
||||
|
||||
// We can pass in only language and modifier.
|
||||
$this->assertEquals(array("sr@latin", "sr"),
|
||||
get_list_of_locales("sr@latin"));
|
||||
|
||||
|
||||
// If locale name is not following the regular POSIX pattern,
|
||||
// it's used verbatim.
|
||||
$this->assertEquals(array("something"),
|
||||
get_list_of_locales("something"));
|
||||
|
||||
// Passing in an empty string returns an empty array.
|
||||
$this->assertEquals(array(),
|
||||
get_list_of_locales(""));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
65
test/libraries/php-gettext/Parsing_test.php
Normal file
65
test/libraries/php-gettext/Parsing_test.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for gettext parsing.
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
//require_once('gettext.php');
|
||||
|
||||
class ParsingTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_extract_plural_forms_header_from_po_header()
|
||||
{
|
||||
$parser = new gettext_reader(NULL);
|
||||
// It defaults to a "Western-style" plural header.
|
||||
$this->assertEquals(
|
||||
'nplurals=2; plural=n == 1 ? 0 : 1;',
|
||||
$parser->extract_plural_forms_header_from_po_header(""));
|
||||
|
||||
// Extracting it from the middle of the header works.
|
||||
$this->assertEquals(
|
||||
'nplurals=1; plural=0;',
|
||||
$parser->extract_plural_forms_header_from_po_header(
|
||||
"Content-type: text/html; charset=UTF-8\n"
|
||||
."Plural-Forms: nplurals=1; plural=0;\n"
|
||||
."Last-Translator: nobody\n"
|
||||
));
|
||||
|
||||
// It's also case-insensitive.
|
||||
$this->assertEquals(
|
||||
'nplurals=1; plural=0;',
|
||||
$parser->extract_plural_forms_header_from_po_header(
|
||||
"PLURAL-forms: nplurals=1; plural=0;\n"
|
||||
));
|
||||
|
||||
// It falls back to default if it's not on a separate line.
|
||||
$this->assertEquals(
|
||||
'nplurals=2; plural=n == 1 ? 0 : 1;',
|
||||
$parser->extract_plural_forms_header_from_po_header(
|
||||
"Content-type: text/html; charset=UTF-8" // note the missing \n here
|
||||
."Plural-Forms: nplurals=1; plural=0;\n"
|
||||
."Last-Translator: nobody\n"
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_provider_test_npgettext
|
||||
*/
|
||||
public function test_npgettext($number, $expected) {
|
||||
$parser = new gettext_reader(NULL);
|
||||
$result = $parser->npgettext("context",
|
||||
"%d pig went to the market\n",
|
||||
"%d pigs went to the market\n",
|
||||
$number);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
public static function data_provider_test_npgettext() {
|
||||
return array(
|
||||
array(1, "%d pig went to the market\n"),
|
||||
array(2, "%d pigs went to the market\n"),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
96
test/libraries/select_lang/PMA_langDetails_test.php
Normal file
96
test/libraries/select_lang/PMA_langDetails_test.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_langDetails from select_lang.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_langDetails_test.php
|
||||
* @group select_lang.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/select_lang.lib.php';
|
||||
|
||||
class PMA_langDetails_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function dataProvider()
|
||||
{
|
||||
return array(
|
||||
array('af|afrikaans', 'af', '', 'af'),
|
||||
array('ar|arabic', 'ar', 'العربية', 'ar'),
|
||||
array('az|azerbaijani', 'az', 'Azərbaycanca', 'az'),
|
||||
array('bn|bangla', 'bn', 'বাংলা', 'bn'),
|
||||
array('be|belarusian', 'be', 'Беларуская', 'be'),
|
||||
array('be[-_]lat|belarusian latin', 'be-lat', 'Biełaruskaja', 'be@latin'),
|
||||
array('bg|bulgarian', 'bg', 'Български', 'bg'),
|
||||
array('bs|bosnian', 'bs', 'Bosanski', 'bs'),
|
||||
array('br|breton', 'br', 'Brezhoneg', 'br'),
|
||||
array('ca|catalan', 'ca', 'Català', 'ca'),
|
||||
array('cs|czech', 'cs', 'Čeština', 'cs'),
|
||||
array('cy|welsh', 'cy', 'Cymraeg', 'cy'),
|
||||
array('da|danish', 'da', 'Dansk', 'da'),
|
||||
array('de|german', 'de', 'Deutsch', 'de'),
|
||||
array('el|greek', 'el', 'Ελληνικά', 'el'),
|
||||
array('en|english', 'en', '', 'en'),
|
||||
array('en[_-]gb|english (United Kingdom)', 'en-gb', '', 'en_GB'),
|
||||
array('es|spanish', 'es', 'Español', 'es'),
|
||||
array('et|estonian', 'et', 'Eesti', 'et'),
|
||||
array('eu|basque', 'eu', 'Euskara', 'eu',),
|
||||
array('fa|persian', 'fa', 'فارسی', 'fa'),
|
||||
array('fi|finnish', 'fi', 'Suomi', 'fi'),
|
||||
array('fr|french', 'fr', 'Français', 'fr'),
|
||||
array('gl|galician', 'gl', 'Galego', 'gl'),
|
||||
array('he|hebrew', 'he', 'עברית', 'he'),
|
||||
array('hi|hindi', 'hi', 'हिन्दी', 'hi'),
|
||||
array('hr|croatian', 'hr', 'Hrvatski', 'hr'),
|
||||
array('hu|hungarian', 'hu', 'Magyar', 'hu'),
|
||||
array('id|indonesian', 'id', 'Bahasa Indonesia', 'id'),
|
||||
array('it|italian', 'it', 'Italiano', 'it'),
|
||||
array('ja|japanese', 'ja', '日本語', 'ja'),
|
||||
array('ko|korean', 'ko', '한국어', 'ko'),
|
||||
array('ka|georgian', 'ka', 'ქართული', 'ka'),
|
||||
array('lt|lithuanian', 'lt', 'Lietuvių', 'lt'),
|
||||
array('lv|latvian', 'lv', 'Latviešu', 'lv'),
|
||||
array('mk|macedonian', 'mk', 'Macedonian', 'mk'),
|
||||
array('mn|mongolian', 'mn', 'Монгол', 'mn'),
|
||||
array('ms|malay', 'ms', 'Bahasa Melayu', 'ms'),
|
||||
array('nl|dutch', 'nl', 'Nederlands', 'nl'),
|
||||
array('nb|norwegian', 'nb', 'Norsk', 'nb'),
|
||||
array('pl|polish', 'pl', 'Polski', 'pl'),
|
||||
array('pt[-_]br|brazilian portuguese', 'pt-BR', 'Português', 'pt_BR'),
|
||||
array('pt|portuguese', 'pt', 'Português', 'pt'),
|
||||
array('ro|romanian', 'ro', 'Română', 'ro'),
|
||||
array('ru|russian', 'ru', 'Русский', 'ru'),
|
||||
array('si|sinhala', 'si', 'සිංහල', 'si'),
|
||||
array('sk|slovak', 'sk', 'Slovenčina', 'sk'),
|
||||
array('sl|slovenian', 'sl', 'Slovenščina', 'sl'),
|
||||
array('sq|albanian', 'sq', 'Shqip', 'sq'),
|
||||
array('sr[-_]lat|serbian latin', 'sr-lat', 'Srpski', 'sr@latin'),
|
||||
array('sr|serbian', 'sr', 'Српски', 'sr'),
|
||||
array('sv|swedish', 'sv', 'Svenska', 'sv'),
|
||||
array('ta|tamil', 'ta', 'தமிழ்', 'ta'),
|
||||
array('te|telugu', 'te', 'తెలుగు', 'te'),
|
||||
array('th|thai', 'th', 'ภาษาไทย', 'th'),
|
||||
array('tr|turkish', 'tr', 'Türkçe', 'tr'),
|
||||
array('tt|tatarish', 'tt', 'Tatarça', 'tt'),
|
||||
array('ug|uyghur', 'ug', 'ئۇيغۇرچە', 'ug'),
|
||||
array('uk|ukrainian', 'uk', 'Українська', 'uk'),
|
||||
array('ur|urdu', 'ur', 'اُردوُ', 'ur'),
|
||||
array('uz[-_]lat|uzbek-latin', 'uz-lat', 'O‘zbekcha', 'uz@latin'),
|
||||
array('uz[-_]cyr|uzbek-cyrillic', 'uz-cyr', 'Ўзбекча', 'uz'),
|
||||
array('zh[-_](tw|hk)|chinese traditional', 'zh-TW', '中文', 'zh_TW'),
|
||||
array('zh|chinese simplified', 'zh', '中文', 'zh_CN'),
|
||||
array('test_lang|test_lang', 'test_lang', 'test_lang', 'test_lang')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
function testLangDetails($a, $b, $c,$d)
|
||||
{
|
||||
$this->assertEquals(array($a, $b, $c), PMA_langDetails($d));
|
||||
}
|
||||
}
|
||||
51
test/libraries/select_lang/PMA_langList_test.php
Normal file
51
test/libraries/select_lang/PMA_langList_test.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_langList from select_lang.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_langList_test.php
|
||||
* @group select_lang.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/select_lang.lib.php';
|
||||
|
||||
class PMA_langList_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testLangList()
|
||||
{
|
||||
$GLOBALS['lang_path'] = '';
|
||||
$expected = array('en' => PMA_langDetails('en'));
|
||||
|
||||
$this->assertEquals($expected, PMA_langList());
|
||||
}
|
||||
|
||||
function testLangListWithDir()
|
||||
{
|
||||
$GLOBALS['lang_path'] = './locale/';
|
||||
$expected = array('en' => PMA_langDetails('en'));
|
||||
|
||||
$handle = @opendir($GLOBALS['lang_path']);
|
||||
if ($handle === false)
|
||||
$this->markTestSkipped("Cannot open file with locales");
|
||||
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != "." && $file != ".." && file_exists($GLOBALS['lang_path'] . '/' . $file . '/LC_MESSAGES/phpmyadmin.mo')) {
|
||||
$expected[$file] = PMA_langDetails($file);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, PMA_langList());
|
||||
}
|
||||
|
||||
function testLangListWithWrongDir()
|
||||
{
|
||||
$GLOBALS['lang_path'] = '/root/';
|
||||
$expected = array('en' => PMA_langDetails('en'));
|
||||
|
||||
$this->assertEquals($expected, PMA_langList());
|
||||
}
|
||||
}
|
||||
35
test/libraries/select_lang/PMA_langName_test.php
Normal file
35
test/libraries/select_lang/PMA_langName_test.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for PMA_langName from select_lang.lib.php
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @version $Id: PMA_langName_test.php
|
||||
* @group select_lang.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/select_lang.lib.php';
|
||||
|
||||
class PMA_langName_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function dataProvider()
|
||||
{
|
||||
return array(
|
||||
array(array('en|english', 'en', ''),'English'),
|
||||
array(array('fr|french', 'fr', 'Français'), 'Français - French'),
|
||||
array(array('zh|chinese simplified', 'zh', '中文'), '中文 - Chinese simplified'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
* @return void
|
||||
*/
|
||||
function testLangName($test, $result)
|
||||
{
|
||||
$this->assertEquals($result, PMA_langName($test));
|
||||
}
|
||||
}
|
||||
43
test/selenium/PmaSeleniumLoginTest.php
Normal file
43
test/selenium/PmaSeleniumLoginTest.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium TestCase for login related tests
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @group Selenium
|
||||
*/
|
||||
|
||||
require_once('PmaSeleniumTestCase.php');
|
||||
|
||||
|
||||
class PmaSeleniumLoginTest extends PmaSeleniumTestCase
|
||||
{
|
||||
protected $captureScreenshotOnFailure = TRUE;
|
||||
protected $screenshotPath = '/var/www/screenshots';
|
||||
protected $screenshotUrl = 'http://localhost/screenshots';
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
$this->doLogin();
|
||||
|
||||
// Check if login error happend
|
||||
if ($this->isElementPresent("//html/body/div/div[@class='error']")){
|
||||
$this->fail($this->getText("//html/body/div/div[@class='error']"));
|
||||
}
|
||||
|
||||
// Check server info heder is present //*[@id="serverinfo"]
|
||||
for ($second = 0;; $second++) {
|
||||
if ($second >= 60)
|
||||
$this->fail("Timeout waiting main page to load!");
|
||||
try {
|
||||
if ($this->isElementPresent("//*[@id=\"serverinfo\"]"))
|
||||
break;
|
||||
} catch (Exception $e) {
|
||||
$this->fail("Exception: ".$e->getMessage());
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -4,6 +4,7 @@
|
||||
* Selenium TestCase for privilege related tests
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @group Selenium
|
||||
*/
|
||||
|
||||
require_once('PmaSeleniumTestCase.php');
|
||||
71
test/selenium/PmaSeleniumTestCase.php
Normal file
71
test/selenium/PmaSeleniumTestCase.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium parent class for TestCases
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @group Selenium
|
||||
*/
|
||||
|
||||
// Optionally add the php-client-driver to your include path
|
||||
//set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/selenium-remote-control-1.0.1/selenium-php-client-driver-1.0.1/PEAR/');
|
||||
|
||||
// Include the main phpMyAdmin user config
|
||||
// currently only $cfg['Test'] is used
|
||||
require_once 'config.sample.inc.php';
|
||||
|
||||
|
||||
|
||||
class PmaSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
|
||||
{
|
||||
protected $selenium;
|
||||
protected $cfg;
|
||||
|
||||
protected $captureScreenshotOnFailure = TRUE;
|
||||
protected $screenshotPath = '/var/www/screenshots';
|
||||
protected $screenshotUrl = 'http://localhost/screenshots';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
global $cfg;
|
||||
$this->cfg =& $cfg;
|
||||
//PHPUnit_Extensions_SeleniumTestCase::$browsers = $this->cfg['Test']['broswers'];
|
||||
|
||||
$this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL);
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* perform a login
|
||||
*/
|
||||
public function doLogin()
|
||||
{
|
||||
$this->open(TESTSUITE_PHPMYADMIN_URL);
|
||||
// Somehow selenium does not like the language selection on the cookie login page, forced English in the config for now.
|
||||
//$this->select("lang", "label=English");
|
||||
|
||||
$this->waitForPageToLoad("30000");
|
||||
$this->type("input_username", TESTSUITE_USER);
|
||||
$this->type("input_password", TESTSUITE_PASSWORD);
|
||||
$this->click("input_go");
|
||||
$this->waitForPageToLoad("30001");
|
||||
}
|
||||
|
||||
/*
|
||||
* Just a dummy to show some example statements
|
||||
*
|
||||
public function mockTest()
|
||||
{
|
||||
// Slow down the testing speed, ideal for debugging
|
||||
//$this->setSpeed(4000);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
||||
@ -4,6 +4,7 @@
|
||||
* Selenium TestCase for XSS related tests
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
* @group Selenium
|
||||
*/
|
||||
|
||||
require_once('PmaSeleniumTestCase.php');
|
||||
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
// unplanned execution path
|
||||
if (!defined('PMA_MINIMUM_COMMON')) {
|
||||
if (!defined('PMA_MINIMUM_COMMON') && !defined('TESTSUITE')) {
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
// unplanned execution path
|
||||
if (!defined('PMA_MINIMUM_COMMON')) {
|
||||
if (!defined('PMA_MINIMUM_COMMON') && !defined('TESTSUITE')) {
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user