1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\LogViewer\Tests\Model; |
4
|
|
|
|
5
|
|
|
use SilverLeague\LogViewer\Model\LogEntry; |
6
|
|
|
use SilverLeague\LogViewer\Tests\Helper\Invoker; |
7
|
|
|
use SilverStripe\Core\Config\Config; |
8
|
|
|
use SilverStripe\Core\Convert; |
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
10
|
|
|
use SilverStripe\Security\Member; |
11
|
|
|
use SilverStripe\Security\Security; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @package silverstripe-logviewer |
15
|
|
|
* @author Robbie Averill <[email protected]> |
16
|
|
|
* @author Simon Erkelens <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class LogEntryTest extends SapphireTest |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Test the gridfield Summary method |
23
|
|
|
*/ |
24
|
|
|
public function testGridfieldSummary() |
25
|
|
|
{ |
26
|
|
|
$shortString = 'abcdefghijklmnopqrstuvwxyz'; |
27
|
|
|
$longString = ''; |
28
|
|
|
// Generate a string of 350 characters. Because we don't care about the actual content |
29
|
|
|
// A set of a's is good enough; |
30
|
|
|
for ($i = 0; $i <= 350; $i++) { |
31
|
|
|
$longString .= 'a'; |
32
|
|
|
} |
33
|
|
|
$logEntry = LogEntry::create(); |
34
|
|
|
$logEntry->Entry = $shortString; |
35
|
|
|
$this->assertEquals($shortString, $logEntry->getGridfieldSummary()); |
36
|
|
|
$logEntry->Entry = $longString; |
37
|
|
|
$elipsisString = substr($longString, 0, 300) . '...'; |
38
|
|
|
$this->assertEquals($elipsisString, $logEntry->getGridfieldSummary()); |
39
|
|
|
$this->assertEquals($longString, $logEntry->getGridfieldSummary(351)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Test if the fields are in the fieldlist |
44
|
|
|
* A literal field is returning null in getCMSFields. |
45
|
|
|
*/ |
46
|
|
|
public function testGetCMSFieldsFormattedEntry() |
47
|
|
|
{ |
48
|
|
|
$logEntry = LogEntry::create(array( |
49
|
|
|
'Level' => 'INFO', |
50
|
|
|
'Entry' => Convert::array2json(array('Test' => 'Message')) |
51
|
|
|
)); |
52
|
|
|
$fields = $logEntry->getCMSFields(); |
53
|
|
|
$levelField = $fields->dataFieldByName('Level'); |
54
|
|
|
$this->assertEquals("SilverStripe\\Forms\\TextField", $levelField->class); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Test if the field shows when not formatting |
59
|
|
|
*/ |
60
|
|
|
public function testGetCMSFieldsUnformattedEntry() |
61
|
|
|
{ |
62
|
|
|
Config::inst()->update('SilverLeague\LogViewer\Model\LogEntry', 'format_entry', false); |
63
|
|
|
$logEntry = LogEntry::create(array( |
64
|
|
|
'Level' => 'INFO', |
65
|
|
|
'Entry' => Convert::array2json(array('Test' => 'Message')) |
66
|
|
|
)); |
67
|
|
|
$fields = $logEntry->getCMSFields(); |
68
|
|
|
$entryField = $fields->dataFieldByName('Entry'); |
69
|
|
|
$this->assertEquals("SilverStripe\\Forms\\TextareaField", $entryField->class); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Test the entire build of a formatted entry |
74
|
|
|
*/ |
75
|
|
|
public function testBuildEntry() |
76
|
|
|
{ |
77
|
|
|
$entry = array( |
78
|
|
|
'Message' => 'Something went wrong', |
79
|
|
|
'DateTime' => '2016-01-22 03:14:23' |
80
|
|
|
); |
81
|
|
|
$logEntry = LogEntry::create(array( |
82
|
|
|
'Level' => 'INFO', |
83
|
|
|
'Entry' => Convert::array2json($entry) |
84
|
|
|
)); |
85
|
|
|
$result = Invoker::invokeMethod($logEntry, 'buildEntry', array()); |
86
|
|
|
$expectedResult = "<pre class='form-control-static logentry-entry' style='white-space: normal; max-width: 85%;'>". |
87
|
|
|
'<ul style="margin-bottom: 0"><li class="list-unstyled"><span style="color: #0000BB">Message</span>'. |
88
|
|
|
'<span style="color: #007700">: </span><span style="color: #DD0000">Something went wrong</span></li>'. |
89
|
|
|
'<li class="list-unstyled"><span style="color: #0000BB">DateTime</span>'. |
90
|
|
|
'<span style="color: #007700">: </span><span style="color: #DD0000">2016-01-22 03:14:23</span></li>'. |
91
|
|
|
'</ul></pre>'; |
92
|
|
|
$this->assertEquals($expectedResult, $result); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|