mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 03:01:43 +09:00
All classes can be tested from now.
1) Add some test files. 2) Create a folder for fronendfile. Move the class file into the folder. 3) Write Bootstrap.php file. 4) Modify phpunit.xml file. 5) Add a context mock class. git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9850 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
aa90148aa3
commit
67751eb85b
8 changed files with 148 additions and 135 deletions
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
if(!defined('__DEBUG__')) define('__DEBUG__', 1);
|
||||
if(!defined('__XE__')) define('__XE__', true);
|
||||
if(!defined('__ZBXE__')) define('__ZBXE__', true);
|
||||
if(!defined('_XE_PATH_')) define('_XE_PATH_', realpath(dirname(__FILE__).'/../').'/');
|
||||
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
|
||||
/**
|
||||
* Print out the message
|
||||
**/
|
||||
function _log($msg) {
|
||||
$args = func_get_args();
|
||||
|
||||
foreach($args as $arg) {
|
||||
fwrite(STDOUT, "\n");
|
||||
fwrite(STDOUT, print_r($arg, true));
|
||||
}
|
||||
fwrite(STDOUT, "\n");
|
||||
}
|
||||
|
||||
/* End of file Bootstrap.php */
|
||||
/* Location: ./tests/Bootstrap.php */
|
||||
62
tests/classes/context/Context.mock.php
Normal file
62
tests/classes/context/Context.mock.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
if(!defined('FOLLOW_REQUEST_SSL')) define('FOLLOW_REQUEST_SSL',0);
|
||||
if(!defined('ENFORCE_SSL')) define('ENFORCE_SSL',1);
|
||||
if(!defined('RELEASE_SSL')) define('RELEASE_SSL',2);
|
||||
|
||||
class Context
|
||||
{
|
||||
public static $mock_vars = array();
|
||||
|
||||
public function gets() {
|
||||
$args = func_get_args();
|
||||
$output = new stdClass;
|
||||
|
||||
foreach($args as $name) {
|
||||
$output->{$name} = Context::$mock_vars[$name];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function get($name) {
|
||||
return array_key_exists($name, Context::$mock_vars)?Context::$mock_vars[$name]:'';
|
||||
}
|
||||
|
||||
public function getRequestVars() {
|
||||
return Context::$mock_vars;
|
||||
}
|
||||
|
||||
public function set($name, $value) {
|
||||
Context::$mock_vars[$name] = $value;
|
||||
}
|
||||
|
||||
public function getLangType() {
|
||||
return 'en';
|
||||
}
|
||||
|
||||
public function getLang($str) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function truncate() {
|
||||
Context::$mock_vars = array();
|
||||
}
|
||||
|
||||
public function getDBInfo() {
|
||||
global $use_cdn;
|
||||
|
||||
$dbInfo = new stdClass;
|
||||
$dbInfo->use_cdn = $use_cdn;
|
||||
|
||||
return $dbInfo;
|
||||
}
|
||||
|
||||
public function getRequestUrl() {
|
||||
global $request_url;
|
||||
return $request_url;
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file Context.mock.php */
|
||||
/* Location: ./tests/classes/context/Context.mock.php */
|
||||
20
tests/classes/context/ContextTest.php
Normal file
20
tests/classes/context/ContextTest.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
if(!defined('__XE__')) require dirname(__FILE__).'/../../Bootstrap.php';
|
||||
|
||||
require_once _XE_PATH_.'classes/context/Context.class.php';
|
||||
require_once _XE_PATH_.'classes/handler/Handler.class.php';
|
||||
require_once _XE_PATH_.'classes/frontendfile/FrontEndFileHandler.class.php';
|
||||
|
||||
class ContextTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* test whether the singleton works
|
||||
*/
|
||||
public function testGetInstance()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file ContextTest.php */
|
||||
/* Location: ./tests/classes/context/ContextTest.php */
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
|
||||
define('__DEBUG__', 1);
|
||||
$xe_path = realpath(dirname(__FILE__).'/../../../');
|
||||
require "{$xe_path}/classes/handler/Handler.class.php";
|
||||
require "{$xe_path}/classes/frontendfile/FrontEndFileHandler.class.php";
|
||||
if(!defined('__XE__')) require dirname(__FILE__).'/../../Bootstrap.php';
|
||||
|
||||
require_once _XE_PATH_.'classes/handler/Handler.class.php';
|
||||
require_once _XE_PATH_.'classes/frontendfile/FrontEndFileHandler.class.php';
|
||||
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
$_SERVER['SCRIPT_NAME'] = '/xe/index.php';
|
||||
|
||||
class FrontEndFileHandlerTest extends PHPUnit_Framework_TestCase
|
||||
|
|
@ -214,43 +213,12 @@ class FrontEndFileHandlerTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
|
||||
$mock_vars = array();
|
||||
|
||||
class Context
|
||||
if(!class_exists('Context'))
|
||||
{
|
||||
public function gets() {
|
||||
global $mock_vars;
|
||||
|
||||
$args = func_get_args();
|
||||
$output = new stdClass;
|
||||
|
||||
foreach($args as $name) {
|
||||
$output->{$name} = $mock_vars[$name];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function get($name) {
|
||||
global $mock_vars;
|
||||
return array_key_exists($name, $mock_vars)?$mock_vars[$name]:'';
|
||||
}
|
||||
|
||||
public function set($name, $value) {
|
||||
global $mock_vars;
|
||||
|
||||
$mock_vars[$name] = $value;
|
||||
}
|
||||
|
||||
public function getRequestUrl() {
|
||||
global $request_url;
|
||||
return $request_url;
|
||||
}
|
||||
public function getDBInfo() {
|
||||
global $use_cdn;
|
||||
$dbInfo->use_cdn = $use_cdn;
|
||||
return $dbInfo;
|
||||
}
|
||||
require _XE_PATH_.'/tests/classes/context/Context.mock.php';
|
||||
}
|
||||
|
||||
function debugPrint(){}
|
||||
if(!function_exists('debugPrint'))
|
||||
{
|
||||
function debugPrint(){}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
define('__DEBUG__', 1);
|
||||
$xe_path = realpath(dirname(__FILE__).'/../../../');
|
||||
require "{$xe_path}/classes/security/Security.class.php";
|
||||
if(!defined('__XE__')) require dirname(__FILE__).'/../../Bootstrap.php';
|
||||
|
||||
require_once _XE_PATH_.'/classes/security/Security.class.php';
|
||||
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
|
||||
|
|
@ -119,32 +119,10 @@ class SecurityTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
|
||||
$mock_vars = array();
|
||||
|
||||
class Context
|
||||
if(!class_exists('Context'))
|
||||
{
|
||||
public function gets() {
|
||||
global $mock_vars;
|
||||
|
||||
$args = func_get_args();
|
||||
$output = new stdClass;
|
||||
|
||||
foreach($args as $name) {
|
||||
$output->{$name} = $mock_vars[$name];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function get($name) {
|
||||
global $mock_vars;
|
||||
return array_key_exists($name, $mock_vars)?$mock_vars[$name]:'';
|
||||
}
|
||||
|
||||
public function set($name, $value) {
|
||||
global $mock_vars;
|
||||
|
||||
$mock_vars[$name] = $value;
|
||||
}
|
||||
|
||||
require _XE_PATH_.'/tests/classes/context/Context.mock.php';
|
||||
}
|
||||
|
||||
/* End of file SecurityTest.php */
|
||||
/* Location: ./tests/classes/security/SecurityTest.php */
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
|
||||
define('__DEBUG__', 1);
|
||||
define('_XE_PATH_', str_replace('tests/classes/template/TemplateHandlerTest.php', '', strtr(__FILE__, '\\', '/')));
|
||||
require_once _XE_PATH_.'/classes/file/FileHandler.class.php';
|
||||
require_once _XE_PATH_.'/classes/template/TemplateHandler.class.php';
|
||||
if(!defined('__XE__')) require dirname(__FILE__).'/../../Bootstrap.php';
|
||||
|
||||
$_SERVER['SCRIPT_NAME'] = '/xe/index.php';
|
||||
require_once _XE_PATH_.'classes/file/FileHandler.class.php';
|
||||
require_once _XE_PATH_.'classes/template/TemplateHandler.class.php';
|
||||
|
||||
class TemplateHandlerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
<?php
|
||||
|
||||
define('__DEBUG__', 1);
|
||||
$xe_path = realpath(dirname(__FILE__).'/../../../');
|
||||
require_once "{$xe_path}/classes/xml/XmlParser.class.php";
|
||||
require_once "{$xe_path}/classes/handler/Handler.class.php";
|
||||
require_once "{$xe_path}/classes/file/FileHandler.class.php";
|
||||
require_once "{$xe_path}/classes/validator/Validator.class.php";
|
||||
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
if(!defined('__XE__')) require dirname(__FILE__).'/../../Bootstrap.php';
|
||||
require_once _XE_PATH_.'classes/xml/XmlParser.class.php';
|
||||
require_once _XE_PATH_.'classes/handler/Handler.class.php';
|
||||
require_once _XE_PATH_.'classes/file/FileHandler.class.php';
|
||||
require_once _XE_PATH_.'classes/validator/Validator.class.php';
|
||||
|
||||
class ValidatorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
|
@ -46,8 +43,6 @@ class ValidatorTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
public function testDefault() {
|
||||
global $mock_vars;
|
||||
|
||||
$vd = new Validator();
|
||||
$vd->addFilter('userid', array('default'=>'ididid'));
|
||||
|
||||
|
|
@ -64,16 +59,18 @@ class ValidatorTest extends PHPUnit_Framework_TestCase
|
|||
$vd->validate(&$arr);
|
||||
$this->assertEquals( $arr, array('userid'=>'ownid') );
|
||||
|
||||
// context data
|
||||
$mock_vars = array(); // empty context variables
|
||||
$vd->validate();
|
||||
$this->assertEquals( 'ididid', Context::get('userid') );
|
||||
if(method_exists()) {
|
||||
// context data
|
||||
$mock_vars = array(); // empty context variables
|
||||
$vd->validate();
|
||||
$this->assertEquals( 'ididid', Context::get('userid') );
|
||||
|
||||
$vd->load(dirname(__FILE__).'/login.xml');
|
||||
$vd->load(dirname(__FILE__).'/login.xml');
|
||||
|
||||
Context::set('userid', '');
|
||||
$vd->validate();
|
||||
$this->assertEquals( 'idididid', Context::get('userid') );
|
||||
Context::set('userid', '');
|
||||
$vd->validate();
|
||||
$this->assertEquals( 'idididid', Context::get('userid') );
|
||||
}
|
||||
}
|
||||
|
||||
public function testLength() {
|
||||
|
|
@ -130,44 +127,10 @@ class ValidatorTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
|
||||
$mock_vars = array();
|
||||
|
||||
class Context
|
||||
if(!class_exists('Context'))
|
||||
{
|
||||
public function gets() {
|
||||
global $mock_vars;
|
||||
|
||||
$args = func_get_args();
|
||||
$output = new stdClass;
|
||||
|
||||
foreach($args as $name) {
|
||||
$output->{$name} = $mock_vars[$name];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getRequestVars() {
|
||||
global $mock_vars;
|
||||
|
||||
return $mock_vars;
|
||||
}
|
||||
|
||||
public function get($name) {
|
||||
global $mock_vars;
|
||||
return array_key_exists($name, $mock_vars)?$mock_vars[$name]:'';
|
||||
}
|
||||
|
||||
public function set($name, $value) {
|
||||
global $mock_vars;
|
||||
|
||||
$mock_vars[$name] = $value;
|
||||
}
|
||||
|
||||
public function getLangType() {
|
||||
return 'en';
|
||||
}
|
||||
public function getLang($str) {
|
||||
return $str;
|
||||
}
|
||||
require _XE_PATH_.'tests/classes/context/Context.mock.php';
|
||||
}
|
||||
|
||||
/* End of file ValidatorTest.php */
|
||||
/* Location: ./tests/classes/validator/ValidatorTest.php */
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
<testsuites>
|
||||
<testsuite name="XE Core Test Suite">
|
||||
<directory>.</directory>
|
||||
<exclude>./classes/context/Context.mock.php</exclude>
|
||||
<exclude>./classes/db/</exclude>
|
||||
<exclude>./classes/security/</exclude>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<logging>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue