1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-22 08:13:14 +02:00

Merge branch 'develop' of github.com:phpbb/phpbb3 into ticket/11832

# By Nathan Guse (22) and others
# Via Nathan Guse (10) and others
* 'develop' of github.com:phpbb/phpbb3: (39 commits)
  [ticket/11843] Added newlines and included numbers in the DEFINE vars test
  [ticket/11843] Add checking DEFINE variables with underscores to template_test
  [ticket/11843] The twig lexer fixes DEFINE variables with underscores again
  [ticket/11727] Fix indentation
  [ticket/11727] Fix indentation
  [ticket/11745] Correct language, coding guidelines
  [ticket/11828] Fix greedy operators in lexer
  [ticket/11833] Prevent Twig errors from invalid template loops using BEGINELSE
  [ticket/11833] Fix bad template loop
  [ticket/11816] !$DOESNT_EXIST test
  [ticket/9550] Add the core.viewtopic_post_rowset_data event to viewtopic.php
  [ticket/11829] Use report_closed to determine status in MCP report_details
  [ticket/11816] Test !$DEFINITION
  [ticket/11822] Use namespace lookup order for asset loading
  [ticket/11727] Template loader support for safe directories to load files from
  [ticket/11816] Fix define/loop checks in IF statements containing parenthesis
  [ticket/11373] Use inheritdoc
  [ticket/11637] generate_text_for_display on search.php
  [ticket/11744] Cast to int
  [ticket/11744] Inheritdoc
  ...
This commit is contained in:
Nathan Guse
2013-09-13 09:15:23 -05:00
35 changed files with 1178 additions and 362 deletions

131
tests/notification/base.php Normal file
View File

