[ticket/12990] Fix unit tests

PHPBB3-12990
This commit is contained in:
Tristan Darricau 2014-08-17 14:43:17 +02:00
parent fe80967535
commit b18fe1203a
16 changed files with 97 additions and 95 deletions

View file

@ -813,9 +813,9 @@ INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_len
INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_googleplus', 'profilefields.type.googleplus', 'phpbb_googleplus', '20', '3', '255', '', '', '[\w]+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 13, 1, 'VIEW_GOOGLEPLUS_PROFILE', 'http://plus.google.com/%s');
# User Notification Options (for first user)
INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('post', 0, 2, '');
INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('post', 0, 2, 'email');
INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('topic', 0, 2, '');
INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('topic', 0, 2, 'email');
INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('notification.type.post', 0, 2, '');
INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('notification.type.post', 0, 2, 'notification.method.email');
INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('notification.type.topic', 0, 2, '');
INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('notification.type.topic', 0, 2, 'notification.method.email');
# POSTGRES COMMIT #

View file

@ -21,20 +21,20 @@ class phpbb_functional_notification_test extends phpbb_functional_test_case
return array(
// Rows inserted by phpBB/install/schemas/schema_data.sql
// Also see PHPBB3-11460
array('post_notification', true),
array('topic_notification', true),
array('post_email', true),
array('topic_email', true),
array('notification.type.post_notification', true),
array('notification.type.topic_notification', true),
array('notification.type.post_notification.method.email', true),
array('notification.type.topic_notification.method.email', true),
// Default behaviour for in-board notifications:
// If user did not opt-out, in-board notifications are on.
array('bookmark_notification', true),
array('quote_notification', true),
array('notification.type.bookmark_notification', true),
array('notification.type.quote_notification', true),
// Default behaviour for email notifications:
// If user did not opt-in, email notifications are off.
array('bookmark_email', false),
array('quote_email', false),
array('notification.type.bookmark_notification.method.email', false),
array('notification.type.quote_notification.method.email', false),
);
}

View file

@ -21,21 +21,21 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
{
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',
'notification.type.approve_post',
'notification.type.approve_topic',
'notification.type.bookmark',
'notification.type.disapprove_post',
'notification.type.disapprove_topic',
'notification.type.pm',
'notification.type.post',
'notification.type.post_in_queue',
'notification.type.quote',
'notification.type.report_pm',
'notification.type.report_pm_closed',
'notification.type.report_post',
'notification.type.report_post_closed',
'notification.type.topic',
'notification.type.topic_in_queue',
);
}
@ -92,10 +92,11 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
$types = array();
foreach ($this->get_notification_types() as $type)
{
$class = $this->build_type('phpbb\notification\type\\' . $type);
$type_parts = explode('.', $type);
$class = $this->build_type('phpbb\notification\type\\' . array_pop($type_parts));
$types[$type] = $class;
$this->container->set('notification.type.' . $type, $class);
$this->container->set($type, $class);
}
$this->notifications->set_var('notification_types', $types);

View file

@ -50,7 +50,7 @@
<column>notification_type_enabled</column>
<row>
<value>1</value>
<value>bookmark</value>
<value>notification.type.bookmark</value>
<value>1</value>
</row>
</table>
@ -123,35 +123,35 @@
<column>method</column>
<column>notify</column>
<row>
<value>bookmark</value>
<value>notification.type.bookmark</value>
<value>0</value>
<value>2</value>
<value></value>
<value>1</value>
</row>
<row>
<value>bookmark</value>
<value>notification.type.bookmark</value>
<value>0</value>
<value>3</value>
<value></value>
<value>1</value>
</row>
<row>
<value>bookmark</value>
<value>notification.type.bookmark</value>
<value>0</value>
<value>4</value>
<value></value>
<value>1</value>
</row>
<row>
<value>bookmark</value>
<value>notification.type.bookmark</value>
<value>0</value>
<value>5</value>
<value></value>
<value>1</value>
</row>
<row>
<value>bookmark</value>
<value>notification.type.bookmark</value>
<value>0</value>
<value>6</value>
<value></value>

View file

