mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-05 15:16:16 +02:00
[feature/soft-delete] Add unit tests for get_visibility_sql()
PHPBB3-9657
This commit is contained in:
parent
38d83da69e
commit
280619eea9
55
tests/content_visibility/fixtures/get_visibility_sql.xml
Normal file
55
tests/content_visibility/fixtures/get_visibility_sql.xml
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_topics">
|
||||
<column>topic_id</column>
|
||||
<column>forum_id</column>
|
||||
<column>topic_visibility</column>
|
||||
<column>topic_title</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>Unapproved</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Approved</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>Softdeleted</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_posts">
|
||||
<column>post_id</column>
|
||||
<column>topic_id</column>
|
||||
<column>forum_id</column>
|
||||
<column>post_visibility</column>
|
||||
<column>post_text</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>Unapproved</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Approved</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>Softdeleted</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
141
tests/content_visibility/get_visibility_sql_test.php
Normal file
141
tests/content_visibility/get_visibility_sql_test.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
||||
|
||||
class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_visibility_sql.xml');
|
||||
}
|
||||
|
||||
public function get_visibility_sql_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'phpbb_posts',
|
||||
'post', 1, '',
|
||||
array(
|
||||
array('m_approve', 1, true),
|
||||
array('m_restore', 1, true),
|
||||
),
|
||||
array(
|
||||
array('post_id' => 1),
|
||||
array('post_id' => 2),
|
||||
array('post_id' => 3),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_posts',
|
||||
'post', 1, '',
|
||||
array(
|
||||
array('m_approve', 1, true),
|
||||
),
|
||||
array(
|
||||
array('post_id' => 1),
|
||||
array('post_id' => 2),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_posts',
|
||||
'post', 1, '',
|
||||
array(
|
||||
array('m_restore', 1, true),
|
||||
),
|
||||
array(
|
||||
array('post_id' => 2),
|
||||
array('post_id' => 3),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_posts',
|
||||
'post', 1, '',
|
||||
array(
|
||||
),
|
||||
array(
|
||||
array('post_id' => 2),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_topics',
|
||||
'topic', 1, '',
|
||||
array(
|
||||
array('m_approve', 1, true),
|
||||
array('m_restore', 1, true),
|
||||
),
|
||||
array(
|
||||
array('topic_id' => 1),
|
||||
array('topic_id' => 2),
|
||||
array('topic_id' => 3),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_topics',
|
||||
'topic', 1, '',
|
||||
array(
|
||||
array('m_approve', 1, true),
|
||||
),
|
||||
array(
|
||||
array('topic_id' => 1),
|
||||
array('topic_id' => 2),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_topics',
|
||||
'topic', 1, '',
|
||||
array(
|
||||
array('m_restore', 1, true),
|
||||
),
|
||||
array(
|
||||
array('topic_id' => 2),
|
||||
array('topic_id' => 3),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_topics',
|
||||
'topic', 1, '',
|
||||
array(),
|
||||
array(
|
||||
array('topic_id' => 2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_visibility_sql_data
|
||||
*/
|
||||
public function test_get_visibility_sql($table, $mode, $forum_id, $table_alias, $permissions, $expected)
|
||||
{
|
||||
global $db, $auth;
|
||||
|
||||
$db = $this->new_dbal();
|
||||
|
||||
// Create auth mock
|
||||
$auth = $this->getMock('phpbb_auth');
|
||||
$acl_get_map = array(
|
||||
array('f_read', 23, true),
|
||||
array('m_', 23, true),
|
||||
);
|
||||
|
||||
$auth->expects($this->any())
|
||||
->method('acl_get')
|
||||
->with($this->stringContains('_'), $this->anything())
|
||||
->will($this->returnValueMap($permissions));
|
||||
|
||||
$result = $db->sql_query('SELECT ' . $mode . '_id
|
||||
FROM ' . $table . '
|
||||
WHERE ' . phpbb_content_visibility::get_visibility_sql($mode, $forum_id, $table_alias) . '
|
||||
ORDER BY ' . $mode . '_id ASC');
|
||||
|
||||
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user