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; }
/** * @group 79 */ public function testRenderCollectionTriggersEvent() { $collection = new HalCollection(array((object) array('id' => 'foo', 'name' => 'foo'), (object) array('id' => 'bar', 'name' => 'bar'), (object) array('id' => 'baz', 'name' => 'baz')), 'hostname/contacts'); $self = new Link('self'); $self->setRoute('hostname/contacts'); $collection->getLinks()->add($self); $collection->setCollectionName('resources'); $this->plugin->getEventManager()->attach('renderCollection', function ($e) { $collection = $e->getParam('collection'); $collection->setAttributes(array('injected' => true)); }); $rendered = $this->plugin->renderCollection($collection); $this->assertArrayHasKey('injected', $rendered); $this->assertTrue($rendered['injected']); }
public function testCollectionNameIsMutable() { $hal = new HalCollection(array(), 'item/route'); $hal->setCollectionName('records'); $this->assertEquals('records', $hal->collectionName); }