@ -50,7 +50,7 @@
<column>notification_type_enabled</column>
<row>
<value>1</value>
<value>post</value>
<value>notification.type.post</value>
<value>1</value>
</row>
</table>
@ -153,49 +153,49 @@
<column>method</column>
<column>notify</column>
<row>
<value>post</value>
<value>notification.type.post</value>
<value>0</value>
<value>2</value>
<value></value>
<value>1</value>
</row>
<row>
<value>post</value>
<value>notification.type.post</value>
<value>0</value>
<value>3</value>
<value></value>
<value>1</value>
</row>
<row>
<value>post</value>
<value>notification.type.post</value>
<value>0</value>
<value>4</value>
<value></value>
<value>1</value>
</row>
<row>
<value>post</value>
<value>notification.type.post</value>
<value>0</value>
<value>5</value>
<value></value>
<value>1</value>
</row>
<row>
<value>post</value>
<value>notification.type.post</value>
<value>0</value>
<value>6</value>
<value></value>
<value>1</value>
</row>
<row>
<value>post</value>
<value>notification.type.post</value>
<value>0</value>
<value>7</value>
<value></value>
<value>1</value>
</row>
<row>
<value>post</value>
<value>notification.type.post</value>
<value>0</value>
<value>8</value>
<value></value>

View file

@ -22,7 +22,7 @@
<column>notification_type_enabled</column>
<row>
<value>1</value>
<value>post_in_queue</value>
<value>notification.type.post_in_queue</value>
<value>1</value>
</row>
</table>
@ -107,49 +107,49 @@
<column>method</column>
<column>notify</column>
<row>
<value>needs_approval</value>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>2</value>
<value></value>
<value>1</value>
</row>
<row>
<value>needs_approval</value>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>3</value>
<value></value>
<value>1</value>
</row>
<row>
<value>needs_approval</value>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>4</value>
<value></value>
<value>1</value>
</row>
<row>
<value>needs_approval</value>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>5</value>
<value></value>
<value>1</value>
</row>
<row>
<value>needs_approval</value>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>6</value>
<value></value>
<value>1</value>
</row>
<row>
<value>needs_approval</value>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>7</value>
<value></value>
<value>0</value>
</row>
<row>
<value>needs_approval</value>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>9</value>
<value></value>

View file

@ -22,7 +22,7 @@
<column>notification_type_enabled</column>
<row>
<value>1</value>
<value>quote</value>
<value>notification.type.quote</value>
<value>1</value>
</row>
</table>
@ -95,35 +95,35 @@
<column>method</column>
<column>notify</column>
<row>
<value>quote</value>
<value>notification.type.quote</value>
<value>0</value>
<value>2</value>
<value></value>
<value>1</value>
</row>
<row>
<value>quote</value>
<value>notification.type.quote</value>
<value>0</value>
<value>3</value>
<value></value>
<value>1</value>
</row>
<row>
<value>quote</value>
<value>notification.type.quote</value>
<value>0</value>
<value>4</value>
<value></value>
<value>1</value>
</row>
<row>
<value>quote</value>
<value>notification.type.quote</value>
<value>0</value>
<value>5</value>
<value></value>
<value>1</value>
</row>
<row>
<value>quote</value>
<value>notification.type.quote</value>
<value>0</value>
<value>6</value>
<value></value>

View file

@ -42,7 +42,7 @@
<column>notification_type_enabled</column>
<row>
<value>1</value>
<value>topic</value>
<value>notification.type.topic</value>
<value>1</value>
</row>
</table>
@ -103,28 +103,28 @@
<column>method</column>
<column>notify</column>
<row>
<value>topic</value>
<value>notification.type.topic</value>
<value>0</value>
<value>2</value>
<value></value>
<value>1</value>
</row>
<row>
<value>topic</value>
<value>notification.type.topic</value>
<value>0</value>
<value>6</value>
<value></value>
<value>1</value>
</row>
<row>
<value>topic</value>
<value>notification.type.topic</value>
<value>0</value>
<value>7</value>
<value></value>
<value>1</value>
</row>
<row>
<value>topic</value>
<value>notification.type.topic</value>
<value>0</value>
<value>8</value>
<value></value>

View file

@ -25,8 +25,8 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas
return array_merge(
parent::get_notification_types(),
array(
'group_request',
'group_request_approved',
'notification.type.group_request',
'notification.type.group_request_approved',
)
);
}

View file

@ -43,7 +43,8 @@ class phpbb_notification_manager_helper extends \phpbb\notification\manager
*/
public function get_item_type_class($item_type, $data = array())
{
$item_type = 'phpbb\notification\type\\' . $item_type;
$item_parts = explode('.', $item_type);
$item_type = 'phpbb\notification\type\\' . array_pop($item_parts);
$item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);

View file

