/** * @test */ public function getBaseHttpUrlByResourceIdReturnsExpected() { $photoId = new PhotoId(); $resourceId = new ResourceId('test'); $name = new PhotoName('test'); $file = new PhotoFile(__DIR__ . '/photo_to_upload.png'); $this->assertEquals(implode('/', [$this->urlBase, $this->getMd5Path($resourceId->id()), $photoId->id(), $name->slug()]) . '.' . $file->format(), $this->storage->getPhotoHttpUrlBy($photoId, $resourceId, $name, $file)->value()); }
/** * @test */ public function photoThumbWorks() { $thumbId = new ThumbId(); $photoId = new PhotoId(); $photoFile = new PhotoFile(__DIR__ . '/pixel.png'); $photoThumb = new PhotoThumb($thumbId, $photoId, new HttpUrl('http://works'), new PhotoThumbSize(10, 10), $photoFile); $this->assertEquals($thumbId->id(), $photoThumb->id()); $this->assertEquals($photoId->id(), $photoThumb->photoId()); $this->assertEquals('http://works', $photoThumb->photoThumbHttpUrl()); $this->assertEquals(10, $photoThumb->height()); $this->assertEquals(10, $photoThumb->width()); $this->assertEquals($photoFile->filePath(), __DIR__ . '/pixel.png'); $photoThumb->updatePhotoThumbFile(null); $this->assertNull($photoThumb->photoThumbFile()); }
/** * @param PhotoId $photoId * @param ResourceId $resourceId * @param PhotoName $photoName * @param PhotoFile $photoFile * @return HttpUrl */ public function getPhotoHttpUrlBy(PhotoId $photoId, ResourceId $resourceId, PhotoName $photoName, PhotoFile $photoFile) { return new HttpUrl($this->config->urlBase() . '/' . $this->getPhotoUri($photoId->id(), $photoName->slug(), $photoFile->format())); }
/** * @test */ public function photoFileInstanceWorks() { $photoFile = new PhotoFile(__DIR__ . '/pixel.png'); $this->assertEquals('png', $photoFile->format()); $this->assertEquals(__DIR__ . '/pixel.png', $photoFile->filePath()); }
/** * @param PhotoId $photoId * @param ResourceId $resourceId * @param PhotoName $photoName * @param PhotoFile $photoFile * @return HttpUrl */ public function getPhotoHttpUrlBy(PhotoId $photoId, ResourceId $resourceId, PhotoName $photoName, PhotoFile $photoFile) { $urlBase = $this->localStorageConfig->urlBase(); $urlBase = $urlBase[strlen($urlBase) - 1] === '/' ? substr($urlBase, 0, -1) : $urlBase; return new HttpUrl(implode('/', [$urlBase, $this->getMd5Path($resourceId->id()), $photoId->id(), $photoName->slug()]) . '.' . $photoFile->format()); }