1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

Merge branch 'develop' of git://github.com/phpbb/phpbb3 into ticket/11103

This commit is contained in:
Nathaniel Guse
2012-12-12 16:30:50 -06:00
38 changed files with 507 additions and 31 deletions

View File

@@ -18,9 +18,19 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// check for logout link
$crawler = $this->request('GET', 'index.php');
$this->assert_response_success();
$this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text());
}
public function test_login_other()
{
$this->create_user('anothertestuser');
$this->login('anothertestuser');
$crawler = $this->request('GET', 'index.php');
$this->assert_response_success();
$this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text());
}
/**
* @depends test_login
*/
@@ -31,10 +41,12 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// logout
$crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
$this->assert_response_success();
$this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());
// look for a register link, which should be visible only when logged out
$crawler = $this->request('GET', 'index.php');
$this->assert_response_success();
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_mock_filesystem_extension_manager extends phpbb_mock_extension_manager
{
public function __construct($phpbb_root_path)
{
$extensions = array();
$iterator = new DirectoryIterator($phpbb_root_path . 'ext/');
foreach ($iterator as $fileinfo)
{
if ($fileinfo->isDir() && substr($fileinfo->getFilename(), 0, 1) != '.')
{
$name = $fileinfo->getFilename();
$extension = array(
'ext_name' => $name,
'ext_active' => true,
'ext_path' => 'ext/' . $name . '/',
);
$extensions[$name] = $extension;
}
}
ksort($extensions);
parent::__construct($phpbb_root_path, $extensions);
}
}

47
tests/mock/null_cache.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_mock_null_cache
{
public function __construct()
{
}
public function get($var_name)
{
return false;
}
public function put($var_name, $var, $ttl = 0)
{
}
public function destroy($var_name, $table = '')
{
}
public function obtain_bots()
{
return array();
}
public function obtain_word_list()
{
return array();
}
public function set_bots($bots)
{
}
public function sql_exists($query_id)
{
return false;
}
}

View File

@@ -0,0 +1 @@
Kappa test event in all

View File

@@ -0,0 +1 @@
Kappa test event in silver

View File

@@ -0,0 +1 @@
Kappa test event in silver_inherit

View File

@@ -0,0 +1 @@
Omega test event in all

View File

@@ -0,0 +1 @@
Omega test event in silver

View File

@@ -0,0 +1 @@
two in silver in omega

View File

@@ -0,0 +1 @@
Zeta test event in all

View File

@@ -0,0 +1 @@
<!-- EVENT test -->

View File

@@ -0,0 +1 @@
<!-- EVENT two -->

View File

@@ -0,0 +1 @@
<!-- EVENT test -->

View File

@@ -0,0 +1 @@
Universal in trivial extension.

View File

@@ -0,0 +1 @@
Simple in trivial extension.

View File

@@ -0,0 +1 @@
<!-- EVENT simple -->

View File

@@ -0,0 +1 @@
<!-- EVENT universal -->

View File

@@ -48,7 +48,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
$this->setup_engine(array('tpl_allow_php' => true));
$this->style->set_custom_style('tests', $cache_dir, '');
$this->style->set_custom_style('tests', $cache_dir, array(), '');
$cache_file = $this->template->cachepath . 'includephp_absolute.html.php';
$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file);

View File

@@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case
protected function setUp()
{
$this->template_compile = new phpbb_template_compile(false, null, '');
$this->template_compile = new phpbb_template_compile(false, null, $this->style_resource_locator, '');
$this->template_path = dirname(__FILE__) . '/templates';
}

View File

@@ -0,0 +1,118 @@
<?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_events_test extends phpbb_template_template_test_case
{
public function template_data()
{
return array(
/*
array(
'', // file
'', // dataset
array(), // style names
array(), // vars
array(), // block vars
array(), // destroy
'', // expected result
),
*/
array(
'Simple template event',
'ext_trivial',
array(),
'event_simple.html',
array(),
array(),
array(),
"Simple in trivial extension.",
),
array(
'Universal template event ("all" style)',
'ext_trivial',
array(),
'event_universal.html',
array(),
array(),
array(),
"Universal in trivial extension.",
),
array(
'Template event with inheritance - parent',
'event_inheritance',
array('silver'),
'event_test.html',
array(),
array(),
array(),
'Kappa test event in all
Omega test event in all
Zeta test event in all
Kappa test event in silver
Omega test event in silver',
),
array(
'Template event with inheritance - child',
'event_inheritance',
array('silver_inherit', 'silver'),
'event_test.html',
array(),
array(),
array(),
'Kappa test event in all
Omega test event in all
Zeta test event in all
Kappa test event in silver_inherit',
),
array(
'Definition in parent style',
'event_inheritance',
array('silver_inherit', 'silver'),
'event_two.html',
array(),
array(),
array(),
'two in silver in omega',
),
);
}
/**
* @dataProvider template_data
*/
public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected)
{
// Reset the engine state
$this->setup_engine_for_events($dataset, $style_names);
// Run test
$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
}
protected function setup_engine_for_events($dataset, $style_names, 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__) . "/datasets/$dataset/styles/silver/template";
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->extension_manager = new phpbb_mock_filesystem_extension_manager(
dirname(__FILE__) . "/datasets/$dataset/"
);
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager);
$this->style_provider = new phpbb_style_path_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('silver', array($this->template_path), $style_names, '');
}
}

View File

@@ -69,7 +69,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
$this->style_provider = new phpbb_style_path_provider();
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
$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', $this->template_path, '');
$this->style->set_custom_style('tests', $this->template_path, array(), '');
}
protected function setUp()

View File

@@ -24,6 +24,6 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
$this->style_provider = new phpbb_style_path_provider();
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
$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), '');
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), '');
}
}

View File

@@ -0,0 +1,4 @@
<!-- EVENT child_only -->
<!-- EVENT parent_only -->
<!-- EVENT parent_and_child -->
<!-- EVENT random_event -->

View File

@@ -231,7 +231,61 @@ class phpbb_functional_test_case extends phpbb_test_case
$db_conn_mgr->recreate_db();
}
protected function login()
/**
* Creates a new user with limited permissions
*
* @param string $username Also doubles up as the user's password
* @return int ID of created user
*/
protected function create_user($username)
{
// Required by unique_id
global $config;
if (!is_array($config))
{
$config = array();
}
$config['rand_seed'] = '';
$config['rand_seed_last_update'] = time() + 600;
// Required by user_add
global $db, $cache, $config, $phpbb_dispatcher;
$db = $this->get_db();
if (!function_exists('phpbb_mock_null_cache'))
{
require_once(__DIR__ . '/../mock/null_cache.php');
}
$cache = new phpbb_mock_null_cache;
if (!function_exists('utf_clean_string'))
{
require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
}
if (!function_exists('user_add'))
{
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
}
$config = new phpbb_config(array());
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user_row = array(
'username' => $username,
'group_id' => 2,
'user_email' => 'nobody@example.com',
'user_type' => 0,
'user_lang' => 'en',
'user_timezone' => 0,
'user_dateformat' => '',
'user_password' => phpbb_hash($username),
);
return user_add($user_row);
}
protected function login($username = 'admin')
{
$this->add_lang('ucp');
@@ -239,7 +293,9 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text());
$form = $crawler->selectButton($this->lang('LOGIN'))->form();
$login = $this->client->submit($form, array('username' => 'admin', 'password' => 'admin'));
$crawler = $this->client->submit($form, array('username' => $username, 'password' => $username));
$this->assert_response_success();
$this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text());
$cookies = $this->cookieJar->all();