Skip to content

Commit

Permalink
Dev: Add EM test for 3 + '2'
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 22, 2017
1 parent 01b9c15 commit 2e08a1d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/helpers/ExpressionCoreHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,24 @@ public function testCompareNumberGeSpace()
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: 3 + '2'
*/
public function testNumberPlusString()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK + "2"))';
$value = 3;
$jsonEncodeResult = false;
$this->compareExpression($sgqa, $value, $expression, $jsonEncodeResult);
}

/**
* @param string $sgqa
* @param string $expression
* @return void
*/
protected function compareExpression($sgqa, $value, $expression)
protected function compareExpression($sgqa, $value, $expression, $jsonEncode = true)
{
// Input value 3.
$_SESSION['survey_563168'][$sgqa] = $value;
Expand All @@ -248,14 +260,18 @@ protected function compareExpression($sgqa, $value, $expression)

$result = $em->GetResult();

if ($jsonEncode) {
$result = json_encode($result);
}

$errors = $em->RDP_GetErrors();
$this->assertEmpty($errors);
$js = $em->GetJavaScriptEquivalentOfExpression();

$nodeOutput = $this->runNode($js);

$this->assertCount(1, $nodeOutput);
$this->assertEquals(json_encode($result), $nodeOutput[0], 'JS and PHP must return same result');
$this->assertEquals($result, $nodeOutput[0], 'JS and PHP must return same result');
}

/**
Expand Down

5 comments on commit 2e08a1d

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i remind : because "2" is a DS_STRING : it must be 32. Because it was send to javascript like this :
LEMVAL(563168X136X5376.NAOK) + "2"

@olleharstedt
Copy link
Collaborator Author

@olleharstedt olleharstedt commented on 2e08a1d Aug 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case LEMval is excluded since there's now jsName field. The generated JS is actuall '3' + '2'. I'm looking into it now.

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With + "2" or +'2' result are always concatenate :).

@olleharstedt
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

@olleharstedt
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with "1" + 2.

Please sign in to comment.