| @@ 503-535 (lines=33) @@ | ||
| 500 | * |
|
| 501 | * @return void |
|
| 502 | */ |
|
| 503 | public function testPatchDeepNestedProperty() |
|
| 504 | { |
|
| 505 | // Load fixtures |
|
| 506 | $this->loadFixtures( |
|
| 507 | ['GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'], |
|
| 508 | null, |
|
| 509 | 'doctrine_mongodb' |
|
| 510 | ); |
|
| 511 | ||
| 512 | // Apply PATCH request |
|
| 513 | $client = static::createRestClient(); |
|
| 514 | $patchJson = json_encode( |
|
| 515 | [ |
|
| 516 | [ |
|
| 517 | 'op' => 'replace', |
|
| 518 | 'path' => '/unstructuredObject/hashField/anotherField', |
|
| 519 | 'value' => 'changed nested hash field with patch' |
|
| 520 | ] |
|
| 521 | ] |
|
| 522 | ); |
|
| 523 | $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson); |
|
| 524 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
| 525 | ||
| 526 | // Get changed showcase |
|
| 527 | $client = static::createRestClient(); |
|
| 528 | $client->request('GET', '/hans/showcase/500'); |
|
| 529 | ||
| 530 | $result = $client->getResults(); |
|
| 531 | $this->assertEquals( |
|
| 532 | 'changed nested hash field with patch', |
|
| 533 | $result->unstructuredObject->hashField->anotherField |
|
| 534 | ); |
|
| 535 | } |
|
| 536 | ||
| 537 | /** |
|
| 538 | * Test success PATCH method - response headers contains link to resource |
|
| @@ 604-636 (lines=33) @@ | ||
| 601 | * |
|
| 602 | * @return void |
|
| 603 | */ |
|
| 604 | public function testPatchAddPropertyToFreeObject() |
|
| 605 | { |
|
| 606 | // Load fixtures |
|
| 607 | $this->loadFixtures( |
|
| 608 | ['GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'], |
|
| 609 | null, |
|
| 610 | 'doctrine_mongodb' |
|
| 611 | ); |
|
| 612 | ||
| 613 | // Apply PATCH request |
|
| 614 | $client = static::createRestClient(); |
|
| 615 | $patchJson = json_encode( |
|
| 616 | [ |
|
| 617 | [ |
|
| 618 | 'op' => 'add', |
|
| 619 | 'path' => '/unstructuredObject/hashField/newAddedField', |
|
| 620 | 'value' => 'new field value' |
|
| 621 | ] |
|
| 622 | ] |
|
| 623 | ); |
|
| 624 | $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson); |
|
| 625 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
| 626 | ||
| 627 | // Get changed showcase |
|
| 628 | $client = static::createRestClient(); |
|
| 629 | $client->request('GET', '/hans/showcase/500'); |
|
| 630 | ||
| 631 | $result = $client->getResults(); |
|
| 632 | $this->assertEquals( |
|
| 633 | 'new field value', |
|
| 634 | $result->unstructuredObject->hashField->newAddedField |
|
| 635 | ); |
|
| 636 | } |
|
| 637 | ||
| 638 | /** |
|
| 639 | * Test PATCH for $ref attribute |
|
| @@ 722-751 (lines=30) @@ | ||
| 719 | * |
|
| 720 | * @return void |
|
| 721 | */ |
|
| 722 | public function testRemoveFromArrayPatch() |
|
| 723 | { |
|
| 724 | // Load fixtures |
|
| 725 | $this->loadFixtures( |
|
| 726 | ['GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'], |
|
| 727 | null, |
|
| 728 | 'doctrine_mongodb' |
|
| 729 | ); |
|
| 730 | ||
| 731 | // Apply PATCH request, remove nested app, initially there are 2 apps |
|
| 732 | $client = static::createRestClient(); |
|
| 733 | $patchJson = json_encode( |
|
| 734 | [ |
|
| 735 | [ |
|
| 736 | 'op' => 'remove', |
|
| 737 | 'path' => '/nestedApps/0' |
|
| 738 | ] |
|
| 739 | ] |
|
| 740 | ); |
|
| 741 | $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson); |
|
| 742 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
| 743 | ||
| 744 | // Check patched result |
|
| 745 | $client = static::createRestClient(); |
|
| 746 | $client->request('GET', '/hans/showcase/500'); |
|
| 747 | ||
| 748 | $result = $client->getResults(); |
|
| 749 | $this->assertEquals(1, count($result->nestedApps)); |
|
| 750 | $this->assertEquals('http://localhost/core/app/admin', $result->nestedApps[0]->{'$ref'}); |
|
| 751 | } |
|
| 752 | ||
| 753 | /** |
|
| 754 | * Test PATCH: add new element to array |
|