Skip to content

Commit

Permalink
refs #1797 : add - working code.
Browse files Browse the repository at this point in the history
 -
  • Loading branch information
inureyes committed Apr 21, 2015
1 parent 773e8bb commit 7da5e91
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 1 deletion.
125 changes: 125 additions & 0 deletions plugins/TestSuite/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/* Test Suite for Textcube
----------------------------------
Version 0.1
Starts at : Apr. 19, 2015
Last modified at : Apr. 20, 2015
Jeongkyu Shin.
E-mail : inureyes@gmail.com
This plugin enables test functions and services for testers.
For the detail, visit http://github.com/Needlworks/Textcube-TestSuite
General Public License
http://www.gnu.org/licenses/gpl.html
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
### Short changelog
* 0.1 Base code.
### TODO
* Add stand-alone autoupdate without preinstalled git binary.
* Exception handling during git process (usually permission issue)
*/

/* Functions */
function TestSuite_upgrade_repos($target, $mother) {
$context = Model_Context::getInstance();
$config = $context->getProperty('plugin.config');

if (empty($config['repos'])) {
$config['repos'] = 'unstable';
}
require_once 'library/PHPGit/Repository.php';

$repo = new PHPGit_Repository(ROOT);
$repo->git('fetch');

switch ($config['repos']) {
case 'master':
$repo->git('checkout master');
break;
case 'unstable':
$repo->git('checkout tags/latest-unstable');
break;
case 'stable':
$repo->git('checkout tags/latest-stable');
break;
}
return $repo->git('pull');
//return $target;
}

function TestSuite_upgrade_repos_via_user() {
if (doesHaveOwnership()) {
$result = TestSuite_upgrade_repos(null, null);
if($result){
Respond::ResultPage(0);
}
}
Respond::Resultpage(-1);
}

/* User interfaces */
function TestSuite_manual_upgrade_button($target) {
/* TODO : add manual upgrade button on dashboard */
$context = Model_Context::getInstance();
$blogURL = $context->getProperty('uri.blog');
$view = <<<EOS
<script type="text/javascript" src="{$blogURL}/plugin/TestSuiteForTextcube.js"></script>
<div id="TestSuite-manual-upgrade">
<button class="input-button" value="Update source" onclick="TestSuite_manual_upgrade();return false;">Update source code</button>
</div>
EOS;
return $view;
}

/* Validators */
function TestSuite_manual_upgrade_javascript() {
$context = Model_Context::getInstance();
$blogURL = $context->getProperty('uri.blog');
$view = <<< EOS
/// Copyright (C) Jeongkyu Shin. / Needlworks
//<![CDATA[
function TestSuite_manual_upgrade() {
/// Set default values.
var request = new HTTPRequest("POST", "{$blogURL}/plugin/TestSuiteManualUpdate/");
request.onSuccess = function () {
PM.removeRequest(this);
PM.showMessage(_t("업데이트가 완료되었습니다"), "center", "bottom");
}
request.onError = function() {
PM.removeRequest(this);
PM.showErrorMessage(_t("업데이트하지 못했습니다"), "center", "bottom");
}
PM.addRequest(request, _t("소스코드를 업데이트하고 있습니다."));
request.send();
return true;
}
//]]>
EOS;
header('Content-Type: text/javascript; charset=UTF-8');
echo $view;
}


function TestSuite_DataHandler($data) {
$context = Model_Context::getInstance();
$config = $context->getProperty('plugin.config');

if (!array_key_exists('repos', $config)) {
return false;
} else {
return true;
}
}

?>
7 changes: 6 additions & 1 deletion plugins/TestSuite/index.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin version="2.0">
<title xml:lang="en">Test suite</title>
<title xml:lang="en"><![CDATA[테스트 도구]]></title>
<version>0.1</version>
<description xml:lang="en">Receive and autoupdate Textcube code from main repository.</description>
<description xml:lang="ko"><![CDATA[자동 업데이트, 버그 레포트 및 상태 보고서 생성을 포함한 테스트용 도구 기능을 제공합니다.]]></description>
<license>GPL</license>
<link>http://forest.nubimaru.com</link>
<author link="http://forest.nubimaru.com"><![CDATA[Jeongkyu Shin (inureyes)]]></author>
Expand All @@ -13,7 +15,10 @@
</textcube>
</requirements>
<binding>
<listener event="Cron5m" handler="TestSuite_upgrade_repos" />
<listener event="Cron5m" handler="TestSuite_upgrade_repos" />
<center handler="TestSuite_manual_upgrade_button" />
<listener event="/plugin/TestSuiteForTextcube.js" handler="TestSuite_manual_upgrade_javascript" />
<listener event="/plugin/TestSuiteManualUpdate" handler="TestSuite_upgrade_repos_via_user" />
<config xml:lang="en" dataValHandler="TestSuite_DataHandler">
<window width="500" height="525" />
<fieldset legend="Repository">
Expand Down

0 comments on commit 7da5e91

Please sign in to comment.