Ejemplo n.º 1
0
         $payload->delete($images);
         expect($payload->serialize())->toEqual(['data' => [['type' => 'image', 'id' => 1], ['type' => 'image', 'id' => 2], ['type' => 'image', 'id' => 3], ['type' => 'image', 'id' => 4], ['type' => 'image', 'id' => 5]]]);
     });
 });
 describe("->export()", function () {
     it("exports payload as nested array", function () {
         $json = file_get_contents($this->fixture . 'collection.json');
         $payload = Payload::parse($json);
         expect($payload->export())->toBe([['id' => '1', 'title' => 'JSON API paints my bikeshed!', 'author' => ['id' => '9', 'firstName' => 'Dan', 'lastName' => 'Gebhardt', 'twitter' => 'dgeb'], 'comments' => [['id' => '5', 'body' => 'First!'], ['id' => '12', 'body' => 'I like XML better']]], ['id' => '2', 'title' => 'JSON API is awesome!', 'author' => ['id' => '9', 'firstName' => 'Dan', 'lastName' => 'Gebhardt', 'twitter' => 'dgeb'], 'comments' => []]]);
         expect($payload->meta())->toBe(['count' => 13]);
     });
 });
 describe("->serialize()", function () {
     it("serializes an empty payload", function () {
         $payload = new Payload();
         expect($payload->serialize())->toEqual(['data' => []]);
     });
     it("serializes unexisting entities", function () {
         $image = Image::create(['title' => 'Amiga 1200']);
         $image->tags[] = ['name' => 'Computer'];
         $image->tags[] = ['name' => 'Science'];
         $image->gallery = ['name' => 'Gallery 1'];
         $payload = new Payload();
         $payload->set($image);
         expect($payload->data())->toBe(['type' => 'image', 'attributes' => ['title' => 'Amiga 1200', 'gallery' => ['name' => 'Gallery 1'], 'tags' => [['name' => 'Computer'], ['name' => 'Science']]]]);
         expect($payload->included())->toBe([]);
     });
     it("serializes existing entities", function () {
         $this->fixtures->populate('gallery');
         $this->fixtures->populate('image');
         $this->fixtures->populate('image_tag');