@@ 2460-2518 (lines=59) @@ | ||
2457 | $this->assertSame($expectedJson, $scope->toJson()); |
|
2458 | } |
|
2459 | ||
2460 | public function testCustomLinkMerge() |
|
2461 | { |
|
2462 | $manager = new Manager(); |
|
2463 | $manager->setSerializer(new JsonApiSerializer('http://test.de')); |
|
2464 | ||
2465 | $bookData = [ |
|
2466 | 'id' => 1, |
|
2467 | 'title' => 'Foo', |
|
2468 | 'year' => '1991', |
|
2469 | '_author' => [ |
|
2470 | 'id' => 1, |
|
2471 | 'name' => 'Dave', |
|
2472 | ], |
|
2473 | 'links' => [ |
|
2474 | 'custom_link' => '/custom/link', |
|
2475 | ], |
|
2476 | ]; |
|
2477 | ||
2478 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
2479 | ||
2480 | $scope = new Scope($manager, $resource); |
|
2481 | ||
2482 | $expected = [ |
|
2483 | 'data' => [ |
|
2484 | 'type' => 'books', |
|
2485 | 'id' => '1', |
|
2486 | 'attributes' => [ |
|
2487 | 'title' => 'Foo', |
|
2488 | 'year' => 1991, |
|
2489 | ], |
|
2490 | 'links' => [ |
|
2491 | 'self' => 'http://test.de/books/1', |
|
2492 | 'custom_link' => '/custom/link', |
|
2493 | ], |
|
2494 | 'relationships' => [ |
|
2495 | 'author' => [ |
|
2496 | 'links' => [ |
|
2497 | 'self' => 'http://test.de/books/1/relationships/author', |
|
2498 | 'related' => 'http://test.de/books/1/author', |
|
2499 | ], |
|
2500 | ], |
|
2501 | 'co-author' => [ |
|
2502 | 'links' => [ |
|
2503 | 'self' => 'http://test.de/books/1/relationships/co-author', |
|
2504 | 'related' => 'http://test.de/books/1/co-author' |
|
2505 | ], |
|
2506 | ], |
|
2507 | 'author-with-meta' => [ |
|
2508 | 'links' => [ |
|
2509 | 'self' => 'http://test.de/books/1/relationships/author-with-meta', |
|
2510 | 'related' => 'http://test.de/books/1/author-with-meta' |
|
2511 | ], |
|
2512 | ], |
|
2513 | ], |
|
2514 | ], |
|
2515 | ]; |
|
2516 | ||
2517 | $this->assertSame(json_encode($expected), $scope->toJson()); |
|
2518 | } |
|
2519 | ||
2520 | public function testCustomLinkMergeNoLink() |
|
2521 | { |
|
@@ 2576-2633 (lines=58) @@ | ||
2573 | $this->assertSame(json_encode($expected), $scope->toJson()); |
|
2574 | } |
|
2575 | ||
2576 | public function testCustomSelfLinkMerge() |
|
2577 | { |
|
2578 | $manager = new Manager(); |
|
2579 | $manager->setSerializer(new JsonApiSerializer('http://test.de')); |
|
2580 | ||
2581 | $bookData = [ |
|
2582 | 'id' => 1, |
|
2583 | 'title' => 'Foo', |
|
2584 | 'year' => '1991', |
|
2585 | '_author' => [ |
|
2586 | 'id' => 1, |
|
2587 | 'name' => 'Dave', |
|
2588 | ], |
|
2589 | 'links' => [ |
|
2590 | 'self' => '/custom/link', |
|
2591 | ], |
|
2592 | ]; |
|
2593 | ||
2594 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
2595 | ||
2596 | $scope = new Scope($manager, $resource); |
|
2597 | ||
2598 | $expected = [ |
|
2599 | 'data' => [ |
|
2600 | 'type' => 'books', |
|
2601 | 'id' => '1', |
|
2602 | 'attributes' => [ |
|
2603 | 'title' => 'Foo', |
|
2604 | 'year' => 1991, |
|
2605 | ], |
|
2606 | 'links' => [ |
|
2607 | 'self' => '/custom/link', |
|
2608 | ], |
|
2609 | 'relationships' => [ |
|
2610 | 'author' => [ |
|
2611 | 'links' => [ |
|
2612 | 'self' => 'http://test.de/books/1/relationships/author', |
|
2613 | 'related' => 'http://test.de/books/1/author', |
|
2614 | ], |
|
2615 | ], |
|
2616 | 'co-author' => [ |
|
2617 | 'links' => [ |
|
2618 | 'self' => 'http://test.de/books/1/relationships/co-author', |
|
2619 | 'related' => 'http://test.de/books/1/co-author' |
|
2620 | ], |
|
2621 | ], |
|
2622 | 'author-with-meta' => [ |
|
2623 | 'links' => [ |
|
2624 | 'self' => 'http://test.de/books/1/relationships/author-with-meta', |
|
2625 | 'related' => 'http://test.de/books/1/author-with-meta' |
|
2626 | ], |
|
2627 | ], |
|
2628 | ], |
|
2629 | ], |
|
2630 | ]; |
|
2631 | ||
2632 | $this->assertSame(json_encode($expected), $scope->toJson()); |
|
2633 | } |
|
2634 | ||
2635 | public function testEmptyAttributesIsObject() |
|
2636 | { |