diff --git a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php index 7d5c660ba..555c2609e 100644 --- a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php +++ b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php @@ -21,6 +21,7 @@ App::uses('CakeEvent', 'Event'); App::uses('CakeEventManager', 'Event'); +App::uses('CakeEventListener', 'Event'); /** * Mock class used to test event dispatching @@ -50,6 +51,30 @@ class CakeEventTestListener { } } +/** + * Mock used for testing the subscriber objects + * + * @package Cake.Test.Case.Event + */ +class CustomTestEventListerner extends CakeEventTestListener implements CakeEventListener { + + public function implementedEvents() { + return array( + 'fake.event' => 'listenerFunction', + 'another.event' => array('callable' => 'secondListenerFunction', 'passParams' => true) + ); + } + +/** + * Test function to be used in event dispatching + * + * @return void + */ + public function thirdListenerFunction() { + $this->callStack[] = __FUNCTION__; + } +} + /** * Tests the CakeEventManager class functionality * @@ -205,4 +230,25 @@ class CakeEventManagerTest extends CakeTestCase { $anotherListener->expects($this->once())->method('secondListenerFunction')->with('data'); $manager->dispatch($event); } + +/** + * Tests subscribing a listener object and firing the events it subscribed to + * + * @return void + */ + public function testAttachSubscriber() { + $manager = new CakeEventManager; + $listener = $this->getMock('CustomTestEventListerner', array('secondListenerFunction')); + $manager->attach($listener); + $event = new CakeEvent('fake.event'); + + $manager->dispatch($event); + + $expected = array('listenerFunction'); + $this->assertEquals($expected, $listener->callStack); + + $listener->expects($this->once())->method('secondListenerFunction')->with('data'); + $event = new CakeEvent('another.event', $this, array('some' => 'data')); + $manager->dispatch($event); + } } \ No newline at end of file