mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[ticket/11495] Throw exception when item that should be deleted does not exist
PHPBB3-11495
This commit is contained in:
parent
6a7378ecbd
commit
d7787682df
2 changed files with 30 additions and 0 deletions
|
@ -181,9 +181,20 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface
|
||||||
*/
|
*/
|
||||||
protected function remove_item_from_nestedset($item_id)
|
protected function remove_item_from_nestedset($item_id)
|
||||||
{
|
{
|
||||||
|
$item_id = (int) $item_id;
|
||||||
|
if (!$item_id)
|
||||||
|
{
|
||||||
|
throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');
|
||||||
|
}
|
||||||
|
|
||||||
$items = $this->get_subtree_data($item_id);
|
$items = $this->get_subtree_data($item_id);
|
||||||
$item_ids = array_keys($items);
|
$item_ids = array_keys($items);
|
||||||
|
|
||||||
|
if (empty($items) || !isset($items[$item_id]))
|
||||||
|
{
|
||||||
|
throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');
|
||||||
|
}
|
||||||
|
|
||||||
$this->remove_subset($item_ids, $items[$item_id]);
|
$this->remove_subset($item_ids, $items[$item_id]);
|
||||||
|
|
||||||
return $item_ids;
|
return $item_ids;
|
||||||
|
|
|
@ -52,6 +52,25 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_
|
||||||
$this->assertEquals($expected, $this->db->sql_fetchrowset($result));
|
$this->assertEquals($expected, $this->db->sql_fetchrowset($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete_throws_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('Not an item', 0),
|
||||||
|
array('Item does not exist', 200),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider delete_throws_data
|
||||||
|
*
|
||||||
|
* @expectedException OutOfBoundsException
|
||||||
|
* @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM
|
||||||
|
*/
|
||||||
|
public function test_delete_throws($explain, $forum_id)
|
||||||
|
{
|
||||||
|
$this->set->delete($forum_id);
|
||||||
|
}
|
||||||
|
|
||||||
public function insert_data()
|
public function insert_data()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
|
Loading…
Add table
Reference in a new issue