1 | <?php |
||
15 | class LogEntryTest extends SapphireTest |
||
16 | { |
||
17 | /** |
||
18 | * Test that LogEntry classes can not be edited |
||
19 | */ |
||
20 | public function testDoNotAllowEditing() |
||
24 | |||
25 | /** |
||
26 | * Test the gridfield Summary method |
||
27 | */ |
||
28 | public function testGridfieldSummary() |
||
45 | |||
46 | public function testEntryToUl() |
||
62 | |||
63 | public function testFormatLegacyEntry() |
||
64 | { |
||
65 | $arrayEntry = 'E_WARNING: Invalid argument supplied for foreach() {"code":2,"message":"Invalid argument supplied' . |
||
66 | 'for foreach()","file":"/data/site/docroot/logviewer/src/Model/LogEntry.php","line":89} []'; |
||
67 | $logEntry = LogEntry::create(array( |
||
68 | 'Level' => 'INFO', |
||
69 | 'Entry' => $arrayEntry |
||
70 | )); |
||
71 | |||
72 | $result = $this->invokeMethod($logEntry, 'formatLegacyEntry', array($arrayEntry)); |
||
73 | $expectedString = '<h2>Entry</h2>E_WARNING: Invalid argument supplied for foreach() => [<ul style="margin-bottom:' . |
||
74 | ' 0"><li class="list-unstyled"><span>code => 2</span></li><li class="list-unstyled"><span>message =>' . |
||
75 | ' Invalid argument suppliedfor foreach()</span></li><li class="list-unstyled"><span>file =>' . |
||
76 | ' /data/site/docroot/logviewer/src/Model/LogEntry.php</span></li><li class="list-unstyled"><span>line' . |
||
77 | " => 89</span></li></ul>]\n" . |
||
78 | 'Other => [<ul style="margin-bottom: 0"></ul>]'; |
||
79 | $this->assertEquals($expectedString, $result); |
||
80 | |||
81 | $stringEntry = 'E_WARNING: Invalid argument supplied for foreach() {"code":2,"message":"Invalid argument supplied' . |
||
82 | 'for foreach()","file":"/data/site/docroot/logviewer/src/Model/LogEntry.php","line":89} OOPS'; |
||
83 | $logEntry->Entry = $stringEntry; |
||
84 | |||
85 | $result = $this->invokeMethod($logEntry, 'formatLegacyEntry', array($stringEntry)); |
||
86 | $expectedString = '<h2>Entry</h2>E_WARNING: Invalid argument supplied for foreach() => [<ul style="margin-bottom:' . |
||
87 | ' 0"><li class="list-unstyled"><span>code => 2</span></li><li class="list-unstyled"><span>message =>' . |
||
88 | ' Invalid argument suppliedfor foreach()</span></li><li class="list-unstyled"><span>file =>' . |
||
89 | ' /data/site/docroot/logviewer/src/Model/LogEntry.php</span></li><li class="list-unstyled"><span>line' . |
||
90 | " => 89</span></li></ul>]\n" . |
||
91 | "Other:\n OOPS"; |
||
92 | $this->assertEquals($result, $expectedString); |
||
93 | |||
94 | $noJsonEntry = "We're making water!"; |
||
95 | $logEntry->Entry = $noJsonEntry; |
||
96 | $result = $this->invokeMethod($logEntry, 'formatLegacyEntry', array($noJsonEntry)); |
||
97 | $this->assertEquals('<p>' . $noJsonEntry . '</p>', $result); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * A literal field is returning null in getCMSFields. |
||
102 | */ |
||
103 | public function testGetCMSFieldsFormattedEntry() |
||
113 | |||
114 | |||
115 | public function testGetCMSFieldsUnformattedEntry() |
||
126 | |||
127 | /** |
||
128 | * Call protected/private method of a class. |
||
129 | * |
||
130 | * @param object &$object Instantiated object that we will run method on. |
||
131 | * @param string $methodName Method name to call |
||
132 | * @param array $parameters Array of parameters to pass into method. |
||
133 | * |
||
134 | * @return mixed Method return. |
||
135 | */ |
||
136 | public function invokeMethod(&$object, $methodName, array $parameters = array()) |
||
144 | } |
||
145 |