Commit 21d40f4e authored by GROSS-AMBLARD David's avatar GROSS-AMBLARD David
Browse files

Fixes artifact updateonce function. Introduce a test page, test.php

parent abdde1cc
......@@ -56,6 +56,8 @@ function sugarFree($str){
case "multi-line input":
$str.="select @TYPE:=3";
break;
default:
break;
// TODO continue with other sugar cubes :)
}
}
......@@ -120,7 +122,10 @@ function updateonce($conn, $artifact, $artifactid, $count)
$actions = '';
foreach ($stateinfo as $dest=>$v) {
if($dest<>"nodetip"){
debug("testing transition: $dest");
if($dest=="nodetip")
debug("a nodetip");
else {
debug("checking transition $node -> $dest");
debug("node data: ".json_encode($stateinfo[$dest]));
......@@ -128,7 +133,7 @@ function updateonce($conn, $artifact, $artifactid, $count)
$guard=$artifact[$node][$dest]["guard"];
$guard=sugarFree($guard);
}
else throw new Exception("No guard in artifact");
if($guard=="none")
$guard="select true from dual";
......@@ -142,6 +147,8 @@ function updateonce($conn, $artifact, $artifactid, $count)
if( isset($artifact[$node][$dest]["actions"]) ){
$actions=str_replace('SESSION_USER', $_SESSION['id'], $artifact[$node][$dest]["actions"]);
}
else
throw new Exception("No action in artifact");
if (isset($_SESSION['skills'])) {
$actions=str_replace('SKILLS', $_SESSION['skills'], $actions);
......@@ -149,23 +156,16 @@ function updateonce($conn, $artifact, $artifactid, $count)
// TODO what for?
}
//We make sure that guard and actions are not empty before sending a query to activate step
if($guard !=='' && $actions !== ''){
$activated=step($conn, $artifactid, $node, $dest, $guard, $actions);
debug("result:".$activated);
if ($activated) {
return true;
}
$activated=step($conn, $artifactid, $node, $dest, $guard, $actions);
if ($activated) {
debug("result:".$activated);
if ($activated)
return true;
}
}
}
debug("no transition from $node");
return false; // no guard is validated
}
}
/**
* Return the json description of an artifact, stored in the artifactclasses directory
......@@ -194,14 +194,6 @@ function DEPRECATEDupdate($conn, $artifact)
}
/*
* for all running artifact of a user, update their state
* Which order ? Which one to start with ?
*/
function updateAll($conn){
}
/*
* update
*
......@@ -343,18 +335,6 @@ function startAllArtifact($conn,$userid){
update($conn,$artifactid);
}
}
/*
$table=$conn->query("select id from Artifact where ownerid=0");
if($table->rowCount()>0){
debug("Artifacts available");
while($tuple=$table->fetch()){
$artifactid=$tuple['id'];
debug("starting one");
startArtifact($conn, $artifactid, $userid);
}
}
*/
}
/**
......@@ -369,7 +349,6 @@ function startAllArtifact($conn,$userid){
function pignistic($conn,$artifactid){
$table=$conn->query("select value from Answer where Artifact=$artifactid group by value order by sum(mass) desc limit 1");
$choice=$table->fetch()['value'];
//$conn->query("insert into Answer(idtask,user,Artifact,value,mass) values (1,1,$artifactid,$choice,1)");
$conn->query("insert into Answer(idtask,user,Artifact,value,mass) select MAX(idtask)+1,1,$artifactid,$choice,1 from Answer where Artifact=$artifactid");
}
......@@ -12,7 +12,7 @@
* MAIN: the main part of the Web page
*/
// checking proer installation
// checking proper installation
if (file_exists("config.php"))
require("config.php");
......
......@@ -5,7 +5,6 @@
"nodetip":"Starting node",
"2": {
"guard": "none",
"guardtip":"Nothing to check",
"actiontip":"We instantiate the template",
"actions": [
......@@ -24,7 +23,6 @@
"nodetip":"Starting node",
"3": {
"guard": "select true from Answered where artifact=CURRENT_ARTIFACT and id=1",
"guardtip":"Nothing to check",
"actiontip":"We instantiate the template",
"actions": [
......
<?php_check_syntax
<?php
require("HWlib.php");
require("HTML.php");
require("profile.php");
require("skills.php");
require("tasks.php");
require("actions.php");
require("connection.php");
require("show-pages.php");
require("artifacts.php");
require("show-artifact.php");
require("drawArtifact.php");
require("workflowdesign.php");
if (preg_match("/^use '(.*)' as template/",$actions,$matches)){
debug("a match");
$actions="@TEMPLATE:=body from Template where id='".$matches[1]."'";
debug("action : $actions");
}
/**
* check
*
* Display the text and result of a boolean test
*
* @param $string: The test message to display
* @param $test: The boolean test result
* @return bool: the boolean test result
*/
function check($string,$test){
echo "<li>$string ";
if($test)
echo "PASS";
else
echo "<span style='color:red;'>FAIL</span>";
return $test;
}
function testArtifact($conn){
$tuple=$conn->query("select node from Artifact where ownerid=2 and classid=6000");
$node=$tuple->fetch()['node'];
return check("At initialization, Headwork artifact should reach node 2",$node==2);
}
session_start();
$conn = HWdbconnect();
// login as admin
$_SESSION["login"]=true;
$_SESSION['wrong']=false;
$_SESSION["id"]=2; // admin
$_SESSION["username"]="admin";
echo "<ul>";
// reset
restart($conn);
initialize($conn);
startAllArtifact($conn,$_SESSION["id"]);
$allPass=true;
$allPass = $allPass && testArtifact($conn);
echo "</ul>";
if ($allPass)
echo "ALL TESTS SUCCESSFUL";
else
echo "TEST FAILURE";
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment