-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtenonOutput.class.php
221 lines (193 loc) · 8.62 KB
/
tenonOutput.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* Project: sample-php-class
* User: karlgroves
* Date: 6/23/14
* Time: 3:58 PM
*/
class tenonOutput extends tenonTest
{
protected $url, $opts;
public $tenonResponse;
/**
* Class constructor
*
* @param string $url the API url to post your request to
* @param array $opts options for the request
*/
public function __construct($url, $opts)
{
parent::__construct($url, $opts);
}
/**
* @return mixed
*/
public function decodeResponse()
{
if ((false !== $this->tenonResponse) && (!is_null($this->tenonResponse))) {
$result = json_decode($this->tenonResponse, true);
if (!is_null($result)) {
$this->rspArray = $result;
} else {
return false;
}
} else {
return false;
}
}
/**
* @param $val
*
* @return string
*/
public static function boolToString($val)
{
if ($val == '1') {
return 'Yes';
} else {
return 'No';
}
}
/**
*
* @return mixed
*/
public function processResponseSummary()
{
if ((false === $this->rspArray) || (is_null($this->rspArray))) {
return false;
}
$output = '';
$output .= '<h2>Your Request</h2>';
$output .= '<ul>';
$output .= '<li>DocID: ' . $this->rspArray['request']['docID'] . '</li>';
$output .= '<li>Certainty: ' . $this->rspArray['request']['certainty'] . '</li>';
$output .= '<li>Level: ' . $this->rspArray['request']['level'] . '</li>';
$output .= '<li>Priority: ' . $this->rspArray['request']['priority'] . '</li>';
$output .= '<li>Importance: ' . $this->rspArray['request']['importance'] . '</li>';
$output .= '<li>Project ID: ' . $this->rspArray['request']['projectID'] . '</li>';
$output .= '<li>User-Agent String: ' . $this->rspArray['request']['uaString'] . '</li>';
$output .= '<li>URL: ' . $this->rspArray['request']['url'] . '</li>';
$output .= '<li>Viewport: ' . $this->rspArray['request']['viewport']['width'] . ' x ' . $this->rspArray['request']['viewport']['height'] . '</li>';
$output .= '<li>Fragment? ' . self::boolToString($this->rspArray['request']['fragment']) . '</li>';
$output .= '<li>Store Results? ' . self::boolToString($this->rspArray['request']['store']) . '</li>';
$output .= '</ul>';
$output .= '<h2>Response</h2>';
$output .= '<ul>';
$output .= '<li>Document Size: ' . $this->rspArray['documentSize'] . ' bytes </li>';
$output .= '<li>Response Code: ' . $this->rspArray['status'] . '</li>';
$output .= '<li>Response Type: ' . $this->rspArray['message'] . '</li>';
$output .= '<li>Response Time: ' . date("F j, Y, g:i a", strtotime($this->rspArray['responseTime'])) . '</li>';
$output .= '<li>Response Execution Time: ' . $this->rspArray['responseExecTime'] . ' seconds</li>';
$output .= '</ul>';
$output .= '<h2>Global Stats</h2>';
$output .= '<ul>';
$output .= '<li>Global Density, overall: ' . $this->rspArray['globalStats']['allDensity'] . '</li>';
$output .= '<li>Global Error Density: ' . $this->rspArray['globalStats']['errorDensity'] . '</li>';
$output .= '<li>Global Warning Density: ' . $this->rspArray['globalStats']['warningDensity'] . '</li>';
$output .= '</ul>';
$output .= '<h3>Density</h3>';
$output .= '<ul>';
$output .= '<li>Overall Density: ' . $this->rspArray['resultSummary']['density']['allDensity'] . '%</li>';
$output .= '<li>Error Density: ' . $this->rspArray['resultSummary']['density']['errorDensity'] . '%</li>';
$output .= '<li>Warning Density: ' . $this->rspArray['resultSummary']['density']['warningDensity'] . '%</li>';
$output .= '</ul>';
$output .= '<h3>Issue Counts</h3>';
$output .= '<ul>';
$output .= '<li>Total Issues: ' . $this->rspArray['resultSummary']['issues']['totalIssues'] . '</li>';
$output .= '<li>Total Errors: ' . $this->rspArray['resultSummary']['issues']['totalErrors'] . '</li>';
$output .= '<li>Total Warnings: ' . $this->rspArray['resultSummary']['issues']['totalWarnings'] . '</li>';
$output .= '</ul>';
$output .= '<h3>Issues By WCAG Level</h3>';
$output .= '<ul>';
$output .= '<li>Level A: ' . $this->rspArray['resultSummary']['issuesByLevel']['A']['count'];
$output .= ' (' . $this->rspArray['resultSummary']['issuesByLevel']['A']['pct'] . '%)</li>';
$output .= '<li>Level AA: ' . $this->rspArray['resultSummary']['issuesByLevel']['AA']['count'];
$output .= ' (' . $this->rspArray['resultSummary']['issuesByLevel']['AA']['pct'] . '%)</li>';
$output .= '<li>Level AAA: ' . $this->rspArray['resultSummary']['issuesByLevel']['AAA']['count'];
$output .= ' (' . $this->rspArray['resultSummary']['issueSummary']['AAA']['pct'] . '%)</li>';
$output .= '</ul>';
$output .= '<h3>Client Script Errors, if any</h3>';
$output .= '<p>(Note: "NULL" or empty array here means there were no errors.)</p>';
$output .= '<pre>' . var_export($this->rspArray['clientScriptErrors'], true) . '</pre>';
return $output;
}
/**
*
* @return string
*/
function processIssues()
{
$issues = $this->rspArray['resultSet'];
$count = count($issues);
if ($count > 0) {
$i = 0;
for ($x = 0; $x < $count; $x++) {
$i++;
$output .= '<div class="issue">';
$output .= '<div>' . $i . ': ' . $issues[$x]['errorTitle'] . '</div>';
$output .= '<div>' . $issues[$x]['errorDescription'] . '</div>';
$output .= '<div><pre><code>' . trim($issues[$x]['errorSnippet']) . '</code></pre></div>';
$output .= '<div>Line: ' . $issues[$x]['position']['line'] . '</div>';
$output .= '<div>Column: ' . $issues[$x]['position']['column'] . '</div>';
$output .= '<div>xPath: <pre><code>' . $issues[$x]['xpath'] . '</code></pre></div>';
$output .= '<div>Certainty: ' . $issues[$x]['certainty'] . '</div>';
$output .= '<div>Priority: ' . $issues[$x]['priority'] . '</div>';
$output .= '<div>Best Practice: ' . $issues[$x]['resultTitle'] . '</div>';
$output .= '<div>Reference: ' . $issues[$x]['ref'] . '</div>';
$output .= '<div>Standards: ' . implode(', ', $issues[$x]['standards']) . '</div>';
$output .= '<div>Issue Signature: ' . $issues[$x]['signature'] . '</div>';
$output .= '<div>Test ID: ' . $issues[$x]['tID'] . '</div>';
$output .= '<div>Best Practice ID: ' . $issues[$x]['bpID'] . '</div>';
$output .= '</div>';
}
}
return $output;
}
/**
* @param $pathToFolder
*
* @return bool
*/
public function writeResultsToCSV($pathToFolder)
{
$url = $this->rspArray['request']['url'];
$issues = $this->rspArray['resultSet'];
$name = htmlspecialchars($this->rspArray['request']['docID']);
$count = count($issues);
if ($count < 1) {
return false;
}
for ($x = 0; $x < $count; $x++) {
$rows[$x] = array(
$url,
$issues[$x]['tID'],
$issues[$x]['resultTitle'],
$issues[$x]['errorTitle'],
$issues[$x]['errorDescription'],
implode(', ', $issues[$x]['standards']),
html_entity_decode($issues[$x]['errorSnippet']),
$issues[$x]['position']['line'],
$issues[$x]['position']['column'],
$issues[$x]['xpath'],
$issues[$x]['certainty'],
$issues[$x]['priority'],
$issues[$x]['ref'],
$issues[$x]['signature']
);
}
// Put a row of headers up on the beginning
array_unshift($rows, array('URL', 'testID', 'Best Practice', 'Issue Title', 'Description',
'WCAG SC', 'Issue Code', 'Line', 'Column', 'xPath', 'Certainty', 'Priority', 'Reference', 'Signature'));
// MAKE SURE THE FILE DOES NOT ALREADY EXIST
if (!file_exists($pathToFolder . $name . '.csv')) {
$fp = fopen($pathToFolder . $name . '.csv', 'w');
foreach ($rows as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
return true;
}
return false;
}
}