/** * Fetch correct thumbnail according to type (medium or large) * * @param Record|Story $record Record for which to fetch the thumbnail * @param string $type Size of the thumbnail * @return null|\PhraseanetSDK\Entity\Subdef * @throws \InvalidArgumentException */ public function fetch($record, $type) { if (!$record instanceof Record && !$record instanceof Story) { throw new \InvalidArgumentException(); } if (!$this->thumbnailMap->hasSubDefinition($type) || $record instanceof Story) { return $record->getThumbnail(); } $subdefinition = $this->thumbnailMap->getSubDefinition($type); if ($record->getSubdefs()->containsKey($subdefinition)) { return $record->getSubdefs()->get($subdefinition); } return $record->getThumbnail(); }
public function testFetchUnmappedThumbnailDefinitionReturnsDefaultThumbnail() { $thumbHelper = new ThumbHelper(new DefinitionMap()); $record = new Record(); $record->setThumbnail(new Subdef()); $this->assertSame($record->getThumbnail(), $thumbHelper->fetch($record, 'unmapped')); }