6e1984c7525267342cc8b255a88ed0d1b5860df1
[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         if (!class_exists('Log')) {
40             $this->markTestSkipped('The PEAR Log package is not installed!');
41         }
42
43         @include_once 'Log.php';
44         if (!defined('PEAR_LOG_DEBUG')) {
45             $this->markTestSkipped('The PEAR_LOG_DEBUG constant is not available!');
46         }
47
48         $this->handler = $this->getMock(
49             'Horde_Notification_Handler_Base', array(), array(), '', false, false
50         );
51         $this->logged_handler = new Horde_Notification_Handler_Decorator_Hordelog(
52             $this->handler
53         );
54     }
55
56     public function testMethodPushHasPostconditionThattheEventGotLoggedIfTheEventWasAnError()
57     {
58         $exception = new Exception('test');
59         $this->handler->expects($this->once())
60             ->method('push')
61             ->with($exception);
62         $this->logged_handler->push($exception);
63     }
64
65     public function testMethodAttachGetsDelegated()
66     {
67         $this->handler->expects($this->once())
68             ->method('attach')
69             ->with('listener', array(), 'class')
70             ->will($this->returnValue('instance'));
71         $this->assertEquals(
72             'instance',
73             $this->logged_handler->attach('listener', array(), 'class')
74         );
75     }
76
77     public function testMethodDetachGetsDelegated()
78     {
79         $this->handler->expects($this->once())
80             ->method('detach')
81             ->with('listener');
82         $this->logged_handler->detach('listener');
83     }
84
85     public function testMethodReplaceGetsDelegated()
86     {
87         $this->handler->expects($this->once())
88             ->method('replace')
89             ->with('listener', array(), 'class')
90             ->will($this->returnValue('instance'));
91         $this->assertEquals(
92             'instance',
93             $this->logged_handler->replace('listener', array(), 'class')
94         );
95     }
96
97     public function testMethodPushGetsDelegated()
98     {
99         $this->handler->expects($this->once())
100             ->method('push')
101             ->with('event', 'type', array());
102         $this->logged_handler->push('event', 'type', array());
103     }
104
105     public function testMethodNotifyGetsDelegated()
106     {
107         $this->handler->expects($this->once())
108             ->method('notify')
109             ->with(array('listeners' => array('test')));
110         $this->logged_handler->notify(array('listeners' => array('test')));
111     }
112
113     public function testMethodSetnotificationlistenersGetsDelegated()
114     {
115         $this->handler->expects($this->once())
116             ->method('setNotificationListeners')
117             ->with(array());
118         $array = array();
119         $this->logged_handler->setNotificationListeners($array);
120     }
121
122     public function testMethodNotifylistenersGetsDelegated()
123     {
124         $this->handler->expects($this->once())
125             ->method('notifyListeners')
126             ->with(array());
127         $this->logged_handler->notifyListeners(array());
128     }
129
130     public function testMethodCountGetsDelegated()
131     {
132         $this->handler->expects($this->once())
133             ->method('count')
134             ->with('listener')
135             ->will($this->returnValue(1));
136         $this->assertEquals(1, $this->logged_handler->count('listener'));
137     }
138
139 }