Skip to content

Commit

Permalink
Dev: Some more EM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt authored and LouisGac committed Aug 28, 2017
1 parent 9e2b15c commit 5ced08c
Showing 1 changed file with 67 additions and 11 deletions.
78 changes: 67 additions & 11 deletions tests/helpers/ExpressionCoreHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,50 @@ public function testCompareNumberLtSpace()
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '3' < 'A'
*/
public function testNumberLtLetter()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK < "A"))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* '3' <= ' '
*/
public function testNumberLeSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK <= " "))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* '3' <= ''
*/
public function testNumberLeEmpty()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK <= ""))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* '' <= ' '
*/
public function testEmptyLeSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK <= " "))';
$value = '';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '' > ' '
*/
Expand Down Expand Up @@ -233,9 +277,23 @@ public function testNumberPlusString()
$this->compareExpression($sgqa, $value, $expression, $jsonEncodeResult);
}

/**
* Expression: 3 + 2
* @todo Need LEMval() to work.
*/
public function testNumberPlusNumber()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK + 2))';
$value = 3;
$jsonEncodeResult = true;
//$this->compareExpression($sgqa, $value, $expression, $jsonEncodeResult);
}

/**
* @param string $sgqa
* @param string $expression
* @param boolean $jsonEncode If true, run json_encode on PHP eval result. Good for when node returns boolean.
* @return void
*/
protected function compareExpression($sgqa, $value, $expression, $jsonEncode = true)
Expand All @@ -244,14 +302,14 @@ protected function compareExpression($sgqa, $value, $expression, $jsonEncode = t
$_SESSION['survey_563168'][$sgqa] = $value;

$em = new \ExpressionManager();
$limeEm = \LimeExpressionManager::singleton();
$limeEm->setVariableAndTokenMappingsForExpressionManager('563168');
$limeEm->setKnownVars(
$lem = \LimeExpressionManager::singleton();
$lem->setVariableAndTokenMappingsForExpressionManager('563168');
$lem->setKnownVars(
[
$sgqa => [
'sgqa' => $sgqa,
'type' => 'N',
//'jsName' => 'anything' This will trigger LEMval()
'type' => 'N'
//'jsName' => 'anything' // This will trigger LEMval()
]
]
);
Expand Down Expand Up @@ -284,13 +342,11 @@ protected function runNode($js)
// Only use single quotes.
$js = str_replace('"', "'", $js);
$output = [];
exec(
sprintf(
'node -p "%s"',
$js
),
$output
$command = sprintf(
'node -p "%s"',
$js
);
exec($command, $output);
return $output;
}

Expand Down

0 comments on commit 5ced08c

Please sign in to comment.