public function testAttributesAreMutable()
 {
     $hal = new Collection([], 'item/route');
     $attributes = ['count' => 1376, 'order' => 'desc'];
     $hal->setAttributes($attributes);
     $this->assertEquals($attributes, $hal->getAttributes());
 }
 public function testRendersAttributeAsPartOfPaginatedCollection()
 {
     $this->setUpHelpers();
     $attributes = array('count' => 100, 'type' => 'foo');
     $prototype = array('foo' => 'bar');
     $items = array();
     foreach (range(1, 100) as $id) {
         $item = $prototype;
         $item['id'] = $id;
         $items[] = $item;
     }
     $adapter = new ArrayAdapter($items);
     $paginator = new Paginator($adapter);
     $collection = new Collection($paginator);
     $collection->setPageSize(5);
     $collection->setPage(3);
     $collection->setAttributes($attributes);
     $collection->setCollectionRoute('resource');
     $collection->setEntityRoute('resource');
     $links = $collection->getLinks();
     $self = new Link('self');
     $self->setRoute('resource');
     $links->add($self);
     $model = new HalJsonModel(array('payload' => $collection));
     $test = $this->renderer->render($model);
     $test = json_decode($test);
     $this->assertInstanceof('stdClass', $test, var_export($test, 1));
     $this->assertObjectHasAttribute('count', $test, var_export($test, 1));
     $this->assertEquals(100, $test->count);
     $this->assertObjectHasAttribute('type', $test);
     $this->assertEquals('foo', $test->type);
 }
Beispiel #3
0
 public function testRendersAttributeAsPartOfPaginatedCollection()
 {
     $attributes = ['count' => 100, 'type' => 'foo'];
     $prototype = ['foo' => 'bar'];
     $items = [];
     foreach (range(1, 100) as $id) {
         $item = $prototype;
         $item['id'] = $id;
         $items[] = $item;
     }
     $adapter = new ArrayPaginator($items);
     $paginator = new Paginator($adapter);
     $collection = new Collection($paginator);
     $collection->setPageSize(5);
     $collection->setPage(3);
     $collection->setAttributes($attributes);
     $collection->setCollectionRoute('resource');
     $collection->setEntityRoute('resource');
     $links = $collection->getLinks();
     $self = new Link('self');
     $self->setRoute('resource');
     $links->add($self);
     $result = $this->plugin->renderCollection($collection);
     $this->assertInternalType('array', $result, var_export($result, 1));
     $this->assertArrayHasKey('count', $result, var_export($result, 1));
     $this->assertEquals(100, $result['count']);
     $this->assertArrayHasKey('type', $result);
     $this->assertEquals('foo', $result['type']);
 }