public function testRendersEmbeddedResourcesOfIndividualPaginatedCollectionResources()
 {
     $this->setUpHelpers();
     $this->router->addRoute('user', new Segment('/user[/:id]'));
     $child = new HalResource(array('id' => 'matthew', 'name' => 'matthew', 'github' => 'weierophinney'), 'matthew', 'user');
     $link = new Link('self');
     $link->setRoute('user')->setRouteParams(array('id' => 'matthew'));
     $child->getLinks()->add($link);
     $prototype = array('foo' => 'bar', 'user' => $child);
     $items = array();
     foreach (range(1, 3) as $id) {
         $item = $prototype;
         $item['id'] = $id;
         $items[] = $item;
     }
     $adapter = new ArrayAdapter($items);
     $paginator = new Paginator($adapter);
     $collection = new HalCollection($paginator);
     $collection->setPageSize(5);
     $collection->setPage(1);
     $collection->setCollectionRoute('resource');
     $collection->setResourceRoute('resource');
     $links = $collection->getLinks();
     $self = new Link('self');
     $self->setRoute('resource');
     $links->add($self);
     $model = new RestfulJsonModel(array('payload' => $collection));
     $test = $this->renderer->render($model);
     $test = json_decode($test);
     $this->assertInstanceof('stdClass', $test, var_export($test, 1));
     $collection = $test->_embedded->items;
     foreach ($collection as $item) {
         $this->assertObjectHasAttribute('_embedded', $item, var_export($item, 1));
         $embedded = $item->_embedded;
         $this->assertObjectHasAttribute('user', $embedded);
         $user = $embedded->user;
         $this->assertRelationalLinkContains('/user/matthew', 'self', $user);
         $user = (array) $user;
         foreach ($child->resource as $key => $value) {
             $this->assertArrayHasKey($key, $user);
             $this->assertEquals($value, $user[$key]);
         }
     }
 }
 public function setUpChildCollection()
 {
     $children = array(array('luke', 'Luke Skywalker'), array('leia', 'Leia Organa'));
     $this->collection = array();
     foreach ($children as $info) {
         $collection[] = call_user_func_array(array($this, 'setUpChildResource'), $info);
     }
     $collection = new HalCollection($this->collection);
     $collection->setCollectionRoute('parent/child');
     $collection->setResourceRoute('parent/child');
     $collection->setPage(1);
     $collection->setPageSize(10);
     $collection->setCollectionName('child');
     $link = new Link('self');
     $link->setRoute('parent/child');
     $collection->getLinks()->add($link);
     return $collection;
 }
 public function testPageIsMutable()
 {
     $hal = new HalCollection(array(), 'item/route');
     $hal->setPage(5);
     $this->assertEquals(5, $hal->page);
 }