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

View File

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