@@ -0,0 +1,131 @@
<?php
/**
*
* @package testing
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/manager_helper.php';
abstract class phpbb_tests_notification_base extends phpbb_database_test_case
{
protected $notifications, $db, $container, $user, $config, $auth, $cache;
protected function get_notification_types()
{
return array(
'test',
'approve_post',
'approve_topic',
'bookmark',
'disapprove_post',
'disapprove_topic',
'pm',
'post',
'post_in_queue',
'quote',
'report_pm',
'report_pm_closed',
'report_post',
'report_post_closed',
'topic',
'topic_in_queue',
);
}
protected function setUp()
{
parent::setUp();
global $phpbb_root_path, $phpEx;
include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx);
global $db, $config, $user, $auth, $cache, $phpbb_container;
$db = $this->db = $this->new_dbal();
$config = $this->config = new phpbb_config(array(
'allow_privmsg' => true,
'allow_bookmarks' => true,
'allow_topic_notify' => true,
'allow_forum_notify' => true,
));
$user = $this->user = new phpbb_user();
$this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
$auth = $this->auth = new phpbb_mock_notifications_auth();
$cache = $this->cache = new phpbb_cache_service(
new phpbb_cache_driver_null(),
$this->config,
$this->db,
$phpbb_root_path,
$phpEx
);
$phpbb_container = $this->container = new phpbb_mock_container_builder();
$this->notifications = new phpbb_notification_manager_helper(
array(),
array(),
$this->container,
$this->user_loader,
$this->db,
$this->cache,
$this->user,
$phpbb_root_path,
$phpEx,
'phpbb_notification_types',
'phpbb_notifications',
'phpbb_user_notifications'
);
$phpbb_container->set('notification_manager', $this->notifications);
$this->notifications->setDependencies($this->auth, $this->config);
$types = array();
foreach ($this->get_notification_types() as $type)
{
$class = $this->build_type('phpbb_notification_type_' . $type);
$types[$type] = $class;
$this->container->set('notification.type.' . $type, $class);
}
$this->notifications->set_var('notification_types', $types);
$this->db->sql_query('DELETE FROM phpbb_notification_types');
$this->db->sql_query('DELETE FROM phpbb_notifications');
$this->db->sql_query('DELETE FROM phpbb_user_notifications');
}
protected function build_type($type)
{
global $phpbb_root_path, $phpEx;
return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
}
protected function assert_notifications($expected, $options = array())
{
$notifications = $this->notifications->load_notifications(array_merge(array(
'count_unread' => true,
'order_by' => 'notification_time',
'order_dir' => 'ASC',
), $options));
$this->assertEquals(sizeof($expected), $notifications['unread_count']);
$i = 0;
foreach ($notifications['notifications'] as $notification)
{
foreach ($expected[$i] as $key => $value)
{
$this->assertEquals($value, $notification->$key, $i . ' ' . $key);
}
$i++;
}
}
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_users">
<column>user_id</column>
<column>username</column>
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
<column>user_occ</column>
<column>user_interests</column>
<row>
<value>2</value>
<value>2</value>
<value>2</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
<row>
<value>3</value>
<value>3</value>
<value>3</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
</table>
</dataset>

View File

@@ -0,0 +1,109 @@
<?php
/**
*
* @package testing
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/base.php';
class phpbb_notification_group_request_test extends phpbb_tests_notification_base
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/group_request.xml');
}
protected function get_notification_types()
{
return array_merge(
parent::get_notification_types(),
array(
'group_request',
'group_request_approved',
)
);
}
public function test_notifications()
{
global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_log;
include_once($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_content.' . $phpEx);
set_config(false, false, false, $this->config);
$this->container->set('groupposition.legend', new phpbb_groupposition_legend(
$this->db,
$this->user
));
$this->container->set('groupposition.teampage', new phpbb_groupposition_teampage(
$this->db,
$this->user,
$this->cache->get_driver()
));
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
$phpbb_log = new phpbb_log_null();
// Now on to the actual test
$group_id = false;
group_create($group_id, GROUP_OPEN, 'test', 'test group', array());
// Add user 2 as group leader
group_user_add($group_id, 2, false, false, false, true, false);
// Add user 3 as pending
group_user_add($group_id, 3, false, false, false, false, true);
$this->assert_notifications(
array(
// user 3 pending notification
array(
'item_id' => 3, // user_id of requesting join
'item_parent_id' => $group_id,
'user_id' => 2,
'notification_read' => 0,
'notification_data' => array(
'group_name' => 'test',
),
),
),
array(
'user_id' => 2,
)
);
// Approve user 3 joining the group
group_user_attributes('approve', $group_id, array(3));
// user 3 pending notification should have been deleted
$this->assert_notifications(
array(),
array(
'user_id' => 2,
)
);
$this->assert_notifications(
array(
// user 3 approved notification
array(
'item_id' => $group_id, // user_id of requesting join
'user_id' => 3,
'notification_read' => 0,
'notification_data' => array(
'group_name' => 'test',
),
),
),
array(
'user_id' => 3,
)
);
}
}

View File

@@ -7,9 +7,9 @@
*
*/
require_once dirname(__FILE__) . '/manager_helper.php';
require_once dirname(__FILE__) . '/base.php';
class phpbb_notification_test extends phpbb_database_test_case
class phpbb_notification_test extends phpbb_tests_notification_base
{
protected $notifications, $db, $container, $user, $config, $auth, $cache;
@@ -18,98 +18,17 @@ class phpbb_notification_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml');
}
protected function setUp()
{
parent::setUp();
global $phpbb_root_path, $phpEx;
include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx);
$this->db = $this->new_dbal();
$this->config = new phpbb_config(array(
'allow_privmsg' => true,
'allow_bookmarks' => true,
'allow_topic_notify' => true,
'allow_forum_notify' => true,
));
$this->user = new phpbb_user();
$this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
$this->auth = new phpbb_mock_notifications_auth();
$this->cache = new phpbb_cache_service(
new phpbb_cache_driver_null(),
$this->config,
$this->db,
$phpbb_root_path,
$phpEx
);
$this->container = new phpbb_mock_container_builder();
$this->notifications = new phpbb_notification_manager_helper(
array(),
array(),
$this->container,
$this->user_loader,
$this->db,
$this->cache,
$this->user,
$phpbb_root_path,
$phpEx,
'phpbb_notification_types',
'phpbb_notifications',
'phpbb_user_notifications'
);
$this->notifications->setDependencies($this->auth, $this->config);
$types = array();
foreach (array(
'test',
'approve_post',
'approve_topic',
'bookmark',
'disapprove_post',
'disapprove_topic',
'pm',
'post',
'post_in_queue',
'quote',
'report_pm',
'report_pm_closed',
'report_post',
'report_post_closed',
'topic',
'topic_in_queue',
) as $type)
{
$class = $this->build_type('phpbb_notification_type_' . $type);
$types[$type] = $class;
$this->container->set('notification.type.' . $type, $class);
}
$this->notifications->set_var('notification_types', $types);
}
protected function build_type($type)
{
global $phpbb_root_path, $phpEx;
return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
}
public function test_get_notification_type_id()
{
// They should be inserted the first time
$this->assertEquals(1, $this->notifications->get_notification_type_id('post'));
$this->assertEquals(2, $this->notifications->get_notification_type_id('quote'));
$this->assertEquals(3, $this->notifications->get_notification_type_id('test'));
$post_type_id = $this->notifications->get_notification_type_id('post');
$quote_type_id = $this->notifications->get_notification_type_id('quote');
$test_type_id = $this->notifications->get_notification_type_id('test');
$this->assertEquals(array(
'test' => 3,
'quote' => 2,
'post' => 1,
'test' => $test_type_id,
'quote' => $quote_type_id,
'post' => $post_type_id,
),
$this->notifications->get_notification_type_ids(array(
'test',
@@ -117,11 +36,11 @@ class phpbb_notification_test extends phpbb_database_test_case
'post',
)
));
$this->assertEquals(2, $this->notifications->get_notification_type_id('quote'));
$this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('quote'));
try
{
$this->assertEquals(3, $this->notifications->get_notification_type_id('fail'));
$this->assertEquals(false, $this->notifications->get_notification_type_id('fail'));
$this->fail('Non-existent type should throw an exception');
}
@@ -241,88 +160,65 @@ class phpbb_notification_test extends phpbb_database_test_case
'post_time' => 1349413326,
));
$notifications = $this->notifications->load_notifications(array(
'count_unread' => true,
));
$expected = array(
1 => array(
'notification_type_id' => 4,
'item_id' => 1,
'item_parent_id' => 1,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413321,
'notification_data' => array(),
),
2 => array(
'notification_type_id' => 4,
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413322,
'notification_data' => array(),
),
3 => array(
'notification_type_id' => 4,
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413323,
'notification_data' => array(),
),
4 => array(
'notification_type_id' => 3,
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413324,
'notification_data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
'post_subject' => 'Re: test-title',
'post_username' => '',
'forum_id' => 2,
'forum_name' => 'Your first forum',
$this->assert_notifications(
array(
array(
'item_id' => 1,
'item_parent_id' => 1,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413321,
'notification_data' => array(),
),
),
5 => array(
'notification_type_id' => 2,
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413325,
'notification_data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
'post_subject' => 'Re: test-title',
'post_username' => '',
'forum_id' => 2,
'forum_name' => 'Your first forum',
array(
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413322,
'notification_data' => array(),
),
),
array(
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413323,
'notification_data' => array(),
),
array(
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413324,
'notification_data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
'post_subject' => 'Re: test-title',
'post_username' => '',
'forum_id' => 2,
'forum_name' => 'Your first forum',
),
),
array(
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413325,
'notification_data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
'post_subject' => 'Re: test-title',
'post_username' => '',
'forum_id' => 2,
'forum_name' => 'Your first forum',
),
),
)
);
$this->assertEquals(sizeof($expected), $notifications['unread_count']);
$notifications = $notifications['notifications'];
foreach ($expected as $notification_id => $notification_data)
{
//echo $notifications[$notification_id];
$this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
foreach ($notification_data as $key => $value)
{
$this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
}
}
// Now test updating -------------------------------
$this->notifications->update_notifications('test', array(
@@ -347,86 +243,63 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your second forum', // change forum_name
));
$notifications = $this->notifications->load_notifications(array(
'count_unread' => true,
));
$expected = array(
1 => array(
'notification_type_id' => 4,
'item_id' => 1,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413321,
'notification_data' => array(),
),
2 => array(
'notification_type_id' => 4,
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413322,
'notification_data' => array(),
),
3 => array(
'notification_type_id' => 4,
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1234,
'notification_data' => array(),
),
4 => array(
'notification_type_id' => 3,
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413324,
'notification_data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
'post_subject' => 'Re: test-title',
'post_username' => '',
'forum_id' => 2,
'forum_name' => 'Your first forum',
$this->assert_notifications(
array(
array(
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1234,
'notification_data' => array(),
),
),
5 => array(
'notification_type_id' => 2,
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413325,
'notification_data' => array(
'poster_id' => 2,
'topic_title' => 'test-title2',
'post_subject' => 'Re: test-title2',
'post_username' => '',
'forum_id' => 3,
'forum_name' => 'Your second forum',
array(
'item_id' => 1,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413321,
'notification_data' => array(),
),
),
array(
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413322,
'notification_data' => array(),
),
array(
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413324,
'notification_data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
'post_subject' => 'Re: test-title',
'post_username' => '',
'forum_id' => 2,
'forum_name' => 'Your first forum',
),
),
array(
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
'notification_read' => 0,
'notification_time' => 1349413325,
'notification_data' => array(
'poster_id' => 2,
'topic_title' => 'test-title2',
'post_subject' => 'Re: test-title2',
'post_username' => '',
'forum_id' => 3,
'forum_name' => 'Your second forum',
),
),
)
);
$this->assertEquals(sizeof($expected), $notifications['unread_count']);
$notifications = $notifications['notifications'];
foreach ($expected as $notification_id => $notification_data)
{
//echo $notifications[$notification_id];
$this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
foreach ($notification_data as $key => $value)
{
$this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
}
}
}
}

