mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-18 22:58:10 +01:00
22c3041e12
phpBB class name lookups follow these rules: - All classes are prefixed with phpbb_ - All classes reside in includes/ or a subdirectory thereof - Directories must not contain underscores - The class name is separated into parts by underscores, the parts are checked from first to last, until one is found which is not a directory, all remaining parts make up the file name. If no parts are left, the last directory name is used. Examples: directory structure: includes/ class_name.php dir/ class_name.php dir.php subdir/ class_name.php lookups: phpbb_class_name -> includes/class_name.php phpbb_dir_class_name -> includes/dir/class_name.php phpbb_dir -> includes/dir/dir.php phpbb_dir_subdir_class_name -> includes/dir/subdir/class_name.php Optionally the class can be supplied with a cache instance, either in the constructor or via set_cache() at a later time. This allows for the lookups to be cached, so the directories do not have to be traveresed on every request. This makes it necessary for the cache and its dependency to continue to be loaded the old way - without autoloading. The code will not be changed to use autoloading, but it will rather only be used for new classes where applicable. PHPBB3-9682
66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* @package testing
|
|
* @version $Id$
|
|
* @copyright (c) 2008 phpBB Group
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
*
|
|
*/
|
|
|
|
require_once 'test_framework/framework.php';
|
|
require_once 'class_loader/cache_mock.php';
|
|
|
|
require_once '../phpBB/includes/class_loader.php';
|
|
|
|
|
|
class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
|
|
{
|
|
public function test_resolve_path()
|
|
{
|
|
$prefix = 'class_loader/';
|
|
$class_loader = new phpbb_class_loader($prefix);
|
|
|
|
$prefix .= 'includes/';
|
|
|
|
$this->assertEquals(
|
|
$prefix . 'class_name.php',
|
|
$class_loader->resolve_path('phpbb_class_name'),
|
|
'Top level class'
|
|
);
|
|
$this->assertEquals(
|
|
$prefix . 'dir/class_name.php',
|
|
$class_loader->resolve_path('phpbb_dir_class_name'),
|
|
'Class in a directory'
|
|
);
|
|
$this->assertEquals(
|
|
$prefix . 'dir/subdir/class_name.php',
|
|
$class_loader->resolve_path('phpbb_dir_subdir_class_name'),
|
|
'Class in a sub-directory'
|
|
);
|
|
}
|
|
|
|
public function test_resolve_cached()
|
|
{
|
|
$cache = new phpbb_cache_mock;
|
|
$cache->put('class_loader', array('phpbb_a_cached_name' => 'a/cached_name'));
|
|
|
|
$prefix = 'class_loader/';
|
|
$class_loader = new phpbb_class_loader($prefix, '.php', $cache);
|
|
|
|
$prefix .= 'includes/';
|
|
|
|
$this->assertEquals(
|
|
$prefix . 'dir/class_name.php',
|
|
$class_loader->resolve_path('phpbb_dir_class_name'),
|
|
'Class in a directory'
|
|
);
|
|
|
|
$this->assertEquals(
|
|
$prefix . 'a/cached_name.php',
|
|
$class_loader->resolve_path('phpbb_a_cached_name'),
|
|
'Class in a directory'
|
|
);
|
|
}
|
|
}
|