|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SourcesTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_tree\Interfaces\ITree; |
|
7
|
|
|
use kalanis\kw_tree\DataSources\ASources; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class SourceTest extends \CommonTestClass |
|
11
|
|
|
{ |
|
12
|
|
|
public function testStartPath(): void |
|
13
|
|
|
{ |
|
14
|
|
|
$lib = new XSource(); |
|
15
|
|
|
$this->assertEquals([], $lib->getStartPath()); |
|
16
|
|
|
$lib->setStartPath(['abc', 'def']); |
|
17
|
|
|
$this->assertEquals(['abc', 'def'], $lib->getStartPath()); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testOrdering(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$lib = new XSource(); |
|
23
|
|
|
$this->assertEquals(ITree::ORDER_NONE, $lib->getOrdering()); |
|
24
|
|
|
$lib->setOrdering('other'); |
|
25
|
|
|
$this->assertEquals(ITree::ORDER_NONE, $lib->getOrdering()); |
|
26
|
|
|
$lib->setOrdering('ASC'); |
|
27
|
|
|
$this->assertEquals(ITree::ORDER_ASC, $lib->getOrdering()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testCallback(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$lib = new XSource(); |
|
33
|
|
|
$this->assertEmpty($lib->getFilterCallback()); |
|
34
|
|
|
$lib->setFilterCallback(['abc', 'def']); |
|
35
|
|
|
$this->assertEquals(['abc', 'def'], $lib->getFilterCallback()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testRecursive(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$lib = new XSource(); |
|
41
|
|
|
$this->assertFalse($lib->isRecursive()); |
|
42
|
|
|
$lib->wantDeep(true); |
|
43
|
|
|
$this->assertTrue($lib->isRecursive()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testNode(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$lib = new XSource(); |
|
49
|
|
|
$lib->process(); |
|
50
|
|
|
$this->assertEmpty($lib->getRoot()); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
class XSource extends ASources |
|
56
|
|
|
{ |
|
57
|
|
|
public function process(): ITree |
|
58
|
|
|
{ |
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return string[] |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getStartPath(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->startPath; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getOrdering(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->ordering; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return callable|null |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getFilterCallback() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->filterCallback; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function isRecursive(): bool |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->recursive; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|