Skip to content

Commit

Permalink
[ticket/16549] Fix tests
Browse files Browse the repository at this point in the history
PHPBB3-16549
  • Loading branch information
rxu committed Oct 18, 2020
1 parent fc63104 commit ec565de
Show file tree
Hide file tree
Showing 43 changed files with 334 additions and 51 deletions.
21 changes: 19 additions & 2 deletions tests/attachment/upload_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ protected function setUp(): void
$this->files_upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
$this->phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$this->user = new \phpbb\user($this->language, '\phpbb\datetime');
$this->user->data['user_id'] = ANONYMOUS;


$this->upload = new \phpbb\attachment\upload(
Expand Down Expand Up @@ -181,7 +182,14 @@ public function data_upload()
)
),
array('foobar', 1, true,
array(),
// Instead of setting to false or empty array, set default filedata array
// as otherwise it throws PHP undefined array key warnings
// in different file upload related services
array(
'realname' => null,
'type' => null,
'size' => null,
),
array(
'error' => array(
'NOT_UPLOADED',
Expand Down Expand Up @@ -244,7 +252,16 @@ public function test_init_error()
$this->phpbb_root_path
);

$filedata = $this->upload->upload('foobar', 1, true);
// Instead of setting to false or empty array, set default filedata array
// as otherwise it throws PHP undefined array key warnings
// in different file upload related services
$filedata = $this->upload->upload('foobar', 1, true, '', false,
[
'realname' => null,
'type' => null,
'size' => null,
]
);

$this->assertSame(array(
'error' => array(),
Expand Down
12 changes: 8 additions & 4 deletions tests/avatar/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ public function data_handle_avatar_delete()
'avatar_type' => '',
'avatar_width' => 0,
'avatar_height' => 0,
), 1, array(
),
array(
'id' => 1,
'avatar' => '[email protected]',
'avatar_type' => 'avatar.driver.gravatar',
'avatar_width' => '16',
Expand All @@ -346,7 +348,9 @@ public function data_handle_avatar_delete()
'avatar_type' => '',
'avatar_width' => 0,
'avatar_height' => 0,
), 5, array(
),
array(
'id' => 5,
'avatar' => 'g5_1414350991.jpg',
'avatar_type' => 'avatar.driver.upload',
'avatar_width' => '80',
Expand All @@ -359,13 +363,13 @@ public function data_handle_avatar_delete()
/**
* @dataProvider data_handle_avatar_delete
*/
public function test_handle_avatar_delete($expected, $id, $avatar_data, $table, $prefix)
public function test_handle_avatar_delete($expected, $avatar_data, $table, $prefix)
{
$this->config['allow_avatar_gravatar'] = true;
$this->assertNull($this->manager->handle_avatar_delete($this->db, $this->user, $avatar_data, $table, $prefix));

$sql = 'SELECT * FROM ' . $table . '
WHERE ' . $prefix . 'id = ' . $id;
WHERE ' . $prefix . 'id = ' . (int) $avatar_data['id'];
$result = $this->db->sql_query_limit($sql, 1);

$row = $this->manager->clean_row($this->db->sql_fetchrow($result), substr($prefix, 0, -1));
Expand Down
2 changes: 1 addition & 1 deletion tests/cache/cache_memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function __construct()
*/
function _read($var)
{
return $this->data[$var];
return $this->data[$var] ?? false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/cache/cache_memory_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function test_cache_single_query($sql_queries, $table)

foreach ($sql_queries as $query)
{
$this->assertNotEquals(false, $this->cache->sql_load($query[0]));
$this->assertFalse($this->cache->sql_load($query[0]));
}
}
}
1 change: 1 addition & 0 deletions tests/console/user/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected function setUp(): void
$this->language,
'\phpbb\datetime'
));
$user->data['user_email'] = '';

$this->user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);

Expand Down
2 changes: 2 additions & 0 deletions tests/content_visibility/delete_post_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
$user->data['user_id'] = ANONYMOUS;

$attachment_delete = new \phpbb\attachment\delete($config, $db, new \phpbb_mock_event_dispatcher(), new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path);

$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
Expand Down
2 changes: 1 addition & 1 deletion tests/dbal/db_tools_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public function test_create_unique_index_against_unique_index_exists()
public function test_create_int_default_null()
{
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282'));
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_13282', array('TINT:2')));
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_13282', array('TINT:2', null)));
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282'));
}

Expand Down
1 change: 1 addition & 0 deletions tests/email/email_parsing_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function setUp(): void
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
$user->data['user_lang'] = 'en';
$phpbb_container->set('user', $user);
$extension_manager = new phpbb_mock_extension_manager(
dirname(__FILE__) . '/',
Expand Down
10 changes: 6 additions & 4 deletions tests/error_collector_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ public function test_collection_with_mask()
// Cause a warning
1/0; $line = __LINE__;

// Cause a notice
$array = array(0 => 'value');
$value = $array[1]; $line2 = __LINE__;
// Cause a "Notice: unserialize(): Error at offset 0 of 27 bytes in ..."
// "Undefined array index" used earlier was promoted to warning in PHP 8.0,
// see https://github.com/php/php-src/commit/c48b745f0090c944e77c1fbcfb6c4df3b54356ad
unserialize("obvious non-serialized data"); $line2 = __LINE__;

$collector->uninstall();

// The notice should not be collected
$this->assertEmpty($collector->errors[1]);
$this->assertFalse(isset($collector->errors[1]));
$this->assertEquals(count($collector->errors), 1);

list($errno, $msg_text, $errfile, $errline) = $collector->errors[0];
$error_contents = $collector->format_errors();
Expand Down
10 changes: 7 additions & 3 deletions tests/files/types_local_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function data_upload_form()
array(
'foo',
array(
'realname' => null,
'tmp_name' => 'foo',
'size' => 500,
'type' => 'image/png',
Expand All @@ -112,13 +113,17 @@ public function data_upload_form()
),
array(
'none',
false,
array(
'realname' => null,
'size' => null,
'type' => null,
),
array('PHP_SIZE_OVERRUN'),
),
array(
'tests/upload/fixture/png',
array(
'realname' => 'foo.png',
'realname' => 'foo.png',
'size' => 500,
'type' => 'image/png',
'local_mode' => true,
Expand Down Expand Up @@ -153,7 +158,6 @@ public function test_upload_form($filename, $upload_ary, $expected)
$upload->set_allowed_extensions(array('png'));
$type_local->set_upload($upload);


$file = $type_local->upload($filename, $upload_ary);
$this->assertSame($expected, $file->error);
$this->assertInstanceOf('\phpbb\files\filespec', $file);
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/acp_groups_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ public function test_acp_groups_teampage($group_id, $tick_legend, $tick_teampage
else
{
$this->form_data = $form->getValues();
$this->assertEquals($tick_legend, $this->form_data['group_legend']);
$this->assertEquals($tick_teampage, $this->form_data['group_teampage']);
// form_data[] values can be bool or null if not ticked, $tick_* value can be bool or null if not set.
// Cast both to the same type to correctly compare the values.
$this->assertEquals((bool) $tick_legend, (bool) ($this->form_data['group_legend'] ?? false));
$this->assertEquals((bool) $tick_teampage, (bool) ($this->form_data['group_teampage'] ?? false));
}
}
}
2 changes: 1 addition & 1 deletion tests/functional/avatar_acp_groups_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public function test_no_avatar_acp_groups()
$crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form_data = $form->getValues();
$this->assertEmpty($form_data['avatar_type']);
$this->assertFalse(isset($form_data['avatar_type']));
}
}
2 changes: 1 addition & 1 deletion tests/functional/smilies_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function test_smilies_mode()
$crawler = self::request('GET', 'posting.php?mode=smilies');
foreach ($smilies as $index => $smiley)
{
$this->assertContains($smiley['smiley_url'],
$this->assertStringContainsString($smiley['smiley_url'],
$crawler->filter('div[class="inner"] > a > img')->eq($index)->attr('src')
);
}
Expand Down
1 change: 1 addition & 0 deletions tests/functions/user_delete_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function setUp(): void
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
$user->data['user_id'] = 2;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$phpbb_container = new phpbb_mock_container_builder();
$config = new \phpbb\config\config(array(
Expand Down
4 changes: 2 additions & 2 deletions tests/functions/validate_num_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function test_validate_num()
$this->helper->assert_valid_data(array(
'empty' => array(
array(),
'',
null, // '' < 0 is true since PHP 8.0, hence use null instead of '' (empty string)
array('num'),
),
'zero' => array(
Expand All @@ -54,7 +54,7 @@ public function test_validate_num()
array('num', false, 2, 3),
),
'string' => array(
array(),
version_compare(PHP_VERSION, '7.5', '<=') ? [] : ['TOO_LARGE'], // See https://wiki.php.net/rfc/string_to_number_comparison
'foobar',
array('num'),
),
Expand Down
1 change: 1 addition & 0 deletions tests/functions/validate_user_email_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function setUp(): void
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$language = new phpbb\language\language(new phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
$this->user = new phpbb\user($language, '\phpbb\datetime');
$this->user->data['user_email'] = '';
$this->helper = new phpbb_functions_validate_data_helper($this);
}

Expand Down
1 change: 1 addition & 0 deletions tests/functions_content/phpbb_format_quote_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$lang_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$this->lang = new \phpbb\language\language($lang_file_loader);
$user = new \phpbb\user($this->lang, '\phpbb\datetime');
$user->data['user_options'] = 230271;
$cache = new phpbb_mock_cache();

parent::setUp();
Expand Down
2 changes: 2 additions & 0 deletions tests/notification/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ protected function setUp(): void
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
$user->data['user_id'] = 0;
$user->data['user_type'] = USER_NORMAL;
$this->user = $user;
$this->user_loader = new \phpbb\user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
$auth = $this->auth = new phpbb_mock_notifications_auth();
Expand Down
11 changes: 10 additions & 1 deletion tests/notification/notification_method_email_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,16 @@ public function data_notification_email()
*/
public function test_notification_email($notification_type, $post_data, $expected_users)
{
$post_data = array_merge(['post_time' => 1349413322], $post_data);
$post_data = array_merge([
'post_time' => 1349413322,
'poster_id' => 1,
'topic_title' => '',
'post_subject' => '',
'post_username' => '',
'forum_name' => '',
],

$post_data);
$notification_options = [
'item_id' => $post_data['post_id'],
'item_parent_id' => $post_data['topic_id'],
Expand Down
7 changes: 7 additions & 0 deletions tests/notification/notification_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public function test_notifications()
'post_subject' => 'Re: test-title',
'forum_id' => 2,
'forum_name' => 'Your first forum',
'post_username' => '',
'post_text' => 'test text',
));

$this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
Expand All @@ -176,6 +178,8 @@ public function test_notifications()
'post_subject' => 'Re: test-title',
'forum_id' => 2,
'forum_name' => 'Your first forum',
'post_username' => '',
'post_text' => 'test text',
));

$this->notifications->delete_subscription('test');
Expand Down Expand Up @@ -267,6 +271,9 @@ public function test_notifications()
'post_subject' => 'Re: test-title2', // change post_subject
'forum_id' => 3, // change forum_id
'forum_name' => 'Your second forum', // change forum_name
'post_username' => '',
'post_text' => 'test text2',
'post_time' => 1349413325,
));

$this->assert_notifications(
Expand Down
4 changes: 4 additions & 0 deletions tests/notification/submit_post_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
'bbcode_bitfield' => '',
'bbcode_uid' => '',
'post_edit_locked' => false,
'notify_set' => 0,
'notify' => false,
'forum_name' => 'Test forum name',
//'force_approved_state' => 1,
);

Expand Down Expand Up @@ -102,6 +105,7 @@ protected function setUp(): void
'username' => 'user-name',
'is_registered' => true,
'user_colour' => '',
'user_lastmark' => 0,
);

// Request
Expand Down
7 changes: 4 additions & 3 deletions tests/notification/submit_post_type_topic_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ public function test_submit_post($additional_post_data, $expected_before, $expec
$this->db->sql_freeresult($result);

$result = $this->db->sql_query(
'SELECT *
FROM ' . POSTS_TABLE . '
WHERE post_id = ' . $reply_id);
'SELECT p.*, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_first_post_id, t.topic_last_post_id
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
WHERE p.topic_id = t.topic_id
AND p.post_id = ' . $reply_id);
$reply_edit_data = array_merge($this->post_data, $this->db->sql_fetchrow($result), array(
'force_approved_state' => false,
'post_edit_reason' => 'PHPBB3-12370',
Expand Down
5 changes: 4 additions & 1 deletion tests/notification/user_list_trim_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ protected function setUp(): void
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
$user->data = array('user_lang' => 'en');
$user->data = [
'user_id' => 1,
'user_lang' => 'en',
];
$lang->add_lang('common');

$user_loader = new phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
Expand Down
2 changes: 2 additions & 0 deletions tests/profilefields/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ protected function setUp(): void
$language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
$collection = new \phpbb\di\service_collection($container);
$user = new \phpbb\user($language, '\phpbb\datetime');
$user->data['user_id'] = 2;
$user->ip = '';

$this->log = new \phpbb\log\log($this->db, $user, $auth, $dispatcher, $phpbb_root_path, 'adm/', $phpEx, $table_prefix . 'log');

Expand Down
6 changes: 4 additions & 2 deletions tests/profilefields/type_bool_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ protected function setUp(): void
'lang_id' => 1,
'lang_name' => 'field',
'field_required' => false,
'field_default_value' => 1,
'field_length' => 1,
'field_default_value' => 1,
'field_length' => 1,
'field_show_novalue' => null,
'field_novalue' => null,
);

$this->options = array(
Expand Down
2 changes: 2 additions & 0 deletions tests/profilefields/type_date_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ protected function setUp(): void
'lang_id' => 1,
'lang_name' => 'field',
'field_required' => false,
'field_show_novalue' => null,
'field_novalue' => null,
);
}

Expand Down
Loading

0 comments on commit ec565de

Please sign in to comment.