mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-12 22:38:52 +00:00
[ticket/10714] Fix dependency injections in unit tests with mocks
PHPBB3-10714
This commit is contained in:
parent
83b8b65016
commit
f4bc9c1673
3 changed files with 24 additions and 7 deletions
|
@ -18,7 +18,16 @@ class phpbb_log_add_test extends phpbb_database_test_case
|
||||||
|
|
||||||
public function test_log_enabled()
|
public function test_log_enabled()
|
||||||
{
|
{
|
||||||
$log = new phpbb_log(LOG_TABLE);
|
global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher;
|
||||||
|
|
||||||
|
$db = $this->new_dbal();
|
||||||
|
$cache = new phpbb_mock_cache;
|
||||||
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$user = $this->getMock('phpbb_user');
|
||||||
|
$auth = $this->getMock('phpbb_auth');
|
||||||
|
|
||||||
|
$log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE);
|
||||||
|
|
||||||
$this->assertTrue($log->is_enabled(), 'Initialise failed');
|
$this->assertTrue($log->is_enabled(), 'Initialise failed');
|
||||||
|
|
||||||
$log->disable();
|
$log->disable();
|
||||||
|
@ -38,10 +47,15 @@ class phpbb_log_add_test extends phpbb_database_test_case
|
||||||
|
|
||||||
public function test_log_add()
|
public function test_log_add()
|
||||||
{
|
{
|
||||||
global $db, $phpbb_dispatcher;
|
global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher;
|
||||||
|
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
|
$cache = new phpbb_mock_cache;
|
||||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$user = $this->getMock('phpbb_user');
|
||||||
|
$auth = $this->getMock('phpbb_auth');
|
||||||
|
|
||||||
|
$log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE);
|
||||||
|
|
||||||
$mode = 'critical';
|
$mode = 'critical';
|
||||||
$user_id = ANONYMOUS;
|
$user_id = ANONYMOUS;
|
||||||
|
@ -51,7 +65,6 @@ class phpbb_log_add_test extends phpbb_database_test_case
|
||||||
$additional_data = array();
|
$additional_data = array();
|
||||||
|
|
||||||
// Add an entry successful
|
// Add an entry successful
|
||||||
$log = new phpbb_log(LOG_TABLE);
|
|
||||||
$this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
|
$this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
|
||||||
|
|
||||||
// Disable logging for all types
|
// Disable logging for all types
|
||||||
|
|
|
@ -142,7 +142,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case
|
||||||
*/
|
*/
|
||||||
public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null)
|
public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null)
|
||||||
{
|
{
|
||||||
global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher;
|
global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
if ($expected)
|
if ($expected)
|
||||||
{
|
{
|
||||||
|
@ -157,7 +157,10 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
$cache = new phpbb_mock_cache;
|
$cache = new phpbb_mock_cache;
|
||||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
$phpbb_log = new phpbb_log(LOG_TABLE);
|
$user = $this->getMock('phpbb_user');
|
||||||
|
$auth = $this->getMock('phpbb_auth');
|
||||||
|
|
||||||
|
$phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE);
|
||||||
|
|
||||||
$user->ip = 'user_ip';
|
$user->ip = 'user_ip';
|
||||||
if ($user_id)
|
if ($user_id)
|
||||||
|
|
|
@ -300,12 +300,11 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
|
||||||
*/
|
*/
|
||||||
public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '')
|
public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '')
|
||||||
{
|
{
|
||||||
global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher;
|
global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
$cache = new phpbb_mock_cache;
|
$cache = new phpbb_mock_cache;
|
||||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
$phpbb_log = new phpbb_log(LOGS_TABLE);
|
|
||||||
|
|
||||||
// Create auth mock
|
// Create auth mock
|
||||||
$auth = $this->getMock('phpbb_auth');
|
$auth = $this->getMock('phpbb_auth');
|
||||||
|
@ -335,6 +334,8 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
|
||||||
'LOG_INSTALL_INSTALLED' => 'installed: %s',
|
'LOG_INSTALL_INSTALLED' => 'installed: %s',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE);
|
||||||
|
|
||||||
$log = array();
|
$log = array();
|
||||||
$this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords));
|
$this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue