mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
Merge remote-tracking branch 'cyberalien/ticket/10733' into develop
* cyberalien/ticket/10733: [ticket/10733] Fixing test [ticket/10733] Removing static from data providers [ticket/10733] Adding test for locator [ticket/10733] Adding functions to locate resources [ticket/10733] Extending get_source_file_for_handle
This commit is contained in:
commit
2b3cfa0f7b
14 changed files with 251 additions and 29 deletions
|
@ -185,9 +185,12 @@ class phpbb_style_resource_locator
|
|||
* handle to a path without any filesystem or styles tree checks.
|
||||
*
|
||||
* @param string $handle Template handle (i.e. "friendly" template name)
|
||||
* @param bool $find_all If true, each root path will be checked and function
|
||||
* will return array of files instead of string and will not
|
||||
* trigger a error if template does not exist
|
||||
* @return string Source file path
|
||||
*/
|
||||
public function get_source_file_for_handle($handle)
|
||||
public function get_source_file_for_handle($handle, $find_all = false)
|
||||
{
|
||||
// If we don't have a file assigned to this handle, die.
|
||||
if (!isset($this->files['style'][0][$handle]))
|
||||
|
@ -198,20 +201,91 @@ class phpbb_style_resource_locator
|
|||
// locate a source file that exists
|
||||
$source_file = $this->files['style'][0][$handle];
|
||||
$tried = $source_file;
|
||||
$found = false;
|
||||
$found_all = array();
|
||||
foreach ($this->roots as $root_key => $root_paths)
|
||||
{
|
||||
foreach ($root_paths as $root_index => $root)
|
||||
{
|
||||
$source_file = $this->files[$root_key][$root_index][$handle];
|
||||
$tried .= ', ' . $source_file;
|
||||
if (file_exists($source_file))
|
||||
{
|
||||
return $source_file;
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($found)
|
||||
{
|
||||
if ($find_all)
|
||||
{
|
||||
$found_all[] = $source_file;
|
||||
$found = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
$tried .= ', ' . $source_file;
|
||||
}
|
||||
}
|
||||
|
||||
// search failed
|
||||
if (!$found && !$find_all)
|
||||
{
|
||||
trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR);
|
||||
}
|
||||
|
||||
return ($find_all) ? $found_all : $source_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates source file path, accounting for styles tree and verifying that
|
||||
* the path exists.
|
||||
*
|
||||
* Unlike previous functions, this function works without template handle
|
||||
* and it can search for more than one file. If more than one file name is
|
||||
* specified, it will return location of file that it finds first.
|
||||
*
|
||||
* @param array $files List of files to locate.
|
||||
* @param bool $return_default Determines what to return if file does not
|
||||
* exist. If true, function will return location where file is
|
||||
* supposed to be. If false, function will return false.
|
||||
* @param bool $return_full_path If true, function will return full path
|
||||
* to file. If false, function will return file name. This
|
||||
* parameter can be used to check which one of set of files
|
||||
* is available.
|
||||
* @return string or boolean Source file path if file exists or $return_default is
|
||||
* true. False if file does not exist and $return_default is false
|
||||
*/
|
||||
public function get_first_file_location($files, $return_default = false, $return_full_path = true)
|
||||
{
|
||||
// set default value
|
||||
$default_result = false;
|
||||
|
||||
// check all available paths
|
||||
foreach ($this->roots as $root_paths)
|
||||
{
|
||||
foreach ($root_paths as $path)
|
||||
{
|
||||
// check all files
|
||||
foreach ($files as $filename)
|
||||
{
|
||||
$source_file = $path . '/' . $filename;
|
||||
if (file_exists($source_file))
|
||||
{
|
||||
return ($return_full_path) ? $source_file : $filename;
|
||||
}
|
||||
|
||||
// assign first file as result if $return_default is true
|
||||
if ($return_default && $default_result === false)
|
||||
{
|
||||
$default_result = $source_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search failed
|
||||
return $default_result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,4 +150,32 @@ class phpbb_style
|
|||
{
|
||||
$this->provider->set_ext_dir_prefix($ext_dir_prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates source file path, accounting for styles tree and verifying that
|
||||
* the path exists.
|
||||
*
|
||||
* @param string or array $files List of files to locate. If there is only
|
||||
* one file, $files can be a string to make code easier to read.
|
||||
* @param bool $return_default Determines what to return if file does not
|
||||
* exist. If true, function will return location where file is
|
||||
* supposed to be. If false, function will return false.
|
||||
* @param bool $return_full_path If true, function will return full path
|
||||
* to file. If false, function will return file name. This
|
||||
* parameter can be used to check which one of set of files
|
||||
* is available.
|
||||
* @return string or boolean Source file path if file exists or $return_default is
|
||||
* true. False if file does not exist and $return_default is false
|
||||
*/
|
||||
public function locate($files, $return_default = false, $return_full_path = true)
|
||||
{
|
||||
// convert string to array
|
||||
if (is_string($files))
|
||||
{
|
||||
$files = array($files);
|
||||
}
|
||||
|
||||
// use resource locator to find files
|
||||
return $this->locator->get_first_file_location($files, $return_default, $return_full_path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -456,4 +456,40 @@ class phpbb_style_template
|
|||
}
|
||||
include($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates source template path, accounting for styles tree and verifying that
|
||||
* the path exists.
|
||||
*
|
||||
* @param string or array $files List of templates to locate. If there is only
|
||||
* one template, $files can be a string to make code easier to read.
|
||||
* @param bool $return_default Determines what to return if template does not
|
||||
* exist. If true, function will return location where template is
|
||||
* supposed to be. If false, function will return false.
|
||||
* @param bool $return_full_path If true, function will return full path
|
||||
* to template. If false, function will return template file name.
|
||||
* This parameter can be used to check which one of set of template
|
||||
* files is available.
|
||||
* @return string or boolean Source template path if template exists or $return_default is
|
||||
* true. False if template does not exist and $return_default is false
|
||||
*/
|
||||
public function locate($files, $return_default = false, $return_full_path = true)
|
||||
{
|
||||
// add tempalte path prefix
|
||||
$templates = array();
|
||||
if (is_string($files))
|
||||
{
|
||||
$templates[] = $this->template_path . $files;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$templates[] = $this->template_path . $file;
|
||||
}
|
||||
}
|
||||
|
||||
// use resource locator to find files
|
||||
return $this->locator->get_first_file_location($templates, $return_default, $return_full_path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
|
|||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml');
|
||||
}
|
||||
|
||||
public static function return_on_error_select_data()
|
||||
public function return_on_error_select_data()
|
||||
{
|
||||
return array(
|
||||
array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))),
|
||||
|
@ -44,7 +44,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||
}
|
||||
|
||||
public static function fetchrow_data()
|
||||
public function fetchrow_data()
|
||||
{
|
||||
return array(
|
||||
array('', array(array('username_clean' => 'barfoo'),
|
||||
|
@ -95,7 +95,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
|
|||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
public static function fetchfield_data()
|
||||
public function fetchfield_data()
|
||||
{
|
||||
return array(
|
||||
array('', array('barfoo', 'foobar', 'bertie')),
|
||||
|
@ -125,7 +125,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $ary);
|
||||
}
|
||||
|
||||
public static function query_limit_data()
|
||||
public function query_limit_data()
|
||||
{
|
||||
return array(
|
||||
array(0, 0, array(array('username_clean' => 'barfoo'),
|
||||
|
@ -166,7 +166,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $ary);
|
||||
}
|
||||
|
||||
public static function like_expression_data()
|
||||
public function like_expression_data()
|
||||
{
|
||||
// * = any_char; # = one_char
|
||||
return array(
|
||||
|
@ -203,7 +203,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
|
|||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
public static function in_set_data()
|
||||
public function in_set_data()
|
||||
{
|
||||
return array(
|
||||
array('user_id', 3, false, false, array(array('username_clean' => 'bertie'))),
|
||||
|
@ -277,7 +277,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
|
|||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
public static function build_array_data()
|
||||
public function build_array_data()
|
||||
{
|
||||
return array(
|
||||
array(array('username_clean' => 'barfoo'), array(array('username_clean' => 'barfoo'))),
|
||||
|
|
|
@ -16,7 +16,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case
|
|||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
|
||||
}
|
||||
|
||||
public static function build_array_insert_data()
|
||||
public function build_array_insert_data()
|
||||
{
|
||||
return array(
|
||||
array(array(
|
||||
|
@ -104,7 +104,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case
|
|||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
public static function update_data()
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
|
|
|
@ -15,7 +15,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case
|
|||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/group_positions.xml');
|
||||
}
|
||||
|
||||
public static function get_group_value_data()
|
||||
public function get_group_value_data()
|
||||
{
|
||||
return array(
|
||||
array('teampage', 1, 0),
|
||||
|
@ -38,7 +38,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $test_class->get_group_value($group_id));
|
||||
}
|
||||
|
||||
public static function get_group_count_data()
|
||||
public function get_group_count_data()
|
||||
{
|
||||
return array(
|
||||
array('teampage', 2),
|
||||
|
@ -59,7 +59,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $test_class->get_group_count());
|
||||
}
|
||||
|
||||
public static function add_group_data()
|
||||
public function add_group_data()
|
||||
{
|
||||
return array(
|
||||
array('teampage', 1, array(
|
||||
|
@ -93,7 +93,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||
}
|
||||
|
||||
public static function delete_group_data()
|
||||
public function delete_group_data()
|
||||
{
|
||||
return array(
|
||||
array('teampage', 1, false, array(
|
||||
|
@ -147,7 +147,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||
}
|
||||
|
||||
public static function move_up_data()
|
||||
public function move_up_data()
|
||||
{
|
||||
return array(
|
||||
array('teampage', 1, array(
|
||||
|
@ -186,7 +186,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||
}
|
||||
|
||||
public static function move_down_data()
|
||||
public function move_down_data()
|
||||
{
|
||||
return array(
|
||||
array('teampage', 1, array(
|
||||
|
@ -225,7 +225,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case
|
|||
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||
}
|
||||
|
||||
public static function move_data()
|
||||
public function move_data()
|
||||
{
|
||||
return array(
|
||||
array('teampage', 1, 1, array(
|
||||
|
|
|
@ -112,7 +112,7 @@ class phpbb_request_var_test extends phpbb_test_case
|
|||
$this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path);
|
||||
}
|
||||
|
||||
public static function deep_access()
|
||||
public function deep_access()
|
||||
{
|
||||
return array(
|
||||
// array(path, default, expected result)
|
||||
|
@ -123,7 +123,7 @@ class phpbb_request_var_test extends phpbb_test_case
|
|||
);
|
||||
}
|
||||
|
||||
public static function request_variables()
|
||||
public function request_variables()
|
||||
{
|
||||
return array(
|
||||
// strings
|
||||
|
|
|
@ -13,7 +13,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
|||
|
||||
class phpbb_security_extract_current_page_test extends phpbb_security_test_base
|
||||
{
|
||||
public static function security_variables()
|
||||
public function security_variables()
|
||||
{
|
||||
return array(
|
||||
array('http://localhost/phpBB/index.php', 'mark=forums&x="><script>alert(/XSS/);</script>', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E'),
|
||||
|
|
|
@ -13,7 +13,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
|||
|
||||
class phpbb_security_redirect_test extends phpbb_security_test_base
|
||||
{
|
||||
public static function provider()
|
||||
public function provider()
|
||||
{
|
||||
// array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false))
|
||||
return array(
|
||||
|
|
|
@ -14,7 +14,7 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t
|
|||
/**
|
||||
* @todo put test data into templates/xyz.test
|
||||
*/
|
||||
public static function template_data()
|
||||
public function template_data()
|
||||
{
|
||||
return array(
|
||||
// First element of the array is test name - keep them distinct
|
||||
|
|
84
tests/template/template_locate_test.php
Normal file
84
tests/template/template_locate_test.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/template_test_case.php';
|
||||
|
||||
class phpbb_template_template_locate_test extends phpbb_template_template_test_case
|
||||
{
|
||||
public function template_data()
|
||||
{
|
||||
return array(
|
||||
// First element of the array is test name - keep them distinct
|
||||
array(
|
||||
'simple inheritance - only parent template exists',
|
||||
dirname(__FILE__) . '/parent_templates/parent_only.html',
|
||||
'parent_only.html',
|
||||
false,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'simple inheritance - only child template exists',
|
||||
dirname(__FILE__) . '/templates/child_only.html',
|
||||
'child_only.html',
|
||||
false,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'simple inheritance - both parent and child templates exist',
|
||||
dirname(__FILE__) . '/templates/parent_and_child.html',
|
||||
'parent_and_child.html',
|
||||
false,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'find first template - only child template exists in main style',
|
||||
'child_only.html',
|
||||
array('parent_only.html', 'child_only.html'),
|
||||
false,
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'find first template - both templates exist in main style',
|
||||
'parent_and_child.html',
|
||||
array('parent_and_child.html', 'child_only.html'),
|
||||
false,
|
||||
false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_template($name, $expected, $files, $return_default, $return_full_path)
|
||||
{
|
||||
// Reset the engine state
|
||||
$this->setup_engine();
|
||||
|
||||
// Locate template
|
||||
$result = $this->template->locate($files, $return_default, $return_full_path);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
protected function setup_engine(array $new_config = array())
|
||||
{
|
||||
global $phpbb_root_path, $phpEx, $user;
|
||||
|
||||
$defaults = $this->config_defaults();
|
||||
$config = new phpbb_config(array_merge($defaults, $new_config));
|
||||
|
||||
$this->template_path = dirname(__FILE__) . '/templates';
|
||||
$this->parent_template_path = dirname(__FILE__) . '/parent_templates';
|
||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
||||
$this->style_provider = new phpbb_style_path_provider();
|
||||
$this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider);
|
||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), '');
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
|||
/**
|
||||
* @todo put test data into templates/xyz.test
|
||||
*/
|
||||
public static function template_data()
|
||||
public function template_data()
|
||||
{
|
||||
return array(
|
||||
/*
|
||||
|
@ -394,7 +394,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
|||
$this->run_template('php.html', array(), array(), array(), 'test', $cache_file);
|
||||
}
|
||||
|
||||
public static function alter_block_array_data()
|
||||
public function alter_block_array_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
|
|
|
@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
|
|||
|
||||
class phpbb_text_processing_make_clickable_test extends phpbb_test_case
|
||||
{
|
||||
public static function make_clickable_data()
|
||||
public function make_clickable_data()
|
||||
{
|
||||
// value => whether it should work
|
||||
$prefix_texts = array(
|
||||
|
|
|
@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
|||
|
||||
class phpbb_utf_utf8_clean_string_test extends phpbb_test_case
|
||||
{
|
||||
public static function cleanable_strings()
|
||||
public function cleanable_strings()
|
||||
{
|
||||
return array(
|
||||
array('MiXed CaSe', 'mixed case', 'Checking case folding'),
|
||||
|
|
Loading…
Add table
Reference in a new issue