mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-04 10:32:40 +00:00
Adding test for event stopPropagation
This commit is contained in:
parent
f1acd70bad
commit
32fe854fab
1 changed files with 28 additions and 0 deletions
|
@ -49,6 +49,16 @@ class CakeEventTestListener {
|
|||
public function secondListenerFunction() {
|
||||
$this->callStack[] = __FUNCTION__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function to help in stopPropagation testing
|
||||
*
|
||||
* @param CakeEvent $event
|
||||
* @return void
|
||||
*/
|
||||
public function stopListener($event) {
|
||||
$event->stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -301,4 +311,22 @@ class CakeEventManagerTest extends CakeTestCase {
|
|||
$generalManager->expects($this->once())->method('dispatch')->with($event);
|
||||
$manager->dispatch($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that stopping an event will not notify the rest of the listeners
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testStopPropagation() {
|
||||
$manager = new CakeEventManager;
|
||||
$listener = new CakeEventTestListener;
|
||||
$manager->attach(array($listener, 'listenerFunction'), 'fake.event');
|
||||
$manager->attach(array($listener, 'stopListener'), 'fake.event', array('priority' => 8));
|
||||
$manager->attach(array($listener, 'secondListenerFunction'), 'fake.event', array('priority' => 5));
|
||||
$event = new CakeEvent('fake.event');
|
||||
$manager->dispatch($event);
|
||||
|
||||
$expected = array('secondListenerFunction');
|
||||
$this->assertEquals($expected, $listener->callStack);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue