1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-29 02:29:21 +02:00

[ticket/13713] Fix tests

PHPBB3-13713
This commit is contained in:
lavigor 2018-08-03 07:11:18 +03:00 committed by Marc Alexander
parent 5651c7f3ff
commit 118b98841c
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995
2 changed files with 82 additions and 38 deletions

View File

@ -1,15 +1,15 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -47,14 +47,15 @@ class phpbb_mention_controller_test extends phpbb_database_test_case
// Auth
$auth = $this->createMock('\phpbb\auth\auth');
$auth->expects($this->any())
->method('acl_gets')
->with('a_group', 'a_groupadd', 'a_groupdel')
->willReturn(false);
->method('acl_gets')
->with('a_group', 'a_groupadd', 'a_groupdel')
->willReturn(false)
;
// Config
$config = new \phpbb\config\config(array(
'allow_mentions' => true,
'mention_names_limit' => 3,
'allow_mentions' => true,
'mention_names_limit' => 3,
));
$cache_driver = new \phpbb\cache\driver\dummy();
@ -79,25 +80,26 @@ class phpbb_mention_controller_test extends phpbb_database_test_case
));
$user->ip = '';
$user->data = array(
'user_id' => 2,
'username' => 'myself',
'is_registered' => true,
'user_colour' => '',
'user_id' => 2,
'username' => 'myself',
'is_registered' => true,
'user_colour' => '',
);
// Request
$this->request = $request = $this->createMock('\phpbb\request\request');
$request->expects($this->any())
->method('is_ajax')
->willReturn(true);
->method('is_ajax')
->willReturn(true)
;
$user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
// Container
$phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__ . '/fixtures'));
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__ . '/fixtures'));
$loader->load('services_mention.yml');
$phpbb_container->set('user_loader', $user_loader);
$phpbb_container->set('user', $user);
@ -142,6 +144,7 @@ class phpbb_mention_controller_test extends phpbb_database_test_case
* NOTE:
* 1) in production comparison with 'myself' is being done in JS
* 2) mention_names_limit does not limit the number of returned items
* 3) team members of hidden groups can also be mentioned (because they are shown on teampage)
*/
return [
['', 0, [
@ -178,6 +181,17 @@ class phpbb_mention_controller_test extends phpbb_database_test_case
'rank' => '',
'priority' => 0,
],
[
'name' => 'team_member_hidden',
'type' => 'u',
'id' => 6,
'avatar' => [
'type' => 'user',
'img' => '',
],
'rank' => '',
'priority' => 1,
],
[
'name' => 'team_member_normal',
'type' => 'u',
@ -345,6 +359,17 @@ class phpbb_mention_controller_test extends phpbb_database_test_case
'rank' => '',
'priority' => 0,
],
[
'name' => 'team_member_hidden',
'type' => 'u',
'id' => 6,
'avatar' => [
'type' => 'user',
'img' => '',
],
'rank' => '',
'priority' => 1,
],
[
'name' => 'team_member_normal',
'type' => 'u',
@ -501,6 +526,17 @@ class phpbb_mention_controller_test extends phpbb_database_test_case
],
]],
['t', 1, [
[
'name' => 'team_member_hidden',
'type' => 'u',
'id' => 6,
'avatar' => [
'type' => 'user',
'img' => '',
],
'rank' => '',
'priority' => 1,
],
[
'name' => 'team_member_normal',
'type' => 'u',
@ -626,32 +662,34 @@ class phpbb_mention_controller_test extends phpbb_database_test_case
],
]],
['test1', 1, [[
'name' => 'test1',
'type' => 'u',
'id' => 9,
'avatar' => [
'type' => 'user',
'img' => '',
'name' => 'test1',
'type' => 'u',
'id' => 9,
'avatar' => [
'type' => 'user',
'img' => '',
],
'rank' => '',
'priority' => 0,
'rank' => '',
'priority' => 0,
]]],
];
}
/**
* @dataProvider handle_data
*/
* @dataProvider handle_data
*/
public function test_handle($keyword, $topic_id, $expected_result)
{
$this->request->expects($this->at(1))
->method('variable')
->with('keyword', '', true)
->willReturn($keyword);
->method('variable')
->with('keyword', '', true)
->willReturn($keyword)
;
$this->request->expects($this->at(2))
->method('variable')
->with('topic_id', 0)
->willReturn($topic_id);
->method('variable')
->with('topic_id', 0)
->willReturn($topic_id)
;
$data = json_decode($this->controller->handle()->getContent(), true);
$this->assertEquals($expected_result, $data);
}

View File

@ -49,9 +49,15 @@
</row>
</table>
<table name="phpbb_teampage">
<column>teampage_id</column>
<column>group_id</column>
<row>
<value>1</value>
<value>1</value>
</row>
<row>
<value>2</value>
<value>2</value>
</row>
</table>
<table name="phpbb_topics">