5
5
use SilverLeague \LogViewer \Handler \DataObjectHandler ;
6
6
use SilverLeague \LogViewer \Model \LogEntry ;
7
7
use SilverStripe \Dev \SapphireTest ;
8
+ use SilverStripe \Core \Config \Config ;
8
9
use SilverStripe \Core \Injector \Injector ;
9
10
10
11
/**
@@ -39,6 +40,8 @@ public function setUp()
39
40
{
40
41
parent ::setUp ();
41
42
43
+ Config::nest ();
44
+
42
45
$ this ->logger = Injector::inst ()->get ('Logger ' );
43
46
44
47
// Clear the default handlers so we can test precisely
@@ -48,17 +51,43 @@ public function setUp()
48
51
49
52
/**
50
53
* Test that arbitary log levels are all written to the database through the DataObjectHandler
51
- *
52
- * @covers \SilverLeague\LogViewer\Handler\DataObjectHandler
53
54
*/
54
55
public function testWriteToDefaultLogger ()
55
56
{
56
57
$ this ->logger ->pushHandler (new DataObjectHandler );
57
- $ this ->logger ->addDebug ('Hello world ' );
58
+ $ this ->logger ->addError ('Hello world ' );
58
59
59
60
$ logEntry = LogEntry::get ()->first ();
60
61
$ this ->assertContains ('Hello world ' , $ logEntry ->Entry );
61
- $ this ->assertSame ('DEBUG ' , $ logEntry ->Level );
62
+ $ this ->assertSame ('ERROR ' , $ logEntry ->Level );
63
+ }
64
+
65
+ /**
66
+ * Test that logs are handled at a minimum level, but not lower than it.
67
+ */
68
+ public function testDontLogMessagesLowerThanMinimumLever ()
69
+ {
70
+ Config::inst ()->update ('LogViewer ' , 'minimum_log_level ' , 300 );
71
+ LogEntry::get ()->removeAll ();
72
+ $ this ->logger ->pushHandler (new DataObjectHandler );
73
+
74
+ $ this ->logger ->addDebug ('Debug ' );
75
+ $ this ->assertSame (0 , LogEntry::get ()->count ());
76
+
77
+ $ this ->logger ->addWarning ('Warning ' );
78
+ $ this ->assertGreaterThan (0 , LogEntry::get ()->filter ('Level ' , 'WARNING ' )->count ());
79
+
80
+ $ this ->logger ->addAlert ('Alert ' );
81
+ $ this ->assertGreaterThan (0 , LogEntry::get ()->filter ('Level ' , 'ALERT ' )->count ());
82
+ }
83
+
84
+ /**
85
+ * Test that the minumum log capture level is returned from configuration
86
+ */
87
+ public function testGetMinimumLogLevelFromConfiguration ()
88
+ {
89
+ Config::inst ()->update ('LogViewer ' , 'minimum_log_level ' , 123 );
90
+ $ this ->assertSame (123 , (new DataObjectHandler )->getMinimumLogLevel ());
62
91
}
63
92
64
93
/**
@@ -68,6 +97,8 @@ public function testWriteToDefaultLogger()
68
97
*/
69
98
public function tearDown ()
70
99
{
100
+ Config::unnest ();
101
+
71
102
$ this ->logger ->setHandlers ($ this ->originalHandlers );
72
103
73
104
parent ::tearDown ();
0 commit comments