3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Fusionforge.
7 * Fusionforge is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Fusionforge is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
22 require_once 'HudsonJobWidget.class.php';
23 require_once 'common/include/HTTPRequest.class.php';
24 require_once 'PluginHudsonJobDao.class.php';
25 require_once 'HudsonJob.class.php';
26 require_once 'HudsonTestResult.class.php';
28 class hudson_Widget_JobTestResults extends HudsonJobWidget {
32 function hudson_Widget_JobTestResults($owner_type, $owner_id) {
33 $request =& HTTPRequest::instance();
34 if ($owner_type == WidgetLayoutManager::OWNER_TYPE_USER) {
35 $this->widget_id = 'plugin_hudson_my_jobtestresults';
36 $this->group_id = $owner_id;
38 $this->widget_id = 'plugin_hudson_project_jobtestresults';
39 $this->group_id = $request->get('group_id');
41 $this->Widget($this->widget_id);
42 $this->setOwner($owner_id, $owner_type);
47 if ($this->job && $this->test_result) {
48 $title .= vsprintf(_('%1$s Test Results (%2$s / %3$s)'),
49 array($this->job->getName(), $this->test_result->getPassCount(), $this->test_result->getTotalCount()));
50 } elseif ($this->job && ! $this->test_result) {
51 $title .= sprintf(_('%1$s Test Results'), $this->job->getName());
53 $title .= _('Test Results');
58 function getDescription() {
59 return _("Show the test results of the latest build for the selected job.To display something, your job needs to execute tests and publish them. The result is shown on a pie chart.");
62 function loadContent($id) {
63 $sql = "SELECT * FROM plugin_hudson_widget WHERE widget_name=$1 AND owner_id=$2 AND owner_type=$3 AND id=$4";
64 $res = db_query_params($sql,array($this->widget_id,$this->owner_id,$this->owner_type,$id));
65 if ($res && db_numrows($res)) {
66 $data = db_fetch_array($res);
67 $this->job_id = $data['job_id'];
68 $this->content_id = $id;
69 $jobs = $this->getAvailableJobs();
70 if (array_key_exists($this->job_id, $jobs)) {
71 $used_job = $jobs[$this->job_id];
72 $this->job_url = $used_job->getUrl();
73 $this->job = $used_job;
75 $this->test_result = new HudsonTestResult($this->job_url);
76 } catch (Exception $e) {
77 $this->test_result = null;
82 $this->test_result = null;
87 function getContent() {
89 if ($this->job != null && $this->test_result != null) {
91 $test_result = $this->test_result;
92 $html .= '<div style="padding: 20px;">';
93 $html .= ' <a href="/plugins/hudson/?action=view_last_test_result&group_id='.$this->group_id.'&job_id='.$this->job_id.'">'.$test_result->getTestResultPieChart().'</a>';
96 if ($this->job != null) {
97 $html .= _("No test found for this job.");
99 $html .= _("Job not found.");