mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-22 00:05:49 +02:00
[feature/oauth] Merge branch 'develop' of git://github.com/phpbb/phpbb3 into feature/oauth
Conflicts: phpBB/composer.json phpBB/composer.lock phpBB/develop/create_schema_files.php phpBB/includes/ucp/ucp_register.php PHPBB3-11673
This commit is contained in:
@@ -15,28 +15,28 @@ class phpbb_controller_helper_url_test extends phpbb_test_case
|
||||
public function helper_url_data()
|
||||
{
|
||||
return array(
|
||||
array('foo/bar?t=1&f=2', false, true, false, 'app.php?t=1&f=2&controller=foo/bar', 'parameters in url-argument'),
|
||||
array('foo/bar', 't=1&f=2', true, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument using amp'),
|
||||
array('foo/bar', 't=1&f=2', false, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument using &'),
|
||||
array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument as array'),
|
||||
array('foo/bar?t=1&f=2', false, true, false, 'foo/bar?t=1&f=2', 'parameters in url-argument'),
|
||||
array('foo/bar', 't=1&f=2', true, false, 'foo/bar?t=1&f=2', 'parameters in params-argument using amp'),
|
||||
array('foo/bar', 't=1&f=2', false, false, 'foo/bar?t=1&f=2', 'parameters in params-argument using &'),
|
||||
array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'foo/bar?t=1&f=2', 'parameters in params-argument as array'),
|
||||
|
||||
// Custom sid parameter
|
||||
array('foo/bar', 't=1&f=2', true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid', 'using session_id'),
|
||||
array('foo/bar', 't=1&f=2', true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid', 'using session_id'),
|
||||
|
||||
// Testing anchors
|
||||
array('foo/bar?t=1&f=2#anchor', false, true, false, 'app.php?t=1&f=2&controller=foo/bar#anchor', 'anchor in url-argument'),
|
||||
array('foo/bar', 't=1&f=2#anchor', true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in params-argument'),
|
||||
array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in params-argument (array)'),
|
||||
array('foo/bar?t=1&f=2#anchor', false, true, false, 'foo/bar?t=1&f=2#anchor', 'anchor in url-argument'),
|
||||
array('foo/bar', 't=1&f=2#anchor', true, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument'),
|
||||
array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
|
||||
|
||||
// Anchors and custom sid
|
||||
array('foo/bar?t=1&f=2#anchor', false, true, 'custom-sid', 'app.php?t=1&f=2&controller=foo/bar&sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
|
||||
array('foo/bar', 't=1&f=2#anchor', true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
|
||||
array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
|
||||
array('foo/bar?t=1&f=2#anchor', false, true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
|
||||
array('foo/bar', 't=1&f=2#anchor', true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
|
||||
array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
|
||||
|
||||
// Empty parameters should not append the &
|
||||
array('foo/bar', false, true, false, 'app.php?controller=foo/bar', 'no params using bool false'),
|
||||
array('foo/bar', '', true, false, 'app.php?controller=foo/bar', 'no params using empty string'),
|
||||
array('foo/bar', array(), true, false, 'app.php?controller=foo/bar', 'no params using empty array'),
|
||||
array('foo/bar', false, true, false, 'foo/bar', 'no params using bool false'),
|
||||
array('foo/bar', '', true, false, 'foo/bar', 'no params using empty string'),
|
||||
array('foo/bar', array(), true, false, 'foo/bar', 'no params using empty array'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,14 +48,12 @@ class phpbb_controller_helper_url_test extends phpbb_test_case
|
||||
global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
||||
$this->user = $this->getMock('phpbb_user');
|
||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
|
||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
||||
$this->style_provider = new phpbb_style_path_provider();
|
||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, new phpbb_config(array()), $this->user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||
|
||||
$helper = new phpbb_controller_helper($this->template, $this->user, '', 'php');
|
||||
|
||||
$request = new phpbb_mock_request($_GET, $_POST, $_COOKIE, $_SERVER, false, $_FILES);
|
||||
$helper = new phpbb_controller_helper($this->template, $this->user, $request, '', 'php');
|
||||
$this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected);
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ class phpbb_di_container_test extends phpbb_test_case
|
||||
$phpbb_root_path = __DIR__ . '/../../phpBB/';
|
||||
$extensions = array(
|
||||
new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
|
||||
new phpbb_di_extension_core($phpbb_root_path),
|
||||
new phpbb_di_extension_core($phpbb_root_path . 'config'),
|
||||
);
|
||||
$container = phpbb_create_container($extensions, $phpbb_root_path, 'php');
|
||||
|
||||
@@ -29,7 +29,7 @@ class phpbb_di_container_test extends phpbb_test_case
|
||||
$phpbb_root_path = __DIR__ . '/../../phpBB/';
|
||||
$extensions = array(
|
||||
new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
|
||||
new phpbb_di_extension_core($phpbb_root_path),
|
||||
new phpbb_di_extension_core($phpbb_root_path . 'config'),
|
||||
);
|
||||
$container = phpbb_create_install_container($phpbb_root_path, 'php');
|
||||
|
||||
@@ -43,7 +43,7 @@ class phpbb_di_container_test extends phpbb_test_case
|
||||
$config_file = __DIR__ . '/fixtures/config.php';
|
||||
$extensions = array(
|
||||
new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
|
||||
new phpbb_di_extension_core($phpbb_root_path),
|
||||
new phpbb_di_extension_core($phpbb_root_path . 'config'),
|
||||
);
|
||||
$container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php');
|
||||
|
||||
|
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_extension_style_path_provider_test extends phpbb_test_case
|
||||
{
|
||||
protected $relative_root_path;
|
||||
protected $root_path;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->relative_root_path = './';
|
||||
$this->root_path = dirname(__FILE__) . '/';
|
||||
}
|
||||
|
||||
public function test_find()
|
||||
{
|
||||
$phpbb_style_path_provider = new phpbb_style_path_provider();
|
||||
$phpbb_style_path_provider->set_styles(array($this->relative_root_path . 'styles/prosilver'));
|
||||
$phpbb_style_extension_path_provider = new phpbb_style_extension_path_provider(new phpbb_mock_extension_manager(
|
||||
$this->root_path,
|
||||
array(
|
||||
'foo' => array(
|
||||
'ext_name' => 'foo',
|
||||
'ext_active' => '1',
|
||||
'ext_path' => 'ext/foo/',
|
||||
),
|
||||
'bar' => array(
|
||||
'ext_name' => 'bar',
|
||||
'ext_active' => '1',
|
||||
'ext_path' => 'ext/bar/',
|
||||
),
|
||||
)), $phpbb_style_path_provider, $this->relative_root_path);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'style' => array(
|
||||
$this->relative_root_path . 'styles/prosilver',
|
||||
),
|
||||
'bar' => array(
|
||||
$this->root_path . 'ext/bar/styles/prosilver',
|
||||
),
|
||||
), $phpbb_style_extension_path_provider->find());
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
require_once dirname(__FILE__) . '/../style_path_provider_test.php';
|
||||
|
||||
class phpbb_extension_subdir_style_path_provider_test extends phpbb_extension_style_path_provider_test
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->relative_root_path = '../';
|
||||
$this->root_path = dirname(__FILE__) . '/../';
|
||||
}
|
||||
}
|
63
tests/functional/avatar_acp_groups_test.php
Normal file
63
tests/functional/avatar_acp_groups_test.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/common_avatar_test.php';
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_avatar_acp_groups_test extends phpbb_functional_common_avatar_test
|
||||
{
|
||||
public function get_url()
|
||||
{
|
||||
return 'adm/index.php?i=acp_groups&mode=manage&action=edit&g=5';
|
||||
}
|
||||
|
||||
public function avatar_acp_groups_data()
|
||||
{
|
||||
return array(
|
||||
// Correct Gravatar
|
||||
array(
|
||||
'GROUP_UPDATED',
|
||||
'avatar_driver_gravatar',
|
||||
array(
|
||||
'avatar_gravatar_email' => 'test@example.com',
|
||||
'avatar_gravatar_width' => 80,
|
||||
'avatar_gravatar_height' => 80,
|
||||
),
|
||||
),
|
||||
// Gravatar with incorrect size
|
||||
array(
|
||||
'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.',
|
||||
'avatar_driver_gravatar',
|
||||
array(
|
||||
'avatar_gravatar_email' => 'test@example.com',
|
||||
'avatar_gravatar_width' => 120,
|
||||
'avatar_gravatar_height' => 120,
|
||||
),
|
||||
),
|
||||
// Delete avatar image to reset group settings
|
||||
array(
|
||||
'GROUP_UPDATED',
|
||||
'avatar_driver_gravatar',
|
||||
array(
|
||||
'avatar_delete' => array('tick', ''),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider avatar_acp_groups_data
|
||||
*/
|
||||
public function test_avatar_acp_groups($expected, $avatar_type, $data)
|
||||
{
|
||||
$this->assert_avatar_submit($expected, $avatar_type, $data);
|
||||
}
|
||||
}
|
61
tests/functional/avatar_acp_users_test.php
Normal file
61
tests/functional/avatar_acp_users_test.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/common_avatar_test.php';
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_avatar_acp_users_test extends phpbb_functional_common_avatar_test
|
||||
{
|
||||
public function get_url()
|
||||
{
|
||||
return 'adm/index.php?i=acp_users&u=2&mode=avatar';
|
||||
}
|
||||
|
||||
public function avatar_acp_users_data()
|
||||
{
|
||||
return array(
|
||||
// Gravatar with incorrect email
|
||||
array(
|
||||
'EMAIL_INVALID_EMAIL',
|
||||
'avatar_driver_gravatar',
|
||||
array(
|
||||
'avatar_gravatar_email' => 'test.example.com',
|
||||
'avatar_gravatar_width' => 80,
|
||||
'avatar_gravatar_height' => 80,
|
||||
),
|
||||
),
|
||||
// Remote avatar with correct link
|
||||
array(
|
||||
'USER_AVATAR_UPDATED',
|
||||
'avatar_driver_upload',
|
||||
array(
|
||||
'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg',
|
||||
),
|
||||
),
|
||||
// Reset avatar settings
|
||||
array(
|
||||
'USER_AVATAR_UPDATED',
|
||||
'avatar_driver_gravatar',
|
||||
array(
|
||||
'avatar_delete' => array('tick', ''),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider avatar_acp_users_data
|
||||
*/
|
||||
public function test_avatar_acp_users($expected, $avatar_type, $data)
|
||||
{
|
||||
$this->assert_avatar_submit($expected, $avatar_type, $data);
|
||||
}
|
||||
}
|
71
tests/functional/avatar_ucp_groups_test.php
Normal file
71
tests/functional/avatar_ucp_groups_test.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/common_avatar_test.php';
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_avatar_ucp_groups_test extends phpbb_functional_common_avatar_test
|
||||
{
|
||||
public function get_url()
|
||||
{
|
||||
return 'ucp.php?i=ucp_groups&mode=manage&action=edit&g=5';
|
||||
}
|
||||
|
||||
public function avatar_ucp_groups_data()
|
||||
{
|
||||
return array(
|
||||
// Incorrect URL
|
||||
array(
|
||||
'AVATAR_URL_INVALID',
|
||||
'avatar_driver_upload',
|
||||
array(
|
||||
'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80',
|
||||
),
|
||||
),
|
||||
/*
|
||||
// Does not work due to DomCrawler issue
|
||||
// Valid file upload
|
||||
array(
|
||||
'GROUP_UPDATED',
|
||||
'avatar_driver_upload',
|
||||
array(
|
||||
'avatar_upload_file' => array('upload', $this->path . 'valid.jpg'),
|
||||
),
|
||||
),
|
||||
*/
|
||||
// Correct remote avatar
|
||||
array(
|
||||
'GROUP_UPDATED',
|
||||
'avatar_driver_remote',
|
||||
array(
|
||||
'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg',
|
||||
'avatar_remote_width' => 80,
|
||||
'avatar_remote_height' => 80,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'GROUP_UPDATED',
|
||||
'avatar_driver_gravatar',
|
||||
array(
|
||||
'avatar_delete' => array('tick', ''),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider avatar_ucp_groups_data
|
||||
*/
|
||||
public function test_avatar_ucp_groups($expected, $avatar_type, $data)
|
||||
{
|
||||
$this->assert_avatar_submit($expected, $avatar_type, $data);
|
||||
}
|
||||
}
|
78
tests/functional/avatar_ucp_users_test.php
Normal file
78
tests/functional/avatar_ucp_users_test.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/common_avatar_test.php';
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_avatar_ucp_users_test extends phpbb_functional_common_avatar_test
|
||||
{
|
||||
public function get_url()
|
||||
{
|
||||
return 'ucp.php?i=ucp_profile&mode=avatar';
|
||||
}
|
||||
|
||||
public function avatar_ucp_groups_data()
|
||||
{
|
||||
return array(
|
||||
// Gravatar with correct settings
|
||||
array(
|
||||
'PROFILE_UPDATED',
|
||||
'avatar_driver_gravatar',
|
||||
array(
|
||||
'avatar_gravatar_email' => 'test@example.com',
|
||||
'avatar_gravatar_width' => 80,
|
||||
'avatar_gravatar_height' => 80,
|
||||
),
|
||||
),
|
||||
// Wrong driver selected
|
||||
array(
|
||||
'NO_AVATAR_SELECTED',
|
||||
'avatar_driver_upload',
|
||||
array(
|
||||
'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg',
|
||||
'avatar_remote_width' => 80,
|
||||
'avatar_remote_height' => 80,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'PROFILE_UPDATED',
|
||||
'avatar_driver_gravatar',
|
||||
array(
|
||||
'avatar_delete' => array('tick', ''),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider avatar_ucp_groups_data
|
||||
*/
|
||||
public function test_avatar_ucp_groups($expected, $avatar_type, $data)
|
||||
{
|
||||
$this->assert_avatar_submit($expected, $avatar_type, $data);
|
||||
}
|
||||
|
||||
public function test_display_upload_avatar()
|
||||
{
|
||||
$this->assert_avatar_submit('PROFILE_UPDATED',
|
||||
'avatar_driver_upload',
|
||||
array(
|
||||
'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg',
|
||||
)
|
||||
);
|
||||
|
||||
$crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid);
|
||||
$avatar_link = $crawler->filter('img')->attr('src');
|
||||
$crawler = self::request('GET', $avatar_link . '&sid=' . $this->sid, array(), false);
|
||||
$content = self::$client->getResponse()->getContent();
|
||||
self::assertEquals(false, stripos(trim($content), 'debug'), 'Output contains debug message');
|
||||
}
|
||||
}
|
@@ -29,4 +29,11 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case
|
||||
$crawler = self::request('GET', 'viewtopic.php?t=1');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.postbody')->count());
|
||||
}
|
||||
|
||||
public function test_feed()
|
||||
{
|
||||
$crawler = self::request('GET', 'feed.php', array(), false);
|
||||
self::assert_response_xml();
|
||||
$this->assertGreaterThan(0, $crawler->filter('entry')->count());
|
||||
}
|
||||
}
|
||||
|
80
tests/functional/common_avatar_test.php
Normal file
80
tests/functional/common_avatar_test.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
abstract class phpbb_functional_common_avatar_test extends phpbb_functional_test_case
|
||||
{
|
||||
private $path;
|
||||
private $form_content;
|
||||
|
||||
abstract function get_url();
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->path = __DIR__ . '/fixtures/files/';
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
$this->add_lang(array('acp/board', 'ucp', 'acp/users', 'acp/groups'));
|
||||
$this->set_acp_settings();
|
||||
}
|
||||
|
||||
private function set_acp_settings()
|
||||
{
|
||||
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=avatar&sid=' . $this->sid);
|
||||
// Check the default entries we should have
|
||||
$this->assertContainsLang('ALLOW_GRAVATAR', $crawler->text());
|
||||
$this->assertContainsLang('ALLOW_REMOTE', $crawler->text());
|
||||
$this->assertContainsLang('ALLOW_AVATARS', $crawler->text());
|
||||
$this->assertContainsLang('ALLOW_LOCAL', $crawler->text());
|
||||
|
||||
// Now start setting the needed settings
|
||||
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
|
||||
$form['config[allow_avatar_local]']->select(1);
|
||||
$form['config[allow_avatar_gravatar]']->select(1);
|
||||
$form['config[allow_avatar_remote]']->select(1);
|
||||
$form['config[allow_avatar_remote_upload]']->select(1);
|
||||
$crawler = self::submit($form);
|
||||
$this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
|
||||
}
|
||||
|
||||
public function assert_avatar_submit($expected, $type, $data, $button_text = 'SUBMIT')
|
||||
{
|
||||
$crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid);
|
||||
|
||||
// Test if setting a gravatar avatar properly works
|
||||
$form = $crawler->selectButton($this->lang($button_text))->form();
|
||||
$form['avatar_driver']->select($type);
|
||||
|
||||
foreach ($data as $key => $value)
|
||||
{
|
||||
if (is_array($value))
|
||||
{
|
||||
$form[$key]->$value[0]($value[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$form[$key]->setValue($value);
|
||||
}
|
||||
}
|
||||
|
||||
$crawler = self::submit($form);
|
||||
|
||||
try
|
||||
{
|
||||
$this->assertContainsLang($expected, $crawler->text());
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->assertContains($expected, $crawler->text());
|
||||
}
|
||||
}
|
||||
}
|
@@ -52,7 +52,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||
public function test_foo_bar()
|
||||
{
|
||||
$this->phpbb_extension_manager->enable('foo/bar');
|
||||
$crawler = self::request('GET', 'app.php?controller=foo/bar', array(), false);
|
||||
$crawler = self::request('GET', 'app.php/foo/bar', array(), false);
|
||||
self::assert_response_status_code();
|
||||
$this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text());
|
||||
$this->phpbb_extension_manager->purge('foo/bar');
|
||||
@@ -64,7 +64,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||
public function test_controller_with_template()
|
||||
{
|
||||
$this->phpbb_extension_manager->enable('foo/bar');
|
||||
$crawler = self::request('GET', 'app.php?controller=foo/template');
|
||||
$crawler = self::request('GET', 'app.php/foo/template');
|
||||
$this->assertContains("I am a variable", $crawler->filter('#content')->text());
|
||||
$this->phpbb_extension_manager->purge('foo/bar');
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||
public function test_missing_argument()
|
||||
{
|
||||
$this->phpbb_extension_manager->enable('foo/bar');
|
||||
$crawler = self::request('GET', 'app.php?controller=foo/baz', array(), false);
|
||||
$crawler = self::request('GET', 'app.php/foo/baz', array(), false);
|
||||
$this->assert_response_html(500);
|
||||
$this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text());
|
||||
$this->phpbb_extension_manager->purge('foo/bar');
|
||||
@@ -88,7 +88,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||
public function test_exception_should_result_in_500_status_code()
|
||||
{
|
||||
$this->phpbb_extension_manager->enable('foo/bar');
|
||||
$crawler = self::request('GET', 'app.php?controller=foo/exception', array(), false);
|
||||
$crawler = self::request('GET', 'app.php/foo/exception', array(), false);
|
||||
$this->assert_response_html(500);
|
||||
$this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text());
|
||||
$this->phpbb_extension_manager->purge('foo/bar');
|
||||
@@ -105,7 +105,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||
*/
|
||||
public function test_error_ext_disabled_or_404()
|
||||
{
|
||||
$crawler = self::request('GET', 'app.php?controller=does/not/exist', array(), false);
|
||||
$crawler = self::request('GET', 'app.php/does/not/exist', array(), false);
|
||||
$this->assert_response_html(404);
|
||||
$this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
|
||||
}
|
||||
|
63
tests/functional/extension_global_lang_test.php
Normal file
63
tests/functional/extension_global_lang_test.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_case
|
||||
{
|
||||
protected $phpbb_extension_manager;
|
||||
|
||||
static private $helper;
|
||||
|
||||
static protected $fixtures = array(
|
||||
'foo/bar/language/en/',
|
||||
'foo/bar/event/',
|
||||
);
|
||||
|
||||
static public function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::$helper = new phpbb_test_case_helpers(self);
|
||||
self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures);
|
||||
}
|
||||
|
||||
static public function tearDownAfterClass()
|
||||
{
|
||||
parent::tearDownAfterClass();
|
||||
|
||||
self::$helper->restore_original_ext_dir();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->get_db();
|
||||
|
||||
$this->phpbb_extension_manager = $this->get_extension_manager();
|
||||
|
||||
$this->purge_cache();
|
||||
}
|
||||
|
||||
public function test_load_extension_lang_globally()
|
||||
{
|
||||
$this->phpbb_extension_manager->enable('foo/bar');
|
||||
|
||||
// The board index, which should contain an overwritten translation
|
||||
$crawler = self::request('GET', 'index.php');
|
||||
|
||||
// language from language/en/common.php
|
||||
$this->assertNotContains('Skip to content', $crawler->filter('.skiplink')->text());
|
||||
|
||||
// language from ext/foo/bar/language/en/foo_global.php
|
||||
$this->assertContains('Overwritten by foo', $crawler->filter('.skiplink')->text());
|
||||
}
|
||||
}
|
@@ -18,6 +18,7 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t
|
||||
|
||||
static protected $fixtures = array(
|
||||
'foo/bar/language/en/',
|
||||
'foo/bar/event/',
|
||||
);
|
||||
|
||||
static public function setUpBeforeClass()
|
||||
@@ -75,6 +76,6 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t
|
||||
$this->assertContains('Can attach files', $crawler->filter('body')->text());
|
||||
|
||||
// language from ext/foo/bar/language/en/permissions_foo.php
|
||||
$this->assertContains('Can view foo', $crawler->filter('body')->text());
|
||||
$this->assertContains('Can view foobar', $crawler->filter('body')->text());
|
||||
}
|
||||
}
|
||||
|
@@ -44,14 +44,14 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
|
||||
public function test_invalid_extension()
|
||||
{
|
||||
$upload = new fileupload('', array('jpg'), 100);
|
||||
$file = $upload->remote_upload('http://example.com/image.gif');
|
||||
$file = $upload->remote_upload(self::$root_url . 'develop/blank.gif');
|
||||
$this->assertEquals('URL_INVALID', $file->error[0]);
|
||||
}
|
||||
|
||||
public function test_non_existant()
|
||||
public function test_empty_file()
|
||||
{
|
||||
$upload = new fileupload('', array('jpg'), 100);
|
||||
$file = $upload->remote_upload('http://example.com/image.jpg');
|
||||
$file = $upload->remote_upload(self::$root_url . 'develop/blank.jpg');
|
||||
$this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]);
|
||||
}
|
||||
|
||||
|
40
tests/functional/fixtures/ext/foo/bar/event/permission.php
Normal file
40
tests/functional/fixtures/ext/foo/bar/event/permission.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener
|
||||
*/
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class phpbb_ext_foo_bar_event_permission implements EventSubscriberInterface
|
||||
{
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'core.permissions' => 'add_permissions',
|
||||
);
|
||||
}
|
||||
|
||||
public function add_permissions($event)
|
||||
{
|
||||
$permissions = $event['permissions'];
|
||||
$permissions['u_foo'] = array('lang' => 'ACL_U_FOOBAR', 'cat' => 'post');
|
||||
$event['permissions'] = $permissions;
|
||||
}
|
||||
}
|
43
tests/functional/fixtures/ext/foo/bar/event/user_setup.php
Normal file
43
tests/functional/fixtures/ext/foo/bar/event/user_setup.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener
|
||||
*/
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class phpbb_ext_foo_bar_event_user_setup implements EventSubscriberInterface
|
||||
{
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'core.user_setup' => 'add_global_translations',
|
||||
);
|
||||
}
|
||||
|
||||
public function add_global_translations($event)
|
||||
{
|
||||
$lang_set_ext = $event['lang_set_ext'];
|
||||
$lang_set_ext[] = array(
|
||||
'ext_name' => 'foo/bar',
|
||||
'lang_set' => 'foo_global',
|
||||
);
|
||||
$event['lang_set_ext'] = $lang_set_ext;
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
$lang = array_merge($lang, array(
|
||||
'SKIP' => 'Overwritten by foo',
|
||||
));
|
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
// Admin Permissions
|
||||
$lang = array_merge($lang, array(
|
||||
'acl_u_foo' => array('lang' => 'Can view foo', 'cat' => 'misc'),
|
||||
'ACL_U_FOOBAR' => 'Can view foobar with permission foo',
|
||||
));
|
||||
|
67
tests/functional/mcp_test.php
Normal file
67
tests/functional/mcp_test.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_mcp_test extends phpbb_functional_test_case
|
||||
{
|
||||
public function test_post_new_topic()
|
||||
{
|
||||
$this->login();
|
||||
|
||||
// Test creating topic
|
||||
$post = $this->create_topic(2, 'Test Topic 2', 'Testing move post with "Move posts" option from Quick-Moderator Tools.');
|
||||
|
||||
$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
|
||||
$this->assertContains('Testing move post with "Move posts" option from Quick-Moderator Tools.', $crawler->filter('html')->text());
|
||||
|
||||
return $crawler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_post_new_topic
|
||||
*/
|
||||
public function test_handle_quickmod($crawler)
|
||||
{
|
||||
// Test moving a post
|
||||
$form = $crawler->selectButton('Go')->eq(1)->form();
|
||||
$form['action']->select('merge');
|
||||
$crawler = self::submit($form);
|
||||
|
||||
return $crawler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_handle_quickmod
|
||||
*/
|
||||
public function test_move_post_to_topic($crawler)
|
||||
{
|
||||
// Select the post in MCP
|
||||
$form = $crawler->selectButton($this->lang('SUBMIT'))->form(array(
|
||||
'to_topic_id' => 1,
|
||||
));
|
||||
$form['post_id_list'][0]->tick();
|
||||
$crawler = self::submit($form);
|
||||
$this->assertContains($this->lang('MERGE_POSTS'), $crawler->filter('html')->text());
|
||||
|
||||
return $crawler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_move_post_to_topic
|
||||
*/
|
||||
public function test_confirm_result($crawler)
|
||||
{
|
||||
$this->add_lang('mcp');
|
||||
$form = $crawler->selectButton('Yes')->form();
|
||||
$crawler = self::submit($form);
|
||||
$this->assertContains($this->lang('POSTS_MERGED_SUCCESS'), $crawler->text());
|
||||
}
|
||||
}
|
@@ -12,13 +12,6 @@
|
||||
*/
|
||||
class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_case
|
||||
{
|
||||
public function test_user_report_post()
|
||||
{
|
||||
$this->login();
|
||||
$crawler = self::request('GET', 'report.php?f=2&p=1');
|
||||
$this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text());
|
||||
}
|
||||
|
||||
public function test_guest_report_post()
|
||||
{
|
||||
$crawler = self::request('GET', 'report.php?f=2&p=1');
|
||||
@@ -31,6 +24,18 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca
|
||||
$this->set_reporting_guest(-1);
|
||||
}
|
||||
|
||||
public function test_user_report_post()
|
||||
{
|
||||
$this->login();
|
||||
$crawler = self::request('GET', 'report.php?f=2&p=1');
|
||||
$this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text());
|
||||
|
||||
$this->add_lang('mcp');
|
||||
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
|
||||
$crawler = self::submit($form);
|
||||
$this->assertContains($this->lang('POST_REPORTED_SUCCESS'), $crawler->text());
|
||||
}
|
||||
|
||||
protected function set_reporting_guest($report_post_allowed)
|
||||
{
|
||||
$this->login();
|
23
tests/mock/auth_provider.php
Normal file
23
tests/mock/auth_provider.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mock auth provider class with basic functions to help test sessions.
|
||||
*/
|
||||
class phpbb_mock_auth_provider extends phpbb_auth_provider_base
|
||||
{
|
||||
public function login($username, $password)
|
||||
{
|
||||
return array(
|
||||
'status' => "",
|
||||
'error_msg' => "",
|
||||
'user_row' => "",
|
||||
);
|
||||
}
|
||||
}
|
@@ -58,5 +58,9 @@ class phpbb_mock_session_testable extends phpbb_session
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
78
tests/session/check_ban_test.php
Normal file
78
tests/session/check_ban_test.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_check_ban_test extends phpbb_session_test_case
|
||||
{
|
||||
protected $user_id = 4;
|
||||
protected $key_id = 4;
|
||||
protected $session;
|
||||
protected $backup_cache;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_banlist.xml');
|
||||
}
|
||||
|
||||
static function check_banned_data()
|
||||
{
|
||||
return array(
|
||||
array('All false values, should not be banned',
|
||||
false, false, false, false, /* should be banned? -> */ false),
|
||||
array('Matching values in the database, should be banned',
|
||||
4, '127.0.0.1', 'bar@example.org', true, /* should be banned? -> */ true),
|
||||
array('IP Banned, should be banned',
|
||||
false, '127.1.1.1', false, false, /* should be banned? -> */ true),
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
// Get session here so that config is mocked correctly
|
||||
$this->session = $this->session_factory->get_session($this->db);
|
||||
global $cache, $config, $phpbb_root_path, $phpEx;
|
||||
$this->backup_cache = $cache;
|
||||
// Change the global cache object for this test because
|
||||
// the mock cache object does not hit the database as is needed
|
||||
// for this test.
|
||||
$cache = new phpbb_cache_service(
|
||||
new phpbb_cache_driver_file(),
|
||||
$config,
|
||||
$this->db,
|
||||
$phpbb_root_path,
|
||||
$phpEx
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
// Set cache back to what it was before the test changed it
|
||||
global $cache;
|
||||
$cache = $this->backup_cache;
|
||||
}
|
||||
|
||||
/** @dataProvider check_banned_data */
|
||||
public function test_check_is_banned($test_msg, $user_id, $user_ips, $user_email, $return, $should_be_banned)
|
||||
{
|
||||
try
|
||||
{
|
||||
$is_banned = $this->session->check_ban($user_id, $user_ips, $user_email, $return);
|
||||
}
|
||||
catch (PHPUnit_Framework_Error_Notice $e)
|
||||
{
|
||||
// User error was triggered, user must have been banned
|
||||
$is_banned = true;
|
||||
}
|
||||
|
||||
$this->assertEquals($should_be_banned, $is_banned, $test_msg);
|
||||
}
|
||||
}
|
61
tests/session/check_isvalid_test.php
Normal file
61
tests/session/check_isvalid_test.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_check_isvalid_test extends phpbb_session_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_full.xml');
|
||||
}
|
||||
|
||||
protected function access_with($session_id, $user_id, $user_agent, $ip)
|
||||
{
|
||||
$this->session_factory->merge_test_data($session_id, $user_id, $user_agent, $ip);
|
||||
|
||||
$session = $this->session_factory->get_session($this->db);
|
||||
$session->page = array('page' => 'page', 'forum' => 0);
|
||||
|
||||
$session->session_begin();
|
||||
$this->session_factory->check($this);
|
||||
return $session;
|
||||
}
|
||||
|
||||
public function test_session_valid_session_exists()
|
||||
{
|
||||
$session = $this->access_with('bar_session000000000000000000000', '4', 'user agent', '127.0.0.1');
|
||||
$session->check_cookies($this, array());
|
||||
|
||||
$this->check_sessions_equals(array(
|
||||
array('session_id' => 'anon_session00000000000000000000', 'session_user_id' => 1),
|
||||
array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
|
||||
),
|
||||
'If a request comes with a valid session id with matching user agent and IP, no new session should be created.'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_session_invalid_make_new_annon_session()
|
||||
{
|
||||
$session = $this->access_with('anon_session00000000000000000000', '4', 'user agent', '127.0.0.1');
|
||||
$session->check_cookies($this, array(
|
||||
'u' => array('1', null),
|
||||
'k' => array(null, null),
|
||||
'sid' => array($session->session_id, null),
|
||||
));
|
||||
|
||||
$this->check_sessions_equals(array(
|
||||
array('session_id' => $session->session_id, 'session_user_id' => 1), // use generated SID
|
||||
array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
|
||||
),
|
||||
'If a request comes with a valid session id and IP but different user id and user agent,
|
||||
a new anonymous session is created and the session matching the supplied session id is deleted.'
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,133 +0,0 @@
|
||||
<?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__) . '/testable_factory.php';
|
||||
|
||||
class phpbb_session_continue_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml');
|
||||
}
|
||||
|
||||
static public function session_begin_attempts()
|
||||
{
|
||||
// The session_id field is defined as CHAR(32) in the database schema.
|
||||
// Thus the data we put in session_id fields has to have a length of 32 characters on stricter DBMSes.
|
||||
// Thus we fill those strings up with zeroes until they have a string length of 32.
|
||||
|
||||
return array(
|
||||
array(
|
||||
'bar_session000000000000000000000', '4', 'user agent', '127.0.0.1',
|
||||
array(
|
||||
array('session_id' => 'anon_session00000000000000000000', 'session_user_id' => 1),
|
||||
array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
|
||||
),
|
||||
array(),
|
||||
'If a request comes with a valid session id with matching user agent and IP, no new session should be created.',
|
||||
),
|
||||
array(
|
||||
'anon_session00000000000000000000', '4', 'user agent', '127.0.0.1',
|
||||
array(
|
||||
array('session_id' => '__new_session_id__', 'session_user_id' => 1), // use generated SID
|
||||
array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
|
||||
),
|
||||
array(
|
||||
'u' => array('1', null),
|
||||
'k' => array(null, null),
|
||||
'sid' => array('__new_session_id__', null),
|
||||
),
|
||||
'If a request comes with a valid session id and IP but different user id and user agent, a new anonymous session is created and the session matching the supplied session id is deleted.',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider session_begin_attempts
|
||||
*/
|
||||
public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $ip, $expected_sessions, $expected_cookies, $message)
|
||||
{
|
||||
global $phpbb_container, $phpbb_root_path, $phpEx;
|
||||
|
||||
$db = $this->new_dbal();
|
||||
$config = new phpbb_config(array());
|
||||
$request = $this->getMock('phpbb_request');
|
||||
$user = $this->getMock('phpbb_user');
|
||||
|
||||
$auth_provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx);
|
||||
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
$phpbb_container->expects($this->any())
|
||||
->method('get')
|
||||
->with('auth.provider.db')
|
||||
->will($this->returnValue($auth_provider));
|
||||
|
||||
$session_factory = new phpbb_session_testable_factory;
|
||||
$session_factory->set_cookies(array(
|
||||
'_sid' => $session_id,
|
||||
'_u' => $user_id,
|
||||
));
|
||||
$session_factory->merge_config_data(array(
|
||||
'session_length' => time(), // need to do this to allow sessions started at time 0
|
||||
));
|
||||
$session_factory->merge_server_data(array(
|
||||
'HTTP_USER_AGENT' => $user_agent,
|
||||
'REMOTE_ADDR' => $ip,
|
||||
));
|
||||
|
||||
$session = $session_factory->get_session($db);
|
||||
$session->page = array('page' => 'page', 'forum' => 0);
|
||||
|
||||
$session->session_begin();
|
||||
|
||||
$sql = 'SELECT session_id, session_user_id
|
||||
FROM phpbb_sessions
|
||||
ORDER BY session_user_id';
|
||||
|
||||
$expected_sessions = $this->replace_session($expected_sessions, $session->session_id);
|
||||
$expected_cookies = $this->replace_session($expected_cookies, $session->session_id);
|
||||
|
||||
$this->assertSqlResultEquals(
|
||||
$expected_sessions,
|
||||
$sql,
|
||||
$message
|
||||
);
|
||||
|
||||
$session->check_cookies($this, $expected_cookies);
|
||||
|
||||
$session_factory->check($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces recursively the value __new_session_id__ with the given session
|
||||
* id.
|
||||
*
|
||||
* @param array $array An array of data
|
||||
* @param string $session_id The new session id to use instead of the
|
||||
* placeholder.
|
||||
* @return array The input array with all occurances of __new_session_id__
|
||||
* replaced.
|
||||
*/
|
||||
public function replace_session($array, $session_id)
|
||||
{
|
||||
foreach ($array as $key => &$value)
|
||||
{
|
||||
if ($value === '__new_session_id__')
|
||||
{
|
||||
$value = $session_id;
|
||||
}
|
||||
|
||||
if (is_array($value))
|
||||
{
|
||||
$value = $this->replace_session($value, $session_id);
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
43
tests/session/create_test.php
Normal file
43
tests/session/create_test.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_create_test extends phpbb_session_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_full.xml');
|
||||
}
|
||||
|
||||
static function bot($bot_agent, $user_id, $bot_ip)
|
||||
{
|
||||
return array(array(
|
||||
'bot_agent' => $bot_agent,
|
||||
'user_id' => $user_id,
|
||||
'bot_ip' => $bot_ip,
|
||||
));
|
||||
}
|
||||
|
||||
function test_bot_session()
|
||||
{
|
||||
$output = $this->session_facade->session_create(
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
array(),
|
||||
'user agent',
|
||||
'127.0.0.1',
|
||||
self::bot('user agent', 13, '127.0.0.1'),
|
||||
''
|
||||
);
|
||||
$this->assertEquals(true, $output->data['is_bot'], 'should be a bot');
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
<?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__) . '/testable_factory.php';
|
||||
|
||||
class phpbb_session_creation_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_empty.xml');
|
||||
}
|
||||
|
||||
// also see security/extract_current_page.php
|
||||
|
||||
public function test_login_session_create()
|
||||
{
|
||||
global $phpbb_container, $phpbb_root_path, $phpEx;
|
||||
|
||||
$db = $this->new_dbal();
|
||||
$config = new phpbb_config(array());
|
||||
$request = $this->getMock('phpbb_request');
|
||||
$user = $this->getMock('phpbb_user');
|
||||
|
||||
$auth_provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx);
|
||||
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
$phpbb_container->expects($this->any())
|
||||
->method('get')
|
||||
->with('auth.provider.db')
|
||||
->will($this->returnValue($auth_provider));
|
||||
|
||||
$session_factory = new phpbb_session_testable_factory;
|
||||
|
||||
$session = $session_factory->get_session($db);
|
||||
$session->page = array('page' => 'page', 'forum' => 0);
|
||||
|
||||
$session->session_create(3);
|
||||
|
||||
$sql = 'SELECT session_user_id
|
||||
FROM phpbb_sessions';
|
||||
|
||||
$this->assertSqlResultEquals(
|
||||
array(array('session_user_id' => 3)),
|
||||
$sql,
|
||||
'Check if exactly one session for user id 3 was created'
|
||||
);
|
||||
|
||||
$one_year_in_seconds = 365 * 24 * 60 * 60;
|
||||
$cookie_expire = $session->time_now + $one_year_in_seconds;
|
||||
|
||||
$session->check_cookies($this, array(
|
||||
'u' => array(null, $cookie_expire),
|
||||
'k' => array(null, $cookie_expire),
|
||||
'sid' => array($session->session_id, $cookie_expire),
|
||||
));
|
||||
|
||||
global $SID, $_SID;
|
||||
$this->assertEquals($session->session_id, $_SID);
|
||||
$this->assertEquals('?sid=' . $session->session_id, $SID);
|
||||
|
||||
$session_factory->check($this);
|
||||
}
|
||||
}
|
||||
|
51
tests/session/extract_hostname_test.php
Normal file
51
tests/session/extract_hostname_test.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_extract_hostname_test extends phpbb_session_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_empty.xml');
|
||||
}
|
||||
|
||||
static public function extract_current_hostname_data()
|
||||
{
|
||||
return array (
|
||||
// [Input] $host, $server_name_config, $cookie_domain_config, [Expected] $output
|
||||
// If host is ip use that
|
||||
// ipv4
|
||||
array('127.0.0.1', 'skipped.org', 'skipped.org', '127.0.0.1'),
|
||||
// ipv6
|
||||
array('::1', 'skipped.org', 'skipped.org', ':'),
|
||||
array('2002::3235:51f9', 'skipped.org', 'skipped.org', '2002::3235'),
|
||||
// If no host but server name matches cookie_domain use that
|
||||
array('', 'example.org', 'example.org', 'example.org'),
|
||||
// If there is a host uri use that
|
||||
array('example.org', false, false, 'example.org'),
|
||||
// 'best approach' guessing
|
||||
array('', 'example.org', false, 'example.org'),
|
||||
array('', false, '127.0.0.1', '127.0.0.1'),
|
||||
array('', false, false, php_uname('n')),
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider extract_current_hostname_data */
|
||||
function test_extract_current_hostname($host, $server_name_config, $cookie_domain_config, $expected)
|
||||
{
|
||||
$output = $this->session_facade->extract_current_hostname(
|
||||
$host,
|
||||
$server_name_config,
|
||||
$cookie_domain_config
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $output);
|
||||
}
|
||||
}
|
115
tests/session/extract_page_test.php
Normal file
115
tests/session/extract_page_test.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_extract_page_test extends phpbb_session_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_empty.xml');
|
||||
}
|
||||
|
||||
static public function extract_current_page_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'./',
|
||||
'/phpBB/index.php',
|
||||
'',
|
||||
'/phpBB/',
|
||||
array(
|
||||
'page_name' => 'index.php',
|
||||
'page_dir' => '',
|
||||
'query_string' => '',
|
||||
'script_path' => '/phpBB/',
|
||||
'root_script_path' => '/phpBB/',
|
||||
'page' => 'index.php',
|
||||
'forum' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'./',
|
||||
'/phpBB/ucp.php',
|
||||
'mode=login',
|
||||
'/phpBB/ucp.php?mode=login',
|
||||
array(
|
||||
'page_name' => 'ucp.php',
|
||||
'page_dir' => '',
|
||||
'query_string' => 'mode=login',
|
||||
'script_path' => '/phpBB/',
|
||||
'root_script_path' => '/phpBB/',
|
||||
'page' => 'ucp.php?mode=login',
|
||||
'forum' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'./',
|
||||
'/phpBB/ucp.php',
|
||||
'mode=register',
|
||||
'/phpBB/ucp.php?mode=register',
|
||||
array(
|
||||
'page_name' => 'ucp.php',
|
||||
'page_dir' => '',
|
||||
'query_string' => 'mode=register',
|
||||
'script_path' => '/phpBB/',
|
||||
'root_script_path' => '/phpBB/',
|
||||
'page' => 'ucp.php?mode=register',
|
||||
'forum' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'./',
|
||||
'/phpBB/ucp.php',
|
||||
'mode=register',
|
||||
'/phpBB/ucp.php?mode=register',
|
||||
array(
|
||||
'page_name' => 'ucp.php',
|
||||
'page_dir' => '',
|
||||
'query_string' => 'mode=register',
|
||||
'script_path' => '/phpBB/',
|
||||
'root_script_path' => '/phpBB/',
|
||||
'page' => 'ucp.php?mode=register',
|
||||
'forum' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'./../',
|
||||
'/phpBB/adm/index.php',
|
||||
'sid=e7215d958cdd41a6fc13509bebe53e42',
|
||||
'/phpBB/adm/index.php?sid=e7215d958cdd41a6fc13509bebe53e42',
|
||||
array(
|
||||
'page_name' => 'index.php',
|
||||
//'page_dir' => 'adm',
|
||||
// ^-- Ignored because .. returns different directory in live vs testing
|
||||
'query_string' => '',
|
||||
'script_path' => '/phpBB/adm/',
|
||||
'root_script_path' => '/phpBB/',
|
||||
//'page' => 'adm/index.php',
|
||||
'forum' => 0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider extract_current_page_data */
|
||||
function test_extract_current_page($root_path, $php_self, $query_string, $request_uri, $expected)
|
||||
{
|
||||
$output = $this->session_facade->extract_current_page(
|
||||
$root_path,
|
||||
$php_self,
|
||||
$query_string,
|
||||
$request_uri
|
||||
);
|
||||
|
||||
// This compares the result of the output.
|
||||
// Any keys that are not in the expected array are overwritten by the output (aka not checked).
|
||||
$this->assert_array_content_equals(array_merge($output, $expected), $output);
|
||||
}
|
||||
}
|
66
tests/session/fixtures/sessions_banlist.xml
Normal file
66
tests/session/fixtures/sessions_banlist.xml
Normal file
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<column>user_occ</column>
|
||||
<column>user_interests</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>anonymous</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_sessions">
|
||||
<column>session_id</column>
|
||||
<column>session_user_id</column>
|
||||
<column>session_ip</column>
|
||||
<column>session_browser</column>
|
||||
<column>session_admin</column>
|
||||
<row>
|
||||
<value>bar_session000000000000000000000</value>
|
||||
<value>4</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>user agent</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_banlist">
|
||||
<column>ban_id</column>
|
||||
<column>ban_userid</column>
|
||||
<column>ban_ip</column>
|
||||
<column>ban_email</column>
|
||||
<column>ban_start</column>
|
||||
<column>ban_end</column>
|
||||
<column>ban_exclude</column>
|
||||
<column>ban_reason</column>
|
||||
<column>ban_give_reason</column>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>4</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>bar@example.org</value>
|
||||
<value>1111</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value>HAHAHA</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>0</value>
|
||||
<value>127.1.1.1</value>
|
||||
<value></value>
|
||||
<value>1111</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value>HAHAHA</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
@@ -37,17 +37,20 @@
|
||||
<column>session_user_id</column>
|
||||
<column>session_ip</column>
|
||||
<column>session_browser</column>
|
||||
<column>session_admin</column>
|
||||
<row>
|
||||
<value>anon_session00000000000000000000</value>
|
||||
<value>1</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>anonymous user agent</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>bar_session000000000000000000000</value>
|
||||
<value>4</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>user agent</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
||||
|
58
tests/session/fixtures/sessions_garbage.xml
Normal file
58
tests/session/fixtures/sessions_garbage.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<column>user_occ</column>
|
||||
<column>user_interests</column>
|
||||
<row>
|
||||
<value>4</value>
|
||||
<value>bar</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_sessions">
|
||||
<column>session_id</column>
|
||||
<column>session_user_id</column>
|
||||
<column>session_ip</column>
|
||||
<column>session_browser</column>
|
||||
<column>session_admin</column>
|
||||
<row>
|
||||
<value>anon_session00000000000000000000</value>
|
||||
<value>1</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>anonymous user agent</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>bar_session000000000000000000000</value>
|
||||
<value>4</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>user agent</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_login_attempts">
|
||||
<column>attempt_ip</column>
|
||||
<column>attempt_browser</column>
|
||||
<column>attempt_forwarded_for</column>
|
||||
<column>attempt_time</column>
|
||||
<column>user_id</column>
|
||||
<column>username</column>
|
||||
<column>username_clean</column>
|
||||
<row>
|
||||
<value>127.0.0.1</value>
|
||||
<value>browser</value>
|
||||
<value></value>
|
||||
<value>0001</value>
|
||||
<value>4</value>
|
||||
<value>bar</value>
|
||||
<value>bar</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
44
tests/session/fixtures/sessions_key.xml
Normal file
44
tests/session/fixtures/sessions_key.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_sessions_keys">
|
||||
<column>key_id</column>
|
||||
<column>user_id</column>
|
||||
<column>last_ip</column>
|
||||
<column>last_login</column>
|
||||
<row>
|
||||
<value>a87ff679a2f3e71d9181a67b7542122c</value>
|
||||
<value>4</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_sessions">
|
||||
<column>session_id</column>
|
||||
<column>session_user_id</column>
|
||||
<column>session_ip</column>
|
||||
<column>session_browser</column>
|
||||
<row>
|
||||
<value>bar_session000000000000000000000</value>
|
||||
<value>4</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>user agent</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<column>user_occ</column>
|
||||
<column>user_interests</column>
|
||||
<row>
|
||||
<value>4</value>
|
||||
<value>bar</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
53
tests/session/garbage_collection_test.php
Normal file
53
tests/session/garbage_collection_test.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_garbage_collection_test extends phpbb_session_test_case
|
||||
{
|
||||
public $session;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_garbage.xml');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->session = $this->session_factory->get_session($this->db);
|
||||
}
|
||||
|
||||
public function test_cleanup_all()
|
||||
{
|
||||
$this->check_sessions_equals(
|
||||
array(
|
||||
array(
|
||||
'session_id' => 'anon_session00000000000000000000',
|
||||
'session_user_id' => 1,
|
||||
),
|
||||
array(
|
||||
'session_id' => 'bar_session000000000000000000000',
|
||||
'session_user_id' => 4,
|
||||
),
|
||||
),
|
||||
'Before test, should have some sessions.'
|
||||
);
|
||||
// Set session length so it clears all
|
||||
global $config;
|
||||
$config['session_length'] = 0;
|
||||
// There is an error unless the captcha plugin is set
|
||||
$config['captcha_plugin'] = 'phpbb_captcha_nogd';
|
||||
$this->session->session_gc();
|
||||
$this->check_sessions_equals(
|
||||
array(),
|
||||
'After setting session time to 0, should remove all.'
|
||||
);
|
||||
}
|
||||
}
|
51
tests/session/session_key_test.php
Normal file
51
tests/session/session_key_test.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_login_keys_test extends phpbb_session_test_case
|
||||
{
|
||||
protected $user_id = 4;
|
||||
protected $key_id = 4;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_key.xml');
|
||||
}
|
||||
|
||||
public function test_set_key_manually()
|
||||
{
|
||||
// With AutoLogin setup
|
||||
$this->session_factory->merge_config_data(array('allow_autologin' => true));
|
||||
$session = $this->session_factory->get_session($this->db);
|
||||
// Using a user_id and key that is already in the database
|
||||
$session->cookie_data['u'] = $this->user_id;
|
||||
$session->cookie_data['k'] = $this->key_id;
|
||||
// Try to access session
|
||||
$session->session_create($this->user_id, false, $this->user_id);
|
||||
|
||||
$this->assertEquals($this->user_id, $session->data['user_id'], "session should automatically login");
|
||||
}
|
||||
|
||||
public function test_reset_keys()
|
||||
{
|
||||
// With AutoLogin setup
|
||||
$this->session_factory->merge_config_data(array('allow_autologin' => true));
|
||||
$session = $this->session_factory->get_session($this->db);
|
||||
// Reset of the keys for this user
|
||||
$session->reset_login_keys($this->user_id);
|
||||
// Using a user_id and key that was in the database (before reset)
|
||||
$session->cookie_data['u'] = $this->user_id;
|
||||
$session->cookie_data['k'] = $this->key_id;
|
||||
// Try to access session
|
||||
$session->session_create($this->user_id, false, $this->user_id);
|
||||
|
||||
$this->assertNotEquals($this->user_id, $session->data['user_id'], "session should be cleared");
|
||||
}
|
||||
}
|
142
tests/session/testable_facade.php
Normal file
142
tests/session/testable_facade.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/testable_factory.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/phpbb/session.php';
|
||||
|
||||
/**
|
||||
* This class exists to expose session.php's functions in a more testable way.
|
||||
*
|
||||
* Since many functions in session.php have global variables inside the function,
|
||||
* this exposes those functions through a testable facade that uses
|
||||
* testable_factory's mock global variables to modify global variables used in
|
||||
* the functions.
|
||||
*
|
||||
* This is using the facade pattern to provide a testable "front" to the
|
||||
* functions in sessions.php.
|
||||
*
|
||||
*/
|
||||
class phpbb_session_testable_facade
|
||||
{
|
||||
protected $db;
|
||||
protected $session_factory;
|
||||
|
||||
function __construct($db, $session_factory)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->session_factory = $session_factory;
|
||||
}
|
||||
|
||||
function extract_current_page(
|
||||
$root_path,
|
||||
$php_self,
|
||||
$query_string,
|
||||
$request_uri
|
||||
)
|
||||
{
|
||||
$this->session_factory->get_session($this->db);
|
||||
global $request;
|
||||
$request->overwrite('PHP_SELF', $php_self, phpbb_request_interface::SERVER);
|
||||
$request->overwrite('QUERY_STRING', $query_string, phpbb_request_interface::SERVER);
|
||||
$request->overwrite('REQUEST_URI', $request_uri, phpbb_request_interface::SERVER);
|
||||
return phpbb_session::extract_current_page($root_path);
|
||||
}
|
||||
|
||||
function extract_current_hostname(
|
||||
$host,
|
||||
$server_name_config,
|
||||
$cookie_domain_config
|
||||
)
|
||||
{
|
||||
$session = $this->session_factory->get_session($this->db);
|
||||
global $config, $request;
|
||||
$config['server_name'] = $server_name_config;
|
||||
$config['cookie_domain'] = $cookie_domain_config;
|
||||
$request->overwrite('SERVER_NAME', $host, phpbb_request_interface::SERVER);
|
||||
$request->overwrite('Host', $host, phpbb_request_interface::SERVER);
|
||||
// Note: There is a php_uname function used as a fallthrough
|
||||
// that this function doesn't override
|
||||
return $session->extract_current_hostname();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This function has a lot of dependencies, so instead of naming them all,
|
||||
* just ask for overrides
|
||||
*
|
||||
* @param update_session_page Boolean of whether to set page of the session
|
||||
* @param config_overrides An array of overrides for the global config object
|
||||
* @param request_overrides An array of overrides for the global request object
|
||||
* @return boolean False if the user is identified, otherwise true.
|
||||
*/
|
||||
function session_begin(
|
||||
$update_session_page = true,
|
||||
$config_overrides = array(),
|
||||
$request_overrides = array(),
|
||||
$cookies_overrides = array()
|
||||
)
|
||||
{
|
||||
$this->session_factory->merge_config_data($config_overrides);
|
||||
$this->session_factory->merge_server_data($request_overrides);
|
||||
$this->session_factory->set_cookies($cookies_overrides);
|
||||
$session = $this->session_factory->get_session($this->db);
|
||||
$session->session_begin($update_session_page);
|
||||
return $session;
|
||||
}
|
||||
|
||||
function session_create(
|
||||
$user_id = false,
|
||||
$set_admin = false,
|
||||
$persist_login = false,
|
||||
$viewonline = true,
|
||||
array $config_overrides = array(),
|
||||
$user_agent = 'user agent',
|
||||
$ip_address = '127.0.0.1',
|
||||
array $bot_overrides = array(),
|
||||
$uri_sid = ""
|
||||
)
|
||||
{
|
||||
$this->session_factory->merge_config_data($config_overrides);
|
||||
// Bots
|
||||
$this->session_factory->merge_cache_data(array('_bots' => $bot_overrides));
|
||||
global $request;
|
||||
$session = $this->session_factory->get_session($this->db);
|
||||
$session->browser = $user_agent;
|
||||
$session->ip = $ip_address;
|
||||
// Uri sid
|
||||
if ($uri_sid)
|
||||
{
|
||||
$_GET['sid'] = $uri_sid;
|
||||
}
|
||||
$session->session_create($user_id, $set_admin, $persist_login, $viewonline);
|
||||
return $session;
|
||||
}
|
||||
|
||||
function validate_referer(
|
||||
$check_script_path,
|
||||
$referer,
|
||||
$host,
|
||||
$force_server_vars,
|
||||
$server_port,
|
||||
$server_name,
|
||||
$root_script_path
|
||||
)
|
||||
{
|
||||
$session = $this->session_factory->get_session($this->db);
|
||||
global $config, $request;
|
||||
$session->referer = $referer;
|
||||
$session->page['root_script_path'] = $root_script_path;
|
||||
$session->host = $host;
|
||||
$config['force_server_vars'] = $force_server_vars;
|
||||
$config['server_name'] = $server_name;
|
||||
$request->overwrite('SERVER_PORT', $server_port, phpbb_request_interface::SERVER);
|
||||
return $session->validate_referer($check_script_path);
|
||||
}
|
||||
}
|
||||
|
@@ -2,11 +2,14 @@
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../mock/container_builder.php';
|
||||
require_once dirname(__FILE__) . '/../mock/auth_provider.php';
|
||||
|
||||
/**
|
||||
* This class exists to setup an instance of phpbb's session class for testing.
|
||||
*
|
||||
@@ -16,6 +19,7 @@
|
||||
*/
|
||||
class phpbb_session_testable_factory
|
||||
{
|
||||
protected $container;
|
||||
protected $config_data;
|
||||
protected $cache_data;
|
||||
protected $cookies;
|
||||
@@ -65,7 +69,7 @@ class phpbb_session_testable_factory
|
||||
public function get_session(phpbb_db_driver $dbal)
|
||||
{
|
||||
// set up all the global variables used by session
|
||||
global $SID, $_SID, $db, $config, $cache, $request;
|
||||
global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container;
|
||||
|
||||
$request = $this->request = new phpbb_mock_request(
|
||||
array(),
|
||||
@@ -83,6 +87,12 @@ class phpbb_session_testable_factory
|
||||
$cache = $this->cache = new phpbb_mock_cache($this->get_cache_data());
|
||||
$SID = $_SID = null;
|
||||
|
||||
$phpbb_container = $this->container = new phpbb_mock_container_builder();
|
||||
$phpbb_container->set(
|
||||
'auth.provider.db',
|
||||
new phpbb_mock_auth_provider()
|
||||
);
|
||||
|
||||
$session = new phpbb_mock_session_testable;
|
||||
return $session;
|
||||
}
|
||||
@@ -164,6 +174,32 @@ class phpbb_session_testable_factory
|
||||
return $this->server_data = array_merge($this->server_data, $server_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cookies, merge config and server data in one step.
|
||||
*
|
||||
* New values overwrite old ones.
|
||||
*
|
||||
* @param $session_id
|
||||
* @param $user_id
|
||||
* @param $user_agent
|
||||
* @param $ip
|
||||
* @param int $time
|
||||
*/
|
||||
public function merge_test_data($session_id, $user_id, $user_agent, $ip, $time = 0)
|
||||
{
|
||||
$this->set_cookies(array(
|
||||
'_sid' => $session_id,
|
||||
'_u' => $user_id,
|
||||
));
|
||||
$this->merge_config_data(array(
|
||||
'session_length' => time() + $time, // need to do this to allow sessions started at time 0
|
||||
));
|
||||
$this->merge_server_data(array(
|
||||
'HTTP_USER_AGENT' => $user_agent,
|
||||
'REMOTE_ADDR' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all server variables to be passed to the session.
|
||||
*
|
||||
|
48
tests/session/unset_admin_test.php
Normal file
48
tests/session/unset_admin_test.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_unset_admin_test extends phpbb_session_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_full.xml');
|
||||
}
|
||||
|
||||
function get_test_session()
|
||||
{
|
||||
return $this->session_facade->session_begin(
|
||||
true,
|
||||
// Config
|
||||
array(
|
||||
'session_length' => time(), // need to do this to allow sessions started at time 0
|
||||
),
|
||||
// Server
|
||||
array(
|
||||
'HTTP_USER_AGENT' => "user agent",
|
||||
'REMOTE_ADDR' => "127.0.0.1",
|
||||
),
|
||||
// Cookies
|
||||
array(
|
||||
'_sid' => 'bar_session000000000000000000000',
|
||||
'_u' => 4,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_unset_admin()
|
||||
{
|
||||
$session = $this->get_test_session();
|
||||
$this->assertEquals(1, $session->data['session_admin'], 'should be an admin before test starts');
|
||||
$session->unset_admin();
|
||||
$session = $this->get_test_session();
|
||||
$this->assertEquals(0, $session->data['session_admin'], 'should be not be an admin after unset_admin');
|
||||
}
|
||||
}
|
70
tests/session/validate_referrer_test.php
Normal file
70
tests/session/validate_referrer_test.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
|
||||
|
||||
class phpbb_session_validate_referrer_test extends phpbb_session_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_empty.xml');
|
||||
}
|
||||
|
||||
static function referrer_inputs()
|
||||
{
|
||||
$ex = "example.org";
|
||||
$alt = "example.com";
|
||||
return array(
|
||||
// checkpath referrer host forcevars port servername rootpath pass?
|
||||
// 0 Referrer or host wasn't collected, therefore should validate
|
||||
array(false, '', $ex, false, 80, $ex, '', true),
|
||||
array(false, $ex, '', false, 80, $ex, '', true),
|
||||
// 2 Referrer doesn't match host or server_name
|
||||
array(false, $alt, $ex, false, 80, $ex, '', false),
|
||||
// 3 Everything should check out
|
||||
array(false, $ex, $ex, false, 80, $ex, '', true),
|
||||
// 4 Check Script Path
|
||||
array(true, $ex, $ex, false, 80, $ex, '', true),
|
||||
array(true, "$ex/foo", $ex, false, 80, $ex, "/foo", true),
|
||||
array(true, "$ex/bar", $ex, false, 80, $ex, "/foo", false),
|
||||
// 7 Port (This is not checked unless path is checked)
|
||||
array(true, "$ex:80/foo", "$ex:80", false, 80, "$ex:80", "/foo", true),
|
||||
array(true, "$ex:80/bar", "$ex:80", false, 80, "$ex:80", "/foo", false),
|
||||
array(true, "$ex:79/foo", "$ex:81", false, 81, "$ex:81", "/foo", false),
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider referrer_inputs */
|
||||
function test_referrer_inputs(
|
||||
$check_script_path,
|
||||
$referrer,
|
||||
$host,
|
||||
$force_server_vars,
|
||||
$server_port,
|
||||
$server_name,
|
||||
$root_script_path,
|
||||
$pass_or_fail
|
||||
)
|
||||
{
|
||||
// Referrer needs http:// because it's going to get stripped in function.
|
||||
$referrer = $referrer ? 'http://' . $referrer : '';
|
||||
$this->assertEquals(
|
||||
$pass_or_fail,
|
||||
$this->session_facade->validate_referer(
|
||||
$check_script_path,
|
||||
$referrer,
|
||||
$host,
|
||||
$force_server_vars,
|
||||
$server_port,
|
||||
$server_name,
|
||||
$root_script_path
|
||||
),
|
||||
"referrer should" . ($pass_or_fail ? '' : "n't") . " be validated");
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
{event_loop.S_ROW_COUNT}<!-- IF not event_loop.S_LAST_ROW -->|<!-- ENDIF -->
|
@@ -0,0 +1,3 @@
|
||||
<!-- BEGIN event_loop -->
|
||||
event_loop<!-- EVENT test_event_loop -->
|
||||
<!-- END event_loop -->
|
@@ -46,7 +46,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, array(), '');
|
||||
$this->template->set_custom_style('tests', $cache_dir);
|
||||
|
||||
$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php");
|
||||
|
||||
|
@@ -80,6 +80,16 @@ Zeta test event in all',
|
||||
array(),
|
||||
'two in silver in omega',
|
||||
),
|
||||
array(
|
||||
'EVENT in loop',
|
||||
'ext_trivial',
|
||||
array('silver'),
|
||||
'event_loop.html',
|
||||
array(),
|
||||
array('event_loop' => array(array(), array(), array())),
|
||||
array(),
|
||||
'event_loop0|event_loop1|event_loop2',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -103,13 +113,10 @@ Zeta test event in all',
|
||||
$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_twig($phpbb_root_path, $phpEx, $config, $user, 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, '');
|
||||
$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));
|
||||
}
|
||||
}
|
||||
|
@@ -62,6 +62,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(),
|
||||
'1!false',
|
||||
),
|
||||
array(
|
||||
'if.html',
|
||||
array('S_OTHER_OTHER_VALUE' => true),
|
||||
array(),
|
||||
array(),
|
||||
'|S_OTHER_OTHER_VALUE|!false',
|
||||
),
|
||||
array(
|
||||
'if.html',
|
||||
array('S_VALUE' => false, 'S_OTHER_VALUE' => true),
|
||||
@@ -93,49 +100,49 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array('loop' => array(array())),
|
||||
array('test_loop' => array(array())),
|
||||
array(),
|
||||
"loop\nloop",
|
||||
),
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array('loop' => array(array(), array()), 'loop.block' => array(array())),
|
||||
array('test_loop' => array(array(), array()), 'test_loop.block' => array(array())),
|
||||
array(),
|
||||
"loop\nloop\nloop\nloop",
|
||||
),
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array('loop' => array(array(), array()), 'loop.block' => array(array()), 'block' => array(array(), array())),
|
||||
array('test_loop' => array(array(), array()), 'test_loop.block' => array(array()), 'block' => array(array(), array())),
|
||||
array(),
|
||||
"loop\nloop\nloop\nloop\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'))),
|
||||
array('test_loop' => array(array('VARIABLE' => 'x'))),
|
||||
array(),
|
||||
"first\n0 - a\nx - b\nset\nlast",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))),
|
||||
array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))),
|
||||
array(),
|
||||
"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())),
|
||||
array(),
|
||||
"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner",
|
||||
),
|
||||
array(
|
||||
'loop_advanced.html',
|
||||
array(),
|
||||
array('loop' => array(array(), array(), array(), array(), array(), array(), array())),
|
||||
array('test_loop' => array(array(), array(), array(), array(), array(), array(), array())),
|
||||
array(),
|
||||
"101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561",
|
||||
),
|
||||
@@ -149,14 +156,14 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(
|
||||
'define.html',
|
||||
array(),
|
||||
array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
|
||||
array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
|
||||
array(),
|
||||
"xyz\nabc\nabc\nbar\nbar\nabc",
|
||||
"xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?\n[]",
|
||||
),
|
||||
array(
|
||||
'define_advanced.html',
|
||||
array(),
|
||||
array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
|
||||
array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
|
||||
array(),
|
||||
"abc\nzxc\ncde\nbcd",
|
||||
),
|
||||
@@ -200,7 +207,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(
|
||||
'include_loop.html',
|
||||
array(),
|
||||
array('loop' => array(array('NESTED_FILE' => 'include_loop1.html')), 'loop.inner' => array(array('NESTED_FILE' => 'include_loop1.html'), array('NESTED_FILE' => 'include_loop2.html'), array('NESTED_FILE' => 'include_loop3.html'))),
|
||||
array('test_loop' => array(array('NESTED_FILE' => 'include_loop1.html')), 'test_loop.inner' => array(array('NESTED_FILE' => 'include_loop1.html'), array('NESTED_FILE' => 'include_loop2.html'), array('NESTED_FILE' => 'include_loop3.html'))),
|
||||
array(),
|
||||
"1\n_1\n_02\n_3",
|
||||
),
|
||||
@@ -221,8 +228,8 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
array('loop'),
|
||||
array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())),
|
||||
array('test_loop'),
|
||||
'',
|
||||
),
|
||||
array(
|
||||
@@ -235,7 +242,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(
|
||||
'include_loop_define.html',
|
||||
array('VARIABLE' => 'value'),
|
||||
array('loop' => array(array('NESTED_FILE' => 'variable.html'))),
|
||||
array('test_loop' => array(array('NESTED_FILE' => 'variable.html'))),
|
||||
array(),
|
||||
'value',
|
||||
),
|
||||
@@ -243,8 +250,8 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
array('loop.inner'),
|
||||
array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())),
|
||||
array('test_loop.inner'),
|
||||
"first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast",
|
||||
),*/
|
||||
array(
|
||||
@@ -295,7 +302,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(
|
||||
'loop_size.html',
|
||||
array(),
|
||||
array('loop' => array(array()), 'empty_loop' => array()),
|
||||
array('test_loop' => array(array()), 'empty_loop' => array()),
|
||||
array(),
|
||||
"nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop",
|
||||
),
|
||||
@@ -410,7 +417,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
|
||||
$this->setup_engine(array('tpl_allow_php' => true));
|
||||
|
||||
$this->style->set_custom_style('tests', $cache_dir, array(), '');
|
||||
$this->template->set_custom_style('tests', $cache_dir);
|
||||
|
||||
$this->run_template('php.html', array(), array(), array(), 'test');
|
||||
}
|
||||
|
@@ -11,11 +11,8 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_template_template_test_case extends phpbb_test_case
|
||||
{
|
||||
protected $style;
|
||||
protected $template;
|
||||
protected $template_path;
|
||||
protected $style_resource_locator;
|
||||
protected $style_provider;
|
||||
protected $user;
|
||||
|
||||
protected $test_path = 'tests/template';
|
||||
@@ -67,11 +64,8 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||
$this->user = new phpbb_user;
|
||||
|
||||
$this->template_path = $this->test_path . '/templates';
|
||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
||||
$this->style_provider = new phpbb_style_path_provider();
|
||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
|
||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||
$this->style->set_custom_style('tests', $this->template_path, array(), '');
|
||||
$this->template->set_custom_style('tests', $this->template_path);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
|
@@ -20,10 +20,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
|
||||
|
||||
$this->template_path = $this->test_path . '/templates';
|
||||
$this->parent_template_path = $this->test_path . '/parent_templates';
|
||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
||||
$this->style_provider = new phpbb_style_path_provider();
|
||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, 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), array(), '');
|
||||
$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
|
||||
}
|
||||
}
|
||||
|
@@ -2,8 +2,17 @@
|
||||
{$VALUE}
|
||||
<!-- DEFINE $VALUE = 'abc' -->
|
||||
{$VALUE}
|
||||
<!-- IF $VALUE != 'abc' -->
|
||||
$VALUE != 'abc'
|
||||
<!-- ELSEIF $VALUE == 'abc' -->
|
||||
$VALUE == 'abc'
|
||||
<!-- ENDIF -->
|
||||
<!-- INCLUDE define_include.html -->
|
||||
{$INCLUDED_VALUE}
|
||||
{$VALUE}
|
||||
<!-- UNDEFINE $VALUE -->
|
||||
{$VALUE}
|
||||
<!-- DEFINE $VALUE = 'test!@#$%^&*()_-=+{}[]:;",<.>/?' -->
|
||||
{$VALUE}
|
||||
<!-- DEFINE $VALUE = '' -->
|
||||
[{$VALUE}]
|
||||
|
@@ -2,6 +2,8 @@
|
||||
1
|
||||
<!-- ELSEIF S_OTHER_VALUE -->
|
||||
2
|
||||
<!-- ELSE IF S_OTHER_OTHER_VALUE -->
|
||||
|S_OTHER_OTHER_VALUE|
|
||||
<!-- ELSE -->
|
||||
03
|
||||
<!-- ENDIF -->
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<!-- BEGIN loop -->
|
||||
<!-- INCLUDE {loop.NESTED_FILE} -->
|
||||
<!-- BEGIN inner -->_<!-- INCLUDE {inner.NESTED_FILE} --><!-- END inner -->
|
||||
<!-- END loop -->
|
||||
<!-- BEGIN test_loop -->
|
||||
<!-- INCLUDE {test_loop.NESTED_FILE} -->
|
||||
<!-- BEGIN inner -->_<!-- INCLUDE {test_loop.inner.NESTED_FILE} --><!-- END inner -->
|
||||
<!-- END test_loop -->
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<!-- BEGIN loop -->
|
||||
<!-- DEFINE $DEF = '{loop.NESTED_FILE}' -->
|
||||
<!-- BEGIN test_loop -->
|
||||
<!-- DEFINE $DEF = '{test_loop.NESTED_FILE}' -->
|
||||
<!-- INCLUDE {$DEF} -->
|
||||
<!-- END loop -->
|
||||
<!-- END test_loop -->
|
||||
|
@@ -1,21 +1,21 @@
|
||||
<!-- BEGIN loop -->
|
||||
<!-- BEGIN test_loop -->
|
||||
loop
|
||||
<!-- BEGINELSE -->
|
||||
noloop
|
||||
<!-- END loop -->
|
||||
<!-- END test_loop -->
|
||||
|
||||
<!-- IF .loop -->
|
||||
<!-- IF .test_loop -->
|
||||
loop
|
||||
<!-- ELSE -->
|
||||
noloop
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF .loop == 2 -->
|
||||
<!-- IF .test_loop == 2 -->
|
||||
loop
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- BEGIN loop -->
|
||||
<!-- BEGIN test_loop -->
|
||||
<!-- BEGIN !block -->
|
||||
loop#{loop.S_ROW_COUNT}-block#{block.S_ROW_COUNT}
|
||||
loop#{test_loop.S_ROW_COUNT}-block#{block.S_ROW_COUNT}
|
||||
<!-- END !block -->
|
||||
<!-- END loop -->
|
||||
<!-- END test_loop -->
|
||||
|
@@ -1,19 +1,19 @@
|
||||
<!-- BEGIN loop -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(0) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(0) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(0,-1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(0,-1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(1,1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(1,1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(0,1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(0,1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(2,4) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(2,4) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(0,-7) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(0,-7) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(-2,6) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(-2,6) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
x
|
||||
<!-- BEGIN loop(-2,-1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
|
||||
<!-- BEGIN test_loop(-2,-1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
|
||||
|
@@ -22,18 +22,18 @@
|
||||
! empty
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF .loop -->
|
||||
<!-- IF .test_loop -->
|
||||
loop
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF .loop == 0 -->
|
||||
<!-- IF .test_loop == 0 -->
|
||||
loop = 0
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF ! .loop -->
|
||||
<!-- IF ! .test_loop -->
|
||||
! loop
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- BEGIN loop -->
|
||||
<!-- BEGIN test_loop -->
|
||||
in loop
|
||||
<!-- END loop -->
|
||||
<!-- END test_loop -->
|
||||
|
@@ -1,13 +1,13 @@
|
||||
<!-- BEGIN loop -->
|
||||
<!-- IF loop.S_FIRST_ROW -->first<!-- ENDIF -->
|
||||
{loop.S_ROW_NUM} - a
|
||||
{loop.VARIABLE} - b
|
||||
<!-- IF loop.VARIABLE -->set<!-- ENDIF -->
|
||||
<!-- IF loop.S_LAST_ROW -->
|
||||
<!-- BEGIN test_loop -->
|
||||
<!-- IF test_loop.S_FIRST_ROW -->first<!-- ENDIF -->
|
||||
{test_loop.S_ROW_NUM} - a
|
||||
{test_loop.VARIABLE} - b
|
||||
<!-- IF test_loop.VARIABLE -->set<!-- ENDIF -->
|
||||
<!-- IF test_loop.S_LAST_ROW -->
|
||||
last
|
||||
<!-- ENDIF -->
|
||||
<!-- BEGIN inner -->
|
||||
{inner.S_ROW_NUM} - c
|
||||
<!-- IF inner.S_LAST_ROW and inner.S_ROW_COUNT and inner.S_NUM_ROWS -->last inner<!-- ENDIF -->
|
||||
{test_loop.inner.S_ROW_NUM} - c
|
||||
<!-- IF test_loop.inner.S_LAST_ROW and test_loop.inner.S_ROW_COUNT and test_loop.inner.S_NUM_ROWS -->last inner<!-- ENDIF -->
|
||||
<!-- END inner -->
|
||||
<!-- END loop -->
|
||||
<!-- END test_loop -->
|
||||
|
@@ -747,6 +747,27 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform some basic assertions for an xml page
|
||||
*
|
||||
* Checks for debug/error output before the actual page content and the status code
|
||||
*
|
||||
* @param mixed $status_code Expected status code, false to disable check
|
||||
* @return null
|
||||
*/
|
||||
static public function assert_response_xml($status_code = 200)
|
||||
{
|
||||
if ($status_code !== false)
|
||||
{
|
||||
self::assert_response_status_code($status_code);
|
||||
}
|
||||
|
||||
// Any output before the xml opening means there was an error
|
||||
$content = self::$client->getResponse()->getContent();
|
||||
self::assertNotContains('[phpBB Debug]', $content);
|
||||
self::assertStringStartsWith('<?xml', trim($content), 'Output found before XML specification.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Heuristic function to check that the response is success.
|
||||
*
|
||||
@@ -936,7 +957,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the requested parameter from a URL
|
||||
*
|
||||
* @param string $url
|
||||
|
36
tests/test_framework/phpbb_session_test_case.php
Normal file
36
tests/test_framework/phpbb_session_test_case.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../session/testable_factory.php';
|
||||
require_once dirname(__FILE__) . '/../session/testable_facade.php';
|
||||
|
||||
abstract class phpbb_session_test_case extends phpbb_database_test_case
|
||||
{
|
||||
protected $session_factory;
|
||||
protected $session_facade;
|
||||
protected $db;
|
||||
|
||||
function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->session_factory = new phpbb_session_testable_factory;
|
||||
$this->db = $this->new_dbal();
|
||||
$this->session_facade =
|
||||
new phpbb_session_testable_facade($this->db, $this->session_factory);
|
||||
}
|
||||
|
||||
protected function check_sessions_equals($expected_sessions, $message)
|
||||
{
|
||||
$sql = 'SELECT session_id, session_user_id
|
||||
FROM phpbb_sessions
|
||||
ORDER BY session_user_id';
|
||||
|
||||
$this->assertSqlResultEquals($expected_sessions, $sql, $message);
|
||||
}
|
||||
}
|
38
tests/text_processing/generate_text_for_display_test.php
Normal file
38
tests/text_processing/generate_text_for_display_test.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
|
||||
require_once dirname(__FILE__) . '/../mock/user.php';
|
||||
require_once dirname(__FILE__) . '/../mock/cache.php';
|
||||
|
||||
class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_case
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
global $cache, $user;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$cache = new phpbb_mock_cache;
|
||||
|
||||
$user = new phpbb_mock_user;
|
||||
$user->optionset('viewcensors', false);
|
||||
}
|
||||
|
||||
public function test_empty_string()
|
||||
{
|
||||
$this->assertSame('', generate_text_for_display('', '', '', 0));
|
||||
}
|
||||
|
||||
public function test_zero_string()
|
||||
{
|
||||
$this->assertSame('0', generate_text_for_display('0', '', '', 0));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user