mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
Merge pull request #4988 from Elsensee/ticket/15389
[ticket/15389] Allow arrays in event dispatcher
This commit is contained in:
@@ -29,5 +29,21 @@ class phpbb_event_dispatcher_test extends phpbb_test_case
|
||||
$result = $dispatcher->trigger_event('core.test_event', compact($vars));
|
||||
|
||||
$this->assertSame(array('foo' => 'foo2', 'bar' => 'bar2'), $result);
|
||||
|
||||
// Test migrating events
|
||||
$dispatcher->addListener('core.foo_br', function(\phpbb\event\data $event) {
|
||||
$event['pi'] = '3.14159';
|
||||
});
|
||||
$dispatcher->addListener('core.foo_bar', function(\phpbb\event\data $event) {
|
||||
$event['pi'] = '3.1';
|
||||
});
|
||||
|
||||
|
||||
$pi = '3';
|
||||
|
||||
$vars = array('pi');
|
||||
$result = $dispatcher->trigger_event(['core.foo_bar', 'core.foo_br'], compact($vars));
|
||||
|
||||
$this->assertSame(array('pi' => '3.14159'), $result);
|
||||
}
|
||||
}
|
||||
|
30
tests/event/fixtures/event_migration.test
Normal file
30
tests/event/fixtures/event_migration.test
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Modify pm and sender data before it is assigned to the template
|
||||
*
|
||||
* @event core.ucp_pm_view_message
|
||||
* @var mixed id Active module category (can be int or string)
|
||||
* @var string mode Active module
|
||||
* @var int folder_id ID of the folder the message is in
|
||||
* @var int msg_id ID of the private message
|
||||
* @var array folder Array with data of user's message folders
|
||||
* @var array message_row Array with message data
|
||||
* @var array cp_row Array with senders custom profile field data
|
||||
* @var array msg_data Template array with message data
|
||||
* @var array user_info User data of the sender
|
||||
* @since 3.1.0-a1
|
||||
* @changed 3.1.6-RC1 Added user_info into event
|
||||
*/
|
||||
$vars = array(
|
||||
'id',
|
||||
'mode',
|
||||
'folder_id',
|
||||
'msg_id',
|
||||
'folder',
|
||||
'message_row',
|
||||
'cp_row',
|
||||
'msg_data',
|
||||
'user_info',
|
||||
);
|
||||
extract($phpbb_dispatcher->trigger_event(['core.ucp_pm_view_message', 'core.ucp_pm_view_messsage'], compact($vars)));
|
@@ -37,6 +37,18 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'event_migration.test',
|
||||
array(
|
||||
'core.ucp_pm_view_message' => array(
|
||||
'event' => 'core.ucp_pm_view_message',
|
||||
'file' => 'event_migration.test',
|
||||
'arguments' => array('cp_row', 'folder', 'folder_id', 'id', 'message_row', 'mode', 'msg_data', 'msg_id', 'user_info'),
|
||||
'since' => '3.1.0-a1',
|
||||
'description' => 'Modify pm and sender data before it is assigned to the template',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'extra_description.test',
|
||||
array(
|
||||
@@ -240,6 +252,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
|
||||
array("\t\$phpbb_dispatcher->dispatch('dispatch.one2.thr_ee4');", 'dispatch.one2.thr_ee4'),
|
||||
array("\$this->dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
|
||||
array("\$phpbb_dispatcher->dispatch('dis_patch.one');", 'dis_patch.one'),
|
||||
array("\$phpbb_dispatcher->dispatch(['dis_patch.one', 'dis_patch.one2']);", 'dis_patch.one'),
|
||||
array("\$phpbb_dispatcher->dispatch(['dis_patch.one', 'dis_patch.one2', 'dis_patch.two3']);", 'dis_patch.one'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -259,6 +273,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
|
||||
array("\$phpbb_dispatcher->dispatch('');"),
|
||||
array("\$phpbb_dispatcher->dispatch('dispatch.2one');"),
|
||||
array("\$phpbb_dispatcher->dispatch('dispatch');"),
|
||||
array("\$phpbb_dispatcher->dispatch(['dispatch.one']);"),
|
||||
array("\$phpbb_dispatcher->dispatch(array('dispatch.one', 'dispatch.one2'));"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -279,6 +295,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
|
||||
array("\textract(\$phpbb_dispatcher->trigger_event('dispatch.one2.thr_ee4', compact(\$vars)));", 'dispatch.one2.thr_ee4'),
|
||||
array("extract(\$this->dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
|
||||
array("extract(\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars)));", 'dis_patch.one'),
|
||||
array("extract(\$phpbb_dispatcher->trigger_event(['dis_patch.one', 'dis_patch.one2'], compact(\$vars)));", 'dis_patch.one'),
|
||||
array("extract(\$phpbb_dispatcher->trigger_event(['dis_patch.one', 'dis_patch.one2', 'dis_patch.two3'], compact(\$vars)));", 'dis_patch.one'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -301,6 +319,7 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
|
||||
array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', \$vars));"),
|
||||
array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$var)));"),
|
||||
array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$array)));"),
|
||||
array("extract(\$phpbb_dispatcher->trigger_event(['dispatch.one'], compact(\$vars)));"),
|
||||
array("\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars));", 'dis_patch.one'),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user