/**
  * @param  int $pages
  * @param  int $currentPage
  * @return Collection
  */
 private function getHalCollection($pages, $currentPage)
 {
     $items = [];
     for ($i = 0; $i < $pages; $i++) {
         $items[] = [];
     }
     $adapter = new ArrayAdapter($items);
     $collection = new Paginator($adapter);
     $jsonLDCollection = new Collection($collection);
     $jsonLDCollection->setCollectionRoute('foo');
     $jsonLDCollection->setPage($currentPage);
     $jsonLDCollection->setPageSize(1);
     return $jsonLDCollection;
 }
 public function testPageIsMutable()
 {
     $jsonLD = new Collection([], 'item/route');
     $jsonLD->setPage(5);
     $this->assertEquals(5, $jsonLD->getPage());
 }
 public function setUpChildCollection()
 {
     $children = [['luke', 'Luke Skywalker'], ['leia', 'Leia Organa']];
     $collection = [];
     foreach ($children as $info) {
         $collection[] = call_user_func_array([$this, 'setUpChildEntity'], $info);
     }
     $collection = new Collection($collection);
     $collection->setCollectionRoute('parent/child');
     $collection->setEntityRoute('parent/child');
     $collection->setPage(1);
     $collection->setPageSize(10);
     $collection->setCollectionName('child');
     $property = new Property('id');
     $property->setRoute('parent/child');
     $collection->getProperties()->add($property);
     return $collection;
 }
Exemple #4
0
 public function testRendersEmbeddedEntitiesOfIndividualPaginatedCollections()
 {
     $this->router->addRoute('user', new Segment('/user[/:id]'));
     $child = new Entity(['id' => 'matthew', 'name' => 'matthew', 'github' => 'weierophinney'], 'matthew');
     $property = new Property('id');
     $property->setRoute('user')->setRouteParams(['id' => 'matthew']);
     $child->getProperties()->add($property);
     $prototype = ['foo' => 'bar', 'user' => $child];
     $items = [];
     foreach (range(1, 3) 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(1);
     $collection->setCollectionRoute('resource');
     $collection->setEntityRoute('resource');
     $properties = $collection->getProperties();
     $idProperty = new Property('id');
     $idProperty->setRoute('resource');
     $properties->add($idProperty);
     $result = $this->plugin->renderCollection($collection);
     $this->assertInternalType('array', $result, var_export($result, 1));
     $collection = $result['member'];
     foreach ($collection as $item) {
         $this->assertArrayHasKey('user', $item, var_export($item, 1));
         $user = $item['user'];
         $this->assertRelationalPropertyContains('/user/matthew', 'id', $user);
         foreach ($child->entity as $key => $value) {
             if ($key === 'id') {
                 $this->assertArrayHasKey('id', $user);
                 $this->assertContains($value, $user['id']);
                 continue;
             }
             $this->assertArrayHasKey($key, $user);
             $this->assertEquals($value, $user[$key]);
         }
     }
 }