@ -25,22 +25,22 @@ class phpbb_notification_test extends phpbb_tests_notification_base
public function test_get_notification_type_id()
{
// They should be inserted the first time
$post_type_id = $this->notifications->get_notification_type_id('post');
$quote_type_id = $this->notifications->get_notification_type_id('quote');
$post_type_id = $this->notifications->get_notification_type_id('notification.type.post');
$quote_type_id = $this->notifications->get_notification_type_id('notification.type.quote');
$test_type_id = $this->notifications->get_notification_type_id('test');
$this->assertEquals(array(
'test' => $test_type_id,
'quote' => $quote_type_id,
'post' => $post_type_id,
'notification.type.quote' => $quote_type_id,
'notification.type.post' => $post_type_id,
),
$this->notifications->get_notification_type_ids(array(
'test',
'quote',
'post',
'notification.type.quote',
'notification.type.post',
)
));
$this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('quote'));
$this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('notification.type.quote'));
try
{
@ -58,12 +58,12 @@ class phpbb_notification_test extends phpbb_tests_notification_base
$this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
$this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
$this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('notification.type.bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('notification.type.post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('notification.type.quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('notification.type.topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
$this->assertArrayHasKey('notification.type.pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
//get_subscription_types
//get_subscription_methods
@ -72,12 +72,12 @@ class phpbb_notification_test extends phpbb_tests_notification_base
public function test_subscriptions()
{
$expected_subscriptions = array(
'post' => array(''),
'topic' => array(''),
'quote' => array(''),
'bookmark' => array(''),
'notification.type.post' => array(''),
'notification.type.topic' => array(''),
'notification.type.quote' => array(''),
'notification.type.bookmark' => array(''),
'test' => array(''),
'pm' => array(''),
'notification.type.pm' => array(''),
);
$subscriptions = $this->notifications->get_global_subscriptions(2);
@ -92,20 +92,20 @@ class phpbb_notification_test extends phpbb_tests_notification_base
$this->assert_array_content_equals($methods, $expected_subscriptions[$item_type]);
}
$this->notifications->delete_subscription('post', 0, '', 2);
$this->notifications->delete_subscription('notification.type.post', 0, '', 2);
$this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2));
$this->assertArrayNotHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2));
$this->notifications->add_subscription('post', 0, '', 2);
$this->notifications->add_subscription('notification.type.post', 0, '', 2);
$this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2));
$this->assertArrayHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2));
}
public function test_notifications()
{
$this->db->sql_query('DELETE FROM phpbb_notification_types');
$types = array('quote', 'bookmark', 'post', 'test');
$types = array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test');
foreach ($types as $id => $type)
{
$this->db->sql_query('INSERT INTO phpbb_notification_types ' .
@ -150,7 +150,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base
'post_time' => 1349413323,
));
$this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
$this->notifications->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array(
'post_id' => '4',
'topic_id' => '2',
'post_time' => 1349413324,
@ -166,7 +166,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base
'user_id' => 0,
)));
$this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
$this->notifications->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array(
'post_id' => '5',
'topic_id' => '2',
'post_time' => 1349413325,
@ -258,7 +258,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base
'post_time' => 1234, // change time
));
$this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array(
$this->notifications->update_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array(
'post_id' => '5',
'topic_id' => '2',
'poster_id' => 2,

View file

@ -15,7 +15,7 @@ require_once dirname(__FILE__) . '/submit_post_base.php';
class phpbb_notification_submit_post_type_bookmark_test extends phpbb_notification_submit_post_base
{
protected $item_type = 'bookmark';
protected $item_type = 'notification.type.bookmark';
public function setUp()
{

View file

@ -15,7 +15,7 @@ require_once dirname(__FILE__) . '/submit_post_base.php';
class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notification_submit_post_base
{
protected $item_type = 'post_in_queue';
protected $item_type = 'notification.type.post_in_queue';
public function setUp()
{

View file

@ -15,7 +15,7 @@ require_once dirname(__FILE__) . '/submit_post_base.php';
class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base
{
protected $item_type = 'post';
protected $item_type = 'notification.type.post';
public function setUp()
{

View file

@ -15,7 +15,7 @@ require_once dirname(__FILE__) . '/submit_post_base.php';
class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base
{
protected $item_type = 'quote';
protected $item_type = 'notification.type.quote';
public function setUp()
{

View file

@ -15,7 +15,7 @@ require_once dirname(__FILE__) . '/submit_post_base.php';
class phpbb_notification_submit_post_type_topic_test extends phpbb_notification_submit_post_base
{
protected $item_type = 'topic';
protected $item_type = 'notification.type.topic';
public function setUp()
{