mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/13713] Add test for mention_helper
PHPBB3-13713
This commit is contained in:
parent
89d65f5da0
commit
c5f515acc4
3 changed files with 243 additions and 1 deletions
|
@ -592,7 +592,7 @@ class phpbb_test_case_helpers
|
||||||
|
|
||||||
// Create and register a mention_helper
|
// Create and register a mention_helper
|
||||||
$mention_helper = new \phpbb\textformatter\s9e\mention_helper(
|
$mention_helper = new \phpbb\textformatter\s9e\mention_helper(
|
||||||
$db_driver,
|
($container->has('dbal.conn')) ? $container->get('dbal.conn') : $db_driver,
|
||||||
$auth,
|
$auth,
|
||||||
$container->get('user'),
|
$container->get('user'),
|
||||||
$phpbb_root_path,
|
$phpbb_root_path,
|
||||||
|
|
116
tests/text_formatter/s9e/fixtures/mention.xml
Normal file
116
tests/text_formatter/s9e/fixtures/mention.xml
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<dataset>
|
||||||
|
<table name="phpbb_groups">
|
||||||
|
<column>group_id</column>
|
||||||
|
<column>group_name</column>
|
||||||
|
<column>group_type</column>
|
||||||
|
<column>group_colour</column>
|
||||||
|
<column>group_desc</column>
|
||||||
|
<row>
|
||||||
|
<value>1</value>
|
||||||
|
<value>Normal group</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>2</value>
|
||||||
|
<value>Hidden group</value>
|
||||||
|
<value>2</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>3</value>
|
||||||
|
<value>Hidden group we are a member of</value>
|
||||||
|
<value>2</value>
|
||||||
|
<value>FF0000</value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
</table>
|
||||||
|
<table name="phpbb_users">
|
||||||
|
<column>user_id</column>
|
||||||
|
<column>username</column>
|
||||||
|
<column>username_clean</column>
|
||||||
|
<column>user_type</column>
|
||||||
|
<column>user_lastvisit</column>
|
||||||
|
<column>user_colour</column>
|
||||||
|
<column>user_permissions</column>
|
||||||
|
<column>user_sig</column>
|
||||||
|
<row>
|
||||||
|
<value>2</value>
|
||||||
|
<value>myself</value>
|
||||||
|
<value>myself</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>3</value>
|
||||||
|
<value>test</value>
|
||||||
|
<value>test</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>00FF00</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>4</value>
|
||||||
|
<value>group_member_normal</value>
|
||||||
|
<value>group_member_normal</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>5</value>
|
||||||
|
<value>group_member_hidden</value>
|
||||||
|
<value>group_member_hidden</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>6</value>
|
||||||
|
<value>group_member_visible</value>
|
||||||
|
<value>group_member_visible</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
</table>
|
||||||
|
<table name="phpbb_user_group">
|
||||||
|
<column>user_id</column>
|
||||||
|
<column>group_id</column>
|
||||||
|
<column>user_pending</column>
|
||||||
|
<row>
|
||||||
|
<value>2</value>
|
||||||
|
<value>3</value>
|
||||||
|
<value>0</value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>4</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>0</value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>5</value>
|
||||||
|
<value>2</value>
|
||||||
|
<value>0</value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>6</value>
|
||||||
|
<value>3</value>
|
||||||
|
<value>0</value>
|
||||||
|
</row>
|
||||||
|
</table>
|
||||||
|
</dataset>
|
126
tests/text_formatter/s9e/mention_helper_test.php
Normal file
126
tests/text_formatter/s9e/mention_helper_test.php
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
<?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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Symfony\Component\Config\FileLocator;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||||
|
|
||||||
|
class mention_helper_test extends phpbb_database_test_case
|
||||||
|
{
|
||||||
|
protected $db, $container, $user, $auth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \phpbb\textformatter\s9e\mention_helper
|
||||||
|
*/
|
||||||
|
protected $mention_helper;
|
||||||
|
|
||||||
|
public function getDataSet()
|
||||||
|
{
|
||||||
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/mention.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
global $auth, $db, $phpbb_container, $phpEx, $phpbb_root_path;
|
||||||
|
|
||||||
|
// Database
|
||||||
|
$this->db = $this->new_dbal();
|
||||||
|
$db = $this->db;
|
||||||
|
|
||||||
|
// Auth
|
||||||
|
$auth = $this->createMock('\phpbb\auth\auth');
|
||||||
|
$auth->expects($this->any())
|
||||||
|
->method('acl_gets')
|
||||||
|
->with('a_group', 'a_groupadd', 'a_groupdel')
|
||||||
|
->willReturn(false)
|
||||||
|
;
|
||||||
|
|
||||||
|
// Language
|
||||||
|
$lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
|
||||||
|
|
||||||
|
// User
|
||||||
|
$user = $this->createMock('\phpbb\user', array(), array(
|
||||||
|
$lang,
|
||||||
|
'\phpbb\datetime'
|
||||||
|
));
|
||||||
|
$user->ip = '';
|
||||||
|
$user->data = array(
|
||||||
|
'user_id' => 2,
|
||||||
|
'username' => 'myself',
|
||||||
|
'is_registered' => true,
|
||||||
|
'user_colour' => '',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Container
|
||||||
|
$phpbb_container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$phpbb_container->set('dbal.conn', $db);
|
||||||
|
$phpbb_container->set('auth', $auth);
|
||||||
|
$phpbb_container->set('user', $user);
|
||||||
|
|
||||||
|
$container = $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
|
||||||
|
$this->mention_helper = $container->get('text_formatter.s9e.mention_helper');
|
||||||
|
|
||||||
|
$phpbb_container->compile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function inject_metadata_data()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'<r><MENTION id="3" type="u"><s>[mention=u:3]</s>test<e>[/mention]</e></MENTION></r>',
|
||||||
|
'mode=viewprofile&u=3',
|
||||||
|
'color="00FF00"',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'<r><MENTION id="3" type="g"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>',
|
||||||
|
'mode=group&g=3',
|
||||||
|
'color="FF0000"',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider inject_metadata_data
|
||||||
|
*/
|
||||||
|
public function test_inject_metadata($incoming_xml, $expected_profile_substring, $expected_colour)
|
||||||
|
{
|
||||||
|
$result = $this->mention_helper->inject_metadata($incoming_xml);
|
||||||
|
$this->assertContains($expected_profile_substring, $result);
|
||||||
|
$this->assertContains($expected_colour, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_mentioned_user_ids_data()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'<r><MENTION id="3" type="u"><s>[mention=u:3]</s>test<e>[/mention]</e></MENTION><MENTION id="4" type="u"><s>[mention=u:4]</s>test<e>[/mention]</e></MENTION><MENTION id="5" type="u"><s>[mention=u:5]</s>test<e>[/mention]</e></MENTION></r>',
|
||||||
|
[3, 4, 5],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'<r><MENTION id="1" type="g"><s>[mention=g:1]</s>test<e>[/mention]</e></MENTION><MENTION id="2" type="g"><s>[mention=g:2]</s>test<e>[/mention]</e></MENTION><MENTION id="3" type="g"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>',
|
||||||
|
[4, 2, 6],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider get_mentioned_user_ids_data
|
||||||
|
*/
|
||||||
|
public function test_get_mentioned_user_ids($incoming_xml, $expected_result)
|
||||||
|
{
|
||||||
|
$this->assertSame($expected_result, $this->mention_helper->get_mentioned_user_ids($incoming_xml));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue