Exemple #1
0
 public function testCreateCollectionFromMetadataWithoutForcedSelfLinks()
 {
     $set = new TestAsset\Collection([(object) ['id' => 'foo', 'name' => 'foo'], (object) ['id' => 'bar', 'name' => 'bar'], (object) ['id' => 'baz', 'name' => 'baz']]);
     $metadata = new MetadataMap(['ZFTest\\Hal\\Plugin\\TestAsset\\Collection' => ['is_collection' => true, 'route_name' => 'hostname/contacts', 'entity_route_name' => 'hostname/embedded', 'links' => [], 'force_self_link' => false]]);
     $this->plugin->setMetadataMap($metadata);
     $collection = $this->plugin->createCollectionFromMetadata($set, $metadata->get('ZFTest\\Hal\\Plugin\\TestAsset\\Collection'));
     $links = $collection->getLinks();
     $this->assertFalse($links->has('self'));
 }
Exemple #2
0
    /**
     * @group 79
     */
    public function testInjectsLinksFromMetadataWhenCreatingCollection()
    {
        $set = new TestAsset\Collection(
            array(
                (object) array('id' => 'foo', 'name' => 'foo'),
                (object) array('id' => 'bar', 'name' => 'bar'),
                (object) array('id' => 'baz', 'name' => 'baz'),
            )
        );

        $metadata = new MetadataMap(array(
            'ZFTest\Hal\Plugin\TestAsset\Collection' => array(
                'is_collection'       => true,
                'route_name'          => 'hostname/contacts',
                'entity_route_name'   => 'hostname/embedded',
                'links'               => array(
                    array(
                        'rel' => 'describedby',
                        'url' => 'http://example.com/api/help/collection',
                    ),
                ),
            ),
        ));

        $this->plugin->setMetadataMap($metadata);

        $collection = $this->plugin->createCollectionFromMetadata(
            $set,
            $metadata->get('ZFTest\Hal\Plugin\TestAsset\Collection')
        );
        $this->assertInstanceof('ZF\Hal\Collection', $collection);
        $links = $collection->getLinks();
        $this->assertTrue($links->has('describedby'));
        $link = $links->get('describedby');
        $this->assertTrue($link->hasUrl());
        $this->assertEquals('http://example.com/api/help/collection', $link->getUrl());
    }