-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidator.php
205 lines (139 loc) · 4.3 KB
/
validator.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
<!DOCTYPE html>
<html>
<head>
<title>rss-bridge-tester</title>
<meta charset='utf-8'>
<link rel="stylesheet" href="style.css" />
<style>
.error {
color : red;
}
.warning {
color: orange;
}
.status {
font-size : 1.2em;
}
.success {
color : green;
}
</style>
</head>
<body>
<?php
/**===================================================================**/
/*| rss-bridge-tester |*/
/*| par teromene |*/
/*| |*/
/*| Ce projet vise à pouvoir tester automatiquement le fonctionnement |*/
/*| des bridges de rss-bridge pour détecter ceux qui nécessitent une |*/
/*| mise à jour. |*/
/*| Pour qu'il fonctionne, vous devez activer tous les bridges dans |*/
/*| votre whitelist de rss-bridge, et remplir la variable |*/
/*| $PATH_TO_RSS_BRIDGE ci-dessous. |*/
/*| Le test utilise des données bidons pour les bridges qui prennent |*/
/*| des paramètres, données stoqués dans l'array $parameters. |*/
/**===================================================================**/
ini_set('display_errors','1'); error_reporting(E_ALL); // For debugging only.
require_once '../rss-bridge/lib/RssBridge.php';
require_once 'test_datas.php';
Bridge::setDir('../rss-bridge/bridges/');
Format::setDir('../rss-bridge/formats/');
Cache::setDir('../rss-bridge/caches/');
?>
<div>
<p>Status : <span id="system-status">Test in progress...</span></p>
<p id="progress"><span id="progress-actual">0</span>/<span id="progress-total">0</span></p>
</div>
<div id="resultSet">
</div>
<script type="text/javascript">
var testArray =
<?php
echo "[";
foreach(Bridge::listBridges() as $bridgeName) {
echo "['".$bridgeName ."',";
if(array_key_exists($bridgeName, $GLOBALS['params'])) {
echo count($GLOBALS['params'][$bridgeName]) - 1;
} else {
echo "0";
}
echo "],";
}
echo "]";
?>
var lastQueried = 0;
var queryNumber = -1;
var hasPrinted = false;
var writeBody = document.getElementById("resultSet");
function performRequest() {
if(lastQueried < testArray.length) {
var t_Array = testArray[lastQueried];
if(queryNumber == 0 && !hasPrinted) {
printBrigeTestStart(t_Array[0]);
hasPrinted = !hasPrinted;
performRequest();
}
if(queryNumber < t_Array[1]) {
queryNumber++;
console.log("Requesting "+t_Array[0]+" test n°"+queryNumber);
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", testRenderer);
oReq.addEventListener("load", performRequest);
oReq.open("GET", "bridge_test.php?bridge="+encodeURIComponent(t_Array[0])+"&t_number="+queryNumber);
oReq.send();
} else {
printBrigeTestEnd();
queryNumber = -1;
lastQueried++;
hasPrinted = !hasPrinted;
}
} else {
console.log("Ended");
}
}
function testRenderer(resultSet) {
console.log(resultSet);
bridgeName = resultSet.target.responseURL.split("bridge=")[1].split("&")[0];
if(resultSet.target.status != 200) {
printFailedTest();
} else {
try {
var resultSet = JSON.parse(resultSet.target.responseText);
if(resultSet.status == "sucess") {
printTestSuccess(resultSet);
} else if(resultSet.status == "warning") {
printTestWarning(resultSet);
} else {
printFailedTest();
}
} catch (e) {
console.log(e);
printFailedTest();
}
}
}
function write(string) {
writeBody.lastChild.innerHTML += string;
}
function printTestSuccess(resultSet) {
write("<p class=\"success\">Test success ! Number of elements : "+resultSet.elementHasContent+" <br /></p>");
}
function printTestWarning(resultSet) {
returnString = "<p class=\"warning\">Test success ! However : <br />";
returnString += resultSet.message+"<br />";
returnString += "List of elements : "+resultSet.elementHasDate+" with date, "+resultSet.elementHasTitle+" with title, "+resultSet.elementHasContent+" with content.</p>";
write(returnString);
}
function printFailedTest() {
write("<p class=\"error\">Test failed !</p>");
}
function printBrigeTestStart(bridgeName) {
writeBody.innerHTML += "<section>Test for "+bridgeName;
}
function printBrigeTestEnd() {
writeBody.innerHTML += "</section>";
}
</script>
<?php
?>