View File

@@ -158,7 +158,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(),
array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
array(),
"xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?\n[]",
"xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n!\$DOESNT_EXIST\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?[]|foobar|",
),
array(
'define_advanced.html',
@@ -237,7 +237,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array('VARIABLE' => 'variable.html'),
array(),
array(),
'variable.html',
"variable.html\nvariable.html\nvariable.html",
),
array(
'include_loop_define.html',

View File

@@ -7,6 +7,15 @@ $VALUE != 'abc'
<!-- ELSEIF $VALUE == 'abc' -->
$VALUE == 'abc'
<!-- ENDIF -->
<!-- IF ($VALUE == 'abc') -->
($VALUE == 'abc')
<!-- ENDIF -->
<!-- IF !$DOESNT_EXIST -->
!$DOESNT_EXIST
<!-- ENDIF -->
<!-- IF (!$DOESNT_EXIST) -->
(!$DOESNT_EXIST)
<!-- ENDIF -->
<!-- INCLUDE define_include.html -->
{$INCLUDED_VALUE}
{$VALUE}
@@ -16,3 +25,4 @@ $VALUE == 'abc'
{$VALUE}
<!-- DEFINE $VALUE = '' -->
[{$VALUE}]
<!-- DEFINE $TEST -->foobar<!-- ENDDEFINE -->|{$TEST}|

View File

@@ -1,2 +1,8 @@
<!-- DEFINE $DEF = '{VARIABLE}' -->
<!-- INCLUDE {$DEF} -->
<!-- DEFINE $DEF_WITH_UNDERSCORES = '{VARIABLE}' -->
<!-- INCLUDE {$DEF_WITH_UNDERSCORES} -->
<!-- DEFINE $DEF123 = '{VARIABLE}' -->
<!-- INCLUDE {$DEF123} -->

View File

@@ -138,7 +138,7 @@ class phpbb_database_test_connection_manager
catch (PDOException $e)
{
$cleaned_dsn = str_replace($this->config['dbpasswd'], '*password*', $dsn);
throw new Exception("Unable do connect to $cleaned_dsn using PDO with error: {$e->getMessage()}");
throw new Exception("Unable to connect to $cleaned_dsn using PDO with error: {$e->getMessage()}");
}
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

View File

@@ -533,12 +533,9 @@ class phpbb_functional_test_case extends phpbb_test_case
$cache = new phpbb_mock_null_cache;
$cache_driver = new phpbb_cache_driver_null();
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$phpbb_container
->expects($this->any())
->method('get')
->with('cache.driver')
->will($this->returnValue($cache_driver));
$phpbb_container = new phpbb_mock_container_builder();
$phpbb_container->set('cache.driver', $cache_driver);
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
if (!function_exists('utf_clean_string'))
{