@@ 513-538 (lines=26) @@ | ||
510 | * |
|
511 | * @return void |
|
512 | */ |
|
513 | public function testPatchDeepNestedProperty() |
|
514 | { |
|
515 | // Apply PATCH request |
|
516 | $client = static::createRestClient(); |
|
517 | $patchJson = json_encode( |
|
518 | [ |
|
519 | [ |
|
520 | 'op' => 'replace', |
|
521 | 'path' => '/unstructuredObject/hashField/anotherField', |
|
522 | 'value' => 'changed nested hash field with patch' |
|
523 | ] |
|
524 | ] |
|
525 | ); |
|
526 | $client->request('PATCH', '/hans/showcase/500', [], [], [], $patchJson); |
|
527 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
528 | ||
529 | // Get changed showcase |
|
530 | $client = static::createRestClient(); |
|
531 | $client->request('GET', '/hans/showcase/500'); |
|
532 | ||
533 | $result = $client->getResults(); |
|
534 | $this->assertEquals( |
|
535 | 'changed nested hash field with patch', |
|
536 | $result->unstructuredObject->hashField->anotherField |
|
537 | ); |
|
538 | } |
|
539 | ||
540 | /** |
|
541 | * Test success PATCH method - response headers contains link to resource |
|
@@ 593-618 (lines=26) @@ | ||
590 | * |
|
591 | * @return void |
|
592 | */ |
|
593 | public function testPatchAddPropertyToFreeObject() |
|
594 | { |
|
595 | // Apply PATCH request |
|
596 | $client = static::createRestClient(); |
|
597 | $patchJson = json_encode( |
|
598 | [ |
|
599 | [ |
|
600 | 'op' => 'add', |
|
601 | 'path' => '/unstructuredObject/hashField/newAddedField', |
|
602 | 'value' => 'new field value' |
|
603 | ] |
|
604 | ] |
|
605 | ); |
|
606 | $client->request('PATCH', '/hans/showcase/500', [], [], [], $patchJson); |
|
607 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
608 | ||
609 | // Get changed showcase |
|
610 | $client = static::createRestClient(); |
|
611 | $client->request('GET', '/hans/showcase/500'); |
|
612 | ||
613 | $result = $client->getResults(); |
|
614 | $this->assertEquals( |
|
615 | 'new field value', |
|
616 | $result->unstructuredObject->hashField->newAddedField |
|
617 | ); |
|
618 | } |
|
619 | ||
620 | /** |
|
621 | * Test PATCH for $ref attribute |
|
@@ 688-710 (lines=23) @@ | ||
685 | * |
|
686 | * @return void |
|
687 | */ |
|
688 | public function testRemoveFromArrayPatch() |
|
689 | { |
|
690 | // Apply PATCH request, remove nested app, initially there are 2 apps |
|
691 | $client = static::createRestClient(); |
|
692 | $patchJson = json_encode( |
|
693 | [ |
|
694 | [ |
|
695 | 'op' => 'remove', |
|
696 | 'path' => '/nestedApps/0' |
|
697 | ] |
|
698 | ] |
|
699 | ); |
|
700 | $client->request('PATCH', '/hans/showcase/500', [], [], [], $patchJson); |
|
701 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
702 | ||
703 | // Check patched result |
|
704 | $client = static::createRestClient(); |
|
705 | $client->request('GET', '/hans/showcase/500'); |
|
706 | ||
707 | $result = $client->getResults(); |
|
708 | $this->assertEquals(1, count($result->nestedApps)); |
|
709 | $this->assertEquals('http://localhost/core/app/admin', $result->nestedApps[0]->{'$ref'}); |
|
710 | } |
|
711 | ||
712 | /** |
|
713 | * Test PATCH: add new element to array |