-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathFMDataAPIUnitTest.php
166 lines (150 loc) · 9.46 KB
/
FMDataAPIUnitTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* Created by PhpStorm.
* User: msyk
* Date: 2018/07/29
* Time: 2:02
*/
namespace INTERMediator\FileMakerServer\RESTAPI;
use \PHPUnit\Framework\TestCase;
class FMDataAPIUnitTest extends TestCase
{
private $fmdataapi;
public function setUp(): void
{
$this->fmdataapi = new FMDataAPI("TestDB", "web", null,
"localhost", "443", "https", null, true);
}
public function test_initializeObjects()
{
$this->assertNotNull($this->fmdataapi, 'FMDataAPI class must be instanticate.');
$this->assertEquals($this->fmdataapi->errorCode(), -1, 'It must be no error before calling.');
$this->assertEquals($this->fmdataapi->errorMessage(), "", 'It must be no error before calling.');
$this->assertEquals($this->fmdataapi->httpStatus(), 0, 'It must be no status before calling.');
}
public function test_Query()
{
$result = $this->fmdataapi->person_layout->query();
$this->assertNotNull($result, 'Returned something.');
$this->assertEquals($result->count(), 3, 'Checking the record number.');
$this->assertEquals($result->getTargetTable(), 'person_to', 'Checking the table occurrence name.');
$this->assertEquals($result->getTotalCount(), 3, 'Checking the total record number.');
$this->assertEquals($result->getFoundCount(), 3, 'Checking the found record number.');
$this->assertEquals($result->getReturnedCount(), 3, 'Checking the returned record number.');
$this->assertEquals($result->getPortalNames(), ['Contact', 'History'], 'The query result returns portal names.');
$counter = 0;
foreach ($result as $record) {
$contacts = $record->Contact;
if ($counter === 0) {
$this->assertEquals($record->id, 1, 'Field value has to match with defined value.');
$this->assertEquals($record->name, 'Masayuki Nii', 'Field value has to match with defined value.');
$this->assertEquals($record->mail, 'msyk@msyk.net', 'Field value has to match with defined value.');
$this->assertEquals($record->getModId(), 6, 'It has ModID.');
$this->assertEquals($record->getRecordId(), 1, 'It has RecordID.');
$pcounter = 0;
$this->assertEquals($contacts->count(), 3, 'Checking the record number.');
$this->assertEquals($contacts->getTargetTable(), 'contact_to', 'Checking the table occurrence name.');
$this->assertNull($contacts->getTotalCount(), 'Checking NULL as the total record number.');
$this->assertEquals($contacts->getFoundCount(), 3, 'Checking the found record number.');
$this->assertEquals($contacts->getReturnedCount(), 3, 'Checking the returned record number.');
foreach ($contacts as $item) {
$item->setPortalName("contact_to");
if ($pcounter === 0) {
$this->assertEquals($item->field("datetime"), '12/01/2009 15:23:00', 'Portal field value has to match with defined value.');
} else if ($pcounter === 1) {
$this->assertEquals($item->field("datetime"), '12/02/2009 15:23:00', 'Portal field value has to match with defined value.');
} else if ($pcounter === 2) {
$this->assertEquals($item->field("datetime"), '12/03/2009 15:23:00', 'Portal field value has to match with defined value.');
}
$pcounter += 1;
}
$this->assertEquals($pcounter, 3, 'Cheking the record number in portal.');
} else if ($counter === 1) {
$this->assertEquals($record->id, 2, '');
$this->assertEquals($record->name, 'Someone', 'Field value has to match with defined value.');
$this->assertEquals($record->mail, 'msyk@msyk.net', 'Field value has to match with defined value.');
$pcounter = 0;
$this->assertEquals($contacts->count(), 2, 'Checking the record number.');
foreach ($contacts as $item) {
if ($pcounter === 0) {
$this->assertEquals($item->field("datetime", "contact_to"), '12/04/2009 15:23:00', 'Portal field value has to match with defined value.');
} else if ($pcounter === 1) {
$this->assertEquals($item->field("datetime", "contact_to"), '12/01/2009 15:23:00', 'Portal field value has to match with defined value.');
}
$pcounter += 1;
}
$this->assertEquals($pcounter, 2, 'Cheking the record number in portal.');
} else if ($counter === 2) {
$this->assertEquals($record->id, 3, 'Field value has to match with defined value.');
$this->assertEquals($record->name, 'Anyone', 'Field value has to match with defined value.');
$this->assertEquals($record->mail, 'msyk@msyk.net', 'Field value has to match with defined value.');
$pcounter = 0;
$this->assertEquals($contacts->count(), 2, 'Checking the record number.');
foreach ($contacts as $item) {
if ($pcounter === 0) {
$this->assertEquals($item->field("datetime", "contact_to"), '12/02/2009 15:23:00', 'Portal field value has to match with defined value.');
} else if ($pcounter === 1) {
$this->assertEquals($item->field("datetime", "contact_to"), '12/03/2009 15:23:00', 'Portal field value has to match with defined value.');
}
$pcounter += 1;
}
$this->assertEquals($pcounter, 2, 'Cheking the record number in portal.');
$recId = $record->getRecordId();
$this->assertEquals($recId, 333, 'The record id of last record must be 333.');
}
$counter += 1;
}
}
public function test_ErrorQuery()
{
$fm = new FMDataAPI("TestDB", "web", null, "localserver123",
"443", "https", null, true);
$result = $fm->person_layout->query(); // Host name is DNS unaware.
$this->assertNull($result, 'No results returns.');
$this->assertEquals($fm->httpStatus(), 0, 'Returns 0 for http status.');
$this->assertEquals($fm->errorCode(), -1, 'The error code has to be -1.');
// $this->assertEquals($fm->curlErrorCode(), 6, 'The error code has to be 6.');
}
public function test_SingleRecord()
{
$result = $this->fmdataapi->person_layout->query();
$record = $result->getFirstRecord();
$this->assertEquals($record->id, 1, 'Field value has to match with defined value.');
$this->assertEquals($record->name, 'Masayuki Nii', 'Field value has to match with defined value.');
$this->assertEquals($record->mail, 'msyk@msyk.net', 'Field value has to match with defined value.');
$pcounter = 0;
$contacts = $record->Contact;
$this->assertEquals($contacts->count(), 3, 'Checking the record number.');
$this->assertEquals($contacts->getTargetTable(), 'contact_to', 'Checking the table occurrence name.');
$this->assertNull($contacts->getTotalCount(), 'Checking NULL as the total record number.');
$this->assertEquals($contacts->getFoundCount(), 3, 'Checking the found record number.');
$this->assertEquals($contacts->getReturnedCount(), 3, 'Checking the returned record number.');
foreach ($contacts as $item) {
if ($pcounter === 0) {
$this->assertEquals($item->field("datetime", "contact_to"), '12/01/2009 15:23:00', 'Portal field value has to match with defined value.');
} else if ($pcounter === 1) {
$this->assertEquals($item->field("datetime", "contact_to"), '12/02/2009 15:23:00', 'Portal field value has to match with defined value.');
} else if ($pcounter === 2) {
$this->assertEquals($item->field("datetime", "contact_to"), '12/03/2009 15:23:00', 'Portal field value has to match with defined value.');
}
$pcounter += 1;
}
$this->assertEquals($pcounter, 3, 'Cheking the record number in portal.');
$this->assertEquals($record->count(), 1, 'The single record is just one record.');
$currentRecord = $record->current();
$this->assertEquals($currentRecord->id, 1, 'The single record can call current and return a Relation.');
$this->assertEquals($record->getPortalNames(), ['Contact', 'History'], 'The single record returns portal names.');
$this->assertEquals($record->getModId(), 6, 'The single record returns ModID.');
$this->assertEquals($record->getRecordId(), 1, 'The single record returns RecordID.');
$this->assertEquals($record->getTargetTable(), 'person_to', 'The single record returns the target table.');
$pcount = 0;
foreach ($record as $item) {
$this->assertEquals($item->id, 1, 'The single record can iterate.');
$pcount++;
}
$this->assertEquals($pcount, 1, 'The single record has to repeat just once.');
$this->assertEquals($record->getTotalCount(), 3,'Checking the total record number for queried data.');
$this->assertEquals($record->getFoundCount(), 3, 'Checking the found record number for queried data.');
$this->assertEquals($record->getReturnedCount(), 1, 'Checking the returned record number.');
}
}