1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © 2018 Thomas Klein, All rights reserved. |
4
|
|
|
* See LICENSE bundled with this library for license details. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace LogicTree\Test; |
8
|
|
|
|
9
|
|
|
use LogicTree\Node\Combine; |
10
|
|
|
use LogicTree\Node\Condition; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use LogicTree\DataSource; |
13
|
|
|
use LogicTree\LogicTreeFacade; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Test the \LogicTree\LogicTreeFacade object. |
17
|
|
|
*/ |
18
|
|
|
class LogicTreeFacadeTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Test the adding operator method |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
public function testAddOperator() |
26
|
|
|
{ |
27
|
|
|
// ToDo: implement test case scenario. |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Test the creation of data source |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function testCreateDataSource() |
36
|
|
|
{ |
37
|
|
|
$data = ['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3']; |
38
|
|
|
$dataSource = new DataSource($data); |
39
|
|
|
$logicTreeFacade = new LogicTreeFacade(); |
40
|
|
|
|
41
|
|
|
$this->assertEquals($dataSource, $logicTreeFacade->createDataSource($data)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Test the execution of combined conditions |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function testExecuteCombineConditions() |
50
|
|
|
{ |
51
|
|
|
$logicTreeFacade = new LogicTreeFacade(); |
52
|
|
|
$data = ['key1' => 'value', 'key2' => 20]; |
53
|
|
|
$dataSource = new DataSource($data); |
54
|
|
|
$cond1 = new Condition('key1', 'eq', 'value'); |
55
|
|
|
$cond2 = new Condition('key2', 'gteq', 10); |
56
|
|
|
$combine1 = new Combine('and', false, [$cond1, $cond2]); |
57
|
|
|
$combine2 = new Combine('and', true, [$cond1, $cond2]); |
58
|
|
|
|
59
|
|
|
$this->assertTrue($logicTreeFacade->executeCombineConditions($combine1, $dataSource)); |
60
|
|
|
$this->assertFalse($logicTreeFacade->executeCombineConditions($combine2, $dataSource)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Test the execution of formated combined conditions |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function testExecuteCombineConditionsFormat() |
69
|
|
|
{ |
70
|
|
|
// ToDo: implement test case scenario. |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Test the format converter |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function testConvertFormat() |
79
|
|
|
{ |
80
|
|
|
// ToDo: implement test case scenario. |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|