Permalink
Browse files

Adding test for event stopPropagation

  • Loading branch information...
1 parent f1acd70 commit 32fe854fab0e001524b88c1540cf5f47a79f7904 @lorenzo lorenzo committed Dec 14, 2011
Showing with 28 additions and 0 deletions.
  1. +28 −0 lib/Cake/Test/Case/Event/CakeEventManagerTest.php
@@ -49,6 +49,16 @@ public function listenerFunction() {
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 @@ public function testDispatchWithGlobal() {
$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);
+ }
}

0 comments on commit 32fe854

Please sign in to comment.