Commit 98425987 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Evaluate.php: parseArray() enhanced to parse also nested arrays.

parent 946691b6
......@@ -35,7 +35,7 @@ class Evaluate {
}
/**
* Evaluate a whole array.
* Evaluate a whole array or a array of arrays.
*
* @param $tokenArray
* @return mixed
......@@ -44,7 +44,11 @@ class Evaluate {
$arr = array();
foreach ($tokenArray as $key => $value) {
$arr[$key] = $this->parse($value);
if (is_array($value)) {
$arr[] = $this->parseArray($value);
} else {
$arr[$key] = $this->parse($value);
}
}
return $arr;
......
......@@ -82,9 +82,11 @@ class EvaluateTest extends AbstractDatabaseTest {
$this->assertEquals('1', $eval->parse('{{SELECT count(id) FROM Person WHERE name="Zappa" AND firstname="Frank"}}'));
// SHOW tables
$expected = "idbigint(20)NOPRIauto_incrementnamevarchar(128)YESfirstnamevarchar(128)YESgenderenum('','male','female')NOgroupsset('','a','b','c')NO";
$expected = "idbigint(20)NOPRIauto_incrementnamevarchar(128)YESfirstnamevarchar(128)YESgenderenum('','male','female')NOmalegroupsset('','a','b','c')NO";
$this->assertEquals($expected, $eval->parse('{{SHOW COLUMNS FROM Person}}'));
}
public function testDbVars() {
......@@ -102,7 +104,7 @@ class EvaluateTest extends AbstractDatabaseTest {
$data = [
'formName' => 'MyTestForm',
'title' => 'Person: {{SELECT firstname, " ", name FROM person LIMIT 1}} / Employee'
'title' => 'Person: {{SELECT firstname, " ", name FROM Person LIMIT 1}} / Employee'
];
$expected = [
'formName' => 'MyTestForm',
......@@ -110,6 +112,34 @@ class EvaluateTest extends AbstractDatabaseTest {
];
$this->assertEquals($expected, $eval->parseArray($data));
}
public function testParseArrayOfArray() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$data = [
[
'formName' => 'MyTestForm',
'title' => 'Person: {{SELECT firstname, " ", name FROM Person LIMIT 1}} / Employee'
],
[
'order' => '100',
'class' => 'Person: {{SELECT firstname, " ", name FROM Person LIMIT 1}} / Employee'
]
];
$expected = [
[
'formName' => 'MyTestForm',
'title' => 'Person: John Doe / Employee'
],
[
'order' => '100',
'class' => 'Person: John Doe / Employee'
]
];
$this->assertEquals($expected, $eval->parseArray($data));
}
protected function setUp() {
......
Supports Markdown
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