|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SearchTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_mapper\Interfaces\IEntryType; |
|
8
|
|
|
use kalanis\kw_mapper\MapperException; |
|
9
|
|
|
use kalanis\kw_mapper\Mappers\Database\ADatabase; |
|
10
|
|
|
use kalanis\kw_mapper\Records\ASimpleRecord; |
|
11
|
|
|
use kalanis\kw_mapper\Search\Connector\Database\TRecordsInJoins; |
|
12
|
|
|
use kalanis\kw_mapper\Storage; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
class RecordsTest extends CommonTestClass |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @throws MapperException |
|
19
|
|
|
*/ |
|
20
|
|
|
public function testSimpleLookup(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$record = new XTRecords(); |
|
23
|
|
|
$record->initRecordLookup(new XaRecordChild()); |
|
24
|
|
|
$this->assertEquals(1, count($record->getRecordsInJoin())); |
|
25
|
|
|
$child = $record->recordLookup('prt'); |
|
26
|
|
|
$this->assertEquals(2, count($record->getRecordsInJoin())); |
|
27
|
|
|
$this->assertInstanceOf('\SearchTests\XaRecordParent', $child->getRecord()); |
|
28
|
|
|
$this->assertEquals($child, $record->recordLookup('prt')); |
|
29
|
|
|
$this->assertEmpty($record->recordLookup('unknown')); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
class XTRecords |
|
35
|
|
|
{ |
|
36
|
|
|
use TRecordsInJoins; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Class XaRecordParent |
|
42
|
|
|
* @package SearchTests |
|
43
|
|
|
* @property int $id |
|
44
|
|
|
* @property string $name |
|
45
|
|
|
* @property XaRecordChild[] $chld |
|
46
|
|
|
*/ |
|
47
|
|
|
class XaRecordParent extends ASimpleRecord |
|
48
|
|
|
{ |
|
49
|
|
|
protected function addEntries(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->addEntry('id', IEntryType::TYPE_INTEGER, 512); |
|
52
|
|
|
$this->addEntry('name', IEntryType::TYPE_STRING, 512); |
|
53
|
|
|
$this->addEntry('chld', IEntryType::TYPE_ARRAY); // FK - makes the array of entries every time |
|
54
|
|
|
$this->setMapper('\SearchTests\XaMapperParent'); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Class XaRecordChild |
|
61
|
|
|
* @package SearchTests |
|
62
|
|
|
* @property int $id |
|
63
|
|
|
* @property string $name |
|
64
|
|
|
* @property int $prtId |
|
65
|
|
|
* @property XaRecordParent[] $prt |
|
66
|
|
|
*/ |
|
67
|
|
|
class XaRecordChild extends ASimpleRecord |
|
68
|
|
|
{ |
|
69
|
|
|
protected function addEntries(): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->addEntry('id', IEntryType::TYPE_INTEGER, 512); |
|
72
|
|
|
$this->addEntry('name', IEntryType::TYPE_STRING, 512); |
|
73
|
|
|
$this->addEntry('prtId', IEntryType::TYPE_INTEGER, 64); // ID of remote |
|
74
|
|
|
$this->addEntry('prt', IEntryType::TYPE_ARRAY); // FK - makes the array of entries every time |
|
75
|
|
|
$this->setMapper('\SearchTests\XaMapperChild'); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
class XaMapperParent extends ADatabase |
|
81
|
|
|
{ |
|
82
|
|
|
public function setMap(): void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->setSource('testing'); |
|
85
|
|
|
$this->setTable('kw_mapper_parent_testing'); |
|
86
|
|
|
$this->setRelation('id', 'kmpt_id'); |
|
87
|
|
|
$this->setRelation('name', 'kmpt_name'); |
|
88
|
|
|
$this->addPrimaryKey('id'); |
|
89
|
|
|
$this->addForeignKey('chld', '\SearchTests\XaRecordChild', 'chldId', 'id'); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
class XaMapperChild extends ADatabase |
|
95
|
|
|
{ |
|
96
|
|
|
public function setMap(): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->setSource('testing'); |
|
99
|
|
|
$this->setTable('kw_mapper_child_testing'); |
|
100
|
|
|
$this->setRelation('id', 'kmct_id'); |
|
101
|
|
|
$this->setRelation('name', 'kmct_name'); |
|
102
|
|
|
$this->setRelation('prtId', 'kmpt_id'); |
|
103
|
|
|
$this->addPrimaryKey('id'); |
|
104
|
|
|
$this->addForeignKey('prt', '\SearchTests\XaRecordParent', 'prtId', 'id'); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|