7336f6365b4c4a4c81ba72bbf2216a259c672f22
[horde.git] /
1 <?php
2 /**
3  * Test the notification handler class that logs to the horde log.
4  *
5  * PHP version 5
6  *
7  * @category Horde
8  * @package  Notification
9  * @author   Gunnar Wrobel <wrobel@pardus.de>
10  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
11  * @link     http://pear.horde.org/index.php?package=Notification
12  */
13
14 /**
15  * Prepare the test setup.
16  */
17 require_once dirname(__FILE__) . '/../../../../Autoload.php';
18
19 /**
20  * Test the notification handler class that logs to the horde log.
21  *
22  * Copyright 2009 The Horde Project (http://www.horde.org/)
23  *
24  * See the enclosed file COPYING for license information (LGPL). If you
25  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
26  *
27  * @category Horde
28  * @package  Notification
29  * @author   Gunnar Wrobel <wrobel@pardus.de>
30  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
31  * @link     http://pear.horde.org/index.php?package=Notification
32  */
33
34 class Horde_Notification_Class_Notification_Handler_Decorator_HordelogTest
35 extends PHPUnit_Framework_TestCase
36 {
37     public function setUp()
38     {
39         @include_once 'Log.php';
40         if (!defined('PEAR_LOG_DEBUG')) {
41             $this->markTestSkipped('The PEAR_LOG_DEBUG constant is not available!');
42         }
43
44         $this->handler = $this->getMock(
45             'Horde_Notification_Handler_Base', array(), array(), '', false, false
46         );
47         $this->logged_handler = new Horde_Notification_Handler_Decorator_Hordelog(
48             $this->handler
49         );
50     }
51
52     public function testMethodPushHasPostconditionThattheEventGotLoggedIfTheEventWasAnError()
53     {
54         $exception = new Exception('test');
55         $this->handler->expects($this->once())
56             ->method('push')
57             ->with($exception);
58         $this->logged_handler->push($exception);
59     }
60
61     public function testMethodAttachGetsDelegated()
62     {
63         $this->handler->expects($this->once())
64             ->method('attach')
65             ->with('listener', array(), 'class')
66             ->will($this->returnValue('instance'));
67         $this->assertEquals(
68             'instance',
69             $this->logged_handler->attach('listener', array(), 'class')
70         );
71     }
72
73     public function testMethodDetachGetsDelegated()
74     {
75         $this->handler->expects($this->once())
76             ->method('detach')
77             ->with('listener');
78         $this->logged_handler->detach('listener');
79     }
80
81     public function testMethodReplaceGetsDelegated()
82     {
83         $this->handler->expects($this->once())
84             ->method('replace')
85             ->with('listener', array(), 'class')
86             ->will($this->returnValue('instance'));
87         $this->assertEquals(
88             'instance',
89             $this->logged_handler->replace('listener', array(), 'class')
90         );
91     }
92
93     public function testMethodPushGetsDelegated()
94     {
95         $this->handler->expects($this->once())
96             ->method('push')
97             ->with('event', 'type', array());
98         $this->logged_handler->push('event', 'type', array());
99     }
100
101     public function testMethodNotifyGetsDelegated()
102     {
103         $this->handler->expects($this->once())
104             ->method('notify')
105             ->with(array('listeners' => array('test')));
106         $this->logged_handler->notify(array('listeners' => array('test')));
107     }
108
109     public function testMethodSetnotificationlistenersGetsDelegated()
110     {
111         $this->handler->expects($this->once())
112             ->method('setNotificationListeners')
113             ->with(array());
114         $array = array();
115         $this->logged_handler->setNotificationListeners($array);
116     }
117
118     public function testMethodNotifylistenersGetsDelegated()
119     {
120         $this->handler->expects($this->once())
121             ->method('notifyListeners')
122             ->with(array());
123         $this->logged_handler->notifyListeners(array());
124     }
125
126     public function testMethodCountGetsDelegated()
127     {
128         $this->handler->expects($this->once())
129             ->method('count')
130             ->with('listener')
131             ->will($this->returnValue(1));
132         $this->assertEquals(1, $this->logged_handler->count('listener'));
133     }
134
135 }