[ticket/305] Add fetch_posts service as replacement for phpbb_fetch_posts
B3P-305
This commit is contained in:
259
tests/unit/portal/fetch_posts_test.php
Normal file
259
tests/unit/portal/fetch_posts_test.php
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package Board3 Portal Testing
|
||||
* @copyright (c) Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_acp.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php');
|
||||
|
||||
class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
protected $default_main_columns = array('topic_count', 'global_id', 'topic_icons');
|
||||
protected $fetch_posts;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
global $auth, $cache, $phpbb_dispatcher, $template, $user;;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$user = new \phpbb\user();
|
||||
$user->data['user_id'] = 2;
|
||||
$user->timezone = new \DateTimeZone('UTC');
|
||||
$user->add_lang('common');
|
||||
$user->add_lang('../../ext/board3/portal/language/en/portal');
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
$cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'get', 'sql_exists', 'put', 'obtain_attach_extensions'));
|
||||
$cache->expects($this->any())
|
||||
->method('obtain_word_list')
|
||||
->with()
|
||||
->will($this->returnValue(array()));
|
||||
$cache->expects($this->any())
|
||||
->method('get')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(false));
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_content.php');
|
||||
$this->config = new \phpbb\config\config(array('allow_attachments' => 1));
|
||||
$auth = new \phpbb\auth\auth();
|
||||
$userdata = array(
|
||||
'user_id' => 2,
|
||||
);
|
||||
$auth->acl($userdata);
|
||||
// Pretend to allow downloads
|
||||
$auth->acl[0][0] = true;
|
||||
// Pretend to allow downloads in forum 1
|
||||
$auth->acl[1][0] = true;
|
||||
$this->auth = $auth;
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth);
|
||||
$this->user = $user;
|
||||
$template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display'));
|
||||
$this->fetch_posts = new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user);
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/news.xml');
|
||||
}
|
||||
|
||||
public function data_phpbb_fetch_news()
|
||||
{
|
||||
return array(
|
||||
array('news', array(
|
||||
'forum_id',
|
||||
'topic_id',
|
||||
'topic_last_post_time',
|
||||
'topic_replies',
|
||||
'topic_replies_real',
|
||||
'topic_type',
|
||||
'topic_status',
|
||||
'topic_posted',
|
||||
'attachment',
|
||||
'forum_name',
|
||||
'topic_title',
|
||||
'username',
|
||||
'username_full',
|
||||
'username_full_last',
|
||||
'user_type',
|
||||
'user_id',
|
||||
'topic_time',
|
||||
'post_text',
|
||||
'topic_views',
|
||||
'icon_id',
|
||||
'poll',
|
||||
'attachments',
|
||||
'forum_name',
|
||||
)),
|
||||
array('news_all', array(
|
||||
'forum_id',
|
||||
'topic_id',
|
||||
'topic_last_post_time',
|
||||
'topic_replies',
|
||||
'topic_replies_real',
|
||||
'topic_type',
|
||||
'topic_status',
|
||||
'topic_posted',
|
||||
'attachment',
|
||||
'forum_name',
|
||||
'topic_title',
|
||||
'username',
|
||||
'username_full',
|
||||
'username_full_last',
|
||||
'user_type',
|
||||
'user_id',
|
||||
'topic_time',
|
||||
'post_text',
|
||||
'topic_views',
|
||||
'icon_id',
|
||||
'poll',
|
||||
'attachments',
|
||||
'forum_name',
|
||||
)),
|
||||
array('announcements', array(), array('topic_icons', 'topic_count'), 5, ''),
|
||||
array('news', array(), array(), 0),
|
||||
array('foobar', array(), array(), 5, '', false, false, false, 150, '\InvalidArgumentException'),
|
||||
array('news', array(
|
||||
'forum_id',
|
||||
'topic_id',
|
||||
'topic_last_post_time',
|
||||
'topic_replies',
|
||||
'topic_replies_real',
|
||||
'topic_type',
|
||||
'topic_status',
|
||||
'topic_posted',
|
||||
'attachment',
|
||||
'forum_name',
|
||||
'topic_title',
|
||||
'username',
|
||||
'username_full',
|
||||
'username_full_last',
|
||||
'user_type',
|
||||
'user_id',
|
||||
'topic_time',
|
||||
'post_text',
|
||||
'topic_views',
|
||||
'icon_id',
|
||||
'poll',
|
||||
'attachments',
|
||||
'forum_name',
|
||||
), array(), 5, '', false, true),
|
||||
array('announcements', array(), array('topic_icons', 'topic_count'), 5, '3'),
|
||||
array('announcements', array(), array('topic_icons', 'topic_count'), 5, '1,2', false, true),
|
||||
array('news', array(), array(), 5, '1,2', true, false, true),
|
||||
array('announcements', array(), array('topic_icons', 'topic_count'), 5, '', false, true),
|
||||
array('announcements', array(), array(), 5, '1,2', true, true, true),
|
||||
array('news', array(
|
||||
'forum_id',
|
||||
'topic_id',
|
||||
'topic_last_post_time',
|
||||
'topic_replies',
|
||||
'topic_replies_real',
|
||||
'topic_type',
|
||||
'topic_status',
|
||||
'topic_posted',
|
||||
'attachment',
|
||||
'forum_name',
|
||||
'topic_title',
|
||||
'username',
|
||||
'username_full',
|
||||
'username_full_last',
|
||||
'user_type',
|
||||
'user_id',
|
||||
'topic_time',
|
||||
'post_text',
|
||||
'topic_views',
|
||||
'icon_id',
|
||||
'poll',
|
||||
'attachments',
|
||||
'forum_name',
|
||||
), array(), 5, '', false, true, false, 5),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_phpbb_fetch_news
|
||||
*/
|
||||
public function test_phpbb_fetch_news($type, $expected_columns, $expected_main_columns = array(), $number_of_posts = 5, $forum_from = '', $empty = false, $permissions = false,
|
||||
$invert = false, $text_length = 150, $expected_exception = false)
|
||||
{
|
||||
$module_id = 5;
|
||||
$time = time();
|
||||
$start = 0;
|
||||
|
||||
if ($expected_exception)
|
||||
{
|
||||
$this->setExpectedException($expected_exception);
|
||||
}
|
||||
|
||||
$this->fetch_posts->set_module_id($module_id);
|
||||
$fetch_posts = $this->fetch_posts->get_posts($forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start, $invert);
|
||||
|
||||
if (!$empty)
|
||||
{
|
||||
if (empty($expected_main_columns))
|
||||
{
|
||||
$expected_main_columns = $this->default_main_columns;
|
||||
}
|
||||
|
||||
foreach ($expected_main_columns as $main_column)
|
||||
{
|
||||
$this->assertArrayHasKey($main_column, $fetch_posts);
|
||||
unset($fetch_posts[$main_column]);
|
||||
}
|
||||
|
||||
foreach ($fetch_posts as $post)
|
||||
{
|
||||
foreach ($expected_columns as $column)
|
||||
{
|
||||
$this->assertArrayHasKey($column, $post);
|
||||
$this->assertNotNull($post[$column]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!empty($fetch_posts))
|
||||
{
|
||||
var_export($fetch_posts);
|
||||
}
|
||||
$this->assertEmpty($fetch_posts);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_cached_first_forum_id()
|
||||
{
|
||||
global $cache;
|
||||
|
||||
$cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'get', 'sql_exists', 'put'));
|
||||
$cache->expects($this->any())
|
||||
->method('obtain_word_list')
|
||||
->with()
|
||||
->will($this->returnValue(array()));
|
||||
$cache->expects($this->any())
|
||||
->method('get')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$this->fetch_posts = new \board3\portal\portal\fetch_posts($this->auth, $cache, $this->config, $this->db, $this->modules_helper, $this->user);
|
||||
$this->fetch_posts->set_module_id(5);
|
||||
|
||||
$fetch_posts = $this->fetch_posts->get_posts('', false, 5, 150, time(), 'announcements');
|
||||
$this->assertEmpty($fetch_posts);
|
||||
}
|
||||
|
||||
public function test_no_allowed_forums()
|
||||
{
|
||||
global $auth;
|
||||
|
||||
$auth = new \phpbb\auth\auth();
|
||||
|
||||
$this->fetch_posts->set_module_id(5);
|
||||
$fetch_posts = $this->fetch_posts->get_posts('2', true, 5, 150, time(), 'announcements');
|
||||
$this->assertSame(array(), $fetch_posts);
|
||||
}
|
||||
}
|
||||
193
tests/unit/portal/fixtures/news.xml
Normal file
193
tests/unit/portal/fixtures/news.xml
Normal file
@@ -0,0 +1,193 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_acl_options">
|
||||
<column>auth_option_id</column>
|
||||
<column>auth_option</column>
|
||||
<column>is_global</column>
|
||||
<column>is_local</column>
|
||||
<column>founder_only</column>
|
||||
<row>
|
||||
<value>93</value>
|
||||
<value>u_download</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>7</value>
|
||||
<value>f_download</value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_attachments">
|
||||
<column>attach_id</column>
|
||||
<column>post_msg_id</column>
|
||||
<column>topic_id</column>
|
||||
<column>poster_id</column>
|
||||
<column>physical_filename</column>
|
||||
<column>real_filename</column>
|
||||
<column>attach_comment</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>foobar</value>
|
||||
<value>foobar</value>
|
||||
<value>foobar</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_topics">
|
||||
<column>forum_id</column>
|
||||
<column>topic_id</column>
|
||||
<column>topic_last_post_id</column>
|
||||
<column>topic_last_post_time</column>
|
||||
<column>topic_time</column>
|
||||
<column>topic_title</column>
|
||||
<column>topic_attachment</column>
|
||||
<column>topic_views</column>
|
||||
<column>poll_title</column>
|
||||
<column>topic_posts_approved</column>
|
||||
<column>topic_posts_unapproved</column>
|
||||
<column>topic_posts_softdeleted</column>
|
||||
<column>topic_poster</column>
|
||||
<column>topic_type</column>
|
||||
<column>topic_status</column>
|
||||
<column>topic_last_poster_name</column>
|
||||
<column>topic_last_poster_id</column>
|
||||
<column>topic_last_poster_colour</column>
|
||||
<column>icon_id</column>
|
||||
<column>topic_visibility</column>
|
||||
<column>topic_first_post_id</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>1404830663</value>
|
||||
<value>1404830663</value>
|
||||
<value>test post</value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value>foobar</value>
|
||||
<value>2</value>
|
||||
<value></value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_posts">
|
||||
<column>post_id</column>
|
||||
<column>poster_id</column>
|
||||
<column>post_time</column>
|
||||
<column>post_text</column>
|
||||
<column>post_attachment</column>
|
||||
<column>post_username</column>
|
||||
<column>enable_smilies</column>
|
||||
<column>enable_bbcode</column>
|
||||
<column>enable_magic_url</column>
|
||||
<column>bbcode_bitfield</column>
|
||||
<column>bbcode_uid</column>
|
||||
<column>forum_id</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>1404830663</value>
|
||||
<value>foobar post</value>
|
||||
<value>1</value>
|
||||
<value>foobar</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value>1404830663</value>
|
||||
<value>foobar post</value>
|
||||
<value>0</value>
|
||||
<value>foobar</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_forums">
|
||||
<column>forum_id</column>
|
||||
<column>parent_id</column>
|
||||
<column>forum_parents</column>
|
||||
<column>forum_desc</column>
|
||||
<column>forum_rules</column>
|
||||
<column>forum_type</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_topics_posted">
|
||||
<column>topic_id</column>
|
||||
<column>user_id</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_users">
|
||||
<column>username</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_id</column>
|
||||
<column>user_type</column>
|
||||
<column>user_colour</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<row>
|
||||
<value>foobar</value>
|
||||
<value>foobar</value>
|
||||
<value>2</value>
|
||||
<value>5</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>barfoo</value>
|
||||
<value>barfoo</value>
|
||||
<value>3</value>
|
||||
<value>5</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
||||
Reference in New Issue
Block a user