Skip to content

Commit 7d42ede

Browse files
committed
Update issue tests
1 parent 38b8fae commit 7d42ede

3 files changed

Lines changed: 424 additions & 11 deletions

File tree

tests/Issues/API194Test.php

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class API194Test extends BaseTest {
4141
/**
4242
* @throws Exception on error
4343
*/
44-
public function testIssue() {
44+
public function testSave() {
4545
/**
4646
* Create test data:
4747
*/
@@ -178,4 +178,141 @@ public function testIssue() {
178178
$this->assertSame($networkID, (int) $entries[0]['net'][0]['id']);
179179
}
180180

181+
/**
182+
* @throws Exception on error
183+
*/
184+
public function testUpdate() {
185+
/**
186+
* Create test data:
187+
*/
188+
189+
$wanID = $this->useCMDBObject()->create(
190+
ObjectType::WAN,
191+
$this->generateRandomString()
192+
);
193+
$this->isID($wanID);
194+
195+
$routerID = $this->useCMDBObject()->create(
196+
ObjectType::ROUTER,
197+
$this->generateRandomString()
198+
);
199+
$this->isID($routerID);
200+
201+
$networkID = $this->useCMDBObject()->create(
202+
ObjectType::LAYER3_NET,
203+
$this->generateRandomString()
204+
);
205+
$this->isID($networkID);
206+
207+
$this->useCMDBCategory()->create(
208+
$wanID,
209+
Category::CATG__WAN,
210+
[
211+
'title' => $this->generateRandomString()
212+
]
213+
);
214+
215+
/**
216+
* Run tests:
217+
*/
218+
219+
$entries = $this->useCMDBCategory()->read(
220+
$wanID,
221+
Category::CATG__WAN
222+
);
223+
224+
$this->assertIsArray($entries);
225+
$this->assertCount(1, $entries);
226+
$this->assertArrayHasKey(0, $entries);
227+
$this->assertIsArray($entries[0]);
228+
$this->isCategoryEntry($entries[0]);
229+
230+
$this->assertArrayHasKey('router', $entries[0]);
231+
$this->assertNull($entries[0]['router']);
232+
233+
$this->assertArrayHasKey('net', $entries[0]);
234+
$this->assertNull($entries[0]['net']);
235+
236+
/**
237+
* Update test data:
238+
*/
239+
240+
$this->useCMDBCategory()->update(
241+
$wanID,
242+
Category::CATG__WAN,
243+
[
244+
'title' => $this->generateRandomString()
245+
]
246+
);
247+
248+
/**
249+
* Run tests again:
250+
*/
251+
252+
$entries = $this->useCMDBCategory()->read(
253+
$wanID,
254+
Category::CATG__WAN
255+
);
256+
257+
$this->assertIsArray($entries);
258+
$this->assertCount(1, $entries);
259+
$this->assertArrayHasKey(0, $entries);
260+
$this->assertIsArray($entries[0]);
261+
$this->isCategoryEntry($entries[0]);
262+
263+
$this->assertArrayHasKey('router', $entries[0]);
264+
$this->assertNull($entries[0]['router']);
265+
266+
$this->assertArrayHasKey('net', $entries[0]);
267+
$this->assertNull($entries[0]['net']);
268+
269+
270+
/**
271+
* Update test data again:
272+
*/
273+
274+
$this->useCMDBCategory()->update(
275+
$wanID,
276+
Category::CATG__WAN,
277+
[
278+
'title' => $this->generateRandomString(),
279+
'router' => [$routerID],
280+
'net' => [$networkID]
281+
]
282+
);
283+
284+
/**
285+
* Run final tests:
286+
*/
287+
288+
$entries = $this->useCMDBCategory()->read(
289+
$wanID,
290+
Category::CATG__WAN
291+
);
292+
293+
$this->assertIsArray($entries);
294+
$this->assertCount(1, $entries);
295+
$this->assertArrayHasKey(0, $entries);
296+
$this->assertIsArray($entries[0]);
297+
$this->isCategoryEntry($entries[0]);
298+
299+
$this->assertArrayHasKey('router', $entries[0]);
300+
$this->assertIsArray($entries[0]['router']);
301+
$this->assertCount(1, $entries[0]['router']);
302+
$this->assertArrayHasKey(0, $entries[0]['router']);
303+
$this->assertIsArray($entries[0]['router'][0]);
304+
$this->isAssignedObject($entries[0]['router'][0]);
305+
$this->assertArrayHasKey('id', $entries[0]['router'][0]);
306+
$this->assertSame($routerID, (int) $entries[0]['router'][0]['id']);
307+
308+
$this->assertArrayHasKey('net', $entries[0]);
309+
$this->assertIsArray($entries[0]['net']);
310+
$this->assertCount(1, $entries[0]['net']);
311+
$this->assertArrayHasKey(0, $entries[0]['net']);
312+
$this->assertIsArray($entries[0]['net'][0]);
313+
$this->isAssignedObject($entries[0]['net'][0]);
314+
$this->assertArrayHasKey('id', $entries[0]['net'][0]);
315+
$this->assertSame($networkID, (int) $entries[0]['net'][0]['id']);
316+
}
317+
181318
}

tests/Issues/API224Test.php

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
3+
/**
4+
* Copyright (C) 2016-2020 Benjamin Heisig
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* @author Benjamin Heisig <https://benjamin.heisig.name/>
20+
* @copyright Copyright (C) 2016-2020 Benjamin Heisig
21+
* @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
22+
* @link https://github.com/bheisig/i-doit-api-client-php
23+
*/
24+
25+
declare(strict_types=1);
26+
27+
namespace bheisig\idoitapi\tests\Issues;
28+
29+
use bheisig\idoitapi\tests\Constants\Category;
30+
use \Exception;
31+
use bheisig\idoitapi\tests\BaseTest;
32+
33+
/**
34+
* @group unreleased
35+
* @group issues
36+
* @group API-224
37+
* @see https://i-doit.atlassian.net/browse/API-224
38+
*/
39+
class API224Test extends BaseTest {
40+
41+
public function provideValues(): array {
42+
return [
43+
['tag', ['tag0', 'tag1', 'tag2']]
44+
];
45+
}
46+
47+
/**
48+
* @param string $attribute Attribute name
49+
* @param array $values Values for a multi dialog+ attribute
50+
* @dataProvider provideValues
51+
* @throws Exception on error
52+
*/
53+
public function testSaveCategoryEntry(string $attribute, array $values) {
54+
/**
55+
* Create test data:
56+
*/
57+
58+
$objectID = $this->createServer();
59+
$this->isID($objectID);
60+
61+
// It's important to fill-out a dialog+ attribute:
62+
$entryID = $this->useCMDBCategory()->save(
63+
$objectID,
64+
Category::CATG__GLOBAL,
65+
[
66+
$attribute => $values
67+
]
68+
);
69+
$this->isID($entryID);
70+
71+
/**
72+
* Run tests:
73+
*/
74+
75+
// Just change another attribute from the same category.
76+
// This failed in the past because it removes all values from the attribute:
77+
$testEntryID = $this->useCMDBCategory()->save(
78+
$objectID,
79+
Category::CATG__GLOBAL,
80+
[
81+
'title' => $this->generateRandomString()
82+
]
83+
);
84+
85+
$this->assertSame($entryID, $testEntryID);
86+
87+
/**
88+
* Double check:
89+
*/
90+
91+
$entries = $this->useCMDBCategory()->read(
92+
$objectID,
93+
Category::CATG__GLOBAL
94+
);
95+
96+
$this->assertIsArray($entries);
97+
$this->assertCount(1, $entries);
98+
$this->assertArrayHasKey(0, $entries);
99+
$this->assertIsArray($entries[0]);
100+
$this->isCategoryEntry($entries[0]);
101+
102+
// Values should be still there…
103+
$this->assertArrayHasKey($attribute, $entries[0]);
104+
$this->assertCount(count($values), $entries[0][$attribute]);
105+
106+
// …and still the same as before:
107+
foreach ($entries[0][$attribute] as $index => $value) {
108+
$this->assertIsArray($value);
109+
$this->isDialog($value);
110+
$this->assertSame($values[$index], $value['title']);
111+
}
112+
}
113+
114+
/**
115+
* @param string $attribute Attribute name
116+
* @param array $values Values for a multi dialog+ attribute
117+
* @dataProvider provideValues
118+
* @throws Exception on error
119+
*/
120+
public function testUpdateCategoryEntry(string $attribute, array $values) {
121+
/**
122+
* Create test data:
123+
*/
124+
125+
$objectID = $this->createServer();
126+
$this->isID($objectID);
127+
128+
// It's important to fill-out a dialog+ attribute:
129+
$this->useCMDBCategory()->update(
130+
$objectID,
131+
Category::CATG__GLOBAL,
132+
[
133+
$attribute => $values
134+
]
135+
);
136+
137+
/**
138+
* Run tests:
139+
*/
140+
141+
// Just change another attribute from the same category.
142+
// This failed in the past because it removes all values from the attribute:
143+
$this->useCMDBCategory()->update(
144+
$objectID,
145+
Category::CATG__GLOBAL,
146+
[
147+
'title' => $this->generateRandomString()
148+
]
149+
);
150+
151+
/**
152+
* Double check:
153+
*/
154+
155+
$entries = $this->useCMDBCategory()->read(
156+
$objectID,
157+
Category::CATG__GLOBAL
158+
);
159+
160+
$this->assertIsArray($entries);
161+
$this->assertCount(1, $entries);
162+
$this->assertArrayHasKey(0, $entries);
163+
$this->assertIsArray($entries[0]);
164+
$this->isCategoryEntry($entries[0]);
165+
166+
// Values should be still there…
167+
$this->assertArrayHasKey($attribute, $entries[0]);
168+
$this->assertCount(count($values), $entries[0][$attribute]);
169+
170+
// …and still the same as before:
171+
foreach ($entries[0][$attribute] as $index => $value) {
172+
$this->assertIsArray($value);
173+
$this->isDialog($value);
174+
$this->assertSame($values[$index], $value['title']);
175+
}
176+
}
177+
178+
}

0 commit comments

Comments
 (0)