-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbridge_test.php
119 lines (77 loc) · 2.66 KB
/
bridge_test.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
<?php
//ini_set('display_errors','1'); error_reporting(E_ALL); // For debugging only.
require_once '../rss-bridge/lib/RssBridge.php';
Bridge::setDir('../rss-bridge/bridges/');
Format::setDir('../rss-bridge/formats/');
Cache::setDir('../rss-bridge/caches/');
require_once 'test_datas.php';
if($_GET['bridge'] && is_numeric($_GET['t_number'])) {
test_bridge($_GET['bridge'], $_GET['t_number']);
}
function test_bridge($bridge_name, $test_number) {
$bridge = Bridge::create($bridge_name);
$bridge->loadMetadatas();
$params = $bridge->parameters;
if($bridge->parameters == NULL) {
$bridgeTestResults = perform_data_test(NULL, 0);
} else {
$params_key = array_keys($params)[$test_number];
$bridgeTestResults = perform_data_test($params[$params_key], $test_number);
}
echo json_encode($bridgeTestResults);
}
function perform_data_test($datas, $number) {
if($datas == NULL) {
return run_test([]);
}
$datas = json_decode($datas, true);
$params = [];
foreach($datas as $element) {
$id = $element['identifier'];
if(!array_key_exists($number, $GLOBALS['params'][$_GET['bridge']])) {
$value = $GLOBALS['params'][$_GET['bridge']][$id];
} else {
$value = $GLOBALS['params'][$_GET['bridge']][$number][$id];
}
$params[$element['identifier']] = $value;
}
return run_test($params);
}
function run_test($parameters) {
$cache = Cache::create('FileCache');
$tested_bridge = Bridge::create($_GET['bridge']);
$tested_bridge->setDatas($parameters);
$tested_bridge->setCache($cache);
$result = $tested_bridge->getDatas();
$answer = [];
$hasContent = 0;
$hasDate = 0;
$hasTitle = 0;
foreach($result as $element) {
if($element->content != null) $hasContent++;
if($element->timestamp != null) $hasDate++;
if($element->title != null) $hasTitle++;
}
$answer['elementHasDate'] = $hasDate;
$answer['elementHasContent'] = $hasContent;
$answer['elementHasTitle'] = $hasTitle;
if($hasContent != $hasDate || $hasDate != $hasTitle) {
$answer["status"] = "warning";
$answer["message"] = "";
if($hasDate < $hasContent || $hasDate < $hasTitle) {
$answer["message"] .= "Some elements haven't got dates. ";
}
if($hasTitle < $hasContent || $hasTitle < $hasDate) {
$answer["message"] .= "Some elements haven't got titles. ";
}
if($hasContent < $hasTitle || $hasContent < $hasDate) {
$answer["message"] .= "Some elements haven't got content.";
}
} else if($hasContent == 0) {
$answer["status"] = "failed";
} else {
$answer["status"] = "sucess";
}
return $answer;
}
?>