/** * Get a thumbnail image * * @param Media $media media instance * @param string $type thumbnail make type * @param string $dimension dimension code * @param bool $defaultSelf if set true, returns self when thumbnail not exists * @return null|Image|Media */ public function getThumbnail(Media $media, $type, $dimension, $defaultSelf = true) { $meta = $this->repo->findByOption(['originId' => $media->getFile()->getId(), 'type' => $type, 'code' => $dimension]); if ($meta !== null) { $file = $this->storage->get($meta->id); return $this->createModel($file, $meta); } return $defaultSelf === true ? $media : null; }
public function testFindByOption() { list($conn, $query) = $this->getMocks(); $instance = new ImageRepository($conn); $id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; $conn->shouldReceive('table')->andReturn($query); $query->shouldReceive('where')->once()->with('originId', $id)->andReturnSelf(); $query->shouldReceive('where')->once()->with('type', 'letter')->andReturnSelf(); $query->shouldReceive('where')->once()->with('code', 'S')->andReturnSelf(); $query->shouldReceive('first')->once()->andReturn(['originId' => $id, 'type' => 'letter', 'code' => 'S']); $meta = $instance->findByOption(['originId' => $id, 'type' => 'letter', 'code' => 'S']); $this->assertInstanceOf('Xpressengine\\Media\\Meta', $meta); $query->shouldReceive('where')->once()->with('originId', $id)->andReturnSelf(); $query->shouldReceive('where')->once()->with('type', 'letter')->andReturnSelf(); $query->shouldReceive('where')->once()->with('code', 'S')->andReturnSelf(); $query->shouldReceive('first')->once()->andReturnNull(); $this->assertNull($instance->findByOption(['originId' => $id, 'type' => 'letter', 'code' => 'S'])); }