mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-13 20:28:44 +01:00
[ticket/11744] Helper function to assert notifications in base test
This also fixes tests PHPBB3-11744
This commit is contained in:
parent
b213be84a7
commit
359aedf664
@ -106,4 +106,26 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,41 +53,28 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas
|
||||
$group_id = false;
|
||||
group_create($group_id, GROUP_OPEN, 'test', 'test group', array());
|
||||
|
||||
// Add user 1 as group leader
|
||||
// Add user 2 as group leader
|
||||
group_user_add($group_id, 2, false, false, false, true, false);
|
||||
|
||||
// Add user 2 as pending
|
||||
// Add user 3 as pending
|
||||
group_user_add($group_id, 3, false, false, false, false, true);
|
||||
|
||||
$notifications = $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
'user_id' => 2,
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
$this->assert_notifications(
|
||||
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',
|
||||
// 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,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(sizeof($expected), $notifications['unread_count']);
|
||||
|
||||
$i = 0;
|
||||
foreach ($notifications['notifications'] as $notification)
|
||||
{
|
||||
foreach ($expected[$i] as $notification_data)
|
||||
{
|
||||
$this->assertEquals($value, $notification->$key, $key . ' ' . $i);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -160,80 +160,65 @@ class phpbb_notification_test extends phpbb_tests_notification_base
|
||||
'post_time' => 1349413326,
|
||||
));
|
||||
|
||||
$notifications = $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
$this->assert_notifications(
|
||||
array(
|
||||
'item_id' => 1,
|
||||
'item_parent_id' => 1,
|
||||
'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' => 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' => 1,
|
||||
'item_parent_id' => 1,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413321,
|
||||
'notification_data' => array(),
|
||||
),
|
||||
),
|
||||
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',
|
||||
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']);
|
||||
|
||||
$i = 0;
|
||||
foreach ($notifications['notifications'] as $notification)
|
||||
{
|
||||
foreach ($expected[$i] as $notification_data)
|
||||
{
|
||||
$this->assertEquals($value, $notification->$key, $key . ' ' . $i);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Now test updating -------------------------------
|
||||
|
||||
$this->notifications->update_notifications('test', array(
|
||||
@ -258,80 +243,63 @@ class phpbb_notification_test extends phpbb_tests_notification_base
|
||||
'forum_name' => 'Your second forum', // change forum_name
|
||||
));
|
||||
|
||||
$notifications = $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
$this->assert_notifications(
|
||||
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(
|
||||
'notification_type_id' => 4,
|
||||
'item_id' => 3,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1234,
|
||||
'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' => 3,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1234,
|
||||
'notification_data' => array(),
|
||||
),
|
||||
),
|
||||
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',
|
||||
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']);
|
||||
|
||||
$i = 0;
|
||||
foreach ($notifications['notifications'] as $notification)
|
||||
{
|
||||
foreach ($expected[$i] as $notification_data)
|
||||
{
|
||||
$this->assertEquals($value, $notification->$key, $key . ' ' . $i);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user