Skip to content

Commit a981e25

Browse files
committed
Issue #34: Fixed unit test for ticket articles due to ZAA-2020-24.
1 parent 251902d commit a981e25

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ $ticket->save();
108108
if ( $ticket->isDirty() ) {...}
109109
```
110110

111+
Note: Some resource types don't support updating the values of certain fields. Please refer to the API documentation (see links above).
112+
111113
### Creating Resource objects
112114
To create a new `Resource` object, use the following code (example):
113115
```php

test/ZammadAPIClient/Resource/TicketArticleTest.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
class TicketArticleTest extends AbstractBaseTest
88
{
99
protected $resource_type = ResourceType::TICKET_ARTICLE;
10-
protected $update_field = 'body';
1110

1211
public function objectCreateProvider()
1312
{
@@ -185,4 +184,55 @@ public function testCreate( $values, $expected_success )
185184
);
186185
}
187186
}
187+
188+
/**
189+
* @depends testCreate
190+
*/
191+
public function testUpdate()
192+
{
193+
foreach ( self::$created_objects as $created_object ) {
194+
$created_object_id = $created_object->getID();
195+
if ( empty( $created_object_id ) ) {
196+
continue;
197+
}
198+
199+
// Change a value.
200+
$is_internal = $created_object->getValue('internal') ? true : false;
201+
$new_is_internal = !$is_internal;
202+
203+
$created_object->setValue( 'internal', $new_is_internal );
204+
$saved_object = $created_object->save();
205+
206+
$this->assertFalse(
207+
$created_object->hasError(),
208+
'Error must not be set after update of object.'
209+
);
210+
211+
$this->assertInstanceOf(
212+
$this->resource_type,
213+
$saved_object
214+
);
215+
216+
$this->assertSame(
217+
$created_object,
218+
$saved_object,
219+
'Saving an object must return the same object again.'
220+
);
221+
222+
// Compare changed value.
223+
$this->assertEquals(
224+
$new_is_internal,
225+
$created_object->getValue('internal') ? true : false,
226+
'Changed value of object must match expected one.'
227+
);
228+
229+
// Fetch object data with a fresh object to check again if value has been changed.
230+
$fetched_object = self::getClient()->resource( $this->resource_type )->get($created_object_id);
231+
$this->assertEquals(
232+
$new_is_internal,
233+
$fetched_object->getValue('internal') ? true : false,
234+
'Value of fetched object must match expected one.'
235+
);
236+
}
237+
}
188238
}

0 commit comments

Comments
 (0)