public function setUp()
 {
     $photoId = new PhotoId();
     $this->expected = ['id' => $photoId->id(), 'resourceId' => '1', 'name' => 'test', 'url' => 'http://test/1/test.jpg', 'alts' => ['ES' => ['name' => 'alt', 'slug' => 'alt']], 'file' => ''];
     $this->photo = new Photo($photoId, new ResourceId('1'), new PhotoName('test'), new HttpUrl('http://test/1/test.jpg'), new PhotoAltCollection([new PhotoAlt($photoId, 'alt', new Lang(Lang::LANGUAGE_ES))]), new Position());
     $this->photoPresenter = new ArrayPhotoPresenter();
 }
 /**
  * @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());
 }
 /**
  * @param PhotoId $photoId
  * @return mixed|Photo
  * @throws PhotoNotFoundException
  */
 public function findById(PhotoId $photoId)
 {
     foreach ($this->photos as $photo) {
         if ($photo->id() === $photoId->id()) {
             return $photo;
         }
     }
     throw new PhotoNotFoundException(sprintf('Photo of id %s not found', $photoId->id()));
 }
 /**
  * @param PhotoId $photoId
  * @return PhotoThumbCollection
  */
 public function findCollectionBy(PhotoId $photoId)
 {
     $thumbCollection = new PhotoThumbCollection();
     foreach ($this->thumbs as $thumb) {
         if ($thumb->photoId() === $photoId->id()) {
             $thumbCollection[] = $thumb;
         }
     }
     return $thumbCollection;
 }
Example #5
0
 /**
  * @test
  */
 public function photoNameCanBeInstantiated()
 {
     $photoId = new PhotoId();
     $alt = 'testing name';
     $altSlug = 'testing-name';
     $photoAlt = new PhotoAlt($photoId, $alt, new Lang(Lang::LANGUAGE_ES));
     $this->assertEquals($photoId->id(), $photoAlt->photoId());
     $this->assertEquals($alt, $photoAlt->name());
     $this->assertEquals($altSlug, $photoAlt->slug());
     $this->assertEquals(Lang::LANGUAGE_ES, $photoAlt->lang());
 }
 /**
  * @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());
 }
Example #7
0
 /**
  * @test
  */
 public function photoWorks()
 {
     $photoFile = new PhotoFile(__DIR__ . '/pixel.png');
     $photoId = new PhotoId();
     $lang = new Lang(Lang::LANGUAGE_EN);
     $alt = new PhotoAlt($photoId, 'alt', $lang);
     $photoAltCollection = new PhotoAltCollection([$alt]);
     $photo = new Photo($photoId, new ResourceId(1), new PhotoName('testing'), new HttpUrl('http://works'), new PhotoAltCollection([new PhotoAlt($photoId, 'alt', new Lang(Lang::LANGUAGE_EN))]), new Position(1), $photoFile);
     $this->assertEquals($photoId->id(), $photo->id());
     $this->assertEquals(1, $photo->resourceId());
     $this->assertEquals('testing', $photo->name());
     $this->assertEquals('testing', $photo->slug());
     $this->assertEquals('http://works', $photo->getPhotoHttpUrl());
     $this->assertEquals($photoAltCollection, $photo->altCollection());
     $this->assertEquals($alt, $photo->altByLang($lang));
     $this->assertNull($photo->altByLang(new Lang(Lang::LANGUAGE_ES)));
     $this->assertSame($photo->position(), 1);
     $this->assertSame($photoFile, $photo->photoFile());
 }
Example #8
0
 /**
  * @return string
  */
 public function id()
 {
     return $this->photoId->id();
 }
 /**
  * @param PhotoId $photoId
  * @return PhotoAltCollection
  */
 private function getAltCollectionBy(PhotoId $photoId)
 {
     $sentence = $this->pdo->prepare("SELECT * FROM \"alternative_text\" WHERE photo_uuid=:uuid");
     $sentence->bindValue(':uuid', $photoId->id());
     $sentence->execute();
     $photoAltCollection = new PhotoAltCollection();
     $rows = $sentence->fetchAll(\PDO::FETCH_ASSOC);
     if ($rows) {
         foreach ($rows as $row) {
             $photoAltCollection[] = new PhotoAlt($photoId, $row['alt'], new Lang($row['lang']));
         }
     }
     return $photoAltCollection;
 }
 /**
  * @param PhotoId $photoId
  * @param PhotoAlt $alt
  */
 private function saveAlternativeText(PhotoId $photoId, PhotoAlt $alt)
 {
     $sentence = $this->pdo->prepare("INSERT INTO `alternative_text`(`photo_id`, `alt`, `lang`) " . "VALUES(:photo_id, :alt, :lang)");
     $sentence->bindValue(':photo_id', $photoId->id());
     $sentence->bindValue(':alt', $alt->name());
     $sentence->bindValue(':lang', $alt->lang());
     $sentence->execute();
 }
 /**
  * @param PhotoId $photoId
  * @param ResourceId $resourceId
  * @param PhotoName $photoName
  * @param PhotoThumbSize $photoThumbSize
  * @param PhotoFormat $photoFormat
  * @return HttpUrl
  */
 public function getPhotoThumbHttpUrlBy(PhotoId $photoId, ResourceId $resourceId, PhotoName $photoName, PhotoThumbSize $photoThumbSize, PhotoFormat $photoFormat)
 {
     return new HttpUrl($this->config->urlBase() . '/' . $this->getThumbUri($photoId->id(), $photoName->slug(), $photoThumbSize->width(), $photoThumbSize->height(), $photoFormat->value()));
 }
 /**
  * @param PhotoId $photoId
  * @return PhotoThumbCollection
  */
 public function findCollectionBy(PhotoId $photoId)
 {
     $sentence = $this->pdo->query("SELECT * FROM photo_thumb WHERE photo_uuid=\"" . $photoId->id() . "\"");
     $rows = $sentence->fetchAll(\PDO::FETCH_ASSOC);
     $thumbCollection = new PhotoThumbCollection();
     if ($rows) {
         foreach ($rows as $row) {
             $thumbCollection[] = $this->createPhotoThumbByRow($row);
         }
     }
     return $thumbCollection;
 }
 /**
  * @param PhotoId $photoId
  * @param ResourceId $resourceId
  * @param PhotoName $photoName
  * @param PhotoThumbSize $photoThumbSize
  * @param PhotoFormat $photoFormat
  * @return HttpUrl
  */
 public function getPhotoThumbHttpUrlBy(PhotoId $photoId, ResourceId $resourceId, PhotoName $photoName, PhotoThumbSize $photoThumbSize, PhotoFormat $photoFormat)
 {
     $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()]) . '_' . $photoThumbSize->width() . 'x' . $photoThumbSize->height() . '.' . $photoFormat->value());
 }