forked from habari/tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.plugin.php
131 lines (113 loc) · 3.72 KB
/
tests.plugin.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
<?php
class TestsPlugin extends Plugin
{
private $attributes = array(
'name',
'cases',
'complete',
'fail',
'pass',
'exception',
'incomplete',
);
public function filter_admin_access( $access, $page, $post_type )
{
if ( $page != 'tests') {
return $access;
}
return true;
}
public function action_init()
{
$this->add_template('tests_admin', dirname($this->get_file()) . '/plugin_admin.php');
}
public function action_admin_header( $theme )
{
if ( $theme->page == 'tests' ) {
Stack::add( 'admin_stylesheet', array( $this->get_url() . '/admin.css', 'screen' ), 'admin-css' );
}
}
public function filter_adminhandler_post_loadplugins_main_menu( array $menu )
{
$item_menu = array( 'tests' =>
array(
'url' => URL::get( 'admin', 'page=tests'),
'title' => _t('Tests'),
'text' => _t('Tests'),
'hotkey' => 'S',
'selected' => false
)
);
$slice_point = array_search( 'groups', array_keys( $menu ) ); // Element will be inserted before "groups"
$pre_slice = array_slice( $menu, 0, $slice_point);
$post_slice = array_slice( $menu, $slice_point);
$menu = array_merge( $pre_slice, $item_menu, $post_slice );
return $menu;
}
/**
* @todo Removing initial newline shouldn't be necessary, find out what's causing it
*/
public function action_admin_theme_get_tests( AdminHandler $handler, Theme $theme )
{
$url = $this->get_url('/index.php?c=symbolic&o=1');
$test_list = new SimpleXMLElement(preg_replace("/^\n/", "", file_get_contents($url.'&d=1')));
$output = '';
$unit_names = array();
foreach ($test_list->unit as $unit) {
$unit_names[] = (string)$unit->attributes()->name;
}
if (isset($_GET['run']) && isset($_GET['unit'])) {
$unit = $_GET['unit'];
if ($unit != 'all') {
$url = '/index.php?c=symbolic&o=1&u='.$unit;
if (isset($_GET['test'])) {
$test = $_GET['test'];
$url = $url.'&t='.$test;
$theme->test = $test;
}
$url = $this->get_url($url);
}
$results = preg_replace("/^\n/", "", file_get_contents($url));
$results = new SimpleXMLElement(preg_replace("/^\n/", "", file_get_contents($url)));
$results_array = array();
foreach ($results as $result) {
$result_array = (array)$result->attributes();
$result_array = array_shift($result_array);
$result_array['methods'] = array();
foreach ($result->method as $method) {
$method_array = (array)$method;
$output_array = array();
if( isset( $method->output ) ) { // output is on, and output can appear whether passing or failing.
foreach( $method->output as $output ) {
$output_array[] = "<div class='method_output'>{$method->output}</div>";
}
}
if( ! isset( $method->message ) ) { // no <message> means the method passed
$result_array['methods'][] = array_merge( array_shift($method_array), array( "result" => "Pass", "output" => implode( " ", $output_array ) ) );
} else {
$message_array = array();
$result = (string)$method->message->attributes()->type;
foreach( $method->message as $message ) {
$message_array[] = "{$method->message}" . ( $result != "Fail" ? "" : "<br><em>" . basename($method->message->attributes()->file) . ":{$method->message->attributes()->line}</em>");
}
$result_array['methods'][] = array_merge( array_shift($method_array), array(
"result" => $result,
"messages" => implode( "<br>", $message_array ),
"output" => implode( " ", $output_array ),
));
}
}
$results_array[] = $result_array;
}
$theme->results = $results_array;
$theme->unit = $unit;
}
$theme->content = $output;
$theme->unit_names = $unit_names;
$theme->display('header');
$theme->display('tests_admin');
$theme->display('footer');
exit;
}
}
?>