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